11// -*- mode: c++ -*-
2- #ifndef NUMBER_H
3- #define NUMBER_H
2+ #ifndef RR_NUMBER_H
3+ #define RR_NUMBER_H
44
55namespace rr {
66 class Number : public Ref <v8::Number> {
@@ -12,35 +12,27 @@ namespace rr {
1212 Number (VALUE self) :
1313 Ref<v8::Number>(self) {}
1414
15- static void Init ();
16- };
15+ static VALUE New (VALUE self, VALUE r_isolate, VALUE value) {
16+ Isolate isolate (r_isolate);
17+ Locker lock (isolate);
1718
18- class Integer : public Ref <v8::Integer> {
19- public:
20- Integer (v8::Isolate* isolate, int32_t value) :
21- Ref<v8::Integer>(isolate, v8::Integer::New(isolate, value)) {}
22- Integer (v8::Isolate* isolate, uint32_t value) :
23- Ref<v8::Integer>(isolate, v8::Integer::NewFromUnsigned(isolate, value)) {}
24- Integer (VALUE self) :
25- Ref<v8::Integer>(self) {}
26- };
19+ return Number (isolate, NUM2DBL (value));
20+ }
2721
28- class Int32 : public Ref <v8::Int32> {
29- public:
30- Int32 (VALUE self) :
31- Ref<v8::Int32>(self) {}
32- Int32 (v8::Isolate* isolate, v8::Handle<v8::Value> value) :
33- Ref<v8::Int32>(isolate, value.As<v8::Int32>()) {}
34- };
22+ static VALUE Value (VALUE self) {
23+ Number number (self);
24+ Locker lock (number);
3525
36- class Uint32 : public Ref <v8::Uint32> {
37- public:
38- Uint32 (VALUE self) :
39- Ref<v8::Uint32>(self) {}
40- Uint32 (v8::Isolate* isolate, v8::Handle<v8::Value> value) :
41- Ref<v8::Uint32>(isolate, value.As<v8::Uint32>()) {}
26+ return DBL2NUM (number->Value ());
27+ }
28+ static void Init () {
29+ ClassBuilder (" Number" , Primitive::Class).
30+ defineSingletonMethod (" New" , &New).
31+ defineMethod (" Value" , &Value).
32+ store (&Class);
33+ }
4234 };
4335}
4436
4537
46- #endif /* NUMBER_H */
38+ #endif /* RR_NUMBER_H */
0 commit comments