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

Commit 18c0775

Browse files
committed
remove c++11 features
1 parent 34804a9 commit 18c0775

7 files changed

Lines changed: 131 additions & 100 deletions

File tree

ext/v8/init.cc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ extern "C" {
1919
Primitive::Init();
2020
Name::Init();
2121
Number::Init();
22+
Integer::Init();
23+
Int32::Init();
24+
Uint32::Init();
2225
String::Init();
2326
Symbol::Init();
2427
Function::Init();

ext/v8/int32.h

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// -*- mode: c++ -*-
2+
#ifndef RR_INT32_H
3+
#define RR_INT32_H
4+
5+
namespace rr {
6+
class Int32 : public Ref<v8::Int32> {
7+
public:
8+
Int32(VALUE self) :
9+
Ref<v8::Int32>(self) {}
10+
Int32(v8::Isolate* isolate, v8::Handle<v8::Value> value) :
11+
Ref<v8::Int32>(isolate, value.As<v8::Int32>()) {}
12+
13+
static VALUE Value(VALUE self) {
14+
Int32 int32(self);
15+
Locker lock(int32);
16+
17+
return INT2NUM(int32->Value());
18+
}
19+
20+
static void Init() {
21+
ClassBuilder("Int32", Integer::Class).
22+
defineMethod("Value", &Value).
23+
store(&Int32::Class);
24+
}
25+
};
26+
27+
}
28+
29+
#endif /* RR_INT32_H */

ext/v8/integer.h

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
// -*- mode: c++ -*-
2+
#ifndef RR_INTEGER_H
3+
#define RR_INTEGER_H
4+
5+
namespace rr {
6+
class Integer : public Ref<v8::Integer> {
7+
public:
8+
Integer(v8::Isolate* isolate, int32_t value) :
9+
Ref<v8::Integer>(isolate, v8::Integer::New(isolate, value)) {}
10+
Integer(v8::Isolate* isolate, uint32_t value) :
11+
Ref<v8::Integer>(isolate, v8::Integer::NewFromUnsigned(isolate, value)) {}
12+
Integer(VALUE self) :
13+
Ref<v8::Integer>(self) {}
14+
15+
static VALUE New(VALUE self, VALUE r_isolate, VALUE value) {
16+
Isolate isolate(r_isolate);
17+
Locker lock(isolate);
18+
19+
v8::Local<v8::Integer> i = v8::Integer::New(isolate, NUM2INT(value));
20+
return Value::handleToRubyObject(isolate, i);
21+
}
22+
23+
static VALUE NewFromUnsigned(VALUE self, VALUE r_isolate, VALUE value) {
24+
Isolate isolate(r_isolate);
25+
Locker lock(isolate);
26+
27+
uint32_t uint = NUM2UINT(value);
28+
v8::Local<v8::Integer> i = v8::Integer::NewFromUnsigned(isolate, uint);
29+
return Value::handleToRubyObject(isolate, i);
30+
}
31+
32+
static VALUE Value(VALUE self) {
33+
Integer integer(self);
34+
Locker lock(integer);
35+
36+
return INT2NUM(integer->Value());
37+
}
38+
39+
static void Init() {
40+
ClassBuilder("Integer", Number::Class).
41+
defineSingletonMethod("New", &New).
42+
defineSingletonMethod("NewFromUnsigned", &NewFromUnsigned).
43+
defineMethod("Value", &Value).
44+
store(&Class);
45+
}
46+
};
47+
}
48+
49+
#endif /* RR_INTEGER_H */

ext/v8/number.cc

Lines changed: 0 additions & 69 deletions
This file was deleted.

ext/v8/number.h

Lines changed: 19 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// -*- mode: c++ -*-
2-
#ifndef NUMBER_H
3-
#define NUMBER_H
2+
#ifndef RR_NUMBER_H
3+
#define RR_NUMBER_H
44

55
namespace 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 */

ext/v8/rr.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,18 @@ inline VALUE not_implemented(const char* message) {
3030
#include "handles.h"
3131
#include "context.h"
3232

33-
#include "uint32.h"
3433
#include "value.h"
3534
#include "backref.h"
3635

3736
#include "object.h"
3837
#include "array.h"
3938
#include "primitive.h"
4039
#include "number.h"
40+
#include "integer.h"
41+
#include "int32.h"
42+
#include "uint32.h"
43+
44+
4145
#include "external.h"
4246
// This one is named v8_string to avoid name collisions with C's string.h
4347
#include "name.h"

ext/v8/uint32.h

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,35 @@
11
// -*- mode: c++ -*-
2-
#ifndef RR_UINT32
3-
#define RR_UINT32
2+
#ifndef RR_UINT32_H
3+
#define RR_UINT32_H
4+
5+
6+
namespace rr {
7+
8+
class Uint32 : public Ref<v8::Uint32> {
9+
public:
10+
Uint32(VALUE self) :
11+
Ref<v8::Uint32>(self) {}
12+
Uint32(v8::Isolate* isolate, v8::Handle<v8::Value> value) :
13+
Ref<v8::Uint32>(isolate, value.As<v8::Uint32>()) {}
14+
15+
static VALUE Value(VALUE self) {
16+
Uint32 uint32(self);
17+
Locker lock(uint32);
18+
19+
return UINT2NUM(uint32->Value());
20+
}
21+
22+
static inline void Init() {
23+
ClassBuilder("Uint32", Integer::Class).
24+
defineMethod("Value", &Value).
25+
store(&Class);
26+
}
27+
};
428

529

630
//TODO: remove this at some point. I don't see what this provides
731
//above and beyond just using UINT2NUM and NUM2UINT.
832
// --cowboyd Jul 9, 2015
9-
namespace rr {
1033

1134
/**
1235
* Converts between Ruby `Number` and the C/C++ `uint32_t`.

0 commit comments

Comments
 (0)