mirror of
https://github.com/rubyjs/therubyracer
synced 2023-03-27 23:21:42 -04:00
align ruby objects so that all instances of the same class have the same constructor.
This commit is contained in:
parent
1ae9f62e49
commit
66d5bf49d7
5 changed files with 13 additions and 15 deletions
|
@ -109,7 +109,6 @@ VALUE rr_v82rb(int32_t value) {
|
|||
return INT2FIX(value);
|
||||
}
|
||||
|
||||
|
||||
Handle<Value> rr_rb2v8(VALUE value) {
|
||||
switch (TYPE(value)) {
|
||||
case T_FIXNUM:
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
#include "v8_external.h"
|
||||
#include "rr.h"
|
||||
#include "v8_external.h"
|
||||
|
||||
#include "v8_ref.h"
|
||||
#include "v8_value.h"
|
||||
using namespace v8;
|
||||
|
||||
namespace {
|
||||
|
@ -30,7 +32,7 @@ namespace {
|
|||
}
|
||||
|
||||
void rr_init_v8_external() {
|
||||
ExternalClass = rr_define_class("External");
|
||||
ExternalClass = rr_define_class("External", rr_cV8_C_Value);
|
||||
references = rb_hash_new();
|
||||
rb_define_const(ExternalClass, "OBJECTS_REFERENCED_FROM_WITHIN_V8", references);
|
||||
rr_define_singleton_method(ExternalClass, "Wrap", Wrap, 1);
|
||||
|
@ -44,7 +46,7 @@ VALUE rr_reflect_v8_external(Handle<Value> external) {
|
|||
|
||||
Handle<Value> rr_v8_external_create(VALUE value) {
|
||||
rb_hash_aset(references, rb_obj_id(value), value);
|
||||
Local<Value> external(External::Wrap((void *)value));
|
||||
Local<Value> external(External::New((void *)value));
|
||||
Persistent<Value> record = Persistent<Value>::New(external);
|
||||
// V8::AdjustAmountOfExternalAllocatedMemory(100000000);
|
||||
record.MakeWeak(NULL, GCWeakReferenceCallback);
|
||||
|
|
|
@ -36,7 +36,7 @@ namespace {
|
|||
for (int i = 0; i < argc; i++) {
|
||||
argv[i] = args->Get(i);
|
||||
}
|
||||
return rr_v82rb(function->NewInstance(argc, argv));
|
||||
return rr_v8_ref_create(rr_cV8_C_Object, function->NewInstance(argc, argv));
|
||||
}
|
||||
VALUE GetName(VALUE self) {
|
||||
return rr_v82rb(unwrap(self)->GetName());
|
||||
|
|
|
@ -18,6 +18,7 @@ namespace {
|
|||
return rr_v8_ref_create(string_class, String::New(RSTRING_PTR(str), RSTRING_LEN(str)));
|
||||
}
|
||||
VALUE NewSymbol(VALUE string_class, VALUE data) {
|
||||
HandleScope scope;
|
||||
VALUE str = rb_funcall(data, rb_intern("to_s"), 0);
|
||||
return rr_v8_ref_create(string_class, String::NewSymbol(RSTRING_PTR(str), RSTRING_LEN(str)));
|
||||
}
|
||||
|
|
16
lib/v8/to.rb
16
lib/v8/to.rb
|
@ -50,7 +50,6 @@ module V8
|
|||
# obj = To.template.NewInstance()
|
||||
args = C::Array::New(1)
|
||||
args.Set(0, C::External::Wrap(value))
|
||||
rputs "about to call this mother."
|
||||
obj = To.class_template(value.class).GetFunction().NewInstance(args)
|
||||
return obj
|
||||
end
|
||||
|
@ -79,13 +78,9 @@ module V8
|
|||
end
|
||||
else
|
||||
class_template = C::FunctionTemplate::New() do |arguments|
|
||||
rputs "In constructor"
|
||||
if arguments.Length() > 0
|
||||
if arguments.Length() > 0 && arguments[0].IsExternal()
|
||||
rputs "this path?"
|
||||
wrapper = arguments[0]
|
||||
else
|
||||
rputs "this path?????"
|
||||
rbargs = []
|
||||
for i in 0..arguments.Length() - 1
|
||||
rbargs << To.rb(arguments[i])
|
||||
|
@ -93,18 +88,19 @@ module V8
|
|||
instance = V8::Function.rubycall(cls.method(:new), *rbargs)
|
||||
wrapper = C::External::Wrap(instance)
|
||||
end
|
||||
arguments.This().SetHiddenValue(C::String::New("TheRubyRacer::RubyObject"), wrapper)
|
||||
arguments.This()
|
||||
arguments.This().tap do |this|
|
||||
this.SetHiddenValue(C::String::New("TheRubyRacer::RubyObject"), wrapper)
|
||||
end
|
||||
end
|
||||
class_template.PrototypeTemplate().SetNamedPropertyHandler(
|
||||
class_template.InstanceTemplate().SetNamedPropertyHandler(
|
||||
NamedPropertyGetter,
|
||||
NamedPropertySetter,
|
||||
nil,
|
||||
nil,
|
||||
NamedPropertyEnumerator
|
||||
)
|
||||
if cls.name && cls.name =~ /::(\w+?)$/
|
||||
class_template.SetClassName(C::String::NewSymbol($1))
|
||||
if cls.name && cls.name =~ /(::)?(\w+?)$/
|
||||
class_template.SetClassName(C::String::NewSymbol($2))
|
||||
else
|
||||
class_template.SetClassName("Ruby")
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue