therubyracer 0.10.2 → 0.11.0beta1
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of therubyracer might be problematic. Click here for more details.
- data/.gitignore +21 -11
- data/.travis.yml +2 -1
- data/Changelog.md +46 -0
- data/Gemfile +16 -1
- data/README.md +31 -13
- data/Rakefile +42 -23
- data/benchmarks.rb +217 -0
- data/ext/v8/accessor.cc +181 -0
- data/ext/v8/array.cc +26 -0
- data/ext/v8/backref.cc +56 -0
- data/ext/v8/build.rb +51 -0
- data/ext/v8/constants.cc +34 -0
- data/ext/v8/constraints.cc +52 -0
- data/ext/v8/context.cc +130 -0
- data/ext/v8/date.cc +18 -0
- data/ext/v8/exception.cc +38 -0
- data/ext/v8/extconf.rb +14 -18
- data/ext/v8/external.cc +43 -0
- data/ext/v8/function.cc +58 -0
- data/ext/v8/gc.cc +43 -0
- data/ext/v8/handles.cc +34 -0
- data/ext/v8/heap.cc +31 -0
- data/ext/v8/init.cc +39 -0
- data/ext/v8/invocation.cc +86 -0
- data/ext/v8/locker.cc +77 -0
- data/ext/v8/message.cc +51 -0
- data/ext/v8/object.cc +334 -0
- data/ext/v8/primitive.cc +8 -0
- data/ext/v8/rr.cc +83 -0
- data/ext/v8/rr.h +878 -36
- data/ext/v8/script.cc +80 -0
- data/ext/v8/signature.cc +18 -0
- data/ext/v8/stack.cc +75 -0
- data/ext/v8/string.cc +47 -0
- data/ext/v8/template.cc +175 -0
- data/ext/v8/trycatch.cc +86 -0
- data/ext/v8/v8.cc +87 -0
- data/ext/v8/value.cc +239 -0
- data/lib/v8.rb +30 -22
- data/lib/v8/access.rb +5 -87
- data/lib/v8/access/indices.rb +40 -0
- data/lib/v8/access/invocation.rb +47 -0
- data/lib/v8/access/names.rb +65 -0
- data/lib/v8/array.rb +19 -10
- data/lib/v8/context.rb +85 -78
- data/lib/v8/conversion.rb +35 -0
- data/lib/v8/conversion/array.rb +11 -0
- data/lib/v8/conversion/class.rb +120 -0
- data/lib/v8/conversion/code.rb +38 -0
- data/lib/v8/conversion/fundamental.rb +11 -0
- data/lib/v8/conversion/hash.rb +11 -0
- data/lib/v8/conversion/indentity.rb +31 -0
- data/lib/v8/conversion/method.rb +26 -0
- data/lib/v8/conversion/object.rb +28 -0
- data/lib/v8/conversion/primitive.rb +7 -0
- data/lib/v8/conversion/proc.rb +5 -0
- data/lib/v8/conversion/reference.rb +16 -0
- data/lib/v8/conversion/string.rb +12 -0
- data/lib/v8/conversion/symbol.rb +7 -0
- data/lib/v8/conversion/time.rb +13 -0
- data/lib/v8/error.rb +18 -123
- data/lib/v8/error/protect.rb +20 -0
- data/lib/v8/error/try.rb +15 -0
- data/lib/v8/function.rb +18 -34
- data/lib/v8/object.rb +48 -52
- data/lib/v8/util/weakcell.rb +29 -0
- data/lib/v8/version.rb +2 -2
- data/spec/c/array_spec.rb +17 -0
- data/spec/c/constants_spec.rb +20 -0
- data/spec/c/exception_spec.rb +26 -0
- data/spec/c/external_spec.rb +9 -0
- data/spec/c/function_spec.rb +46 -0
- data/spec/c/handles_spec.rb +35 -0
- data/spec/c/locker_spec.rb +38 -0
- data/spec/c/object_spec.rb +46 -0
- data/spec/c/script_spec.rb +28 -0
- data/spec/c/string_spec.rb +16 -0
- data/spec/c/template_spec.rb +30 -0
- data/spec/c/trycatch_spec.rb +51 -0
- data/spec/mem/blunt_spec.rb +42 -0
- data/spec/redjs_spec.rb +10 -0
- data/spec/spec_helper.rb +40 -4
- data/spec/threading_spec.rb +52 -0
- data/spec/v8/context_spec.rb +19 -0
- data/spec/v8/conversion_spec.rb +9 -0
- data/spec/v8/error_spec.rb +15 -125
- data/spec/v8/function_spec.rb +9 -0
- data/therubyracer.gemspec +15 -24
- metadata +102 -135
- data/.gitmodules +0 -3
- data/.rspec +0 -1
- data/.yardopts +0 -1
- data/bin/therubyracer +0 -11
- data/ext/v8/rr.cpp +0 -189
- data/ext/v8/v8.cpp +0 -48
- data/ext/v8/v8_array.cpp +0 -48
- data/ext/v8/v8_array.h +0 -8
- data/ext/v8/v8_callbacks.cpp +0 -81
- data/ext/v8/v8_callbacks.h +0 -8
- data/ext/v8/v8_context.cpp +0 -92
- data/ext/v8/v8_context.h +0 -6
- data/ext/v8/v8_date.cpp +0 -34
- data/ext/v8/v8_date.h +0 -6
- data/ext/v8/v8_debug.cpp +0 -17
- data/ext/v8/v8_debug.h +0 -6
- data/ext/v8/v8_exception.cpp +0 -133
- data/ext/v8/v8_exception.h +0 -11
- data/ext/v8/v8_external.cpp +0 -70
- data/ext/v8/v8_external.h +0 -8
- data/ext/v8/v8_function.cpp +0 -69
- data/ext/v8/v8_function.h +0 -11
- data/ext/v8/v8_handle.cpp +0 -186
- data/ext/v8/v8_handle.h +0 -48
- data/ext/v8/v8_locker.cpp +0 -139
- data/ext/v8/v8_locker.h +0 -6
- data/ext/v8/v8_message.cpp +0 -67
- data/ext/v8/v8_message.h +0 -10
- data/ext/v8/v8_object.cpp +0 -122
- data/ext/v8/v8_object.h +0 -10
- data/ext/v8/v8_script.cpp +0 -36
- data/ext/v8/v8_script.h +0 -8
- data/ext/v8/v8_string.cpp +0 -52
- data/ext/v8/v8_string.h +0 -9
- data/ext/v8/v8_template.cpp +0 -344
- data/ext/v8/v8_template.h +0 -8
- data/ext/v8/v8_try_catch.cpp +0 -70
- data/ext/v8/v8_try_catch.h +0 -5
- data/ext/v8/v8_v8.cpp +0 -35
- data/ext/v8/v8_v8.h +0 -6
- data/ext/v8/v8_value.cpp +0 -175
- data/ext/v8/v8_value.h +0 -10
- data/ext/v8/v8_weakref.cpp +0 -61
- data/ext/v8/v8_weakref.h +0 -29
- data/lib/v8/c/locker.rb +0 -18
- data/lib/v8/cli.rb +0 -133
- data/lib/v8/portal.rb +0 -86
- data/lib/v8/portal/caller.rb +0 -37
- data/lib/v8/portal/constructor.rb +0 -98
- data/lib/v8/portal/function.rb +0 -63
- data/lib/v8/portal/interceptors.rb +0 -152
- data/lib/v8/portal/proxies.rb +0 -151
- data/lib/v8/portal/templates.rb +0 -73
- data/lib/v8/stack.rb +0 -66
- data/lib/v8/tap.rb +0 -9
- data/spec/ext/array_spec.rb +0 -15
- data/spec/ext/cxt_spec.rb +0 -57
- data/spec/ext/ext_spec_helper.rb +0 -27
- data/spec/ext/func_spec.rb +0 -64
- data/spec/ext/object_spec.rb +0 -10
- data/spec/ext/string_spec.rb +0 -11
- data/spec/ext/try_catch_spec.rb +0 -60
- data/spec/redjs_helper.rb +0 -3
- data/spec/v8/portal/proxies_spec.rb +0 -106
- data/specmem/handle_memspec.rb +0 -41
- data/specmem/object_memspec.rb +0 -14
- data/specmem/proxies_memspec.rb +0 -49
- data/specmem/spec_helper.rb +0 -24
- data/specthread/spec_helper.rb +0 -2
- data/specthread/threading_spec.rb +0 -13
data/lib/v8/object.rb
CHANGED
@@ -1,69 +1,65 @@
|
|
1
|
+
class V8::Object
|
2
|
+
include Enumerable
|
3
|
+
attr_reader :native
|
4
|
+
alias_method :to_v8, :native
|
1
5
|
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
@native, @portal = native, portal
|
8
|
-
end
|
6
|
+
def initialize(native = nil)
|
7
|
+
@context = V8::Context.current or fail "tried to initialize a #{self.class} without being in an entered V8::Context"
|
8
|
+
@native = block_given? ? yield : native || V8::C::Object::New()
|
9
|
+
@context.link self, @native
|
10
|
+
end
|
9
11
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
end
|
12
|
+
def [](key)
|
13
|
+
@context.enter do
|
14
|
+
@context.to_ruby @native.Get(@context.to_v8(key))
|
14
15
|
end
|
16
|
+
end
|
15
17
|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
@native.Set(to.v8(key), to.v8(value))
|
20
|
-
end
|
21
|
-
end
|
18
|
+
def []=(key, value)
|
19
|
+
@context.enter do
|
20
|
+
@native.Set(@context.to_v8(key), @context.to_v8(value))
|
22
21
|
end
|
22
|
+
return value
|
23
|
+
end
|
23
24
|
|
24
|
-
|
25
|
-
|
26
|
-
|
25
|
+
def each
|
26
|
+
@context.enter do
|
27
|
+
names = @native.GetPropertyNames()
|
28
|
+
0.upto(names.Length() - 1) do |i|
|
29
|
+
name = names.Get(i)
|
30
|
+
yield @context.to_ruby(name), @context.to_ruby(@native.Get(name))
|
27
31
|
end
|
28
32
|
end
|
33
|
+
end
|
29
34
|
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
yield prop, self[prop]
|
34
|
-
end
|
35
|
-
end
|
35
|
+
def to_s
|
36
|
+
@context.enter do
|
37
|
+
@context.to_ruby @native.ToString()
|
36
38
|
end
|
39
|
+
end
|
37
40
|
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
+
def respond_to?(method)
|
42
|
+
super or self[method] != nil
|
43
|
+
end
|
41
44
|
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
else
|
48
|
-
self[$1] = args.first
|
49
|
-
return args
|
50
|
-
end
|
51
|
-
end
|
52
|
-
return super(name, *args, &block) unless self.respond_to?(name)
|
53
|
-
property = self[name]
|
54
|
-
if property.kind_of?(V8::Function)
|
55
|
-
property.methodcall(self, *args)
|
56
|
-
elsif args.empty?
|
57
|
-
property
|
45
|
+
def method_missing(name, *args, &block)
|
46
|
+
if name.to_s =~ /(.*)=$/
|
47
|
+
if args.length > 1
|
48
|
+
self[$1] = args
|
49
|
+
return args
|
58
50
|
else
|
59
|
-
|
51
|
+
self[$1] = args.first
|
52
|
+
return args
|
60
53
|
end
|
61
54
|
end
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
55
|
+
return super(name, *args, &block) unless self.respond_to?(name)
|
56
|
+
property = self[name]
|
57
|
+
if property.kind_of?(V8::Function)
|
58
|
+
property.methodcall(self, *args)
|
59
|
+
elsif args.empty?
|
60
|
+
property
|
61
|
+
else
|
62
|
+
raise ArgumentError, "wrong number of arguments (#{args.length} for 0)" unless args.empty?
|
63
|
+
end
|
68
64
|
end
|
69
65
|
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
module V8
|
2
|
+
module Util
|
3
|
+
module Weakcell
|
4
|
+
def weakcell(name, &block)
|
5
|
+
unless storage = instance_variable_get("@#{name}")
|
6
|
+
storage = instance_variable_set("@#{name}", Storage.new)
|
7
|
+
end
|
8
|
+
storage.access(&block)
|
9
|
+
end
|
10
|
+
class Storage
|
11
|
+
def access(&block)
|
12
|
+
if @ref
|
13
|
+
@ref.object || populate(block)
|
14
|
+
else
|
15
|
+
populate(block)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
private
|
20
|
+
|
21
|
+
def populate(block)
|
22
|
+
occupant = block.call()
|
23
|
+
@ref = Ref::WeakReference.new(occupant)
|
24
|
+
return occupant
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
data/lib/v8/version.rb
CHANGED
@@ -1,3 +1,3 @@
|
|
1
1
|
module V8
|
2
|
-
VERSION = "0.
|
3
|
-
end
|
2
|
+
VERSION = "0.11.0beta1"
|
3
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe V8::C::Array do
|
4
|
+
it "can store and retrieve a value" do
|
5
|
+
o = V8::C::Object::New()
|
6
|
+
a = V8::C::Array::New()
|
7
|
+
a.Length().should eql 0
|
8
|
+
a.Set(0, o)
|
9
|
+
a.Length().should eql 1
|
10
|
+
a.Get(0).Equals(o).should be_true
|
11
|
+
end
|
12
|
+
|
13
|
+
it "can be initialized with a length" do
|
14
|
+
a = V8::C::Array::New(5)
|
15
|
+
a.Length().should eql 5
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe V8::C do
|
4
|
+
it "has constant methods for Undefined, Null, True and False" do
|
5
|
+
[:Undefined, :Null, :True, :False].each do |name|
|
6
|
+
constant = V8::C.send(name)
|
7
|
+
constant.should_not be_nil
|
8
|
+
V8::C.send(name).should be constant
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
it "has a value for the Empty handle" do
|
13
|
+
V8::C::Value::Empty.should_not be_nil
|
14
|
+
V8::C::Value::Empty.should be V8::C::Value::Empty
|
15
|
+
end
|
16
|
+
|
17
|
+
it "can access the V8 version" do
|
18
|
+
V8::C::V8::GetVersion().should match /^3\.11/
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe V8::C::Exception do
|
4
|
+
it "can be thrown from Ruby" do
|
5
|
+
t = V8::C::FunctionTemplate::New(method(:explode))
|
6
|
+
@cxt.Global().Set("explode", t.GetFunction())
|
7
|
+
script = V8::C::Script::New(<<-JS, '<eval>')
|
8
|
+
(function() {
|
9
|
+
try {
|
10
|
+
explode()
|
11
|
+
} catch (e) {
|
12
|
+
return e.message
|
13
|
+
}
|
14
|
+
})()
|
15
|
+
JS
|
16
|
+
result = script.Run()
|
17
|
+
result.should_not be_nil
|
18
|
+
result.should be_kind_of(V8::C::String)
|
19
|
+
result.Utf8Value().should eql 'did not pay syntax'
|
20
|
+
end
|
21
|
+
|
22
|
+
def explode(arguments)
|
23
|
+
error = V8::C::Exception::SyntaxError('did not pay syntax')
|
24
|
+
V8::C::ThrowException(error)
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe V8::C::Function do
|
4
|
+
it "can be called" do
|
5
|
+
fn = run '(function() {return "foo"})'
|
6
|
+
fn.Call(@cxt.Global(), []).Utf8Value().should eql "foo"
|
7
|
+
end
|
8
|
+
|
9
|
+
it "can be called with arguments and context" do
|
10
|
+
fn = run '(function(one, two, three) {this.one = one; this.two = two; this.three = three})'
|
11
|
+
one = V8::C::Object::New()
|
12
|
+
two = V8::C::Object::New()
|
13
|
+
fn.Call(@cxt.Global(), [one, two, 3])
|
14
|
+
@cxt.Global().Get("one").should eql one
|
15
|
+
@cxt.Global().Get("two").should eql two
|
16
|
+
@cxt.Global().Get("three").should eql 3
|
17
|
+
end
|
18
|
+
|
19
|
+
it "can be called as a constructor" do
|
20
|
+
fn = run '(function() {this.foo = "foo"})'
|
21
|
+
fn.NewInstance().Get(V8::C::String::New('foo')).Utf8Value().should eql "foo"
|
22
|
+
end
|
23
|
+
|
24
|
+
it "can be called as a constructor with arguments" do
|
25
|
+
fn = run '(function(foo) {this.foo = foo})'
|
26
|
+
object = fn.NewInstance([V8::C::String::New("bar")])
|
27
|
+
object.Get(V8::C::String::New('foo')).Utf8Value().should eql "bar"
|
28
|
+
end
|
29
|
+
|
30
|
+
it "doesn't kill the world if invoking it throws a javascript exception" do
|
31
|
+
V8::C::TryCatch() do
|
32
|
+
fn = run '(function() { throw new Error("boom!")})'
|
33
|
+
fn.Call(@cxt.Global(), [])
|
34
|
+
fn.NewInstance([])
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
|
39
|
+
def run(source)
|
40
|
+
source = V8::C::String::New(source.to_s)
|
41
|
+
filename = V8::C::String::New("<eval>")
|
42
|
+
script = V8::C::Script::New(source, filename)
|
43
|
+
result = script.Run()
|
44
|
+
result.kind_of?(V8::C::String) ? result.Utf8Value() : result
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe "setting up handles scopes" do
|
4
|
+
include ExplicitScoper
|
5
|
+
|
6
|
+
before do
|
7
|
+
def self.instance_eval(*args, &block)
|
8
|
+
V8::C::Locker() do
|
9
|
+
cxt = V8::C::Context::New()
|
10
|
+
begin
|
11
|
+
cxt.Enter()
|
12
|
+
super(*args, &block)
|
13
|
+
ensure
|
14
|
+
cxt.Exit()
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
it "can allocate handle scopes" do
|
21
|
+
V8::C::HandleScope() do
|
22
|
+
V8::C::Object::New()
|
23
|
+
end.class.should eql V8::C::Object
|
24
|
+
end
|
25
|
+
|
26
|
+
it "isn't the end of the world if a ruby exception is raised inside a HandleScope" do
|
27
|
+
begin
|
28
|
+
V8::C::HandleScope() do
|
29
|
+
raise "boom!"
|
30
|
+
end
|
31
|
+
rescue StandardError => e
|
32
|
+
e.message.should eql "boom!"
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe V8::C::Locker do
|
4
|
+
include ExplicitScoper
|
5
|
+
|
6
|
+
it "can lock and unlock the VM" do
|
7
|
+
V8::C::Locker::IsLocked().should be_false
|
8
|
+
V8::C::Locker() do
|
9
|
+
V8::C::Locker::IsLocked().should be_true
|
10
|
+
V8::C::Unlocker() do
|
11
|
+
V8::C::Locker::IsLocked().should be_false
|
12
|
+
end
|
13
|
+
end
|
14
|
+
V8::C::Locker::IsLocked().should be_false
|
15
|
+
end
|
16
|
+
|
17
|
+
it "properly unlocks if an exception is thrown inside a lock block" do
|
18
|
+
begin
|
19
|
+
V8::C::Locker() do
|
20
|
+
raise "boom!"
|
21
|
+
end
|
22
|
+
rescue
|
23
|
+
V8::C::Locker::IsLocked().should be_false
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
it "properly re-locks if an exception is thrown inside an un-lock block" do
|
28
|
+
V8::C::Locker() do
|
29
|
+
begin
|
30
|
+
V8::C::Unlocker() do
|
31
|
+
raise "boom!"
|
32
|
+
end
|
33
|
+
rescue
|
34
|
+
V8::C::Locker::IsLocked().should be_true
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe V8::C::Object do
|
4
|
+
|
5
|
+
it "can store and retrieve a value" do
|
6
|
+
o = V8::C::Object::New()
|
7
|
+
key = V8::C::String::New("foo")
|
8
|
+
value = V8::C::String::New("bar")
|
9
|
+
o.Set(key, value)
|
10
|
+
o.Get(key).Utf8Value().should eql "bar"
|
11
|
+
end
|
12
|
+
|
13
|
+
it "can retrieve all property names" do
|
14
|
+
o = V8::C::Object::New()
|
15
|
+
o.Set(V8::C::String::New("foo"), V8::C::String::New("bar"))
|
16
|
+
o.Set(V8::C::String::New("baz"), V8::C::String::New("bang"))
|
17
|
+
names = o.GetPropertyNames()
|
18
|
+
names.Length().should eql 2
|
19
|
+
names.Get(0).Utf8Value().should eql "foo"
|
20
|
+
names.Get(1).Utf8Value().should eql "baz"
|
21
|
+
end
|
22
|
+
it "can set an accessor from ruby" do
|
23
|
+
o = V8::C::Object::New()
|
24
|
+
property = V8::C::String::New("statement")
|
25
|
+
callback_data = V8::C::String::New("I am Legend")
|
26
|
+
left = V8::C::String::New("Yo! ")
|
27
|
+
getter = proc do |name, info|
|
28
|
+
info.This().StrictEquals(o).should be_true
|
29
|
+
info.Holder().StrictEquals(o).should be_true
|
30
|
+
V8::C::String::Concat(left, info.Data())
|
31
|
+
end
|
32
|
+
setter = proc do |name, value, info|
|
33
|
+
left = value
|
34
|
+
end
|
35
|
+
o.SetAccessor(property, getter, setter, callback_data)
|
36
|
+
o.Get(property).Utf8Value().should eql "Yo! I am Legend"
|
37
|
+
o.Set(property, V8::C::String::New("Bro! "))
|
38
|
+
o.Get(property).Utf8Value().should eql "Bro! I am Legend"
|
39
|
+
end
|
40
|
+
it "always returns the same ruby object for the same V8 object" do
|
41
|
+
one = V8::C::Object::New()
|
42
|
+
two = V8::C::Object::New()
|
43
|
+
one.Set("two", two)
|
44
|
+
one.Get("two").should be two
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
require 'spec_helper'
|
3
|
+
|
4
|
+
describe V8::C::Script do
|
5
|
+
it "can run a script and return a polymorphic result" do
|
6
|
+
source = V8::C::String::New("(new Array())")
|
7
|
+
filename = V8::C::String::New("<eval>")
|
8
|
+
script = V8::C::Script::New(source, filename)
|
9
|
+
result = script.Run()
|
10
|
+
result.should be_kind_of V8::C::Array
|
11
|
+
end
|
12
|
+
|
13
|
+
it "can accept precompiled script data" do
|
14
|
+
source = "7 * 6"
|
15
|
+
name = V8::C::String::New("<spec>")
|
16
|
+
origin = V8::C::ScriptOrigin.new(name)
|
17
|
+
data = V8::C::ScriptData::PreCompile(source, source.length)
|
18
|
+
data.HasError().should be_false
|
19
|
+
script = V8::C::Script::New(V8::C::String::New(source), origin, data)
|
20
|
+
script.Run().should eql 42
|
21
|
+
end
|
22
|
+
|
23
|
+
it "can detect errors in the script data" do
|
24
|
+
source = "^ = ;"
|
25
|
+
data = V8::C::ScriptData::PreCompile(source, source.length)
|
26
|
+
data.HasError().should be_true
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe V8::C::String do
|
4
|
+
it "can hold Unicode values outside the Basic Multilingual Plane" do
|
5
|
+
string = V8::C::String::New("\u{100000}")
|
6
|
+
string.Utf8Value().should eql "\u{100000}"
|
7
|
+
end
|
8
|
+
|
9
|
+
it "can naturally translate ruby strings into v8 strings" do
|
10
|
+
V8::C::String::Concat(V8::C::String::New("Hello "), "World").Utf8Value().should eql "Hello World"
|
11
|
+
end
|
12
|
+
|
13
|
+
it "can naturally translate ruby objects into v8 strings" do
|
14
|
+
V8::C::String::Concat(V8::C::String::New("forty two is "), 42).Utf8Value().should eql "forty two is 42"
|
15
|
+
end
|
16
|
+
end
|