1
0
Fork 0
mirror of https://github.com/rubyjs/therubyracer synced 2023-03-27 23:21:42 -04:00

expose all v8:Context methods.

This commit is contained in:
Charles Lowell 2012-05-08 16:04:47 -05:00
parent 0800d82988
commit b9b15e8838
5 changed files with 122 additions and 5 deletions

View file

@ -2,11 +2,96 @@
namespace rr {
VALUE Context::Class;
void Context::Init() {
ClassBuilder("Context").
defineSingletonMethod("New", &New).
defineSingletonMethod("GetCurrent", &GetCurrent).
defineSingletonMethod("GetEntered", &GetEntered).
defineSingletonMethod("GetCalling", &GetCalling).
defineSingletonMethod("InContext", &InContext).
defineMethod("Global", &Global).
defineMethod("DetachGlobal", &Global).
defineMethod("ReattachGlobal", &ReattachGlobal).
defineMethod("SetSecurityToken", &SetSecurityToken).
defineMethod("UseDefaultSecurityToken", &UseDefaultSecurityToken).
defineMethod("GetSecurityToken", &GetSecurityToken).
defineMethod("HasOutOfMemoryException", &HasOutOfMemoryException).
defineMethod("SetData", &SetData).
defineMethod("GetData", &GetData).
defineMethod("AllowCodeGenerationFromStrings", &AllowCodeGenerationFromStrings).
defineMethod("IsCodeGenerationFromStringsAllowed", &IsCodeGenerationFromStringsAllowed).
defineMethod("Enter", &Enter).
defineMethod("Exit", &Exit);
defineMethod("Exit", &Exit).
store(&Class);
}
VALUE Context::Global(VALUE self) {
return Convert(Context(self)->Global());
}
VALUE Context::DetachGlobal(VALUE self) {
Context(self)->DetachGlobal();
return Qnil;
}
VALUE Context::ReattachGlobal(VALUE self, VALUE global) {
Context(self)->ReattachGlobal(Object(global));
return Qnil;
}
VALUE Context::GetEntered(VALUE self) {
return Context::create(v8::Context::GetEntered(), Class);
}
VALUE Context::GetCurrent(VALUE self) {
return Context::create(v8::Context::GetCurrent(), Class);
}
VALUE Context::GetCalling(VALUE self) {
return Context::create(v8::Context::GetCalling(), Class);
}
VALUE Context::SetSecurityToken(VALUE self, VALUE token) {
Context(self)->SetSecurityToken(Value(token));
return Qnil;
}
VALUE Context::UseDefaultSecurityToken(VALUE self) {
Context(self)->UseDefaultSecurityToken();
return Qnil;
}
VALUE Context::GetSecurityToken(VALUE self) {
return Convert(Context(self)->GetSecurityToken());
}
VALUE Context::HasOutOfMemoryException(VALUE self) {
return Convert(Context(self)->HasOutOfMemoryException());
}
VALUE Context::InContext(VALUE self) {
return Convert(v8::Context::InContext());
}
VALUE Context::SetData(VALUE self, VALUE data) {
Context(self)->SetData(String(data));
return Qnil;
}
VALUE Context::GetData(VALUE self) {
return Convert(Context(self)->GetData());
}
VALUE Context::AllowCodeGenerationFromStrings(VALUE self, VALUE allow) {
Context(self)->AllowCodeGenerationFromStrings(RTEST(allow));
return Qnil;
}
VALUE Context::IsCodeGenerationFromStringsAllowed(VALUE self) {
return Convert(Context(self)->IsCodeGenerationFromStringsAllowed());
}
VALUE Context::New(VALUE ContextClass) {

View file

@ -59,4 +59,9 @@ namespace rr {
rb_define_const(this->value, name, INT2FIX(value));
return *this;
}
ClassBuilder& ClassBuilder::store(VALUE* storage) {
rb_gc_register_address(storage);
*storage = this->value;
return *this;
}
}

View file

@ -120,8 +120,23 @@ public:
static VALUE New(VALUE self);
static VALUE Enter(VALUE self);
static VALUE Exit(VALUE self);
static VALUE Global(VALUE self);
static VALUE DetachGlobal(VALUE self);
static VALUE ReattachGlobal(VALUE self, VALUE global);
static VALUE GetEntered(VALUE self);
static VALUE GetCurrent(VALUE self);
static VALUE GetCalling(VALUE self);
static VALUE SetSecurityToken(VALUE self, VALUE token);
static VALUE UseDefaultSecurityToken(VALUE self);
static VALUE GetSecurityToken(VALUE self);
static VALUE HasOutOfMemoryException(VALUE self);
static VALUE InContext(VALUE self);
static VALUE SetData(VALUE self, VALUE data);
static VALUE GetData(VALUE self);
static VALUE AllowCodeGenerationFromStrings(VALUE self, VALUE allow);
static VALUE IsCodeGenerationFromStringsAllowed(VALUE self);
private:
static VALUE Class;
inline Context(VALUE value) : Ref<v8::Context>(value) {}
};
@ -209,6 +224,7 @@ public:
ClassBuilder& defineSingletonMethod(const char* name, VALUE (*impl)(VALUE, VALUE));
ClassBuilder& defineSingletonMethod(const char* name, VALUE (*impl)(VALUE, VALUE, VALUE));
ClassBuilder& defineEnumConst(const char* name, int value);
ClassBuilder& store(VALUE* storage);
inline operator VALUE() {return this->value;}
private:
VALUE value;

View file

@ -5,10 +5,10 @@ namespace rr {
VALUE String::Class;
void String::Init() {
rb_gc_register_address(&Class);
Class = ClassBuilder("String", "Value").
ClassBuilder("String", "Value").
defineSingletonMethod("New", &New).
defineMethod("Utf8Value", &Utf8Value);
defineMethod("Utf8Value", &Utf8Value).
store(&Class);
}
VALUE String::New(VALUE StringClass, VALUE string) {

View file

@ -17,5 +17,16 @@ module V8
ensure
@native.Exit()
end
def []=(key, value)
V8::C::HandleScope() do
@native.Global().Set(key, value)
end
end
def [](key)
V8::C::HandleScope() do
@native.Global().Get(key)
end
end
end
end