From c37045ecf6db73cf5f805d7e7cddfa62fbd1240b Mon Sep 17 00:00:00 2001 From: Benoit Daloze Date: Fri, 8 Jul 2022 14:34:50 +0200 Subject: [PATCH 1/2] GraalVM 22.2+ needs `gu install js` for JavaScript to be available --- .github/workflows/ci.yml | 4 ++++ lib/execjs/graaljs_runtime.rb | 1 + 2 files changed, 5 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 26fb819..7a5bc80 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -29,6 +29,10 @@ jobs: - name: Set TRUFFLERUBYOPT run: echo "TRUFFLERUBYOPT=--jvm --polyglot" >> $GITHUB_ENV if: startsWith(matrix.ruby, 'truffleruby+graalvm') + - name: Install GraalVM js component + run: if ! gu list | grep '^js '; then gu install js; fi + if: startsWith(matrix.ruby, 'truffleruby+graalvm') + - name: Run test run: rake - name: Install gem diff --git a/lib/execjs/graaljs_runtime.rb b/lib/execjs/graaljs_runtime.rb index acb931a..484f18f 100644 --- a/lib/execjs/graaljs_runtime.rb +++ b/lib/execjs/graaljs_runtime.rb @@ -136,6 +136,7 @@ module ExecJS unless Polyglot.languages.include? "js" warn "The language 'js' is not available, you likely need to `export TRUFFLERUBYOPT='--jvm --polyglot'`", uplevel: 0 if $VERBOSE + warn "You also need to install the 'js' component with 'gu install js' on GraalVM 22.2+", uplevel: 0 if $VERBOSE warn "Note that you need TruffleRuby+GraalVM and not just the TruffleRuby standalone to use #{self.class}", uplevel: 0 if $VERBOSE return @available = false end From 19b1e4f9f61e8530f406a0c1dfb64b872b95ef9b Mon Sep 17 00:00:00 2001 From: Benoit Daloze Date: Fri, 8 Jul 2022 15:05:47 +0200 Subject: [PATCH 2/2] Convert Ruby Strings to TruffleString when passing them to JavaScript * To work around JavaScript not yet preferring JS String methods to Ruby String methods inside JS code (GR-39371). --- lib/execjs/graaljs_runtime.rb | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/execjs/graaljs_runtime.rb b/lib/execjs/graaljs_runtime.rb index 484f18f..fe2b5db 100644 --- a/lib/execjs/graaljs_runtime.rb +++ b/lib/execjs/graaljs_runtime.rb @@ -51,7 +51,7 @@ module ExecJS def translate convert_js_to_ruby yield rescue ForeignException => e - if e.message.start_with?('SyntaxError:') + if e.message && e.message.start_with?('SyntaxError:') error_class = ExecJS::RuntimeError else error_class = ExecJS::ProgramError @@ -96,8 +96,10 @@ module ExecJS def convert_ruby_to_js(value) case value - when nil, true, false, Integer, Float, String + when nil, true, false, Integer, Float value + when String + Truffle::Interop.as_truffle_string value when Symbol value.to_s when Array