mirror of
https://github.com/rubyjs/therubyracer
synced 2023-03-27 23:21:42 -04:00
Use more conventional means layout for .cc files
This commit is contained in:
parent
99d225c450
commit
889918adae
5 changed files with 76 additions and 62 deletions
|
@ -2,27 +2,28 @@
|
|||
|
||||
namespace rr {
|
||||
|
||||
VALUE New(VALUE ContextClass) {
|
||||
v8::Persistent<v8::Context> context = v8::Context::New();
|
||||
Ref<v8::Context> ref = Context::create(context, ContextClass);
|
||||
context.Dispose();
|
||||
return ref;
|
||||
}
|
||||
void Context::Init() {
|
||||
ClassBuilder("Context").
|
||||
defineSingletonMethod("New", &New).
|
||||
defineMethod("Enter", &Enter).
|
||||
defineMethod("Exit", &Exit);
|
||||
}
|
||||
|
||||
VALUE Enter(VALUE self) {
|
||||
Context(self)->Enter();
|
||||
return Qnil;
|
||||
}
|
||||
VALUE Context::New(VALUE ContextClass) {
|
||||
v8::Persistent<v8::Context> context = v8::Context::New();
|
||||
Ref<v8::Context> ref = Context::create(context, ContextClass);
|
||||
context.Dispose();
|
||||
return ref;
|
||||
}
|
||||
|
||||
VALUE Exit(VALUE self) {
|
||||
Context(self)->Exit();
|
||||
return Qnil;
|
||||
}
|
||||
VALUE Context::Enter(VALUE self) {
|
||||
Context(self)->Enter();
|
||||
return Qnil;
|
||||
}
|
||||
|
||||
void Context::Init() {
|
||||
ClassBuilder("Context").
|
||||
defineSingletonMethod("New", &New).
|
||||
defineMethod("Enter", &Enter).
|
||||
defineMethod("Exit", &Exit);
|
||||
}
|
||||
}
|
||||
VALUE Context::Exit(VALUE self) {
|
||||
Context(self)->Exit();
|
||||
return Qnil;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
20
ext/v8/rr.h
20
ext/v8/rr.h
|
@ -100,28 +100,42 @@ public:
|
|||
|
||||
class Context : public Ref<v8::Context> {
|
||||
public:
|
||||
inline Context(VALUE value) : Ref<v8::Context>(value) {}
|
||||
static void Init();
|
||||
static VALUE New(VALUE self);
|
||||
static VALUE Enter(VALUE self);
|
||||
static VALUE Exit(VALUE self);
|
||||
|
||||
private:
|
||||
inline Context(VALUE value) : Ref<v8::Context>(value) {}
|
||||
};
|
||||
|
||||
class Script : public Ref<v8::Script> {
|
||||
public:
|
||||
inline Script(VALUE value) : Ref<v8::Script>(value) {}
|
||||
static void Init();
|
||||
static VALUE New(VALUE klass, VALUE source, VALUE filename);
|
||||
static VALUE Run(VALUE self);
|
||||
|
||||
private:
|
||||
inline Script(VALUE value) : Ref<v8::Script>(value) {}
|
||||
};
|
||||
|
||||
class String: public Ref<v8::String> {
|
||||
public:
|
||||
static void Init();
|
||||
static VALUE New(VALUE self, VALUE value);
|
||||
static VALUE Utf8Value(VALUE self);
|
||||
|
||||
inline String(VALUE value) : Ref<v8::String>(value) {}
|
||||
virtual operator v8::Handle<v8::Value>();
|
||||
static VALUE ToRuby(v8::Handle<v8::String> value);
|
||||
static void Init();
|
||||
private:
|
||||
static VALUE Class;
|
||||
};
|
||||
|
||||
class V8 {
|
||||
public:
|
||||
static void Init();
|
||||
static VALUE IdleNotification(VALUE self);
|
||||
};
|
||||
|
||||
class ClassBuilder {
|
||||
|
|
|
@ -1,19 +1,6 @@
|
|||
#include "rr.h"
|
||||
|
||||
namespace rr {
|
||||
namespace {
|
||||
|
||||
VALUE New(VALUE klass, VALUE source, VALUE filename) {
|
||||
v8::HandleScope scope;
|
||||
return Script::create(v8::Script::New(String(source), Value(filename)), klass);
|
||||
}
|
||||
|
||||
VALUE Run(VALUE self) {
|
||||
v8::HandleScope scope;
|
||||
return Value(Script(self)->Run());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void Script::Init() {
|
||||
ClassBuilder("Script").
|
||||
|
@ -21,4 +8,14 @@ void Script::Init() {
|
|||
defineMethod("Run", &Run);
|
||||
}
|
||||
|
||||
}
|
||||
VALUE Script::New(VALUE klass, VALUE source, VALUE filename) {
|
||||
v8::HandleScope scope;
|
||||
return Script::create(v8::Script::New(String(source), Value(filename)), klass);
|
||||
}
|
||||
|
||||
VALUE Script::Run(VALUE self) {
|
||||
v8::HandleScope scope;
|
||||
return Value(Script(self)->Run());
|
||||
}
|
||||
|
||||
} //namespace rr
|
|
@ -1,16 +1,25 @@
|
|||
#include "rr.h"
|
||||
|
||||
namespace rr {
|
||||
namespace {
|
||||
VALUE New(VALUE StringClass, VALUE string) {
|
||||
v8::HandleScope h;
|
||||
return String::ToRuby(v8::String::New(RSTRING_PTR(string), (int)RSTRING_LEN(string)));
|
||||
}
|
||||
VALUE Utf8Value(VALUE self) {
|
||||
v8::HandleScope h;
|
||||
String str(self);
|
||||
return rb_str_new(*v8::String::Utf8Value(str), str->Utf8Length());
|
||||
}
|
||||
|
||||
VALUE String::Class;
|
||||
|
||||
void String::Init() {
|
||||
rb_gc_register_address(&Class);
|
||||
Class = ClassBuilder("String").
|
||||
defineSingletonMethod("New", &New).
|
||||
defineMethod("Utf8Value", &Utf8Value);
|
||||
}
|
||||
|
||||
VALUE String::New(VALUE StringClass, VALUE string) {
|
||||
v8::HandleScope h;
|
||||
return String::ToRuby(v8::String::New(RSTRING_PTR(string), (int)RSTRING_LEN(string)));
|
||||
}
|
||||
|
||||
VALUE String::Utf8Value(VALUE self) {
|
||||
v8::HandleScope h;
|
||||
String str(self);
|
||||
return rb_str_new(*v8::String::Utf8Value(str), str->Utf8Length());
|
||||
}
|
||||
|
||||
VALUE String::ToRuby(v8::Handle<v8::String> string) {
|
||||
|
@ -21,12 +30,4 @@ String::operator v8::Handle<v8::Value>() {
|
|||
return this->GetHandle();
|
||||
}
|
||||
|
||||
VALUE String::Class;
|
||||
|
||||
void String::Init() {
|
||||
rb_gc_register_address(&Class);
|
||||
Class = ClassBuilder("String").
|
||||
defineSingletonMethod("New", &New).
|
||||
defineMethod("Utf8Value", &Utf8Value);
|
||||
}
|
||||
} //namespace rr
|
13
ext/v8/v8.cc
13
ext/v8/v8.cc
|
@ -1,13 +1,14 @@
|
|||
#include "rr.h"
|
||||
|
||||
namespace rr {
|
||||
namespace {
|
||||
VALUE IdleNotification(VALUE self) {
|
||||
return v8::V8::IdleNotification() ? Qtrue : Qfalse;
|
||||
}
|
||||
}
|
||||
|
||||
void V8::Init() {
|
||||
ClassBuilder("V8").
|
||||
defineSingletonMethod("IdleNotification", &IdleNotification);
|
||||
defineSingletonMethod("IdleNotification", &V8::IdleNotification);
|
||||
}
|
||||
|
||||
VALUE V8::IdleNotification(VALUE self) {
|
||||
return v8::V8::IdleNotification() ? Qtrue : Qfalse;
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in a new issue