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

Commit 7491cc6

Browse files
committed
Add return value to PropertyCallbackInfo<void>
1 parent 19438dd commit 7491cc6

5 files changed

Lines changed: 118 additions & 72 deletions

File tree

ext/v8/function-callback.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ namespace rr {
102102
static VALUE GetReturnValue(VALUE self) {
103103
FunctionCallbackInfo info(self);
104104
Locker lock(info->GetIsolate());
105-
return ReturnValue(info->GetReturnValue());
105+
return ReturnValue::Value(info->GetReturnValue());
106106
}
107107

108108
static inline void Init() {

ext/v8/init.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ extern "C" {
77
using namespace rr;
88

99
VALUE PropertyCallbackInfo::Class;
10+
VALUE ReturnValue::Class;
1011

1112
extern "C" {
1213
void Init_init() {
Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ namespace rr {
102102
static VALUE GetReturnValue(VALUE self) {
103103
Value info(self);
104104
Locker lock(info->GetIsolate());
105-
return ReturnValue(info->GetReturnValue());
105+
return ReturnValue::Value(info->GetReturnValue());
106106
}
107107

108108
static inline void Init() {
@@ -156,12 +156,18 @@ namespace rr {
156156
);
157157
}
158158

159+
static VALUE GetReturnValue(VALUE self) {
160+
Value info(self);
161+
Locker lock(info->GetIsolate());
162+
return ReturnValue::Void(info->GetReturnValue());
163+
}
164+
159165
static inline void Init() {
160166
ClassBuilder("Void", PropertyCallbackInfo::Class, PropertyCallbackInfo::Class).
161167
defineMethod("This", &This).
162168
defineMethod("Data", &Data).
163169
defineMethod("GetIsolate", &GetIsolate).
164-
// defineMethod("GetReturnValue", &GetReturnValue).
170+
defineMethod("GetReturnValue", &GetReturnValue).
165171
store(&Class);
166172
}
167173

ext/v8/return-value.h

Lines changed: 107 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -3,88 +3,127 @@
33
#define RR_RETURN_VALUE_H
44

55
namespace rr {
6-
typedef Wrapper<v8::ReturnValue<v8::Value>> ReturnValueWrapper;
76

8-
class ReturnValue : public ReturnValueWrapper {
7+
class ReturnValue {
98
public:
10-
ReturnValue(v8::ReturnValue<v8::Value> value) : ReturnValueWrapper(value) {}
11-
ReturnValue(VALUE self) : ReturnValueWrapper(self) {}
12-
13-
static VALUE Set(VALUE self, VALUE handle) {
14-
ReturnValue ret(self);
15-
Locker lock(ret->GetIsolate());
16-
v8::Local<v8::Value> value((Value(handle)));
17-
ret->Set(value);
18-
return Qnil;
19-
}
209

21-
static VALUE Set_bool(VALUE self, VALUE value) {
22-
ReturnValue ret(self);
23-
Locker lock(ret->GetIsolate());
24-
ret->Set((bool)Bool(value));
25-
return Qnil;
26-
}
10+
template <class T>
11+
class Base : public Wrapper<v8::ReturnValue<T>> {
12+
public:
2713

28-
static VALUE Set_double(VALUE self, VALUE value) {
29-
ReturnValue ret(self);
30-
Locker lock(ret->GetIsolate());
31-
ret->Set(NUM2DBL(value));
32-
return Qnil;
33-
}
14+
Base(v8::ReturnValue<T> value) : Wrapper<v8::ReturnValue<T>>(value) {}
15+
Base(VALUE self) : Wrapper<v8::ReturnValue<T>>(self) {}
3416

35-
static VALUE Set_int32_t(VALUE self, VALUE i) {
36-
ReturnValue ret(self);
37-
Locker lock(ret->GetIsolate());
38-
ret->Set(NUM2INT(i));
39-
return Qnil;
40-
}
17+
static VALUE GetIsolate(VALUE self) {
18+
Base<T> ret(self);
19+
return Isolate(ret->GetIsolate());
20+
}
4121

42-
static VALUE Set_uint32_t(VALUE self, VALUE i) {
43-
ReturnValue ret(self);
44-
Locker lock(ret->GetIsolate());
45-
ret->Set(NUM2UINT(i));
46-
return Qnil;
47-
}
22+
};
4823

49-
static VALUE SetNull(VALUE self) {
50-
ReturnValue ret(self);
51-
Locker lock(ret->GetIsolate());
52-
ret->SetNull();
53-
return Qnil;
54-
}
24+
class Value : public Base<v8::Value> {
25+
public:
5526

56-
static VALUE SetUndefined(VALUE self) {
57-
ReturnValue ret(self);
58-
Locker lock(ret->GetIsolate());
59-
ret->SetUndefined();
60-
return Qnil;
61-
}
27+
Value(v8::ReturnValue<v8::Value> value) : Base(value) {}
28+
Value(VALUE self) : Base(self) {}
6229

63-
static VALUE SetEmptyString(VALUE self) {
64-
ReturnValue ret(self);
65-
Locker lock(ret->GetIsolate());
66-
ret->SetEmptyString();
67-
return Qnil;
68-
}
30+
static VALUE Set(VALUE self, VALUE handle) {
31+
Value ret(self);
32+
Locker lock(ret->GetIsolate());
33+
v8::Local<v8::Value> value((rr::Value(handle)));
34+
ret->Set(value);
35+
return Qnil;
36+
}
6937

70-
static VALUE GetIsolate(VALUE self) {
71-
ReturnValue ret(self);
72-
return Isolate(ret->GetIsolate());
73-
}
38+
static VALUE Set_bool(VALUE self, VALUE value) {
39+
Value ret(self);
40+
Locker lock(ret->GetIsolate());
41+
ret->Set((bool)Bool(value));
42+
return Qnil;
43+
}
44+
45+
static VALUE Set_double(VALUE self, VALUE value) {
46+
Value ret(self);
47+
Locker lock(ret->GetIsolate());
48+
ret->Set(NUM2DBL(value));
49+
return Qnil;
50+
}
51+
52+
static VALUE Set_int32_t(VALUE self, VALUE i) {
53+
Value ret(self);
54+
Locker lock(ret->GetIsolate());
55+
ret->Set(NUM2INT(i));
56+
return Qnil;
57+
}
58+
59+
static VALUE Set_uint32_t(VALUE self, VALUE i) {
60+
Value ret(self);
61+
Locker lock(ret->GetIsolate());
62+
ret->Set(NUM2UINT(i));
63+
return Qnil;
64+
}
7465

75-
static inline void Init() {
66+
static VALUE SetNull(VALUE self) {
67+
Value ret(self);
68+
Locker lock(ret->GetIsolate());
69+
ret->SetNull();
70+
return Qnil;
71+
}
72+
73+
static VALUE SetUndefined(VALUE self) {
74+
Value ret(self);
75+
Locker lock(ret->GetIsolate());
76+
ret->SetUndefined();
77+
return Qnil;
78+
}
79+
80+
static VALUE SetEmptyString(VALUE self) {
81+
Value ret(self);
82+
Locker lock(ret->GetIsolate());
83+
ret->SetEmptyString();
84+
return Qnil;
85+
}
86+
87+
static inline void Init() {
88+
ClassBuilder("Value", ReturnValue::Class, ReturnValue::Class).
89+
defineMethod("Set", &Set).
90+
defineMethod("Set_bool", &Set_bool).
91+
defineMethod("Set_double", &Set_double).
92+
defineMethod("Set_int32_t", &Set_int32_t).
93+
defineMethod("Set_uint32_t", &Set_uint32_t).
94+
defineMethod("SetNull", &SetNull).
95+
defineMethod("SetUndefined", &SetUndefined).
96+
defineMethod("SetEmptyString", &SetEmptyString).
97+
defineMethod("GetIsolate", &GetIsolate).
98+
store(&Class);
99+
}
100+
101+
};
102+
103+
class Void : public Base<void> {
104+
public:
105+
106+
Void(v8::ReturnValue<void> value) : Base(value) {}
107+
Void(VALUE self) : Base(self) {}
108+
109+
static inline void Init() {
110+
ClassBuilder("Void", ReturnValue::Class, ReturnValue::Class).
111+
defineMethod("GetIsolate", &GetIsolate).
112+
store(&Class);
113+
}
114+
115+
};
116+
117+
static VALUE Class;
118+
119+
static void Init() {
76120
ClassBuilder("ReturnValue").
77-
defineMethod("Set", &Set).
78-
defineMethod("Set_bool", &Set_bool).
79-
defineMethod("Set_double", &Set_double).
80-
defineMethod("Set_int32_t", &Set_int32_t).
81-
defineMethod("Set_uint32_t", &Set_uint32_t).
82-
defineMethod("SetNull", &SetNull).
83-
defineMethod("SetUndefined", &SetUndefined).
84-
defineMethod("SetEmptyString", &SetEmptyString).
85-
defineMethod("GetIsolate", &GetIsolate).
86121
store(&Class);
122+
123+
Value::Init();
124+
Void::Init();
87125
}
126+
88127
};
89128
}
90129
#endif /* RR_RETURN_VALUE_H */

ext/v8/rr.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ inline VALUE not_implemented(const char* message) {
5353

5454
#include "object.h"
5555
#include "return-value.h"
56-
#include "property-callback.h"
56+
#include "property-callback-info.h"
5757
#include "array.h"
5858

5959
#include "script.h"

0 commit comments

Comments
 (0)