diff --git a/ext/v8/context.cc b/ext/v8/context.cc index 19d2825..3e004e3 100644 --- a/ext/v8/context.cc +++ b/ext/v8/context.cc @@ -2,27 +2,28 @@ namespace rr { - VALUE New(VALUE ContextClass) { - v8::Persistent context = v8::Context::New(); - Ref 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 context = v8::Context::New(); + Ref 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); - } -} \ No newline at end of file +VALUE Context::Exit(VALUE self) { + Context(self)->Exit(); + return Qnil; +} + +} diff --git a/ext/v8/rr.h b/ext/v8/rr.h index b985bba..7b4f2d5 100644 --- a/ext/v8/rr.h +++ b/ext/v8/rr.h @@ -100,28 +100,42 @@ public: class Context : public Ref { public: - inline Context(VALUE value) : Ref(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(value) {} }; class Script : public Ref { public: - inline Script(VALUE value) : Ref(value) {} static void Init(); + static VALUE New(VALUE klass, VALUE source, VALUE filename); + static VALUE Run(VALUE self); + +private: + inline Script(VALUE value) : Ref(value) {} }; class String: public Ref { public: + static void Init(); + static VALUE New(VALUE self, VALUE value); + static VALUE Utf8Value(VALUE self); + inline String(VALUE value) : Ref(value) {} virtual operator v8::Handle(); static VALUE ToRuby(v8::Handle value); - static void Init(); +private: static VALUE Class; }; class V8 { public: static void Init(); + static VALUE IdleNotification(VALUE self); }; class ClassBuilder { diff --git a/ext/v8/script.cc b/ext/v8/script.cc index 3f35502..b5ae070 100644 --- a/ext/v8/script.cc +++ b/ext/v8/script.cc @@ -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); } -} \ No newline at end of file +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 \ No newline at end of file diff --git a/ext/v8/string.cc b/ext/v8/string.cc index abb60bb..a9a47a8 100644 --- a/ext/v8/string.cc +++ b/ext/v8/string.cc @@ -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 string) { @@ -21,12 +30,4 @@ String::operator v8::Handle() { 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 \ No newline at end of file diff --git a/ext/v8/v8.cc b/ext/v8/v8.cc index 0a2edef..0cd1d3e 100644 --- a/ext/v8/v8.cc +++ b/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; +} + } \ No newline at end of file