Skip to content

Commit

Permalink
Merge pull request #113 from rails/remove-outdated-encoding
Browse files Browse the repository at this point in the history
Remove outdated Encoding workaround
  • Loading branch information
byroot committed Mar 2, 2022
2 parents 610e88a + a8b0f04 commit 5a5d36a
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 46 deletions.
6 changes: 3 additions & 3 deletions lib/execjs/duktape_runtime.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,21 @@ 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

def exec(source, options = {})
return unless /\S/ =~ source
@ctx.eval_string("(function(){#{encode(source)}})()", '(execjs)')
@ctx.eval_string("(function(){#{source.encode(Encoding::UTF_8)}})()", '(execjs)')
rescue Exception => e
raise wrap_error(e)
end

def eval(source, options = {})
return unless /\S/ =~ source
@ctx.eval_string("(#{encode(source)})", '(execjs)')
@ctx.eval_string("(#{source.encode(Encoding::UTF_8)})", '(execjs)')
rescue Exception => e
raise wrap_error(e)
end
Expand Down
26 changes: 0 additions & 26 deletions lib/execjs/encoding.rb

This file was deleted.

6 changes: 3 additions & 3 deletions lib/execjs/external_runtime.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ module ExecJS
class ExternalRuntime < Runtime
class Context < Runtime::Context
def initialize(runtime, source = "", options = {})
source = encode(source)
source = source.encode(Encoding::UTF_8)

@runtime = runtime
@source = source
Expand All @@ -16,15 +16,15 @@ def initialize(runtime, source = "", options = {})
end

def eval(source, options = {})
source = encode(source)
source = source.encode(Encoding::UTF_8)

if /\S/ =~ source
exec("return eval(#{::JSON.generate("(#{source})", quirks_mode: true)})")
end
end

def exec(source, options = {})
source = encode(source)
source = source.encode(Encoding::UTF_8)
source = "#{@source}\n#{source}" if @source != ""
source = @runtime.compile_source(source)

Expand Down
8 changes: 4 additions & 4 deletions lib/execjs/graaljs_runtime.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down
6 changes: 3 additions & 3 deletions lib/execjs/mini_racer_runtime.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ module ExecJS
class MiniRacerRuntime < Runtime
class Context < Runtime::Context
def initialize(runtime, source = "", options={})
source = encode(source)
source = source.encode(Encoding::UTF_8)
@context = ::MiniRacer::Context.new
@context.eval("delete this.console");
translate do
Expand All @@ -13,15 +13,15 @@ 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}})()"
end
end

def eval(source, options = {})
source = encode(source)
source = source.encode(Encoding::UTF_8)

if /\S/ =~ source
translate do
Expand Down
6 changes: 3 additions & 3 deletions lib/execjs/ruby_rhino_runtime.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -15,15 +15,15 @@ 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
end
end

def eval(source, options = {})
source = encode(source)
source = source.encode(Encoding::UTF_8)

if /\S/ =~ source
unbox @rhino_context.eval("(#{source})")
Expand Down
4 changes: 0 additions & 4 deletions lib/execjs/runtime.rb
Original file line number Diff line number Diff line change
@@ -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

Expand Down

0 comments on commit 5a5d36a

Please sign in to comment.