33#define RR_INTEGER_H
44
55namespace rr {
6+ class Uint32 : public Ref <v8::Uint32> {
7+ public:
8+ Uint32 (VALUE self) :
9+ Ref<v8::Uint32>(self) {}
10+ Uint32 (v8::Isolate* isolate, v8::Handle<v8::Value> value) :
11+ Ref<v8::Uint32>(isolate, value.As<v8::Uint32>()) {}
12+
13+ static VALUE Value (VALUE self) {
14+ Uint32 uint32 (self);
15+ Locker lock (uint32);
16+
17+ return UINT2NUM (uint32->Value ());
18+ }
19+ };
20+
21+ class Int32 : public Ref <v8::Int32> {
22+ public:
23+ Int32 (VALUE self) :
24+ Ref<v8::Int32>(self) {}
25+ Int32 (v8::Isolate* isolate, v8::Handle<v8::Value> value) :
26+ Ref<v8::Int32>(isolate, value.As<v8::Int32>()) {}
27+
28+ static VALUE Value (VALUE self) {
29+ Int32 int32 (self);
30+ Locker lock (int32);
31+
32+ return INT2NUM (int32->Value ());
33+ }
34+ };
35+
636 class Integer : public Ref <v8::Integer> {
737 public:
838 Integer (v8::Isolate* isolate, v8::Handle<v8::Integer> integer) :
@@ -14,17 +44,21 @@ namespace rr {
1444 Isolate isolate (r_isolate);
1545 Locker lock (isolate);
1646
17- v8::Local<v8::Integer> i = v8::Integer::New (isolate, NUM2INT (value));
18- return Value::handleToRubyObject (isolate, i);
47+ v8::Local<v8::Integer> integer (v8::Integer::New (isolate, NUM2INT (value)));
48+ if (integer->IsUint32 ()) {
49+ return Uint32 (isolate, integer);
50+ } else if (integer->IsInt32 ()) {
51+ return Int32 (isolate, integer);
52+ } else {
53+ return Integer (isolate, integer);
54+ }
1955 }
2056
2157 static VALUE NewFromUnsigned (VALUE self, VALUE r_isolate, VALUE value) {
2258 Isolate isolate (r_isolate);
2359 Locker lock (isolate);
2460
25- uint32_t uint = NUM2UINT (value);
26- v8::Local<v8::Integer> i = v8::Integer::NewFromUnsigned (isolate, uint);
27- return Value::handleToRubyObject (isolate, i);
61+ return Uint32 (isolate, v8::Integer::NewFromUnsigned (isolate, NUM2UINT (value)));
2862 }
2963
3064 static VALUE Value (VALUE self) {
@@ -40,6 +74,14 @@ namespace rr {
4074 defineSingletonMethod (" NewFromUnsigned" , &NewFromUnsigned).
4175 defineMethod (" Value" , &Value).
4276 store (&Class);
77+
78+ ClassBuilder (" Int32" , Integer::Class).
79+ defineMethod (" Value" , &Value).
80+ store (&Int32::Class);
81+
82+ ClassBuilder (" Uint32" , Integer::Class).
83+ defineMethod (" Value" , &Value).
84+ store (&Uint32::Class);
4385 }
4486 };
4587}
0 commit comments