Skip to content
This repository was archived by the owner on Dec 4, 2023. It is now read-only.

Commit 0ddf0be

Browse files
committed
Merge remote-tracking branch 'origin/upgrade-to-v8-4.5' into coordinate-isolate-teardown
2 parents 38af541 + d1dd01d commit 0ddf0be

10 files changed

Lines changed: 215 additions & 4 deletions

File tree

.travis.yml

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,34 @@
1-
cache: bundler
1+
#cache: bundler
22
rvm:
33
- 2.1.0
44
- 2.0.0
55
- 1.9.3
66
- 1.9.2
77
- 1.8.7
88
- rbx-2.2.3
9+
matrix:
10+
allow_failures:
11+
- rvm: 1.9.3
12+
- rvm: 1.9.2
13+
- rvm: 1.8.7
14+
- rvm: rbx-2.2.3
15+
env:
16+
- CXX=g++-4.8
17+
- CXX=clang++
918
notifications:
1019
recipients:
1120
- cowboyd@thefrontside.net
1221
before_install:
1322
- gem update --system 2.1.11
14-
script: bundle exec rake compile spec
23+
script:
24+
- bundle exec rake compile
25+
- bundle exec rspec spec/c
26+
sudo: false
27+
addons:
28+
apt:
29+
sources:
30+
- ubuntu-toolchain-r-test
31+
packages:
32+
- gcc-4.8
33+
- g++-4.8
34+
- clang

ext/v8/extconf.rb

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
require 'mkmf'
2+
cxx = RbConfig::MAKEFILE_CONFIG['CXX'] = ENV['CXX'] if ENV['CXX']
23

34
have_library('pthread')
45
have_library('objc') if RUBY_PLATFORM =~ /darwin/
@@ -9,7 +10,9 @@
910
$CPPFLAGS += " -fPIC" unless $CPPFLAGS.split.include? "-rdynamic" or RUBY_PLATFORM =~ /darwin/
1011
$CPPFLAGS += " -std=c++11"
1112

12-
$LDFLAGS += " -stdlib=libstdc++"
13+
if cxx =~ /clang/
14+
$LDFLAGS += " -stdlib=libstdc++"
15+
end
1316

1417
CONFIG['LDSHARED'] = '$(CXX) -shared' unless RUBY_PLATFORM =~ /darwin/
1518
if CONFIG['warnflags']

ext/v8/init.cc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@ extern "C" {
1616
Value::Init();
1717
Object::Init();
1818
Primitive::Init();
19+
Name::Init();
1920
String::Init();
21+
Symbol::Init();
2022
Function::Init();
2123
Script::Init();
2224
ScriptOrigin::Init();

ext/v8/name.cc

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#include "rr.h"
2+
3+
namespace rr {
4+
void Name::Init() {
5+
ClassBuilder("Name", Primitive::Class).
6+
defineMethod("GetIdentityHash", &GetIdentityHash).
7+
8+
store(&Class);
9+
}
10+
VALUE Name::GetIdentityHash(VALUE self) {
11+
Name name(self);
12+
Locker lock(name.getIsolate());
13+
14+
return INT2FIX(name->GetIdentityHash());
15+
}
16+
}

ext/v8/name.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
//mode -*- c++ -*-
2+
#ifndef NAME_H
3+
#define NAME_H
4+
5+
namespace rr {
6+
class Name : public Ref<v8::Name> {
7+
public:
8+
static void Init();
9+
static VALUE GetIdentityHash(VALUE self);
10+
11+
Name(VALUE self) : Ref<v8::Name>(self) {}
12+
};
13+
}
14+
15+
#endif /* NAME_H */

ext/v8/rr.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,9 @@ inline VALUE not_implemented(const char* message) {
3939
#include "primitive.h"
4040
#include "external.h"
4141
// This one is named v8_string to avoid name collisions with C's string.h
42+
#include "name.h"
4243
#include "rr_string.h"
44+
#include "symbol.h"
4345

4446
#include "script.h"
4547
#include "script-origin.h"

ext/v8/rr_string.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
namespace rr {
44

55
void String::Init() {
6-
ClassBuilder("String", Primitive::Class).
6+
ClassBuilder("String", Name::Class).
77
defineSingletonMethod("NewFromUtf8", &NewFromUtf8).
88
defineSingletonMethod("Concat", &Concat).
99

ext/v8/symbol.cc

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
#include "rr.h"
2+
3+
namespace rr {
4+
void Symbol::Init() {
5+
ClassBuilder("Symbol", Name::Class).
6+
defineSingletonMethod("New", &New).
7+
defineSingletonMethod("For", &For).
8+
defineSingletonMethod("ForApi", &ForApi).
9+
defineSingletonMethod("GetIterator", &GetIterator).
10+
defineSingletonMethod("GetUnscopables", &GetUnscopables).
11+
defineSingletonMethod("GetToStringTag", &GetToStringTag).
12+
defineMethod("Name", &Name).
13+
14+
store(&Class);
15+
}
16+
17+
VALUE Symbol::New(int argc, VALUE argv[], VALUE self) {
18+
VALUE rb_isolate, rb_name;
19+
rb_scan_args(argc, argv, "11", &rb_isolate, &rb_name);
20+
21+
Isolate isolate(rb_isolate);
22+
Locker lock(isolate);
23+
v8::HandleScope handle_scope(isolate);
24+
25+
if (RTEST(rb_name)) {
26+
return Symbol(isolate, v8::Symbol::New(isolate, String(rb_name)));
27+
} else {
28+
return Symbol(isolate, v8::Symbol::New(isolate));
29+
}
30+
}
31+
32+
VALUE Symbol::For(VALUE self, VALUE rb_isolate, VALUE name) {
33+
Isolate isolate(rb_isolate);
34+
Locker lock(isolate);
35+
36+
return Symbol(isolate, v8::Symbol::For(isolate, String(name)));
37+
}
38+
39+
VALUE Symbol::ForApi(VALUE self, VALUE rb_isolate, VALUE name) {
40+
Isolate isolate(rb_isolate);
41+
Locker lock(isolate);
42+
43+
return Symbol(isolate, v8::Symbol::ForApi(isolate, String(name)));
44+
}
45+
46+
VALUE Symbol::GetIterator(VALUE self, VALUE rb_isolate) {
47+
Isolate isolate(rb_isolate);
48+
Locker lock(isolate);
49+
50+
return Symbol(isolate, v8::Symbol::GetIterator(isolate));
51+
}
52+
53+
VALUE Symbol::GetUnscopables(VALUE self, VALUE rb_isolate) {
54+
Isolate isolate(rb_isolate);
55+
Locker lock(isolate);
56+
57+
return Symbol(isolate, v8::Symbol::GetUnscopables(isolate));
58+
}
59+
60+
VALUE Symbol::GetToStringTag(VALUE self, VALUE rb_isolate) {
61+
Isolate isolate(rb_isolate);
62+
Locker lock(isolate);
63+
64+
return Symbol(isolate, v8::Symbol::GetToStringTag(isolate));
65+
}
66+
67+
VALUE Symbol::Name(VALUE self) {
68+
Symbol symbol(self);
69+
Isolate isolate(symbol.getIsolate());
70+
Locker lock(isolate);
71+
72+
return Value::handleToRubyObject(isolate, symbol->Name());
73+
}
74+
}

ext/v8/symbol.h

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// -*- mode: c++ -*-
2+
#ifndef SYMBOL_H
3+
#define SYMBOL_H
4+
5+
#include "rr.h"
6+
7+
namespace rr {
8+
class Symbol : public Ref<v8::Symbol> {
9+
public:
10+
static void Init();
11+
12+
static VALUE Name(VALUE self);
13+
static VALUE New(int argc, VALUE argv[], VALUE self);
14+
static VALUE For(VALUE self, VALUE isolate, VALUE name);
15+
static VALUE ForApi(VALUE self, VALUE isolate, VALUE name);
16+
static VALUE GetIterator(VALUE self, VALUE isolate);
17+
static VALUE GetUnscopables(VALUE self, VALUE isolate);
18+
static VALUE GetToStringTag(VALUE self, VALUE isolate);
19+
20+
Symbol(VALUE self) : Ref<v8::Symbol>(self) {}
21+
Symbol(v8::Isolate* isolate, v8::Local<v8::Symbol> symbol) :
22+
Ref<v8::Symbol>(isolate, symbol) {}
23+
};
24+
}
25+
26+
#endif /* SYMBOL_H */

spec/c/symbol_spec.rb

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
require 'c_spec_helper'
2+
3+
describe V8::C::Symbol do
4+
requires_v8_context
5+
6+
describe "without a description" do
7+
let(:symbol) { V8::C::Symbol::New(@isolate)}
8+
9+
it "exists" do
10+
expect(symbol).to be
11+
end
12+
13+
it "has an identity hash" do
14+
expect(symbol.GetIdentityHash()).to be
15+
end
16+
end
17+
18+
describe "with a description" do
19+
let(:description) { V8::C::String::NewFromUtf8(@isolate, "bob") }
20+
let(:symbol) { V8::C::Symbol::New(@isolate, description) }
21+
22+
it "has a name" do
23+
expect(symbol.Name().Utf8Value()).to eql "bob"
24+
end
25+
end
26+
27+
describe "from symbol registries" do
28+
let(:key) { V8::C::String::NewFromUtf8(@isolate, "mysym") }
29+
let(:global) { V8::C::Symbol::For(@isolate, key) }
30+
let(:api) { V8::C::Symbol::ForApi(@isolate, key) }
31+
32+
it "always retrieves the same value for a given key" do
33+
expect(V8::C::Symbol::For(@isolate, key).StrictEquals(global)).to be true
34+
expect(V8::C::Symbol::ForApi(@isolate, key).StrictEquals(api)).to be true
35+
end
36+
37+
it "returns different symbols for different registries" do
38+
expect(global.StrictEquals(api)).to be false
39+
end
40+
end
41+
42+
describe "well-known symbols" do
43+
it "GetIterator" do
44+
expect(V8::C::Symbol::GetIterator(@isolate)).to be_kind_of V8::C::Symbol
45+
end
46+
it "GetUnscopables" do
47+
expect(V8::C::Symbol::GetUnscopables(@isolate)).to be_kind_of V8::C::Symbol
48+
end
49+
it "GetToStringTag" do
50+
expect(V8::C::Symbol::GetToStringTag(@isolate)).to be_kind_of V8::C::Symbol
51+
end
52+
end
53+
end

0 commit comments

Comments
 (0)