mirror of
https://github.com/rubyjs/therubyracer
synced 2023-03-27 23:21:42 -04:00
49 lines
1 KiB
C++
49 lines
1 KiB
C++
#include <v8_object.h>
|
|
#include <ruby_data.h>
|
|
#include <v8_data.h>
|
|
#include <generic_data.h>
|
|
|
|
VALUE rb_cV8_JSObject;
|
|
|
|
using namespace v8;
|
|
|
|
v8_object::v8_object() : handle(Persistent<Object>(*Object::New())) {
|
|
dispose = false;
|
|
}
|
|
v8_object::v8_object(Handle<Object>& object) : handle(Persistent<Object>(*object)) {
|
|
dispose = true;
|
|
}
|
|
v8_object::~v8_object() {
|
|
if (dispose) {
|
|
handle.Dispose();
|
|
}
|
|
|
|
}
|
|
|
|
VALUE v8_object_hash_access(VALUE self, VALUE key) {
|
|
v8_object* object = 0;
|
|
Data_Get_Struct(self, struct v8_object, object);
|
|
|
|
RubyValueSource<StringDest, std::string> tostring;
|
|
const std::string cppkey(tostring.push(key));
|
|
|
|
HandleScope scope;
|
|
Handle<Value> result = object->handle->Get(String::New(cppkey.c_str()));
|
|
|
|
V8HandleSource<RubyDest, VALUE> toValue;
|
|
return toValue.push(result);
|
|
}
|
|
|
|
VALUE v8_object_allocate(VALUE clazz) {
|
|
v8_object *wrapper = new v8_object;
|
|
return Data_Wrap_Struct(clazz, v8_object_mark, v8_object_free, wrapper);
|
|
}
|
|
|
|
void v8_object_mark(v8_object *o) {
|
|
|
|
}
|
|
void v8_object_free(v8_object *o) {
|
|
delete o;
|
|
}
|
|
|
|
|