mirror of
https://github.com/rails/execjs
synced 2023-03-27 23:21:20 -04:00
Fix rhino memory limit issue
This commit is contained in:
parent
043c06b699
commit
cea2f6a380
2 changed files with 16 additions and 0 deletions
|
@ -5,6 +5,7 @@ module ExecJS
|
|||
source = source.encode('UTF-8') if source.respond_to?(:encode)
|
||||
|
||||
@rhino_context = ::Rhino::Context.new
|
||||
fix_memory_limit! @rhino_context
|
||||
@rhino_context.eval(source)
|
||||
end
|
||||
|
||||
|
@ -53,6 +54,16 @@ module ExecJS
|
|||
value
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
# Disables bytecode compiling which limits you to 64K scripts
|
||||
def fix_memory_limit!(context)
|
||||
if context.respond_to?(:optimization_level=)
|
||||
context.optimization_level = -1
|
||||
else
|
||||
context.instance_eval { @native.setOptimizationLevel(-1) }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def name
|
||||
|
|
|
@ -86,6 +86,11 @@ class TestRuntime < Test::Unit::TestCase
|
|||
assert_equal true, @runtime.exec("return this === (function() {return this})()")
|
||||
end
|
||||
|
||||
def test_compile_large_scripts
|
||||
body = "var foo = 'bar';\n" * 100_000
|
||||
assert @runtime.exec("function foo() {\n#{body}\n};\nreturn true")
|
||||
end
|
||||
|
||||
def test_syntax_error
|
||||
assert_raise ExecJS::RuntimeError do
|
||||
@runtime.exec(")")
|
||||
|
|
Loading…
Reference in a new issue