From: <ol...@us...> - 2012-09-08 00:49:38
|
Revision: 13751 http://swig.svn.sourceforge.net/swig/?rev=13751&view=rev Author: oliv3rb Date: 2012-09-08 00:49:32 +0000 (Sat, 08 Sep 2012) Log Message: ----------- Improve v8 generator regarding registration of function wrappers. Modified Paths: -------------- branches/oliverb-javascript-v8/Lib/javascript/v8/javascriptcode.swg branches/oliverb-javascript-v8/Source/Modules/javascript_v8.cxx Modified: branches/oliverb-javascript-v8/Lib/javascript/v8/javascriptcode.swg =================================================================== --- branches/oliverb-javascript-v8/Lib/javascript/v8/javascriptcode.swg 2012-09-08 00:49:15 UTC (rev 13750) +++ branches/oliverb-javascript-v8/Lib/javascript/v8/javascriptcode.swg 2012-09-08 00:49:32 UTC (rev 13751) @@ -68,7 +68,7 @@ %} %fragment("v8_function", "templates") %{ -v8::Handle<v8::Value> ${NAME_MANGLED}(const Arguments &args) { +v8::Handle<v8::Value> wrap_${NAME_MANGLED}(const Arguments &args) { v8::HandleScope scope; v8::Handle<v8::Object> ret; ${LOCALS} @@ -79,11 +79,14 @@ } %} -%fragment("v8_register_member_function", "templates") %{ -SWIGV8_AddClassMethod(SWIGV8_${CLASSNAME_MANGLED}, "${NAME_UNQUALIFIED}", ${WRAPPER});%} - %fragment("v8_create_namespace", "templates") %{ v8::Handle<v8::ObjectTemplate> ${NAME_MANGLED} = v8::ObjectTemplate::New();%} +%fragment("v8_register_member_function", "templates") %{ +SWIGV8_AddClassMethod(SWIGV8_${CLASSNAME_MANGLED}, "${NAME_UNQUALIFIED}", wrap_${NAME_MANGLED});%} + +%fragment("v8_register_global_function", "templates") %{ +${CONTEXT}->Set(v8::String::NewSymbol("${NAME_UNQUALIFIED}"), v8::FunctionTemplate::New(wrap_${NAME_MANGLED})->GetFunction());%} + %fragment("v8_register_namespace", "templates") %{ ${CONTEXT}->Set(v8::String::NewSymbol("${NAME_UNQUALIFIED}", ${NAME_MANGLED}->NewInstance()));%} Modified: branches/oliverb-javascript-v8/Source/Modules/javascript_v8.cxx =================================================================== --- branches/oliverb-javascript-v8/Source/Modules/javascript_v8.cxx 2012-09-08 00:49:15 UTC (rev 13750) +++ branches/oliverb-javascript-v8/Source/Modules/javascript_v8.cxx 2012-09-08 00:49:32 UTC (rev 13751) @@ -17,6 +17,7 @@ #define V8_FUNCTION "v8_function" #define V8_RETRIEVE_THIS "v8_retrieve_this" #define V8_REGISTER_MEMBER_FUNCTION "v8_register_member_function" +#define V8_REGISTER_GLOBAL_FUNCTION "v8_register_global_function" #define V8_CREATE_NAMESPACE "v8_create_namespace" #define V8_REGISTER_NAMESPACE "v8_register_namespace" @@ -247,6 +248,7 @@ { // TODO: Register variable in context + Swig_print_node(n); Delete(current_variable_mangled); Delete(current_variable_unqualified); @@ -271,9 +273,7 @@ } int V8Emitter::ExitFunction(Node* n) -{ - // TODO: Register function in context - +{ Delete(current_function_mangled); Delete(current_function_unqualified); current_function_mangled = 0; @@ -385,18 +385,21 @@ .Replace(KW_ACTION, action) .Replace(KW_MARSHAL_INPUT, input) .Replace(KW_MARSHAL_OUTPUT, output); - Wrapper_pretty_print(t_function.str(), f_wrapper); // register the function at the specific context if (is_member) { Template t_register(GetTemplate(V8_REGISTER_MEMBER_FUNCTION)); t_register.Replace(KW_UNQUALIFIED_NAME, current_function_unqualified) - .Replace(KW_WRAPPER, wrap_name) + .Replace(KW_MANGLED_NAME, wrap_name) .Replace(KW_CLASSNAME_MANGLED, current_classname_mangled); Printv(f_init_wrappers, t_register.str(), "\n", 0); } else { - // TODO + Template t_register(GetTemplate(V8_REGISTER_GLOBAL_FUNCTION)); + t_register.Replace(KW_CONTEXT, current_context) + .Replace(KW_UNQUALIFIED_NAME, current_function_unqualified) + .Replace(KW_MANGLED_NAME, wrap_name); + Printv(f_init_wrappers, t_register.str(), 0); } // clean up This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |