1
0
Fork 0
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:
Joshua Peek 2011-06-07 21:57:12 -05:00
parent 043c06b699
commit cea2f6a380
2 changed files with 16 additions and 0 deletions

View file

@ -5,6 +5,7 @@ module ExecJS
source = source.encode('UTF-8') if source.respond_to?(:encode) source = source.encode('UTF-8') if source.respond_to?(:encode)
@rhino_context = ::Rhino::Context.new @rhino_context = ::Rhino::Context.new
fix_memory_limit! @rhino_context
@rhino_context.eval(source) @rhino_context.eval(source)
end end
@ -53,6 +54,16 @@ module ExecJS
value value
end end
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 end
def name def name

View file

@ -86,6 +86,11 @@ class TestRuntime < Test::Unit::TestCase
assert_equal true, @runtime.exec("return this === (function() {return this})()") assert_equal true, @runtime.exec("return this === (function() {return this})()")
end 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 def test_syntax_error
assert_raise ExecJS::RuntimeError do assert_raise ExecJS::RuntimeError do
@runtime.exec(")") @runtime.exec(")")