mirror of
https://github.com/rubyjs/therubyracer
synced 2023-03-27 23:21:42 -04:00
remove c++11 features
This commit is contained in:
parent
34804a9909
commit
18c07758a9
7 changed files with 131 additions and 100 deletions
|
@ -19,6 +19,9 @@ extern "C" {
|
|||
Primitive::Init();
|
||||
Name::Init();
|
||||
Number::Init();
|
||||
Integer::Init();
|
||||
Int32::Init();
|
||||
Uint32::Init();
|
||||
String::Init();
|
||||
Symbol::Init();
|
||||
Function::Init();
|
||||
|
|
29
ext/v8/int32.h
Normal file
29
ext/v8/int32.h
Normal file
|
@ -0,0 +1,29 @@
|
|||
// -*- mode: c++ -*-
|
||||
#ifndef RR_INT32_H
|
||||
#define RR_INT32_H
|
||||
|
||||
namespace rr {
|
||||
class Int32 : public Ref<v8::Int32> {
|
||||
public:
|
||||
Int32(VALUE self) :
|
||||
Ref<v8::Int32>(self) {}
|
||||
Int32(v8::Isolate* isolate, v8::Handle<v8::Value> value) :
|
||||
Ref<v8::Int32>(isolate, value.As<v8::Int32>()) {}
|
||||
|
||||
static VALUE Value(VALUE self) {
|
||||
Int32 int32(self);
|
||||
Locker lock(int32);
|
||||
|
||||
return INT2NUM(int32->Value());
|
||||
}
|
||||
|
||||
static void Init() {
|
||||
ClassBuilder("Int32", Integer::Class).
|
||||
defineMethod("Value", &Value).
|
||||
store(&Int32::Class);
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif /* RR_INT32_H */
|
49
ext/v8/integer.h
Normal file
49
ext/v8/integer.h
Normal file
|
@ -0,0 +1,49 @@
|
|||
// -*- mode: c++ -*-
|
||||
#ifndef RR_INTEGER_H
|
||||
#define RR_INTEGER_H
|
||||
|
||||
namespace rr {
|
||||
class Integer : public Ref<v8::Integer> {
|
||||
public:
|
||||
Integer(v8::Isolate* isolate, int32_t value) :
|
||||
Ref<v8::Integer>(isolate, v8::Integer::New(isolate, value)) {}
|
||||
Integer(v8::Isolate* isolate, uint32_t value) :
|
||||
Ref<v8::Integer>(isolate, v8::Integer::NewFromUnsigned(isolate, value)) {}
|
||||
Integer(VALUE self) :
|
||||
Ref<v8::Integer>(self) {}
|
||||
|
||||
static VALUE New(VALUE self, VALUE r_isolate, VALUE value) {
|
||||
Isolate isolate(r_isolate);
|
||||
Locker lock(isolate);
|
||||
|
||||
v8::Local<v8::Integer> i = v8::Integer::New(isolate, NUM2INT(value));
|
||||
return Value::handleToRubyObject(isolate, i);
|
||||
}
|
||||
|
||||
static VALUE NewFromUnsigned(VALUE self, VALUE r_isolate, VALUE value) {
|
||||
Isolate isolate(r_isolate);
|
||||
Locker lock(isolate);
|
||||
|
||||
uint32_t uint = NUM2UINT(value);
|
||||
v8::Local<v8::Integer> i = v8::Integer::NewFromUnsigned(isolate, uint);
|
||||
return Value::handleToRubyObject(isolate, i);
|
||||
}
|
||||
|
||||
static VALUE Value(VALUE self) {
|
||||
Integer integer(self);
|
||||
Locker lock(integer);
|
||||
|
||||
return INT2NUM(integer->Value());
|
||||
}
|
||||
|
||||
static void Init() {
|
||||
ClassBuilder("Integer", Number::Class).
|
||||
defineSingletonMethod("New", &New).
|
||||
defineSingletonMethod("NewFromUnsigned", &NewFromUnsigned).
|
||||
defineMethod("Value", &Value).
|
||||
store(&Class);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
#endif /* RR_INTEGER_H */
|
|
@ -1,69 +0,0 @@
|
|||
#include "rr.h"
|
||||
|
||||
namespace rr {
|
||||
void Number::Init() {
|
||||
ClassBuilder("Number", Primitive::Class).
|
||||
|
||||
defineSingletonMethod("New", [] (VALUE self, VALUE r_isolate, VALUE value) -> VALUE {
|
||||
Isolate isolate(r_isolate);
|
||||
Locker lock(isolate);
|
||||
|
||||
return Number(isolate, NUM2DBL(value));
|
||||
}).
|
||||
|
||||
defineMethod("Value", [] (VALUE self) -> VALUE {
|
||||
Number number(self);
|
||||
Locker lock(number);
|
||||
|
||||
return DBL2NUM(number->Value());
|
||||
}).
|
||||
|
||||
store(&Class);
|
||||
|
||||
ClassBuilder("Integer", Number::Class).
|
||||
|
||||
defineSingletonMethod("New", [] (VALUE self, VALUE r_isolate, VALUE value) -> VALUE {
|
||||
Isolate isolate(r_isolate);
|
||||
Locker lock(isolate);
|
||||
|
||||
auto integer = v8::Integer::New(isolate, NUM2INT(value));
|
||||
return Value::handleToRubyObject(isolate, integer);
|
||||
}).
|
||||
|
||||
defineSingletonMethod("NewFromUnsigned", [] (VALUE self, VALUE r_isolate, VALUE value) -> VALUE {
|
||||
Isolate isolate(r_isolate);
|
||||
Locker lock(isolate);
|
||||
|
||||
auto uint = v8::Integer::NewFromUnsigned(isolate, NUM2UINT(value));
|
||||
return Value::handleToRubyObject(isolate, uint);
|
||||
}).
|
||||
|
||||
defineMethod("Value", [] (VALUE self) -> VALUE {
|
||||
Integer integer(self);
|
||||
Locker lock(integer);
|
||||
|
||||
return INT2NUM(integer->Value());
|
||||
}).
|
||||
|
||||
store(&Integer::Class);
|
||||
|
||||
ClassBuilder("Int32", Integer::Class).
|
||||
|
||||
defineMethod("Value", [] (VALUE self) -> VALUE {
|
||||
Int32 int32(self);
|
||||
Locker lock(int32);
|
||||
|
||||
return INT2NUM(int32->Value());
|
||||
}).
|
||||
store(&Int32::Class);
|
||||
|
||||
ClassBuilder("Uint32", Integer::Class).
|
||||
defineMethod("Value", [] (VALUE self) -> VALUE {
|
||||
Uint32 uint32(self);
|
||||
Locker lock(uint32);
|
||||
|
||||
return UINT2NUM(uint32->Value());
|
||||
}).
|
||||
store(&Uint32::Class);
|
||||
}
|
||||
}
|
|
@ -1,6 +1,6 @@
|
|||
// -*- mode: c++ -*-
|
||||
#ifndef NUMBER_H
|
||||
#define NUMBER_H
|
||||
#ifndef RR_NUMBER_H
|
||||
#define RR_NUMBER_H
|
||||
|
||||
namespace rr {
|
||||
class Number : public Ref<v8::Number> {
|
||||
|
@ -12,35 +12,27 @@ namespace rr {
|
|||
Number(VALUE self) :
|
||||
Ref<v8::Number>(self) {}
|
||||
|
||||
static void Init();
|
||||
};
|
||||
static VALUE New(VALUE self, VALUE r_isolate, VALUE value) {
|
||||
Isolate isolate(r_isolate);
|
||||
Locker lock(isolate);
|
||||
|
||||
class Integer : public Ref<v8::Integer> {
|
||||
public:
|
||||
Integer(v8::Isolate* isolate, int32_t value) :
|
||||
Ref<v8::Integer>(isolate, v8::Integer::New(isolate, value)) {}
|
||||
Integer(v8::Isolate* isolate, uint32_t value) :
|
||||
Ref<v8::Integer>(isolate, v8::Integer::NewFromUnsigned(isolate, value)) {}
|
||||
Integer(VALUE self) :
|
||||
Ref<v8::Integer>(self) {}
|
||||
};
|
||||
return Number(isolate, NUM2DBL(value));
|
||||
}
|
||||
|
||||
class Int32 : public Ref<v8::Int32> {
|
||||
public:
|
||||
Int32(VALUE self) :
|
||||
Ref<v8::Int32>(self) {}
|
||||
Int32(v8::Isolate* isolate, v8::Handle<v8::Value> value) :
|
||||
Ref<v8::Int32>(isolate, value.As<v8::Int32>()) {}
|
||||
};
|
||||
static VALUE Value(VALUE self) {
|
||||
Number number(self);
|
||||
Locker lock(number);
|
||||
|
||||
class Uint32 : public Ref<v8::Uint32> {
|
||||
public:
|
||||
Uint32(VALUE self) :
|
||||
Ref<v8::Uint32>(self) {}
|
||||
Uint32(v8::Isolate* isolate, v8::Handle<v8::Value> value) :
|
||||
Ref<v8::Uint32>(isolate, value.As<v8::Uint32>()) {}
|
||||
return DBL2NUM(number->Value());
|
||||
}
|
||||
static void Init() {
|
||||
ClassBuilder("Number", Primitive::Class).
|
||||
defineSingletonMethod("New", &New).
|
||||
defineMethod("Value", &Value).
|
||||
store(&Class);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
#endif /* NUMBER_H */
|
||||
#endif /* RR_NUMBER_H */
|
||||
|
|
|
@ -30,7 +30,6 @@ inline VALUE not_implemented(const char* message) {
|
|||
#include "handles.h"
|
||||
#include "context.h"
|
||||
|
||||
#include "uint32.h"
|
||||
#include "value.h"
|
||||
#include "backref.h"
|
||||
|
||||
|
@ -38,6 +37,11 @@ inline VALUE not_implemented(const char* message) {
|
|||
#include "array.h"
|
||||
#include "primitive.h"
|
||||
#include "number.h"
|
||||
#include "integer.h"
|
||||
#include "int32.h"
|
||||
#include "uint32.h"
|
||||
|
||||
|
||||
#include "external.h"
|
||||
// This one is named v8_string to avoid name collisions with C's string.h
|
||||
#include "name.h"
|
||||
|
|
|
@ -1,12 +1,35 @@
|
|||
// -*- mode: c++ -*-
|
||||
#ifndef RR_UINT32
|
||||
#define RR_UINT32
|
||||
#ifndef RR_UINT32_H
|
||||
#define RR_UINT32_H
|
||||
|
||||
|
||||
namespace rr {
|
||||
|
||||
class Uint32 : public Ref<v8::Uint32> {
|
||||
public:
|
||||
Uint32(VALUE self) :
|
||||
Ref<v8::Uint32>(self) {}
|
||||
Uint32(v8::Isolate* isolate, v8::Handle<v8::Value> value) :
|
||||
Ref<v8::Uint32>(isolate, value.As<v8::Uint32>()) {}
|
||||
|
||||
static VALUE Value(VALUE self) {
|
||||
Uint32 uint32(self);
|
||||
Locker lock(uint32);
|
||||
|
||||
return UINT2NUM(uint32->Value());
|
||||
}
|
||||
|
||||
static inline void Init() {
|
||||
ClassBuilder("Uint32", Integer::Class).
|
||||
defineMethod("Value", &Value).
|
||||
store(&Class);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
//TODO: remove this at some point. I don't see what this provides
|
||||
//above and beyond just using UINT2NUM and NUM2UINT.
|
||||
// --cowboyd Jul 9, 2015
|
||||
namespace rr {
|
||||
|
||||
/**
|
||||
* Converts between Ruby `Number` and the C/C++ `uint32_t`.
|
||||
|
|
Loading…
Add table
Reference in a new issue