Several fixes in generator for v8 initializer function.
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/oliverb-javascript-v8@13796 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
parent
78f5b46381
commit
46cff47ada
3 changed files with 60 additions and 61 deletions
|
|
@ -69,37 +69,37 @@ fail:
|
||||||
%}
|
%}
|
||||||
|
|
||||||
%fragment("jsv8_declare_class_template", "templates")
|
%fragment("jsv8_declare_class_template", "templates")
|
||||||
%{v8::Persistent<v8::FunctionTemplate> SWIGV8_$jsmangledname;%}
|
%{v8::Persistent<v8::FunctionTemplate> $jsmangledname_class;%}
|
||||||
|
|
||||||
%fragment("jsv8_define_class_template", "templates")
|
%fragment("jsv8_define_class_template", "templates")
|
||||||
%{SWIGV8_$jsmangledname = SWIGV8_CreateClassTemplate("$jsname" , $jsctor);%}
|
%{$jsmangledname_class = SWIGV8_CreateClassTemplate("$jsname" , $jsctor);%}
|
||||||
|
|
||||||
%fragment("jsv8_create_class_instance", "templates")
|
%fragment("jsv8_create_class_instance", "templates")
|
||||||
%{v8::Handle<v8::Object> class_$jsmangledname = SWIGV8_$jsmangledname->GetFunction();%}
|
%{v8::Handle<v8::Object> $jsmangledname = $jsmangledname_class->GetFunction();%}
|
||||||
|
|
||||||
%fragment("jsv8_inherit", "templates")
|
%fragment("jsv8_inherit", "templates")
|
||||||
%{SWIGV8_$jsmangledname->Inherit(SWIGV8_$jsbaseclass);%}
|
%{$jsmangledname_class->Inherit($jsbaseclass_class);%}
|
||||||
|
|
||||||
%fragment("jsv8_register_class", "templates")
|
%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")
|
%fragment("jsv8_create_namespace", "templates")
|
||||||
%{v8::Handle<v8::ObjectTemplate> $jsmangledname = v8::ObjectTemplate::New();%}
|
%{v8::Handle<v8::Object> $jsmangledname = v8::Object::New();%}
|
||||||
|
|
||||||
%fragment("jsv8_register_member_function", "templates")
|
%fragment("jsv8_register_member_function", "templates")
|
||||||
%{SWIGV8_AddMemberFunction(SWIGV8_$jsmangledname, "$jsname", $jswrapper);%}
|
%{SWIGV8_AddMemberFunction($jsmangledname_class, "$jsname", $jswrapper);%}
|
||||||
|
|
||||||
%fragment("jsv8_register_static_function", "templates")
|
|
||||||
%{SWIGV8_AddGlobalFunction(SWIGV8_$jsparent, "$jsname", $jswrapper);%}
|
|
||||||
|
|
||||||
%fragment("jsv8_register_member_variable", "templates")
|
%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")
|
%fragment("jsv8_register_static_variable", "templates")
|
||||||
%{SWIGV8_AddGlobalVariable(SWIGV8_$jsparent, "$jsname", $jsgetter, $jssetter);%}
|
%{SWIGV8_AddStaticVariable($jsparent, "$jsname", $jsgetter, $jssetter);%}
|
||||||
|
|
||||||
%fragment("jsv8_register_namespace", "templates")
|
%fragment("jsv8_register_namespace", "templates")
|
||||||
%{$jsparent->Set(v8::String::NewSymbol("$jsname"), $jsmangledname->NewInstance());%}
|
%{$jsparent->Set(v8::String::NewSymbol("$jsname"), $jsmangledname);%}
|
||||||
|
|
||||||
%fragment("JS_initializer", "templates")
|
%fragment("JS_initializer", "templates")
|
||||||
%{
|
%{
|
||||||
|
|
@ -107,32 +107,32 @@ extern "C" {
|
||||||
|
|
||||||
void $jsname_initialize(v8::Handle<v8::Context> context)
|
void $jsname_initialize(v8::Handle<v8::Context> context)
|
||||||
{
|
{
|
||||||
v8::HandleScope scope;
|
v8::HandleScope scope;
|
||||||
v8::Local<v8::Object> global = context->Global();
|
v8::Local<v8::Object> global = context->Global();
|
||||||
|
|
||||||
/* create object templates for namespaces */
|
/* create objects for namespaces */
|
||||||
$jsv8nspaces
|
$jsv8nspaces
|
||||||
|
|
||||||
/* create class templates */
|
/* create class templates */
|
||||||
$jsv8classtemplates
|
$jsv8classtemplates
|
||||||
|
|
||||||
/* register wrapper functions */
|
/* register wrapper functions */
|
||||||
$jsv8wrappers
|
$jsv8wrappers
|
||||||
|
|
||||||
/* setup inheritances */
|
/* setup inheritances */
|
||||||
$jsv8inheritance
|
$jsv8inheritance
|
||||||
|
|
||||||
/* add static class functions and variables */
|
/* class instances */
|
||||||
$jsv8staticwrappers
|
$jsv8classinstances
|
||||||
|
|
||||||
/* class instances */
|
/* add static class functions and variables */
|
||||||
$jsv8classinstances
|
$jsv8staticwrappers
|
||||||
|
|
||||||
/* register classes */
|
/* register classes */
|
||||||
$jsv8registerclasses
|
$jsv8registerclasses
|
||||||
|
|
||||||
/* create and register namespace objects */
|
/* create and register namespace objects */
|
||||||
$jsv8registernspaces
|
$jsv8registernspaces
|
||||||
}
|
}
|
||||||
|
|
||||||
}%}
|
}%}
|
||||||
|
|
|
||||||
|
|
@ -21,28 +21,26 @@ void SWIGV8_AddMemberFunction(v8::Handle<v8::FunctionTemplate> class_templ, cons
|
||||||
proto_templ->Set(v8::String::NewSymbol(symbol), v8::FunctionTemplate::New(_func));
|
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<v8::FunctionTemplate> class_templ, const char* symbol, v8::InvocationCallback _func) {
|
|
||||||
v8::Handle<v8::ObjectTemplate> 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.
|
* Registers a class property with given name for a given class template.
|
||||||
*/
|
*/
|
||||||
void SWIGV8_AddMemberVariable(v8::Handle<v8::FunctionTemplate> class_templ, const char* symbol, v8::AccessorGetter getter, v8::AccessorSetter setter) {
|
void SWIGV8_AddMemberVariable(v8::Handle<v8::FunctionTemplate> class_templ, const char* symbol, v8::AccessorGetter getter, v8::AccessorSetter setter) {
|
||||||
v8::Handle<v8::ObjectTemplate> proto_templ = class_templ->InstanceTemplate();
|
v8::Handle<v8::ObjectTemplate> proto_templ = class_templ->InstanceTemplate();
|
||||||
proto_templ->SetAccessor(v8::String::NewSymbol(symbol), getter, setter);
|
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<v8::FunctionTemplate> class_templ, const char* symbol, v8::AccessorGetter getter, v8::AccessorSetter setter) {
|
void SWIGV8_AddStaticFunction(v8::Handle<v8::Object> obj, const char* symbol, v8::InvocationCallback _func) {
|
||||||
v8::Handle<v8::ObjectTemplate> obj_templ = class_templ->InstanceTemplate();
|
obj->Set(v8::String::NewSymbol(symbol), v8::FunctionTemplate::New(_func)->GetFunction());
|
||||||
obj_templ->SetAccessor(v8::String::NewSymbol(symbol), getter, setter);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Registers a class method with given name for a given object.
|
||||||
|
*/
|
||||||
|
void SWIGV8_AddStaticVariable(v8::Handle<v8::Object> obj, const char* symbol, v8::AccessorGetter getter, v8::AccessorSetter setter) {
|
||||||
|
obj->SetAccessor(v8::String::NewSymbol(symbol), getter, setter);
|
||||||
|
}
|
||||||
|
|
||||||
%} // v8_helper_functions
|
%} // v8_helper_functions
|
||||||
|
|
|
||||||
|
|
@ -1728,7 +1728,8 @@ int V8Emitter::exitClass(Node *n)
|
||||||
.pretty_print(f_init_class_templates);
|
.pretty_print(f_init_class_templates);
|
||||||
|
|
||||||
Template t_class_instance(getTemplate("jsv8_create_class_instance"));
|
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);
|
.pretty_print(f_init_class_instances);
|
||||||
|
|
||||||
// emit inheritance setup
|
// emit inheritance setup
|
||||||
|
|
@ -1790,7 +1791,7 @@ int V8Emitter::exitVariable(Node* n)
|
||||||
.replace(T_SETTER, state.variable(SETTER))
|
.replace(T_SETTER, state.variable(SETTER))
|
||||||
.pretty_print(f_init_wrappers);
|
.pretty_print(f_init_wrappers);
|
||||||
}
|
}
|
||||||
|
|
||||||
return SWIG_OK;
|
return SWIG_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1809,14 +1810,14 @@ int V8Emitter::exitFunction(Node* n)
|
||||||
Template t_register(getTemplate("jsv8_register_static_function"));
|
Template t_register(getTemplate("jsv8_register_static_function"));
|
||||||
t_register.replace(T_PARENT, state.clazz(NAME_MANGLED))
|
t_register.replace(T_PARENT, state.clazz(NAME_MANGLED))
|
||||||
.replace(T_NAME, state.function(NAME))
|
.replace(T_NAME, state.function(NAME))
|
||||||
.replace(T_WRAPPER, Getattr(n, "wrap:name"));
|
.replace(T_WRAPPER, Getattr(n, "wrap:name"))
|
||||||
Printv(f_init_static_wrappers, t_register.str(), 0);
|
.pretty_print(f_init_static_wrappers);
|
||||||
} else {
|
} else {
|
||||||
Template t_register(getTemplate("jsv8_register_member_function"));
|
Template t_register(getTemplate("jsv8_register_member_function"));
|
||||||
t_register.replace(T_NAME_MANGLED, state.clazz(NAME_MANGLED))
|
t_register.replace(T_NAME_MANGLED, state.clazz(NAME_MANGLED))
|
||||||
.replace(T_NAME, state.function(NAME))
|
.replace(T_NAME, state.function(NAME))
|
||||||
.replace(T_WRAPPER, Getattr(n, "wrap:name"));
|
.replace(T_WRAPPER, Getattr(n, "wrap:name"))
|
||||||
Printv(f_init_wrappers, t_register.str(), "\n", 0);
|
.pretty_print(f_init_wrappers);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// Note: a global function is treated like a static function
|
// 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"));
|
Template t_register(getTemplate("jsv8_register_static_function"));
|
||||||
t_register.replace(T_PARENT, Getattr(current_namespace, NAME))
|
t_register.replace(T_PARENT, Getattr(current_namespace, NAME))
|
||||||
.replace(T_NAME, state.function(NAME))
|
.replace(T_NAME, state.function(NAME))
|
||||||
.replace(T_WRAPPER, Getattr(n, "wrap:name"));
|
.replace(T_WRAPPER, Getattr(n, "wrap:name"))
|
||||||
Printv(f_init_wrappers, t_register.str(), 0);
|
.pretty_print(f_init_wrappers);
|
||||||
}
|
}
|
||||||
|
|
||||||
return SWIG_OK;
|
return SWIG_OK;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue