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

add beginnings of a generic v8 reference

This commit is contained in:
Charles Lowell 2009-12-07 09:20:16 +02:00
parent 14028505b7
commit 0b4b40a241
8 changed files with 97 additions and 5 deletions

View file

@ -44,10 +44,10 @@ template<class DEST, class RET> class RubyValueSource {
return dest.pushBool(true, name);
case T_FALSE:
return dest.pushBool(false, name);
case T_DATA:
if (rb_is_function(value)) {
return dest.pushCode(new Code<RubyCaller>)
}
// case T_DATA:
// if (rb_is_function(value)) {
// return dest.pushCode(new Code<RubyCaller>)
// }
}
return dest.pushUndefined(name);
}

4
spike.sh Normal file
View file

@ -0,0 +1,4 @@
#!/usr/bin/env bash
make clean all
ruby -e "require 'v8'; V8::N::Context.new"

6
v8.cpp
View file

@ -2,6 +2,7 @@
#include "generic_data.h"
#include "v8_data.h"
#include "v8_context.h"
#include "v8_cxt.h"
#include "v8_standalone.h"
#include <stdio.h>
@ -32,6 +33,11 @@ extern "C" {
rb_define_method(rb_cV8, "eval", (VALUE(*)(...)) v8_context_eval, 1);
rb_define_method(rb_cV8, "[]=", (VALUE(*)(...)) v8_context_inject, 2);
//native module setup
VALUE rb_mNative = rb_define_module_under(rb_mModule, "N");
VALUE V8_N_Context = rb_define_class_under(rb_mNative, "Context", rb_cObject);
rb_define_alloc_func(V8_N_Context, v8_cxt_allocate);
// js object setup
rb_cV8_JSObject = rb_define_class_under(rb_mModule, "JSObject", rb_cObject);
rb_define_alloc_func(rb_cV8_JSObject, v8_object_allocate);

22
v8_cxt.cpp Normal file
View file

@ -0,0 +1,22 @@
#include "v8_cxt.h"
#include "ruby.h"
#include "stdio.h"
using namespace v8;
v8_cxt::v8_cxt() {
// v8_cxt::v8_cxt() {
handle = Context::New();
printf("Allocate Native V8 Context\n");
}
}
VALUE v8_cxt_allocate(VALUE clazz) {
printf("This is the big leagues chew!\n");
v8_cxt* cxt = new v8_cxt();
return Data_Wrap_Struct(clazz, 0, 0, cxt);
}

16
v8_cxt.h Normal file
View file

@ -0,0 +1,16 @@
#ifndef _RUBY_V8_CXT_
#define _RUBY_V8_CXT_
#include "ruby.h"
#include "v8.h"
#include "v8_ref.h"
class v8_cxt : v8_ref<v8::Context> {
public:
v8_cxt();
~v8_cxt();
};
//memory management
VALUE v8_cxt_allocate(VALUE clazz);
#endif

View file

@ -8,7 +8,6 @@
VALUE rb_cV8_JSObject;
using namespace v8;
v8_object::v8_object(VALUE clazz) {

21
v8_ref.cpp Normal file
View file

@ -0,0 +1,21 @@
#include <v8_ref.h>
#include "stdio.h"
using namespace v8;
template <class T> v8_ref<T>::v8_ref(Handle<T> object) : handle(*object) {
printf("Allocated v8 reference\n");
}
template <class T> v8_ref<T>::~v8_ref() {
printf("Disposing of v8 reference\n");
handle.Dispose();
}
void v8_ref_mark(v8_ref_data* ref) {
}
void v8_ref_free(v8_ref_data* ref) {
delete ref;
}

24
v8_ref.h Normal file
View file

@ -0,0 +1,24 @@
#ifndef _RUBY_V8_REF_
#define _RUBY_V8_REF_
#include <v8.h>
class v8_ref_data {
};
template <class T> class v8_ref : v8_ref_data {
public:
v8_ref(v8::Handle<T> object);
~v8_ref();
private:
v8::Persistent<T> handle;
};
//memory management
void v8_ref_mark(v8_ref_data* ref);
void v8_ref_free(v8_ref_data* ref);
#endif