From 7912eec8cdc6caac5563597aba20bb1c272fc345 Mon Sep 17 00:00:00 2001 From: Charles Lowell Date: Wed, 16 Dec 2009 07:40:19 +0100 Subject: [PATCH] get the ruby racer running on the shared specs (which fail horribly) --- Manifest.txt | 6 +- Rakefile | 6 +- config.sh | 1 - ext/v8/convert_ruby.h | 4 +- ext/v8/v8.cpp | 22 +----- ext/v8/v8_context.cpp | 66 ------------------ ext/v8/v8_context.h | 46 ------------- ext/v8/v8_object.cpp | 67 ------------------ ext/v8/v8_object.h | 31 --------- ext/v8/v8_script.cpp | 1 - lib/v8.rb | 1 + lib/v8/context.rb | 27 +++++++- spec/therubyracer_spec.rb | 138 -------------------------------------- 13 files changed, 39 insertions(+), 377 deletions(-) delete mode 100755 config.sh delete mode 100644 ext/v8/v8_context.cpp delete mode 100644 ext/v8/v8_context.h delete mode 100644 ext/v8/v8_object.cpp delete mode 100644 ext/v8/v8_object.h delete mode 100644 spec/therubyracer_spec.rb diff --git a/Manifest.txt b/Manifest.txt index ba07215..47cdaa4 100644 --- a/Manifest.txt +++ b/Manifest.txt @@ -3,7 +3,6 @@ History.txt Manifest.txt README.rdoc Rakefile -config.sh docs/data_conversion.txt ext/v8/convert_ruby.cpp ext/v8/convert_ruby.h @@ -31,10 +30,13 @@ ext/v8/v8_str.h ext/v8/v8_template.cpp ext/v8/v8_template.h lib/v8.rb -lib/v8/v8.bundle +lib/v8/context.rb script/console script/destroy script/generate +spec/jsapi/README.txt +spec/jsapi/spec.rb +spec/jsapi_spec.rb spec/spec.opts spec/spec_helper.rb spec/therubyracer_spec.rb diff --git a/Rakefile b/Rakefile index 9adfc49..e6ca4bc 100644 --- a/Rakefile +++ b/Rakefile @@ -2,7 +2,11 @@ require 'rubygems' gem 'hoe', '>= 2.1.0' require 'hoe' require 'fileutils' -require './lib/v8' +begin + require './lib/v8' +rescue LoadError + #it will fail to load if we don't have the extensions compiled yet +end gem 'rake-compiler', '>= 0.4.1' require "rake/extensiontask" diff --git a/config.sh b/config.sh deleted file mode 100755 index c674153..0000000 --- a/config.sh +++ /dev/null @@ -1 +0,0 @@ -ruby extconf.rb --with-v8-lib=$1 --with-v8-include=$1/include diff --git a/ext/v8/convert_ruby.h b/ext/v8/convert_ruby.h index ded0b92..55c7d30 100644 --- a/ext/v8/convert_ruby.h +++ b/ext/v8/convert_ruby.h @@ -5,7 +5,6 @@ #include #include #include -#include "v8_object.h" /** * A RubyValueSource takes a Destination class and a return @@ -95,8 +94,7 @@ class RubyValueDest { } VALUE pushObject(v8::Handle& value) { - v8_object* wrapper = new v8_object(value); - return wrapper->ruby_value; + return Qnil; } }; diff --git a/ext/v8/v8.cpp b/ext/v8/v8.cpp index 44fa674..91bb97f 100644 --- a/ext/v8/v8.cpp +++ b/ext/v8/v8.cpp @@ -1,5 +1,3 @@ -#include "v8_object.h" -#include "v8_context.h" #include "v8_cxt.h" #include "v8_str.h" #include "v8_script.h" @@ -27,13 +25,7 @@ extern "C" { ruby_method_class = rb_eval_string("::Method"); rb_mModule = rb_define_module("V8"); - - // context setup - rb_cV8 = rb_define_class_under(rb_mModule, "Context", rb_cObject); - rb_define_alloc_func(rb_cV8, v8_context_allocate); - 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, "C"); @@ -59,16 +51,6 @@ extern "C" { rb_define_singleton_method(V8__C__ObjectTemplate, "new", (VALUE(*)(...))v8_ObjectTemplate_New, 0); VALUE V8__C__FunctionTemplate = rb_define_class_under(rb_mNative, "FunctionTemplate", V8__C__Template); - rb_define_singleton_method(V8__C__FunctionTemplate, "new", (VALUE(*)(...))v8_FunctionTemplate_New, -1); - - - // 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); - rb_define_method(rb_cV8_JSObject, "[]", (VALUE(*)(...)) v8_object_hash_access, 1); - rb_define_method(rb_cV8_JSObject, "[]=", (VALUE(*)(...)) v8_object_hash_assignment, 2); - rb_define_method(rb_cV8_JSObject, "call_something", (VALUE(*)(...)) v8_object_call_something, 1); - // stand alone methods - rb_define_singleton_method(rb_mModule, "what_is_this?",(VALUE(*)(...)) v8_what_is_this, 1); + rb_define_singleton_method(V8__C__FunctionTemplate, "new", (VALUE(*)(...))v8_FunctionTemplate_New, -1); } } diff --git a/ext/v8/v8_context.cpp b/ext/v8/v8_context.cpp deleted file mode 100644 index 06a1cae..0000000 --- a/ext/v8/v8_context.cpp +++ /dev/null @@ -1,66 +0,0 @@ -#include "converters.h" -#include "v8_context.h" - -#include - -using namespace v8; - -v8_context::v8_context() : handle(Context::New()) {} - -v8_context::~v8_context() { - handle.Dispose(); -} - -VALUE v8_context_allocate(VALUE clazz) { - v8_context *cxt = new v8_context; - return Data_Wrap_Struct(clazz, v8_context_mark, v8_context_free, cxt); - -} -void v8_context_free(v8_context *context) { - delete context; -} -void v8_context_mark(v8_context *context) { - //don't mark anything. -} - - -//methods -VALUE v8_context_eval(VALUE self, VALUE javascript) { - v8_context* cxt = 0; - Data_Get_Struct(self, struct v8_context, cxt); - - Context::Scope enter(cxt->handle); - HandleScope handles; - - RubyValueSource tostring; - const std::string source(tostring(javascript)); - - Local