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

Commit d4c68df

Browse files
committed
Merge branch 'stormbreakerbg-4.5/object-methods' into upgrade-to-v8-4.5
2 parents bafd35c + 5ac3483 commit d4c68df

14 files changed

Lines changed: 848 additions & 108 deletions

ext/v8/array.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ namespace rr {
1313

1414
inline Array(v8::Isolate* isolate, v8::Handle<v8::Array> array) : Ref<v8::Array>(isolate, array) {}
1515
inline Array(VALUE value) : Ref<v8::Array>(value) {}
16+
17+
typedef MaybeLocal<Array, v8::Array> Maybe;
1618
};
1719

1820
}

ext/v8/enum.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,15 @@ namespace rr {
1616
operator T() {
1717
return RTEST(value) ? (T)NUM2INT(value) : defaultValue;
1818
}
19+
20+
class Maybe : public rr::Maybe {
21+
public:
22+
Maybe(v8::Maybe<T> maybe) {
23+
if (maybe.IsJust()) {
24+
just(INT2FIX((int)maybe.FromJust()));
25+
}
26+
}
27+
};
1928
};
2029

2130
inline void DefineEnums() {

ext/v8/object-template.h

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,12 @@ namespace rr {
88
ObjectTemplate(VALUE self) : Ref<v8::ObjectTemplate>(self) {}
99
ObjectTemplate(v8::Isolate* isolate, v8::Handle<v8::ObjectTemplate> tmpl) :
1010
Ref<v8::ObjectTemplate>(isolate, tmpl) {}
11+
1112
inline static void Init() {
1213
ClassBuilder("ObjectTemplate", Template::Class).
1314
defineSingletonMethod("New", &New).
1415
defineMethod("NewInstance", &NewInstance).
16+
defineMethod("SetInternalFieldCount", &SetInternalFieldCount).
1517
store(&Class);
1618
}
1719

@@ -20,16 +22,26 @@ namespace rr {
2022
rb_scan_args(argc, argv, "11", &r_isolate, &r_constructor);
2123
Isolate isolate(r_isolate);
2224
Locker lock(isolate);
25+
2326
return ObjectTemplate(isolate, v8::ObjectTemplate::New(isolate));
2427
}
2528

26-
static VALUE NewInstance(VALUE self , VALUE r_context) {
29+
static VALUE NewInstance(VALUE self, VALUE r_context) {
2730
ObjectTemplate t(self);
2831
Context context(r_context);
2932
Isolate isolate(context.getIsolate());
3033
Locker lock(isolate);
31-
v8::MaybeLocal<v8::Object> object(t->NewInstance());
32-
return Object::Maybe(isolate, ObjectTemplate(self)->NewInstance(context));
34+
35+
return Object::Maybe(isolate, t->NewInstance(context));
36+
}
37+
38+
static VALUE SetInternalFieldCount(VALUE self, VALUE value) {
39+
ObjectTemplate t(self);
40+
Locker lock(t);
41+
42+
t->SetInternalFieldCount(NUM2INT(value));
43+
44+
return Qnil;
3345
}
3446
};
3547
}

0 commit comments

Comments
 (0)