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

check please

This commit is contained in:
Charles Lowell 2010-06-08 12:47:20 +03:00
parent 2651184833
commit 4a372c2382
3 changed files with 60 additions and 18 deletions

View file

@ -8,7 +8,7 @@
using namespace v8;
namespace {
VALUE ObjectTemplateClass;
VALUE FunctionTemplateClass;
@ -182,6 +182,11 @@ namespace {
func(self)->Inherit(func(function_template));
return Qnil;
}
VALUE SetClassName(VALUE self, VALUE name) {
HandleScope scope;
func(self)->SetClassName(rr_rb2v8(name)->ToString());
return Qnil;
}
VALUE GetFunction(VALUE self) {
HandleScope handles;
if (!Context::InContext()) {
@ -197,15 +202,16 @@ void rr_init_template() {
VALUE Template = rr_define_class("Template");
rr_define_method(Template, "Set", Set, 2);
VALUE ObjectTemplateClass = rr_define_class("ObjectTemplate", Template);
ObjectTemplateClass = rr_define_class("ObjectTemplate", Template);
rr_define_singleton_method(ObjectTemplateClass, "New", Obj::New, 0);
rr_define_method(ObjectTemplateClass, "NewInstance", Obj::NewInstance, 0);
rr_define_method(ObjectTemplateClass, "SetNamedPropertyHandler", Obj::SetNamedPropertyHandler, 5);
VALUE FunctionTemplateClass = rr_define_class("FunctionTemplate", Template);
FunctionTemplateClass = rr_define_class("FunctionTemplate", Template);
rr_define_singleton_method(FunctionTemplateClass, "New", Func::New, 0);
rr_define_method(FunctionTemplateClass, "PrototypeTemplate", Func::PrototypeTemplate, 0);
rr_define_method(FunctionTemplateClass, "InstanceTemplate", Func::InstanceTemplate, 0);
rr_define_method(FunctionTemplateClass, "Inherit", Func::Inherit, 1);
rr_define_method(FunctionTemplateClass, "SetClassName", Func::SetClassName, 1);
rr_define_method(FunctionTemplateClass, "GetFunction", Func::GetFunction, 0);
}

View file

@ -32,6 +32,5 @@ module V8
V8::C::ThrowException(V8::C::Exception::Error(V8::C::String::New(e.message)))
end
end
end
end

View file

@ -1,3 +1,4 @@
require 'weakref'
module V8
module To
@ -46,20 +47,11 @@ module V8
when nil,Numeric,TrueClass,FalseClass, C::Value
value
else
obj = nil
unless C::Context::InContext()
cxt = C::Context::New()
cxt.Enter()
begin
obj = To.template.NewInstance()
obj.SetHiddenValue(C::String::New("TheRubyRacer::RubyObject"), C::External::Wrap(value))
ensure
cxt.Exit()
end
else
obj = To.template.NewInstance()
obj.SetHiddenValue(C::String::New("TheRubyRacer::RubyObject"), C::External::Wrap(value))
end
# 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
end
@ -76,6 +68,51 @@ module V8
end
end
def class_template(cls)
@classes ||= {}
if ref = @classes[cls.object_id]
if ref.weakref_alive?
ref.__getobj__
else
@classes.delete(cls.object_id)
self.class_template(cls)
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])
end
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()
end
class_template.PrototypeTemplate().SetNamedPropertyHandler(
NamedPropertyGetter,
NamedPropertySetter,
nil,
nil,
NamedPropertyEnumerator
)
if cls.name && cls.name =~ /::(\w+?)$/
class_template.SetClassName(C::String::NewSymbol($1))
else
class_template.SetClassName("Ruby")
end
@classes[cls.object_id] = WeakRef.new(class_template)
class_template
end
end
def camel_case(str)
str.to_s.gsub(/_(\w)/) {$1.upcase}
end