mirror of
https://github.com/rubyjs/therubyracer
synced 2023-03-27 23:21:42 -04:00
resolve merge conflicts
This commit is contained in:
commit
f208e10fde
9 changed files with 100 additions and 59 deletions
|
@ -10,6 +10,7 @@ ext/v8/convert_string.cpp
|
||||||
ext/v8/convert_string.h
|
ext/v8/convert_string.h
|
||||||
ext/v8/convert_v8.cpp
|
ext/v8/convert_v8.cpp
|
||||||
ext/v8/convert_v8.h
|
ext/v8/convert_v8.h
|
||||||
|
ext/v8/converters.cpp
|
||||||
ext/v8/converters.h
|
ext/v8/converters.h
|
||||||
ext/v8/extconf.rb
|
ext/v8/extconf.rb
|
||||||
ext/v8/v8.cpp
|
ext/v8/v8.cpp
|
||||||
|
|
|
@ -2,9 +2,6 @@
|
||||||
#define __convert_ruby_h__
|
#define __convert_ruby_h__
|
||||||
|
|
||||||
#include <ruby.h>
|
#include <ruby.h>
|
||||||
#include <v8.h>
|
|
||||||
#include "v8_ref.h"
|
|
||||||
#include "v8_obj.h"
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -44,16 +41,6 @@ template<class DEST, class RET> class RubyValueSource {
|
||||||
return dest.pushBool(true);
|
return dest.pushBool(true);
|
||||||
case T_FALSE:
|
case T_FALSE:
|
||||||
return dest.pushBool(false);
|
return dest.pushBool(false);
|
||||||
case T_DATA:
|
|
||||||
/*
|
|
||||||
VALUE clsProc = rb_eval_string("::Proc");
|
|
||||||
VALUE clsMethod = rb_eval_string("::Method");
|
|
||||||
VALUE smartMatch = rb_intern("===");
|
|
||||||
if (RTEST(rb_funcall(clsProc, smartMatch, value)) || RTEST(rb_funcall(clsMethod, smartMatch, value))) {
|
|
||||||
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
return dest.pushUndefined();
|
return dest.pushUndefined();
|
||||||
}
|
}
|
||||||
|
@ -99,10 +86,6 @@ class RubyValueDest {
|
||||||
VALUE pushUndefined() {
|
VALUE pushUndefined() {
|
||||||
return Qnil;
|
return Qnil;
|
||||||
}
|
}
|
||||||
|
|
||||||
VALUE pushObject(v8::Handle<v8::Object>& value) {
|
|
||||||
return V8_Ref_Create(V8_C_Object, value);
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -15,57 +15,69 @@ template<class T, class R> class V8HandleSource {
|
||||||
V8HandleSource() {}
|
V8HandleSource() {}
|
||||||
~V8HandleSource() {}
|
~V8HandleSource() {}
|
||||||
|
|
||||||
R operator() (v8::Handle<v8::Value>& value) {
|
bool operator() (v8::Handle<v8::Value>& value, R& result) {
|
||||||
|
|
||||||
|
// a bit klunky, but alternative is to evaluate what type the
|
||||||
|
// object is twice, which is unappealing
|
||||||
|
|
||||||
if (value.IsEmpty()) {
|
if (value.IsEmpty()) {
|
||||||
return dest.pushNull();
|
result = dest.pushNull();
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (value->IsUndefined()) {
|
if (value->IsUndefined()) {
|
||||||
return dest.pushNull();
|
result = dest.pushNull();
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(value->IsNull()) {
|
if(value->IsNull()) {
|
||||||
return dest.pushNull();
|
result = dest.pushNull();
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(value->IsTrue()) {
|
if(value->IsTrue()) {
|
||||||
return dest.pushBool(true);
|
result = dest.pushBool(true);
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(value->IsFalse()) {
|
if(value->IsFalse()) {
|
||||||
return dest.pushBool(false);
|
result = dest.pushBool(false);
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(value->IsString()) {
|
if(value->IsString()) {
|
||||||
v8::Local<v8::String> str = value->ToString();
|
v8::Local<v8::String> str = value->ToString();
|
||||||
char buffer[1024];
|
result = convertString(str);
|
||||||
int strlen = str->Length();
|
return true;
|
||||||
std::string output(strlen, 0);
|
|
||||||
for (int total = 0; total < strlen;) {
|
|
||||||
int written = str->WriteAscii(buffer, total, 1024);
|
|
||||||
output.replace(total, written, buffer);
|
|
||||||
total += written;
|
|
||||||
}
|
|
||||||
return dest.pushString(output);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if(value->IsInt32()) {
|
if(value->IsInt32()) {
|
||||||
return dest.pushInt(value->Int32Value());
|
result = dest.pushInt(value->Int32Value());
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(value->IsNumber()) {
|
if(value->IsNumber()) {
|
||||||
return dest.pushDouble(value->NumberValue());
|
result = dest.pushDouble(value->NumberValue());
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (value->IsObject()) {
|
result = dest.pushNull();
|
||||||
v8::Local<v8::Object> object(v8::Object::Cast(*value));
|
return false;
|
||||||
return dest.pushObject(object);
|
|
||||||
}
|
|
||||||
|
|
||||||
return dest.pushNull();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
R convertString(v8::Local<v8::String>& str) {
|
||||||
|
char buffer[1024];
|
||||||
|
int strlen = str->Length();
|
||||||
|
std::string output(strlen, 0);
|
||||||
|
for (int total = 0; total < strlen;) {
|
||||||
|
int written = str->WriteAscii(buffer, total, 1024);
|
||||||
|
output.replace(total, written, buffer);
|
||||||
|
total += written;
|
||||||
|
}
|
||||||
|
return dest.pushString(output);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -103,10 +115,6 @@ public:
|
||||||
v8::Local<v8::Value> pushUndefined() {
|
v8::Local<v8::Value> pushUndefined() {
|
||||||
return v8::Local<v8::Value>::New(v8::Undefined());
|
return v8::Local<v8::Value>::New(v8::Undefined());
|
||||||
}
|
}
|
||||||
|
|
||||||
// v8:Local<v8:Value> pushFunction(Function) {
|
|
||||||
//
|
|
||||||
// }
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,51 @@
|
||||||
#include "converters.h"
|
#include "converters.h"
|
||||||
|
|
||||||
convert_v8_to_rb_t V82RB;
|
#include "v8_ref.h"
|
||||||
convert_rb_to_v8_t RB2V8;
|
#include "v8_obj.h"
|
||||||
|
|
||||||
|
namespace {
|
||||||
|
std::string UNDEFINED_STR("undefined");
|
||||||
|
}
|
||||||
|
|
||||||
|
VALUE V82RB(v8::Handle<v8::Value>& value) {
|
||||||
|
convert_v8_to_rb_t convert;
|
||||||
|
VALUE result;
|
||||||
|
if(convert(value, result)) {
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (value->IsObject()) {
|
||||||
|
v8::Local<v8::Object> object(v8::Object::Cast(*value));
|
||||||
|
return V8_Ref_Create(V8_C_Object, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
return Qnil;
|
||||||
|
}
|
||||||
|
|
||||||
|
v8::Local<v8::Value> RB2V8(VALUE value) {
|
||||||
|
convert_rb_to_v8_t convert;
|
||||||
|
return convert(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string RB2String(VALUE value) {
|
||||||
|
convert_rb_to_string_t convert;
|
||||||
|
return convert(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string V82String(v8::Handle<v8::Value>& value) {
|
||||||
|
convert_v8_to_string_t convert;
|
||||||
|
std::string result;
|
||||||
|
if(convert(value, result)) {
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (value->IsObject()) {
|
||||||
|
v8::Local<v8::Object> object(v8::Object::Cast(*value));
|
||||||
|
v8::Local<v8::String> str = object->ToString();
|
||||||
|
if(convert(value, result)) {
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return UNDEFINED_STR;
|
||||||
|
}
|
|
@ -4,6 +4,7 @@
|
||||||
#include "convert_ruby.h"
|
#include "convert_ruby.h"
|
||||||
#include "convert_string.h"
|
#include "convert_string.h"
|
||||||
#include "convert_v8.h"
|
#include "convert_v8.h"
|
||||||
|
#include <cstring>
|
||||||
|
|
||||||
typedef RubyValueSource<V8LocalDest, v8::Local<v8::Value> > convert_rb_to_v8_t;
|
typedef RubyValueSource<V8LocalDest, v8::Local<v8::Value> > convert_rb_to_v8_t;
|
||||||
typedef V8HandleSource<RubyValueDest, VALUE> convert_v8_to_rb_t;
|
typedef V8HandleSource<RubyValueDest, VALUE> convert_v8_to_rb_t;
|
||||||
|
@ -11,7 +12,10 @@ typedef V8HandleSource<RubyValueDest, VALUE> convert_v8_to_rb_t;
|
||||||
typedef RubyValueSource<StringDest, std::string> convert_rb_to_string_t;
|
typedef RubyValueSource<StringDest, std::string> convert_rb_to_string_t;
|
||||||
typedef V8HandleSource<StringDest, std::string> convert_v8_to_string_t;
|
typedef V8HandleSource<StringDest, std::string> convert_v8_to_string_t;
|
||||||
|
|
||||||
extern convert_v8_to_rb_t V82RB;
|
VALUE V82RB(v8::Handle<v8::Value>& value);
|
||||||
extern convert_rb_to_v8_t RB2V8;
|
v8::Local<v8::Value> RB2V8(VALUE value);
|
||||||
|
|
||||||
|
std::string RB2String(VALUE value);
|
||||||
|
std::string V82String(v8::Handle<v8::Value>& value);
|
||||||
|
|
||||||
#endif
|
#endif
|
|
@ -18,10 +18,9 @@ VALUE v8_Context_New(int argc, VALUE *argv, VALUE self) {
|
||||||
|
|
||||||
VALUE v8_cxt_Global(VALUE self) {
|
VALUE v8_cxt_Global(VALUE self) {
|
||||||
HandleScope handles;
|
HandleScope handles;
|
||||||
convert_v8_to_rb_t v82rb;
|
|
||||||
Local<Context> cxt = V8_Ref_Get<Context>(self);
|
Local<Context> cxt = V8_Ref_Get<Context>(self);
|
||||||
Local<Value> global = *cxt->Global();
|
Local<Value> global = *cxt->Global();
|
||||||
return v82rb(global);
|
return V82RB(global);
|
||||||
}
|
}
|
||||||
|
|
||||||
VALUE v8_cxt_open(VALUE self) {
|
VALUE v8_cxt_open(VALUE self) {
|
||||||
|
|
|
@ -28,10 +28,10 @@ VALUE v8_Object_Set(VALUE self, VALUE key, VALUE value) {
|
||||||
|
|
||||||
VALUE valueClass = rb_class_of(value);
|
VALUE valueClass = rb_class_of(value);
|
||||||
if(valueClass == rb_cProc) {
|
if(valueClass == rb_cProc) {
|
||||||
printf("** This is a proc! We should do something different.\n");
|
//printf("** This is a proc! We should do something different.\n");
|
||||||
}
|
}
|
||||||
else if(valueClass == rb_cMethod) {
|
else if(valueClass == rb_cMethod) {
|
||||||
printf("** This is a method! We should do something different.\n");
|
//printf("** This is a method! We should do something different.\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
obj->Set(RB2V8(keystr), RB2V8(value));
|
obj->Set(RB2V8(keystr), RB2V8(value));
|
||||||
|
|
|
@ -15,7 +15,6 @@ VALUE v8_script_new(VALUE self, VALUE source) {
|
||||||
VALUE v8_script_Run(VALUE self) {
|
VALUE v8_script_Run(VALUE self) {
|
||||||
HandleScope handles;
|
HandleScope handles;
|
||||||
Local<Script> script = V8_Ref_Get<Script>(self);
|
Local<Script> script = V8_Ref_Get<Script>(self);
|
||||||
convert_v8_to_rb_t toValue;
|
|
||||||
Local<Value> result = script->Run();
|
Local<Value> result = script->Run();
|
||||||
return toValue(result);
|
return V82RB(result);
|
||||||
}
|
}
|
|
@ -6,18 +6,18 @@ Gem::Specification.new do |s|
|
||||||
|
|
||||||
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
||||||
s.authors = ["Charles Lowell", "Bill Robertson"]
|
s.authors = ["Charles Lowell", "Bill Robertson"]
|
||||||
s.date = %q{2009-12-15}
|
s.date = %q{2009-12-22}
|
||||||
s.description = %q{FIX (describe your package)}
|
s.description = %q{Embed the V8 Javascript interpreter into Ruby.}
|
||||||
s.email = ["cowboyd@thefrontside.net", "billrobertson42@gmail.com"]
|
s.email = ["cowboyd@thefrontside.net", "billrobertson42@gmail.com"]
|
||||||
s.extensions = ["ext/v8/extconf.rb"]
|
s.extensions = ["ext/v8/extconf.rb"]
|
||||||
s.extra_rdoc_files = ["History.txt", "Manifest.txt", "docs/data_conversion.txt"]
|
s.extra_rdoc_files = ["History.txt", "Manifest.txt", "docs/data_conversion.txt"]
|
||||||
s.files = ["Doxyfile", "History.txt", "Manifest.txt", "README.rdoc", "Rakefile", "config.sh", "docs/data_conversion.txt", "ext/v8/convert_ruby.cpp", "ext/v8/convert_ruby.h", "ext/v8/convert_string.cpp", "ext/v8/convert_string.h", "ext/v8/convert_v8.cpp", "ext/v8/convert_v8.h", "ext/v8/converters.h", "ext/v8/extconf.rb", "ext/v8/v8.cpp", "ext/v8/v8_context.cpp", "ext/v8/v8_context.h", "ext/v8/v8_cxt.cpp", "ext/v8/v8_cxt.h", "ext/v8/v8_object.cpp", "ext/v8/v8_object.h", "ext/v8/v8_ref.cpp", "ext/v8/v8_ref.h", "ext/v8/v8_script.cpp", "ext/v8/v8_script.h", "ext/v8/v8_standalone.cpp", "ext/v8/v8_standalone.h", "ext/v8/v8_str.cpp", "ext/v8/v8_str.h", "ext/v8/v8_template.cpp", "ext/v8/v8_template.h", "lib/v8.rb", "lib/v8/v8.bundle", "script/console", "script/destroy", "script/generate", "spec/spec.opts", "spec/spec_helper.rb", "spec/therubyracer_spec.rb", "spike.rb", "tasks/rspec.rake"]
|
s.files = ["Doxyfile", "History.txt", "Manifest.txt", "README.rdoc", "Rakefile", "docs/data_conversion.txt", "ext/v8/convert_ruby.cpp", "ext/v8/convert_ruby.h", "ext/v8/convert_string.cpp", "ext/v8/convert_string.h", "ext/v8/convert_v8.cpp", "ext/v8/convert_v8.h", "ext/v8/converters.cpp", "ext/v8/converters.h", "ext/v8/extconf.rb", "ext/v8/v8.cpp", "ext/v8/v8_cxt.cpp", "ext/v8/v8_cxt.h", "ext/v8/v8_func.cpp", "ext/v8/v8_func.h", "ext/v8/v8_msg.cpp", "ext/v8/v8_msg.h", "ext/v8/v8_obj.cpp", "ext/v8/v8_obj.h", "ext/v8/v8_ref.cpp", "ext/v8/v8_ref.h", "ext/v8/v8_script.cpp", "ext/v8/v8_script.h", "ext/v8/v8_standalone.cpp", "ext/v8/v8_standalone.h", "ext/v8/v8_str.cpp", "ext/v8/v8_str.h", "ext/v8/v8_template.cpp", "ext/v8/v8_template.h", "lib/v8.rb", "lib/v8/context.rb", "lib/v8/object.rb", "lib/v8/to.rb", "script/console", "script/destroy", "script/generate", "spec/redjs/README.txt", "spec/redjs/jsapi_spec.rb", "spec/redjs_helper.rb", "spec/spec.opts", "spec/spec_helper.rb", "tasks/rspec.rake", "therubyracer.gemspec"]
|
||||||
s.homepage = %q{http://github.com/#{github_username}/#{project_name}}
|
s.homepage = %q{http://github.com/cowboyd/therubyracer}
|
||||||
s.rdoc_options = ["--main", "README.rdoc"]
|
s.rdoc_options = ["--main", "README.rdoc"]
|
||||||
s.require_paths = ["lib", "ext"]
|
s.require_paths = ["lib", "ext"]
|
||||||
s.rubyforge_project = %q{therubyracer}
|
s.rubyforge_project = %q{therubyracer}
|
||||||
s.rubygems_version = %q{1.3.5}
|
s.rubygems_version = %q{1.3.5}
|
||||||
s.summary = %q{FIX (describe your package)}
|
s.summary = %q{Embed the V8 Javascript interpreter into Ruby.}
|
||||||
|
|
||||||
if s.respond_to? :specification_version then
|
if s.respond_to? :specification_version then
|
||||||
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
||||||
|
|
Loading…
Reference in a new issue