mirror of
https://github.com/rubyjs/therubyracer
synced 2023-03-27 23:21:42 -04:00
Auto-lock, Auto-scope all specs, except where not.
This commit is contained in:
parent
ec1d910b3d
commit
8976cb9fc7
11 changed files with 165 additions and 164 deletions
|
@ -1,9 +1,7 @@
|
||||||
require 'spec_helper'
|
require 'spec_helper'
|
||||||
|
|
||||||
describe V8::C::Array do
|
describe V8::C::Array do
|
||||||
include C::ContextHelper
|
|
||||||
it "can store and retrieve a value" do
|
it "can store and retrieve a value" do
|
||||||
V8::C::HandleScope() do
|
|
||||||
o = V8::C::Object::New()
|
o = V8::C::Object::New()
|
||||||
a = V8::C::Array::New()
|
a = V8::C::Array::New()
|
||||||
a.Length().should eql 0
|
a.Length().should eql 0
|
||||||
|
@ -11,12 +9,9 @@ describe V8::C::Array do
|
||||||
a.Length().should eql 1
|
a.Length().should eql 1
|
||||||
a.Get(0).Equals(o).should be_true
|
a.Get(0).Equals(o).should be_true
|
||||||
end
|
end
|
||||||
end
|
|
||||||
|
|
||||||
it "can be initialized with a length" do
|
it "can be initialized with a length" do
|
||||||
V8::C::HandleScope() do
|
|
||||||
a = V8::C::Array::New(5)
|
a = V8::C::Array::New(5)
|
||||||
a.Length().should eql 5
|
a.Length().should eql 5
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
|
|
@ -1,15 +0,0 @@
|
||||||
module C
|
|
||||||
module ContextHelper
|
|
||||||
def self.included(base)
|
|
||||||
base.instance_eval do
|
|
||||||
before do
|
|
||||||
@cxt = V8::C::Context::New()
|
|
||||||
@cxt.Enter()
|
|
||||||
end
|
|
||||||
after do
|
|
||||||
@cxt.Exit()
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
|
@ -1,12 +1,9 @@
|
||||||
require 'spec_helper'
|
require 'spec_helper'
|
||||||
|
|
||||||
describe V8::C::External do
|
describe V8::C::External do
|
||||||
include C::ContextHelper
|
|
||||||
it "can store and retrieve a value" do
|
it "can store and retrieve a value" do
|
||||||
V8::C::HandleScope() do
|
|
||||||
o = Object.new
|
o = Object.new
|
||||||
external = V8::C::External::New(o)
|
external = V8::C::External::New(o)
|
||||||
external.Value().should be(o)
|
external.Value().should be(o)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
|
|
@ -1,28 +1,21 @@
|
||||||
require 'spec_helper'
|
require 'spec_helper'
|
||||||
|
|
||||||
describe V8::C::Function do
|
describe V8::C::Function do
|
||||||
include C::ContextHelper
|
|
||||||
it "can be called" do
|
it "can be called" do
|
||||||
V8::C::HandleScope() do
|
|
||||||
fn = run '(function() {return "foo"})'
|
fn = run '(function() {return "foo"})'
|
||||||
fn.Call(@cxt.Global(), 0, []).Utf8Value().should eql "foo"
|
fn.Call(@cxt.Global(), 0, []).Utf8Value().should eql "foo"
|
||||||
end
|
end
|
||||||
end
|
|
||||||
|
|
||||||
it "can be called as a constructor" do
|
it "can be called as a constructor" do
|
||||||
V8::C::HandleScope() do
|
|
||||||
fn = run '(function() {this.foo = "foo"})'
|
fn = run '(function() {this.foo = "foo"})'
|
||||||
fn.NewInstance().Get(V8::C::String::New('foo')).Utf8Value().should eql "foo"
|
fn.NewInstance().Get(V8::C::String::New('foo')).Utf8Value().should eql "foo"
|
||||||
end
|
end
|
||||||
end
|
|
||||||
|
|
||||||
it "can be called as a constructor with arguments" do
|
it "can be called as a constructor with arguments" do
|
||||||
V8::C::HandleScope() do
|
|
||||||
fn = run '(function(foo) {this.foo = foo})'
|
fn = run '(function(foo) {this.foo = foo})'
|
||||||
object = fn.NewInstance(1, [V8::C::String::New("bar")])
|
object = fn.NewInstance(1, [V8::C::String::New("bar")])
|
||||||
object.Get(V8::C::String::New('foo')).Utf8Value().should eql "bar"
|
object.Get(V8::C::String::New('foo')).Utf8Value().should eql "bar"
|
||||||
end
|
end
|
||||||
end
|
|
||||||
|
|
||||||
def run(source)
|
def run(source)
|
||||||
source = V8::C::String::New(source.to_s)
|
source = V8::C::String::New(source.to_s)
|
||||||
|
|
|
@ -1,7 +1,22 @@
|
||||||
require 'spec_helper'
|
require 'spec_helper'
|
||||||
|
|
||||||
describe "setting up handles scopes" do
|
describe "setting up handles scopes" do
|
||||||
include C::ContextHelper
|
include ExplicitScoper
|
||||||
|
|
||||||
|
before do
|
||||||
|
def self.instance_eval(*args, &block)
|
||||||
|
V8::C::Locker() do
|
||||||
|
cxt = V8::C::Context::New()
|
||||||
|
begin
|
||||||
|
cxt.Enter()
|
||||||
|
super(*args, &block)
|
||||||
|
ensure
|
||||||
|
cxt.Exit()
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
it "can allocate handle scopes" do
|
it "can allocate handle scopes" do
|
||||||
V8::C::HandleScope() do
|
V8::C::HandleScope() do
|
||||||
V8::C::Object::New()
|
V8::C::Object::New()
|
||||||
|
|
|
@ -1,8 +1,9 @@
|
||||||
require 'spec_helper'
|
require 'spec_helper'
|
||||||
|
|
||||||
describe V8::C::Locker do
|
describe V8::C::Locker do
|
||||||
|
include ExplicitScoper
|
||||||
|
|
||||||
it "can lock and unlock the VM" do
|
it "can lock and unlock the VM" do
|
||||||
pending "need to figure out how to wrap rspec methods"
|
|
||||||
V8::C::Locker::IsLocked().should be_false
|
V8::C::Locker::IsLocked().should be_false
|
||||||
V8::C::Locker() do
|
V8::C::Locker() do
|
||||||
V8::C::Locker::IsLocked().should be_true
|
V8::C::Locker::IsLocked().should be_true
|
||||||
|
@ -14,7 +15,6 @@ describe V8::C::Locker do
|
||||||
end
|
end
|
||||||
|
|
||||||
it "properly unlocks if an exception is thrown inside a lock block" do
|
it "properly unlocks if an exception is thrown inside a lock block" do
|
||||||
pending "need to figure out how to wrap rspec methods"
|
|
||||||
begin
|
begin
|
||||||
V8::C::Locker() do
|
V8::C::Locker() do
|
||||||
raise "boom!"
|
raise "boom!"
|
||||||
|
@ -23,4 +23,16 @@ describe V8::C::Locker do
|
||||||
V8::C::Locker::IsLocked().should be_false
|
V8::C::Locker::IsLocked().should be_false
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it "properly re-locks if an exception is thrown inside an un-lock block" do
|
||||||
|
V8::C::Locker() do
|
||||||
|
begin
|
||||||
|
V8::C::Unlocker() do
|
||||||
|
raise "boom!"
|
||||||
|
end
|
||||||
|
rescue
|
||||||
|
V8::C::Locker::IsLocked().should be_true
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
|
@ -1,20 +1,16 @@
|
||||||
require 'spec_helper'
|
require 'spec_helper'
|
||||||
|
|
||||||
describe V8::C::Object do
|
describe V8::C::Object do
|
||||||
include C::ContextHelper
|
|
||||||
|
|
||||||
it "can store and retrieve a value" do
|
it "can store and retrieve a value" do
|
||||||
V8::C::HandleScope() do
|
|
||||||
o = V8::C::Object::New()
|
o = V8::C::Object::New()
|
||||||
key = V8::C::String::New("foo")
|
key = V8::C::String::New("foo")
|
||||||
value = V8::C::String::New("bar")
|
value = V8::C::String::New("bar")
|
||||||
o.Set(key, value)
|
o.Set(key, value)
|
||||||
o.Get(key).Utf8Value().should eql "bar"
|
o.Get(key).Utf8Value().should eql "bar"
|
||||||
end
|
end
|
||||||
end
|
|
||||||
|
|
||||||
it "can retrieve all property names" do
|
it "can retrieve all property names" do
|
||||||
V8::C::HandleScope() do
|
|
||||||
o = V8::C::Object::New()
|
o = V8::C::Object::New()
|
||||||
o.Set(V8::C::String::New("foo"), V8::C::String::New("bar"))
|
o.Set(V8::C::String::New("foo"), V8::C::String::New("bar"))
|
||||||
o.Set(V8::C::String::New("baz"), V8::C::String::New("bang"))
|
o.Set(V8::C::String::New("baz"), V8::C::String::New("bang"))
|
||||||
|
@ -23,9 +19,7 @@ describe V8::C::Object do
|
||||||
names.Get(0).Utf8Value().should eql "foo"
|
names.Get(0).Utf8Value().should eql "foo"
|
||||||
names.Get(1).Utf8Value().should eql "baz"
|
names.Get(1).Utf8Value().should eql "baz"
|
||||||
end
|
end
|
||||||
end
|
|
||||||
it "can set an accessor from ruby" do
|
it "can set an accessor from ruby" do
|
||||||
V8::C::HandleScope() do
|
|
||||||
o = V8::C::Object::New()
|
o = V8::C::Object::New()
|
||||||
property = V8::C::String::New("statement")
|
property = V8::C::String::New("statement")
|
||||||
callback_data = V8::C::String::New("I am Legend")
|
callback_data = V8::C::String::New("I am Legend")
|
||||||
|
@ -44,4 +38,3 @@ describe V8::C::Object do
|
||||||
o.Get(property).Utf8Value().should eql "Bro! I am Legend"
|
o.Get(property).Utf8Value().should eql "Bro! I am Legend"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
|
|
@ -1,9 +1,7 @@
|
||||||
require 'spec_helper'
|
require 'spec_helper'
|
||||||
|
|
||||||
describe V8::C::External do
|
describe V8::C::Script do
|
||||||
include C::ContextHelper
|
|
||||||
it "can run a script and return a polymorphic result" do
|
it "can run a script and return a polymorphic result" do
|
||||||
V8::C::HandleScope() do
|
|
||||||
source = V8::C::String::New("(new Array())")
|
source = V8::C::String::New("(new Array())")
|
||||||
filename = V8::C::String::New("<eval>")
|
filename = V8::C::String::New("<eval>")
|
||||||
script = V8::C::Script::New(source, filename)
|
script = V8::C::Script::New(source, filename)
|
||||||
|
@ -11,4 +9,3 @@ describe V8::C::External do
|
||||||
result.should be_kind_of V8::C::Array
|
result.should be_kind_of V8::C::Array
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
|
|
@ -1,18 +1,14 @@
|
||||||
require 'spec_helper'
|
require 'spec_helper'
|
||||||
|
|
||||||
describe V8::C::Template do
|
describe V8::C::Template do
|
||||||
include C::ContextHelper
|
|
||||||
|
|
||||||
describe V8::C::FunctionTemplate do
|
describe V8::C::FunctionTemplate do
|
||||||
it "can be created with no arguments" do
|
it "can be created with no arguments" do
|
||||||
V8::C::HandleScope() do
|
|
||||||
t = V8::C::FunctionTemplate::New()
|
t = V8::C::FunctionTemplate::New()
|
||||||
t.GetFunction().Call(@cxt.Global(),0, []).StrictEquals(@cxt.Global()).should be_true
|
t.GetFunction().Call(@cxt.Global(),0, []).StrictEquals(@cxt.Global()).should be_true
|
||||||
end
|
end
|
||||||
end
|
|
||||||
|
|
||||||
it "can be created with a callback" do
|
it "can be created with a callback" do
|
||||||
V8::C::HandleScope() do
|
|
||||||
receiver = V8::C::Object::New()
|
receiver = V8::C::Object::New()
|
||||||
f = nil
|
f = nil
|
||||||
callback = lambda do |arguments|
|
callback = lambda do |arguments|
|
||||||
|
@ -32,4 +28,3 @@ describe V8::C::Template do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
|
|
@ -1,12 +1,10 @@
|
||||||
require 'spec_helper'
|
require 'spec_helper'
|
||||||
|
|
||||||
describe V8::C::External do
|
describe V8::C::External do
|
||||||
include C::ContextHelper
|
|
||||||
|
|
||||||
it "can catch javascript exceptions" do
|
it "can catch javascript exceptions" do
|
||||||
V8::C::V8::SetCaptureStackTraceForUncaughtExceptions(true, 99, V8::C::StackTrace::kDetailed)
|
V8::C::V8::SetCaptureStackTraceForUncaughtExceptions(true, 99, V8::C::StackTrace::kDetailed)
|
||||||
V8::C::TryCatch() do |trycatch|
|
V8::C::TryCatch() do |trycatch|
|
||||||
V8::C::HandleScope() do
|
|
||||||
source = V8::C::String::New(<<-JS)
|
source = V8::C::String::New(<<-JS)
|
||||||
function one() {
|
function one() {
|
||||||
two()
|
two()
|
||||||
|
@ -42,7 +40,7 @@ describe V8::C::External do
|
||||||
stack.GetFrameCount().should eql 6
|
stack.GetFrameCount().should eql 6
|
||||||
frame = stack.GetFrame(0)
|
frame = stack.GetFrame(0)
|
||||||
frame.GetLineNumber().should eql 11
|
frame.GetLineNumber().should eql 11
|
||||||
frame.GetColumn().should eql 17
|
frame.GetColumn().should eql 15
|
||||||
frame.GetScriptName().Utf8Value().should eql "<eval>"
|
frame.GetScriptName().Utf8Value().should eql "<eval>"
|
||||||
frame.GetScriptNameOrSourceURL().Utf8Value().should eql "<eval>"
|
frame.GetScriptNameOrSourceURL().Utf8Value().should eql "<eval>"
|
||||||
frame.IsEval().should be_false
|
frame.IsEval().should be_false
|
||||||
|
@ -51,4 +49,3 @@ describe V8::C::External do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
|
|
@ -1,5 +1,4 @@
|
||||||
require 'v8'
|
require 'v8'
|
||||||
load File.expand_path '../c/context_helper.rb', __FILE__
|
|
||||||
|
|
||||||
def run_v8_gc
|
def run_v8_gc
|
||||||
while !V8::C::V8::IdleNotification() do
|
while !V8::C::V8::IdleNotification() do
|
||||||
|
@ -10,3 +9,26 @@ def rputs(msg)
|
||||||
puts "<pre>#{ERB::Util.h(msg)}</pre>"
|
puts "<pre>#{ERB::Util.h(msg)}</pre>"
|
||||||
$stdout.flush
|
$stdout.flush
|
||||||
end
|
end
|
||||||
|
|
||||||
|
module ExplicitScoper;end
|
||||||
|
module Autoscope
|
||||||
|
def instance_eval(*args, &block)
|
||||||
|
V8::C::Locker() do
|
||||||
|
V8::C::HandleScope() do
|
||||||
|
@cxt = V8::C::Context::New()
|
||||||
|
begin
|
||||||
|
@cxt.Enter()
|
||||||
|
super(*args, &block)
|
||||||
|
ensure
|
||||||
|
@cxt.Exit()
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
RSpec.configure do |c|
|
||||||
|
c.before(:each) do
|
||||||
|
extend Autoscope unless is_a? ExplicitScoper
|
||||||
|
end
|
||||||
|
end
|
Loading…
Reference in a new issue