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

Commit 38caf7e

Browse files
committed
Move the set methods to the base class of ReturnValue
1 parent 60f6069 commit 38caf7e

1 file changed

Lines changed: 28 additions & 29 deletions

File tree

ext/v8/return-value.h

Lines changed: 28 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -7,83 +7,82 @@ namespace rr {
77
class ReturnValue {
88
public:
99

10-
template <class T>
11-
class Base : public Wrapper<v8::ReturnValue<T>> {
10+
template <class V8Type, class RRType>
11+
class Base : public Wrapper<v8::ReturnValue<V8Type>> {
1212
public:
1313

14-
Base(v8::ReturnValue<T> value) : Wrapper<v8::ReturnValue<T>>(value) {}
15-
Base(VALUE self) : Wrapper<v8::ReturnValue<T>>(self) {}
16-
17-
static VALUE GetIsolate(VALUE self) {
18-
Base<T> ret(self);
19-
return Isolate(ret->GetIsolate());
20-
}
21-
22-
};
23-
24-
class Value : public Base<v8::Value> {
25-
public:
26-
27-
Value(v8::ReturnValue<v8::Value> value) : Base(value) {}
28-
Value(VALUE self) : Base(self) {}
14+
Base(v8::ReturnValue<V8Type> value) : Wrapper<v8::ReturnValue<V8Type>>(value) {}
15+
Base(VALUE self) : Wrapper<v8::ReturnValue<V8Type>>(self) {}
2916

3017
static VALUE Set(VALUE self, VALUE handle) {
31-
Value ret(self);
18+
Base<V8Type, RRType> ret(self);
3219
Locker lock(ret->GetIsolate());
33-
v8::Local<v8::Value> value((rr::Value(handle)));
20+
v8::Local<V8Type> value((RRType(handle)));
3421
ret->Set(value);
3522
return Qnil;
3623
}
3724

3825
static VALUE Set_bool(VALUE self, VALUE value) {
39-
Value ret(self);
26+
Base<V8Type, RRType> ret(self);
4027
Locker lock(ret->GetIsolate());
4128
ret->Set((bool)Bool(value));
4229
return Qnil;
4330
}
4431

4532
static VALUE Set_double(VALUE self, VALUE value) {
46-
Value ret(self);
33+
Base<V8Type, RRType> ret(self);
4734
Locker lock(ret->GetIsolate());
4835
ret->Set(NUM2DBL(value));
4936
return Qnil;
5037
}
5138

5239
static VALUE Set_int32_t(VALUE self, VALUE i) {
53-
Value ret(self);
40+
Base<V8Type, RRType> ret(self);
5441
Locker lock(ret->GetIsolate());
5542
ret->Set(NUM2INT(i));
5643
return Qnil;
5744
}
5845

5946
static VALUE Set_uint32_t(VALUE self, VALUE i) {
60-
Value ret(self);
47+
Base<V8Type, RRType> ret(self);
6148
Locker lock(ret->GetIsolate());
6249
ret->Set(NUM2UINT(i));
6350
return Qnil;
6451
}
6552

6653
static VALUE SetNull(VALUE self) {
67-
Value ret(self);
54+
Base<V8Type, RRType> ret(self);
6855
Locker lock(ret->GetIsolate());
6956
ret->SetNull();
7057
return Qnil;
7158
}
7259

7360
static VALUE SetUndefined(VALUE self) {
74-
Value ret(self);
61+
Base<V8Type, RRType> ret(self);
7562
Locker lock(ret->GetIsolate());
7663
ret->SetUndefined();
7764
return Qnil;
7865
}
7966

8067
static VALUE SetEmptyString(VALUE self) {
81-
Value ret(self);
68+
Base<V8Type, RRType> ret(self);
8269
Locker lock(ret->GetIsolate());
8370
ret->SetEmptyString();
8471
return Qnil;
8572
}
8673

74+
static VALUE GetIsolate(VALUE self) {
75+
Base<V8Type, RRType> ret(self);
76+
return Isolate(ret->GetIsolate());
77+
}
78+
79+
};
80+
81+
class Value : public Base<v8::Value, rr::Value> {
82+
public:
83+
Value(v8::ReturnValue<v8::Value> value) : Base<v8::Value, rr::Value>(value) {}
84+
Value(VALUE self) : Base<v8::Value, rr::Value>(self) {}
85+
8786
static inline void Init() {
8887
ClassBuilder("Value", ReturnValue::Class, ReturnValue::Class).
8988
defineMethod("Set", &Set).
@@ -100,11 +99,11 @@ namespace rr {
10099

101100
};
102101

103-
class Void : public Base<void> {
102+
class Void : public Base<void, rr::Value> {
104103
public:
105104

106-
Void(v8::ReturnValue<void> value) : Base(value) {}
107-
Void(VALUE self) : Base(self) {}
105+
Void(v8::ReturnValue<void> value) : Base<void, rr::Value>(value) {}
106+
Void(VALUE self) : Base<void, rr::Value>(self) {}
108107

109108
static inline void Init() {
110109
ClassBuilder("Void", ReturnValue::Class, ReturnValue::Class).

0 commit comments

Comments
 (0)