From d69363fb06e9bae476625441287d035c19ea568c Mon Sep 17 00:00:00 2001 From: Jean Boussier Date: Wed, 2 Mar 2022 18:17:47 +0100 Subject: [PATCH] Remove outdated Encoding workaround --- lib/execjs/duktape_runtime.rb | 2 +- lib/execjs/encoding.rb | 26 -------------------------- lib/execjs/graaljs_runtime.rb | 8 ++++---- lib/execjs/ruby_rhino_runtime.rb | 6 +++--- lib/execjs/runtime.rb | 4 ---- 5 files changed, 8 insertions(+), 38 deletions(-) delete mode 100644 lib/execjs/encoding.rb diff --git a/lib/execjs/duktape_runtime.rb b/lib/execjs/duktape_runtime.rb index 7758fdf..204617d 100644 --- a/lib/execjs/duktape_runtime.rb +++ b/lib/execjs/duktape_runtime.rb @@ -6,7 +6,7 @@ class DuktapeRuntime < Runtime class Context < Runtime::Context def initialize(runtime, source = "", options = {}) @ctx = Duktape::Context.new(complex_object: nil) - @ctx.exec_string(encode(source), '(execjs)') + @ctx.exec_string(source.encode(Encoding::UTF_8), '(execjs)') rescue Exception => e raise wrap_error(e) end diff --git a/lib/execjs/encoding.rb b/lib/execjs/encoding.rb deleted file mode 100644 index 8296144..0000000 --- a/lib/execjs/encoding.rb +++ /dev/null @@ -1,26 +0,0 @@ -module ExecJS - # Encodes strings as UTF-8 - module Encoding - if RUBY_ENGINE == 'jruby' || RUBY_ENGINE == 'rbx' - # workaround for jruby bug http://jira.codehaus.org/browse/JRUBY-6588 - # workaround for rbx bug https://github.com/rubinius/rubinius/issues/1729 - def encode(string) - if string.encoding == ::Encoding::BINARY - data = string.dup - data.force_encoding(::Encoding::UTF_8) - - unless data.valid_encoding? - raise ::Encoding::UndefinedConversionError, "Could not encode binary data #{string.dump} as UTF-8" - end - else - data = string.encode(::Encoding::UTF_8) - end - data - end - else - def encode(string) - string.encode(::Encoding::UTF_8) - end - end - end -end diff --git a/lib/execjs/graaljs_runtime.rb b/lib/execjs/graaljs_runtime.rb index d3cab2a..acb931a 100644 --- a/lib/execjs/graaljs_runtime.rb +++ b/lib/execjs/graaljs_runtime.rb @@ -8,7 +8,7 @@ def initialize(runtime, source = "", options = {}) @context.eval('js', 'delete this.console') @js_object = @context.eval('js', 'Object') - source = encode(source) + source = source.encode(Encoding::UTF_8) unless source.empty? translate do eval_in_context(source) @@ -17,7 +17,7 @@ def initialize(runtime, source = "", options = {}) end def exec(source, options = {}) - source = encode(source) + source = source.encode(Encoding::UTF_8) source = "(function(){#{source}})()" if /\S/.match?(source) translate do @@ -26,7 +26,7 @@ def exec(source, options = {}) end def eval(source, options = {}) - source = encode(source) + source = source.encode(Encoding::UTF_8) source = "(#{source})" if /\S/.match?(source) translate do @@ -35,7 +35,7 @@ def eval(source, options = {}) end def call(source, *args) - source = encode(source) + source = source.encode(Encoding::UTF_8) source = "(#{source})" if /\S/.match?(source) translate do diff --git a/lib/execjs/ruby_rhino_runtime.rb b/lib/execjs/ruby_rhino_runtime.rb index b740b72..4829263 100644 --- a/lib/execjs/ruby_rhino_runtime.rb +++ b/lib/execjs/ruby_rhino_runtime.rb @@ -5,7 +5,7 @@ module ExecJS class RubyRhinoRuntime < Runtime class Context < Runtime::Context def initialize(runtime, source = "", options = {}) - source = encode(source) + source = source.encode(Encoding::UTF_8) @rhino_context = ::Rhino::Context.new fix_memory_limit! @rhino_context @@ -15,7 +15,7 @@ def initialize(runtime, source = "", options = {}) end def exec(source, options = {}) - source = encode(source) + source = source.encode(Encoding::UTF_8) if /\S/ =~ source eval "(function(){#{source}})()", options @@ -23,7 +23,7 @@ def exec(source, options = {}) end def eval(source, options = {}) - source = encode(source) + source = source.encode(Encoding::UTF_8) if /\S/ =~ source unbox @rhino_context.eval("(#{source})") diff --git a/lib/execjs/runtime.rb b/lib/execjs/runtime.rb index 822bf5a..726e57b 100644 --- a/lib/execjs/runtime.rb +++ b/lib/execjs/runtime.rb @@ -1,11 +1,7 @@ -require "execjs/encoding" - module ExecJS # Abstract base class for runtimes class Runtime class Context - include Encoding - def initialize(runtime, source = "", options = {}) end