diff --git a/Lib/javascript/v8/javascriptcode.swg b/Lib/javascript/v8/javascriptcode.swg index c2b6819d3..8ba811354 100644 --- a/Lib/javascript/v8/javascriptcode.swg +++ b/Lib/javascript/v8/javascriptcode.swg @@ -69,37 +69,37 @@ fail: %} %fragment("jsv8_declare_class_template", "templates") -%{v8::Persistent SWIGV8_$jsmangledname;%} +%{v8::Persistent $jsmangledname_class;%} %fragment("jsv8_define_class_template", "templates") -%{SWIGV8_$jsmangledname = SWIGV8_CreateClassTemplate("$jsname" , $jsctor);%} +%{$jsmangledname_class = SWIGV8_CreateClassTemplate("$jsname" , $jsctor);%} %fragment("jsv8_create_class_instance", "templates") -%{v8::Handle class_$jsmangledname = SWIGV8_$jsmangledname->GetFunction();%} +%{v8::Handle $jsmangledname = $jsmangledname_class->GetFunction();%} %fragment("jsv8_inherit", "templates") -%{SWIGV8_$jsmangledname->Inherit(SWIGV8_$jsbaseclass);%} +%{$jsmangledname_class->Inherit($jsbaseclass_class);%} %fragment("jsv8_register_class", "templates") -%{$jsparent->Set(v8::String::NewSymbol("$jsname"), class_$jsmangledname);%} +%{$jsparent->Set(v8::String::NewSymbol("$jsname"), $jsmangledname);%} %fragment("jsv8_create_namespace", "templates") -%{v8::Handle $jsmangledname = v8::ObjectTemplate::New();%} +%{v8::Handle $jsmangledname = v8::Object::New();%} %fragment("jsv8_register_member_function", "templates") -%{SWIGV8_AddMemberFunction(SWIGV8_$jsmangledname, "$jsname", $jswrapper);%} - -%fragment("jsv8_register_static_function", "templates") -%{SWIGV8_AddGlobalFunction(SWIGV8_$jsparent, "$jsname", $jswrapper);%} +%{SWIGV8_AddMemberFunction($jsmangledname_class, "$jsname", $jswrapper);%} %fragment("jsv8_register_member_variable", "templates") -%{SWIGV8_AddMemberVariable(SWIGV8_$jsmangledname, "$jsname", $jsgetter, $jssetter);%} +%{SWIGV8_AddMemberVariable($jsmangledname_class, "$jsname", $jsgetter, $jssetter);%} + +%fragment("jsv8_register_static_function", "templates") +%{SWIGV8_AddStaticFunction($jsparent, "$jsname", $jswrapper);%} %fragment("jsv8_register_static_variable", "templates") -%{SWIGV8_AddGlobalVariable(SWIGV8_$jsparent, "$jsname", $jsgetter, $jssetter);%} +%{SWIGV8_AddStaticVariable($jsparent, "$jsname", $jsgetter, $jssetter);%} %fragment("jsv8_register_namespace", "templates") -%{$jsparent->Set(v8::String::NewSymbol("$jsname"), $jsmangledname->NewInstance());%} +%{$jsparent->Set(v8::String::NewSymbol("$jsname"), $jsmangledname);%} %fragment("JS_initializer", "templates") %{ @@ -107,32 +107,32 @@ extern "C" { void $jsname_initialize(v8::Handle context) { - v8::HandleScope scope; - v8::Local global = context->Global(); + v8::HandleScope scope; + v8::Local global = context->Global(); - /* create object templates for namespaces */ - $jsv8nspaces - - /* create class templates */ - $jsv8classtemplates - - /* register wrapper functions */ - $jsv8wrappers - - /* setup inheritances */ - $jsv8inheritance - - /* add static class functions and variables */ - $jsv8staticwrappers - - /* class instances */ - $jsv8classinstances - - /* register classes */ - $jsv8registerclasses - - /* create and register namespace objects */ - $jsv8registernspaces + /* create objects for namespaces */ + $jsv8nspaces + + /* create class templates */ + $jsv8classtemplates + + /* register wrapper functions */ + $jsv8wrappers + + /* setup inheritances */ + $jsv8inheritance + + /* class instances */ + $jsv8classinstances + + /* add static class functions and variables */ + $jsv8staticwrappers + + /* register classes */ + $jsv8registerclasses + + /* create and register namespace objects */ + $jsv8registernspaces } }%} diff --git a/Lib/javascript/v8/javascripthelpers.swg b/Lib/javascript/v8/javascripthelpers.swg index bd103702c..5de11feb3 100644 --- a/Lib/javascript/v8/javascripthelpers.swg +++ b/Lib/javascript/v8/javascripthelpers.swg @@ -21,28 +21,26 @@ void SWIGV8_AddMemberFunction(v8::Handle class_templ, cons proto_templ->Set(v8::String::NewSymbol(symbol), v8::FunctionTemplate::New(_func)); } -/** - * Registers a class method with given name for a given class template. - */ -void SWIGV8_AddGlobalFunction(v8::Handle class_templ, const char* symbol, v8::InvocationCallback _func) { - v8::Handle obj_templ = class_templ->InstanceTemplate(); - obj_templ->Set(v8::String::NewSymbol(symbol), v8::FunctionTemplate::New(_func)->GetFunction()); -} - - /** * Registers a class property with given name for a given class template. */ void SWIGV8_AddMemberVariable(v8::Handle class_templ, const char* symbol, v8::AccessorGetter getter, v8::AccessorSetter setter) { - v8::Handle proto_templ = class_templ->InstanceTemplate(); - proto_templ->SetAccessor(v8::String::NewSymbol(symbol), getter, setter); + v8::Handle proto_templ = class_templ->InstanceTemplate(); + proto_templ->SetAccessor(v8::String::NewSymbol(symbol), getter, setter); } /** - * Registers a class method with given name for a given class template. + * Registers a class method with given name for a given object. */ -void SWIGV8_AddGlobalVariable(v8::Handle class_templ, const char* symbol, v8::AccessorGetter getter, v8::AccessorSetter setter) { - v8::Handle obj_templ = class_templ->InstanceTemplate(); - obj_templ->SetAccessor(v8::String::NewSymbol(symbol), getter, setter); +void SWIGV8_AddStaticFunction(v8::Handle obj, const char* symbol, v8::InvocationCallback _func) { + obj->Set(v8::String::NewSymbol(symbol), v8::FunctionTemplate::New(_func)->GetFunction()); } + +/** + * Registers a class method with given name for a given object. + */ +void SWIGV8_AddStaticVariable(v8::Handle obj, const char* symbol, v8::AccessorGetter getter, v8::AccessorSetter setter) { + obj->SetAccessor(v8::String::NewSymbol(symbol), getter, setter); +} + %} // v8_helper_functions diff --git a/Source/Modules/javascript.cxx b/Source/Modules/javascript.cxx index 14b2e7859..a415e8371 100644 --- a/Source/Modules/javascript.cxx +++ b/Source/Modules/javascript.cxx @@ -1728,7 +1728,8 @@ int V8Emitter::exitClass(Node *n) .pretty_print(f_init_class_templates); Template t_class_instance(getTemplate("jsv8_create_class_instance")); - t_class_instance.replace(T_NAME_MANGLED, state.clazz(NAME_MANGLED)) + t_class_instance.replace(T_NAME, state.clazz(NAME)) + .replace(T_NAME_MANGLED, state.clazz(NAME_MANGLED)) .pretty_print(f_init_class_instances); // emit inheritance setup @@ -1790,7 +1791,7 @@ int V8Emitter::exitVariable(Node* n) .replace(T_SETTER, state.variable(SETTER)) .pretty_print(f_init_wrappers); } - + return SWIG_OK; } @@ -1809,14 +1810,14 @@ int V8Emitter::exitFunction(Node* n) Template t_register(getTemplate("jsv8_register_static_function")); t_register.replace(T_PARENT, state.clazz(NAME_MANGLED)) .replace(T_NAME, state.function(NAME)) - .replace(T_WRAPPER, Getattr(n, "wrap:name")); - Printv(f_init_static_wrappers, t_register.str(), 0); + .replace(T_WRAPPER, Getattr(n, "wrap:name")) + .pretty_print(f_init_static_wrappers); } else { Template t_register(getTemplate("jsv8_register_member_function")); t_register.replace(T_NAME_MANGLED, state.clazz(NAME_MANGLED)) .replace(T_NAME, state.function(NAME)) - .replace(T_WRAPPER, Getattr(n, "wrap:name")); - Printv(f_init_wrappers, t_register.str(), "\n", 0); + .replace(T_WRAPPER, Getattr(n, "wrap:name")) + .pretty_print(f_init_wrappers); } } else { // Note: a global function is treated like a static function @@ -1824,8 +1825,8 @@ int V8Emitter::exitFunction(Node* n) Template t_register(getTemplate("jsv8_register_static_function")); t_register.replace(T_PARENT, Getattr(current_namespace, NAME)) .replace(T_NAME, state.function(NAME)) - .replace(T_WRAPPER, Getattr(n, "wrap:name")); - Printv(f_init_wrappers, t_register.str(), 0); + .replace(T_WRAPPER, Getattr(n, "wrap:name")) + .pretty_print(f_init_wrappers); } return SWIG_OK;