mirror of
https://github.com/rubyjs/therubyracer
synced 2023-03-27 23:21:42 -04:00
move context init to cxt.cpp
This commit is contained in:
parent
df2881af3b
commit
1b2c6e276c
5 changed files with 26 additions and 17 deletions
7
ext/v8/rr.cpp
Normal file
7
ext/v8/rr.cpp
Normal file
|
@ -0,0 +1,7 @@
|
|||
#include "rr.h"
|
||||
|
||||
VALUE rr_define_class(const char *name) {
|
||||
VALUE V8 = rb_define_module("V8");
|
||||
VALUE V8_C = rb_define_module_under(V8, "C");
|
||||
return rb_define_class_under(V8_C, name, rb_cObject);
|
||||
}
|
|
@ -6,4 +6,6 @@
|
|||
#define RR_DEFINE_METHOD(klass, name, impl, argc) rb_define_method(klass, name, (VALUE(*)(...))impl, argc)
|
||||
#define RR_DEFINE_SINGLETON_METHOD(object, name, impl, argc) rb_define_singleton_method(object, name, (VALUE(*)(...))impl, argc)
|
||||
|
||||
VALUE rr_define_class(const char *name);
|
||||
|
||||
#endif
|
|
@ -22,12 +22,7 @@ VALUE rb_cV8;
|
|||
|
||||
extern "C" {
|
||||
void Init_v8() {
|
||||
|
||||
ruby_call_symbol = ID2SYM(rb_intern("call"));
|
||||
ruby_respond_to_ID = rb_intern("respond_to?");
|
||||
ruby_proc_class = rb_eval_string("::Proc");
|
||||
ruby_method_class = rb_eval_string("::Method");
|
||||
|
||||
|
||||
rb_mModule = rb_define_module("V8");
|
||||
rb_define_singleton_method(rb_mModule, "what_is_this?", (VALUE(*)(...)) v8_what_is_this, 1);
|
||||
|
||||
|
@ -36,17 +31,7 @@ extern "C" {
|
|||
//native module setup
|
||||
VALUE rb_mNative = rb_define_module_under(rb_mModule, "C");
|
||||
|
||||
//native context
|
||||
V8_C_Context = rb_define_class_under(rb_mNative, "Context", rb_cObject);
|
||||
rb_define_singleton_method(V8_C_Context, "new", (VALUE(*)(...)) v8_Context_New, -1);
|
||||
rb_define_singleton_method(V8_C_Context, "InContext", (VALUE(*)(...)) v8_Context_InContext, 0);
|
||||
rb_define_singleton_method(V8_C_Context, "GetCurrent", (VALUE(*)(...)) v8_Context_GetCurrent, 0);
|
||||
rb_define_method(V8_C_Context, "Global", (VALUE(*)(...)) v8_cxt_Global, 0);
|
||||
rb_define_method(V8_C_Context, "open", (VALUE(*)(...)) v8_cxt_open, 0);
|
||||
rb_define_method(V8_C_Context, "eval", (VALUE(*)(...)) v8_cxt_eval, 2);
|
||||
rb_define_method(V8_C_Context, "eql?", (VALUE(*)(...)) v8_cxt_eql, 1);
|
||||
rb_define_method(V8_C_Context, "==", (VALUE(*)(...)) v8_cxt_eql, 1);
|
||||
|
||||
rr_init_cxt();
|
||||
//native String
|
||||
VALUE V8__C__String = rb_define_class_under(rb_mNative, "String", rb_cObject);
|
||||
rb_define_singleton_method(V8__C__String, "new", (VALUE(*)(...)) v8_str_new, 1);
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
#include "rr.h"
|
||||
#include "v8_cxt.h"
|
||||
#include "v8_msg.h"
|
||||
#include "v8_template.h"
|
||||
|
@ -10,6 +11,18 @@ VALUE V8_C_Context;
|
|||
//TODO: rename everything to Context_
|
||||
//TODO: do the object init from within here
|
||||
|
||||
void rr_init_cxt() {
|
||||
VALUE Context = V8_C_Context = rr_define_class("Context");
|
||||
rb_define_singleton_method(Context, "new", (VALUE(*)(...)) v8_Context_New, -1);
|
||||
rb_define_singleton_method(Context, "InContext", (VALUE(*)(...)) v8_Context_InContext, 0);
|
||||
rb_define_singleton_method(Context, "GetCurrent", (VALUE(*)(...)) v8_Context_GetCurrent, 0);
|
||||
rb_define_method(Context, "Global", (VALUE(*)(...)) v8_cxt_Global, 0);
|
||||
rb_define_method(Context, "open", (VALUE(*)(...)) v8_cxt_open, 0);
|
||||
rb_define_method(Context, "eval", (VALUE(*)(...)) v8_cxt_eval, 2);
|
||||
rb_define_method(Context, "eql?", (VALUE(*)(...)) v8_cxt_eql, 1);
|
||||
rb_define_method(Context, "==", (VALUE(*)(...)) v8_cxt_eql, 1);
|
||||
}
|
||||
|
||||
VALUE v8_Context_New(int argc, VALUE *argv, VALUE self) {
|
||||
HandleScope handles;
|
||||
VALUE scope;
|
||||
|
|
|
@ -9,6 +9,8 @@ extern VALUE rb_cV8;
|
|||
extern VALUE V8_C_Object;
|
||||
extern VALUE V8_C_Context;
|
||||
|
||||
void rr_init_cxt();
|
||||
|
||||
VALUE v8_Context_New(int argc, VALUE *argv, VALUE self);
|
||||
VALUE v8_Context_InContext(VALUE self);
|
||||
VALUE v8_Context_GetCurrent(VALUE self);
|
||||
|
|
Loading…
Reference in a new issue