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

Commit 3792d74

Browse files
committed
extract ReturnValue into its own file
1 parent c6c9bc3 commit 3792d74

4 files changed

Lines changed: 93 additions & 84 deletions

File tree

ext/v8/function-callback.h

Lines changed: 0 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -4,90 +4,6 @@
44

55
namespace rr {
66

7-
typedef Wrapper<v8::ReturnValue<v8::Value>> ReturnValueWrapper;
8-
9-
class ReturnValue : public ReturnValueWrapper {
10-
public:
11-
ReturnValue(v8::ReturnValue<v8::Value> value) : ReturnValueWrapper(value) {}
12-
ReturnValue(VALUE self) : ReturnValueWrapper(self) {}
13-
14-
static VALUE Set(VALUE self, VALUE handle) {
15-
ReturnValue ret(self);
16-
Locker lock(ret->GetIsolate());
17-
v8::Local<v8::Value> value((Value(handle)));
18-
ret->Set(value);
19-
return Qnil;
20-
}
21-
22-
static VALUE Set_bool(VALUE self, VALUE value) {
23-
ReturnValue ret(self);
24-
Locker lock(ret->GetIsolate());
25-
ret->Set((bool)Bool(value));
26-
return Qnil;
27-
}
28-
29-
static VALUE Set_double(VALUE self, VALUE value) {
30-
ReturnValue ret(self);
31-
Locker lock(ret->GetIsolate());
32-
ret->Set(NUM2DBL(value));
33-
return Qnil;
34-
}
35-
36-
static VALUE Set_int32_t(VALUE self, VALUE i) {
37-
ReturnValue ret(self);
38-
Locker lock(ret->GetIsolate());
39-
ret->Set(NUM2INT(i));
40-
return Qnil;
41-
}
42-
43-
static VALUE Set_uint32_t(VALUE self, VALUE i) {
44-
ReturnValue ret(self);
45-
Locker lock(ret->GetIsolate());
46-
ret->Set(NUM2UINT(i));
47-
return Qnil;
48-
}
49-
50-
static VALUE SetNull(VALUE self) {
51-
ReturnValue ret(self);
52-
Locker lock(ret->GetIsolate());
53-
ret->SetNull();
54-
return Qnil;
55-
}
56-
57-
static VALUE SetUndefined(VALUE self) {
58-
ReturnValue ret(self);
59-
Locker lock(ret->GetIsolate());
60-
ret->SetUndefined();
61-
return Qnil;
62-
}
63-
64-
static VALUE SetEmptyString(VALUE self) {
65-
ReturnValue ret(self);
66-
Locker lock(ret->GetIsolate());
67-
ret->SetEmptyString();
68-
return Qnil;
69-
}
70-
71-
static VALUE GetIsolate(VALUE self) {
72-
ReturnValue ret(self);
73-
return Isolate(ret->GetIsolate());
74-
}
75-
76-
static inline void Init() {
77-
ClassBuilder("ReturnValue").
78-
defineMethod("Set", &Set).
79-
defineMethod("Set_bool", &Set_bool).
80-
defineMethod("Set_double", &Set_double).
81-
defineMethod("Set_int32_t", &Set_int32_t).
82-
defineMethod("Set_uint32_t", &Set_uint32_t).
83-
defineMethod("SetNull", &SetNull).
84-
defineMethod("SetUndefined", &SetUndefined).
85-
defineMethod("SetEmptyString", &SetEmptyString).
86-
defineMethod("GetIsolate", &GetIsolate).
87-
store(&Class);
88-
}
89-
};
90-
917
typedef Wrapper<v8::FunctionCallbackInfo<v8::Value>> FunctionCallbackInfoWrapper;
928

939
class FunctionCallbackInfo : public FunctionCallbackInfoWrapper {

ext/v8/function.cc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ namespace rr {
2626
Isolate isolate(r_isolate);
2727
Locker lock(isolate);
2828

29+
// package up the function's callback data to have bot the code and the data
30+
// parameter.
2931
v8::Local<v8::Value> data(FunctionCallbackInfo::wrapData(isolate, r_callback, r_data));
3032

3133
int length = RTEST(r_length) ? NUM2INT(r_length) : 0;

ext/v8/return-value.h

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
// -*- mode: c++ -*-
2+
#ifndef RR_RETURN_VALUE_H
3+
#define RR_RETURN_VALUE_H
4+
5+
namespace rr {
6+
typedef Wrapper<v8::ReturnValue<v8::Value>> ReturnValueWrapper;
7+
8+
class ReturnValue : public ReturnValueWrapper {
9+
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+
}
20+
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+
}
27+
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+
}
34+
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+
}
41+
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+
}
48+
49+
static VALUE SetNull(VALUE self) {
50+
ReturnValue ret(self);
51+
Locker lock(ret->GetIsolate());
52+
ret->SetNull();
53+
return Qnil;
54+
}
55+
56+
static VALUE SetUndefined(VALUE self) {
57+
ReturnValue ret(self);
58+
Locker lock(ret->GetIsolate());
59+
ret->SetUndefined();
60+
return Qnil;
61+
}
62+
63+
static VALUE SetEmptyString(VALUE self) {
64+
ReturnValue ret(self);
65+
Locker lock(ret->GetIsolate());
66+
ret->SetEmptyString();
67+
return Qnil;
68+
}
69+
70+
static VALUE GetIsolate(VALUE self) {
71+
ReturnValue ret(self);
72+
return Isolate(ret->GetIsolate());
73+
}
74+
75+
static inline void Init() {
76+
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).
86+
store(&Class);
87+
}
88+
};
89+
}
90+
#endif /* RR_RETURN_VALUE_H */

ext/v8/rr.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ inline VALUE not_implemented(const char* message) {
4747
#include "script.h"
4848
#include "script-origin.h"
4949
#include "function.h"
50+
#include "return-value.h"
5051
#include "function-callback.h"
5152

5253
#endif

0 commit comments

Comments
 (0)