mirror of
https://github.com/rubyjs/therubyracer
synced 2023-03-27 23:21:42 -04:00
Use #around
for creation of context for C examples
This fixes segmentation fault in the tests as extending the examples in a before block with override of `#instance_eval` seems to not work. Also, the context wrap is now opt-in with a helper method, instead of opt-out and relying on `#described_class` (which has slightly different behavior in RSpec 3). Tested on Ruby 2.1.5 and RSpec 2.99.2.
This commit is contained in:
parent
8dae8f7890
commit
654b808ac5
13 changed files with 50 additions and 43 deletions
|
@ -1,6 +1,8 @@
|
||||||
require 'spec_helper'
|
require 'spec_helper'
|
||||||
|
|
||||||
describe V8::C::Array do
|
describe V8::C::Array do
|
||||||
|
requires_v8_context
|
||||||
|
|
||||||
it "can store and retrieve a value" do
|
it "can store and retrieve a value" do
|
||||||
o = V8::C::Object::New()
|
o = V8::C::Object::New()
|
||||||
a = V8::C::Array::New()
|
a = V8::C::Array::New()
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
require 'spec_helper'
|
require 'spec_helper'
|
||||||
|
|
||||||
describe V8::C do
|
describe V8::C do
|
||||||
|
requires_v8_context
|
||||||
|
|
||||||
it "has constant methods for Undefined, Null, True and False" do
|
it "has constant methods for Undefined, Null, True and False" do
|
||||||
[:Undefined, :Null, :True, :False].each do |name|
|
[:Undefined, :Null, :True, :False].each do |name|
|
||||||
constant = V8::C.send(name)
|
constant = V8::C.send(name)
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
require 'spec_helper'
|
require 'spec_helper'
|
||||||
|
|
||||||
describe V8::C::Exception do
|
describe V8::C::Exception do
|
||||||
|
requires_v8_context
|
||||||
|
|
||||||
it "can be thrown from Ruby" do
|
it "can be thrown from Ruby" do
|
||||||
t = V8::C::FunctionTemplate::New(method(:explode))
|
t = V8::C::FunctionTemplate::New(method(:explode))
|
||||||
@cxt.Global().Set("explode", t.GetFunction())
|
@cxt.Global().Set("explode", t.GetFunction())
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
require 'spec_helper'
|
require 'spec_helper'
|
||||||
|
|
||||||
describe V8::C::External do
|
describe V8::C::External do
|
||||||
|
requires_v8_context
|
||||||
|
|
||||||
it "can store and retrieve a value" do
|
it "can store and retrieve a value" do
|
||||||
o = Object.new
|
o = Object.new
|
||||||
external = V8::C::External::New(o)
|
external = V8::C::External::New(o)
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
require 'spec_helper'
|
require 'spec_helper'
|
||||||
|
|
||||||
describe V8::C::Function do
|
describe V8::C::Function do
|
||||||
|
requires_v8_context
|
||||||
|
|
||||||
it "can be called" do
|
it "can be called" do
|
||||||
fn = run '(function() {return "foo"})'
|
fn = run '(function() {return "foo"})'
|
||||||
fn.Call(@cxt.Global(), []).Utf8Value().should eql "foo"
|
fn.Call(@cxt.Global(), []).Utf8Value().should eql "foo"
|
||||||
|
|
|
@ -1,21 +1,17 @@
|
||||||
require 'spec_helper'
|
require 'spec_helper'
|
||||||
|
|
||||||
describe "setting up handles scopes" do
|
describe "setting up handles scopes" do
|
||||||
include ExplicitScoper
|
around(:each) do |example|
|
||||||
|
|
||||||
before do
|
|
||||||
def self.instance_eval(*args, &block)
|
|
||||||
V8::C::Locker() do
|
V8::C::Locker() do
|
||||||
cxt = V8::C::Context::New()
|
cxt = V8::C::Context::New()
|
||||||
begin
|
begin
|
||||||
cxt.Enter()
|
cxt.Enter()
|
||||||
super(*args, &block)
|
example.run
|
||||||
ensure
|
ensure
|
||||||
cxt.Exit()
|
cxt.Exit()
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
|
||||||
|
|
||||||
it "can allocate handle scopes" do
|
it "can allocate handle scopes" do
|
||||||
V8::C::HandleScope() do
|
V8::C::HandleScope() do
|
||||||
|
|
|
@ -1,8 +1,6 @@
|
||||||
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
|
||||||
V8::C::Locker::IsLocked().should be_false
|
V8::C::Locker::IsLocked().should be_false
|
||||||
V8::C::Locker() do
|
V8::C::Locker() do
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
require 'spec_helper'
|
require 'spec_helper'
|
||||||
|
|
||||||
describe V8::C::Object do
|
describe V8::C::Object do
|
||||||
|
requires_v8_context
|
||||||
|
|
||||||
it "can store and retrieve a value" do
|
it "can store and retrieve a value" do
|
||||||
o = V8::C::Object::New()
|
o = V8::C::Object::New()
|
||||||
|
|
|
@ -2,6 +2,8 @@
|
||||||
require 'spec_helper'
|
require 'spec_helper'
|
||||||
|
|
||||||
describe V8::C::Script do
|
describe V8::C::Script do
|
||||||
|
requires_v8_context
|
||||||
|
|
||||||
it "can run a script and return a polymorphic result" do
|
it "can run a script and return a polymorphic result" 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>")
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
require 'spec_helper'
|
require 'spec_helper'
|
||||||
|
|
||||||
describe V8::C::String do
|
describe V8::C::String do
|
||||||
|
requires_v8_context
|
||||||
|
|
||||||
it "can hold Unicode values outside the Basic Multilingual Plane" do
|
it "can hold Unicode values outside the Basic Multilingual Plane" do
|
||||||
string = V8::C::String::New("\u{100000}")
|
string = V8::C::String::New("\u{100000}")
|
||||||
string.Utf8Value().should eql "\u{100000}"
|
string.Utf8Value().should eql "\u{100000}"
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
require 'spec_helper'
|
require 'spec_helper'
|
||||||
|
|
||||||
describe V8::C::Template do
|
describe V8::C::Template do
|
||||||
|
requires_v8_context
|
||||||
|
|
||||||
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
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
require 'spec_helper'
|
require 'spec_helper'
|
||||||
|
|
||||||
describe V8::C::External do
|
describe V8::C::External do
|
||||||
|
requires_v8_context
|
||||||
|
|
||||||
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)
|
||||||
|
|
|
@ -11,35 +11,31 @@ def rputs(msg)
|
||||||
$stdout.flush
|
$stdout.flush
|
||||||
end
|
end
|
||||||
|
|
||||||
module ExplicitScoper;end
|
module V8ContextHelpers
|
||||||
module Autoscope
|
module GroupMethods
|
||||||
def instance_eval(*args, &block)
|
def requires_v8_context
|
||||||
return super unless low_level_c_spec? && !explicitly_defines_scope?
|
around(:each) do |example|
|
||||||
|
bootstrap_v8_context(&example)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def bootstrap_v8_context
|
||||||
V8::C::Locker() do
|
V8::C::Locker() do
|
||||||
V8::C::HandleScope() do
|
V8::C::HandleScope() do
|
||||||
@cxt = V8::C::Context::New()
|
@cxt = V8::C::Context::New()
|
||||||
begin
|
begin
|
||||||
@cxt.Enter()
|
@cxt.Enter()
|
||||||
super(*args, &block)
|
yield
|
||||||
ensure
|
ensure
|
||||||
@cxt.Exit()
|
@cxt.Exit()
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def low_level_c_spec?
|
|
||||||
return false unless described_class
|
|
||||||
described_class.name =~ /^V8::C::/
|
|
||||||
end
|
|
||||||
|
|
||||||
def explicitly_defines_scope?
|
|
||||||
is_a?(ExplicitScoper)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
RSpec.configure do |c|
|
RSpec.configure do |c|
|
||||||
c.before(:each) do
|
c.include V8ContextHelpers
|
||||||
extend Autoscope
|
c.extend V8ContextHelpers::GroupMethods
|
||||||
end
|
|
||||||
end
|
end
|
Loading…
Add table
Reference in a new issue