|
| 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 */ |
0 commit comments