Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Getting Duktape::ReferenceError: after upgrading to version 2.0.1.0 #41

Closed
KapilSachdev opened this issue May 22, 2018 · 11 comments
Closed

Comments

@KapilSachdev
Copy link

KapilSachdev commented May 22, 2018

Just upgraded to use 2.0.1.0 to verify #38 but got

#<Duktape::ReferenceError: identifier '(function(opts, pluginOpts) {return eval(process' undefined>

The error is raised by line

# duktape_runtime.rb from execjs (2.7.0) gem
@ctx.call_prop(identifier.split("."), *args)

where identifier is

"(function(opts, pluginOpts) {return eval(process.apply(this, opts, pluginOpts));})"
@judofyr
Copy link
Owner

judofyr commented May 22, 2018

That is completely not an identifier though. The usage should something like this:

# Do this once:
code = "(function(opts, pluginOpts) {return eval(process.apply(this, opts, pluginOpts));})"
@ctx.exec_script("code = #{code}")

# Every time you want to execute it:
@ctx.call_prop("code", *args)

In ExecJS you want to use compile:

code = "(function(opts, pluginOpts) {return eval(process.apply(this, opts, pluginOpts));})"
context = ExecJS.compile("code = #{code}")
context.call("code", )

@KapilSachdev
Copy link
Author

I'm not using execjs explicitly, I just upgraded to check #38 and encountered this error after i ran rails s

ActionView::Template::Error (identifier '(function(opts, pluginOpts) {return eval(process' undefined):
     5:     <%= csrf_meta_tags %>
     6:     <%= csp_meta_tag %>
     7:
     8:     <%= stylesheet_link_tag    'application', media: 'all', 'data-turbolinks-track': 'reload' %>
     9:     <%= javascript_include_tag 'application', 'data-turbolinks-track': 'reload' %>
    10:   </head>
    11:

(execjs):1
app/views/layouts/application.html.erb:8:in `_app_views_layouts_application_html_erb__967139250_71511880'

So the error in #38 doesn't occur but something this one does.
To figure ot what was causing this issue, i backtracked and found the culprit, stated above.

To be fair I don't know how execjs should or might work.
Its just that execjs causes this issue when using the latest duktape version.

@judofyr
Copy link
Owner

judofyr commented May 23, 2018

This is a duplicate of rails/execjs#45 essentially

@larskanis
Copy link

rails/execjs#46 fixed this issue for me.

@judofyr
Copy link
Owner

judofyr commented May 29, 2018

Yikes. Does no one maintain ExecJS anymore?

@judofyr
Copy link
Owner

judofyr commented May 29, 2018

I've asked for clarification here rails/execjs#76.

@judofyr
Copy link
Owner

judofyr commented May 29, 2018

@KapilSachdev:

Here's a monkey-patch that will make it work for now:

Duktape::Context.prepend Module.new {
  def call_prop(name, *args)
    if name.is_a?(Array)
      name = name.join(".")
    end
    exec_string("__call_prop = #{name}")
    name = "__call_prop"
    super
  end
}

ctx = Duktape::Context.new
if ctx.call_prop("(function(a, b) { return a + b })", 1, 1) != 2
  raise "Monkey-patch failed to apply"
end

@KapilSachdev
Copy link
Author

Thanks @judofyr, I will try the patch.
And as per the thread I see that you are planning to create a PR to fix and make it available in the stable version 👍.

@kokblan
Copy link

kokblan commented Nov 15, 2018

Hello, any time I try to bundle install on my server I have this error
Building native extensions. This could take a while...
ERROR: Error installing duktape:
ERROR: Failed to build gem native extension.

current directory: /usr/local/rvm/gems/ruby-2.5.1/gems/duktape-1.3.0.3/ext/duktape

/usr/local/rvm/rubies/ruby-2.5.1/bin/ruby -r ./siteconf20181115-158871-ab9r3y.rb extconf.rb
creating Makefile

current directory: /usr/local/rvm/gems/ruby-2.5.1/gems/duktape-1.3.0.3/ext/duktape
make "DESTDIR=" clean

current directory: /usr/local/rvm/gems/ruby-2.5.1/gems/duktape-1.3.0.3/ext/duktape
make "DESTDIR="
compiling duktape.c
duk_error_macros.c: In function ‘duk_err_handle_error’:
duk_error_macros.c:16:2: warning: function ‘duk_err_handle_error’ might be a candidate for ‘gnu_printf’ format attribute [-Wsuggest-attribute=format]
duk_api_stack.c: In function ‘duk__try_push_vsprintf’:
duk_api_stack.c:3378:2: warning: function ‘duk__try_push_vsprintf’ might be a candidate for ‘gnu_printf’ format attribute [-Wsuggest-attribute=format]
duk_api_debug.c: In function ‘duk_debugger_attach’:
duk_api_debug.c:138:19: warning: function might be candidate for attribute ‘noreturn’ [-Wsuggest-attribute=noreturn]
duk_api_debug.c: In function ‘duk_debugger_detach’:
duk_api_debug.c:157:19: warning: function might be candidate for attribute ‘noreturn’ [-Wsuggest-attribute=noreturn]
duk_hobject_props.c: In function ‘duk__realloc_props’:
duk_heap_stringtable.c:962:33: warning: ‘%lu’ directive output may be truncated writing between 1 and 20 bytes into a region of size 11 [-Wformat-truncation=]
duk_heap_stringtable.c:962:33: note: directive argument in the range [0, 18446744073709551614]
In file included from /usr/include/stdio.h:862:0,
from duk_config.h:578,
from duktape.h:123,
from duk_internal.h:26:
/usr/include/x86_64-linux-gnu/bits/stdio2.h:64:10: note: ‘__builtin___snprintf_chk’ output between 2 and 21 bytes into a destination of size 11
return __builtin___snprintf_chk (__s, __n, __USE_FORTIFY_LEVEL - 1,
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
__bos (__s), __fmt, __va_arg_pack ());
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
duk_bi_date.c: In function ‘duk_bi_date_prototype_tostring_shared’:
duk_bi_date.c:981:39: warning: ‘%02d’ directive output may be truncated writing 2 bytes into a region of size between 0 and 4 [-Wformat-truncation=]
duk_bi_date.c:981:39: note: directive argument in the range [0, 59]
In file included from /usr/include/stdio.h:862:0,
from duk_config.h:578,
from duktape.h:123,
from duk_internal.h:26:
/usr/include/x86_64-linux-gnu/bits/stdio2.h:64:10: note: ‘__builtin___snprintf_chk’ output between 7 and 11 bytes into a destination of size 8
return __builtin___snprintf_chk (__s, __n, __USE_FORTIFY_LEVEL - 1,
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
__bos (__s), __fmt, __va_arg_pack ());
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
duk_hobject_enum.c: In function ‘duk_hobject_enumerator_create’:
duk_heap_stringtable.c:962:33: warning: ‘%lu’ directive output may be truncated writing between 1 and 20 bytes into a region of size 11 [-Wformat-truncation=]
duk_heap_stringtable.c:962:33: note: directive argument in the range [0, 18446744073709551614]
In file included from /usr/include/stdio.h:862:0,
from duk_config.h:578,
from duktape.h:123,
from duk_internal.h:26:
/usr/include/x86_64-linux-gnu/bits/stdio2.h:64:10: note: ‘__builtin___snprintf_chk’ output between 2 and 21 bytes into a destination of size 11
return __builtin___snprintf_chk (__s, __n, __USE_FORTIFY_LEVEL - 1,
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
__bos (__s), __fmt, __va_arg_pack ());
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
gcc: internal compiler error: Killed (program cc1)
Please submit a full bug report,
with preprocessed source if appropriate.
See file:///usr/share/doc/gcc-7/README.Bugs for instructions.
Makefile:241: recipe for target 'duktape.o' failed
make: *** [duktape.o] Error 4

make failed, exit code 2

Gem files will remain installed in /usr/local/rvm/gems/ruby-2.5.1/gems/duktape-1.3.0.3 for inspection.
Results logged to /usr/local/rvm/gems/ruby-2.5.1/extensions/x86_64-linux/2.5.0/duktape-1.3.0.3/gem_make.out

@judofyr
Copy link
Owner

judofyr commented Nov 27, 2018

Woah. You're getting an internal GCC bug when compiling duktape.c. Maybe try another compiler? Later/earlier version of GCC? Or maybe Clang?

@judofyr
Copy link
Owner

judofyr commented May 14, 2019

This original issue was fixed by rails/execjs#77. kokblan's compilation error is unrelated to this.

@judofyr judofyr closed this as completed May 14, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants