1
0
Fork 0
mirror of https://github.com/rubyjs/therubyracer synced 2023-03-27 23:21:42 -04:00
therubyracer/spec/c/script_spec.rb
Charles Lowell e1c8f9ef5f compile scripts via maybe apis
This adds the ability to compile and run an script, passing in the
ScriptOrigin so that it can track file information.
2015-07-22 00:06:15 -05:00

35 lines
1.1 KiB
Ruby

require 'c_spec_helper'
describe V8::C::Script do
requires_v8_context
it 'can run a script and return a polymorphic result' do
source = V8::C::String::NewFromUtf8(@isolate, "(new Array())")
name = V8::C::String::NewFromUtf8(@isolate, "a/file.js")
origin = V8::C::ScriptOrigin.new(name)
script = V8::C::Script::Compile(@ctx, source, origin)
expect(script.IsJust()).to be true
result = script.FromJust().Run(@ctx)
expect(result.IsJust()).to be true
expect(result.FromJust()).to be_an V8::C::Array
end
# TODO
# it 'can accept precompiled script data' do
# source = "7 * 6"
# name = V8::C::String::New("<spec>")
# origin = V8::C::ScriptOrigin.new(name)
# data = V8::C::ScriptData::PreCompile(source, source.length)
# data.HasError().should be_false
# script = V8::C::Script::New(V8::C::String::New(source), origin, data)
# script.Run().should eql 42
# end
# TODO
# it 'can detect errors in the script data' do
# source = "^ = ;"
# data = V8::C::ScriptData::PreCompile(source, source.length)
# data.HasError().should be_true
# end
end