Several fixes in v8 emitter and code templates.

Achieves first compile of example "class" after re-integration.

git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/oliverb-javascript-v8@13793 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
Oliver Buchtala 2012-09-08 01:06:58 +00:00
commit cda09239ad
4 changed files with 112 additions and 75 deletions

View file

@ -1,5 +1,5 @@
%fragment("JS_ctordefn", "templates") %{
v8::Handle<v8::Value> $jsmangledname_new(const v8::Arguments& args) {
v8::Handle<v8::Value> $jswrapper(const v8::Arguments& args) {
v8::HandleScope scope;
v8::Handle<v8::Object> self = args.Holder();
$jslocals
@ -8,13 +8,21 @@ v8::Handle<v8::Value> $jsmangledname_new(const v8::Arguments& args) {
return scope.Close(self);
goto fail;
fail:
return scope.Close(v8::Undefined);
return scope.Close(v8::Undefined());
}%}
%fragment ("JS_veto_ctor", "templates")
%{
v8::Handle<v8::Value> $jsctor(const v8::Arguments& args) {
v8::HandleScope scope;
SWIG_exception(SWIG_ERROR, "Class $jsname can not be instantiated");
return scope.Close(v8::Undefined());
}%}
%fragment("JS_getproperty", "templates") %{
v8::Handle<v8::Value> $jsgetter(v8::Local<v8::String> property, const v8::AccessorInfo& info) {
v8::HandleScope scope;
v8::Handle<v8::Object> jsresult;
v8::Handle<v8::Value> jsresult;
$jslocals
$jscode
return scope.Close(jsresult);
@ -36,7 +44,7 @@ fail:
%fragment("JS_functionwrapper", "templates") %{
v8::Handle<v8::Value> $jswrapper(const v8::Arguments &args) {
v8::HandleScope scope;
v8::Handle<v8::Object> jsresult;
v8::Handle<v8::Value> jsresult;
$jslocals
$jscode
return scope.Close(jsresult);
@ -45,7 +53,6 @@ fail:
return scope.Close(v8::Undefined());
}%}
// TODO: implement ctor overloading properly!
%fragment ("JS_mainctordefn", "templates")
%{
// TODO: implement JS_mainctordefn
@ -61,41 +68,41 @@ fail:
// TODO: implement JS_destructordefn
%}
%fragment("jsv8_declare_class_template", "templates") %{
v8::Persistent<v8::FunctionTemplate> SWIGV8_$jsmangledname;%}
%fragment("jsv8_declare_class_template", "templates")
%{v8::Persistent<v8::FunctionTemplate> SWIGV8_$jsmangledname;%}
%fragment("jsv8_define_class_template", "templates") %{
SWIGV8_$jsmangledname = SWIGV8_CreateClassTemplate("$jsname" , $jsmangledname_new);%}
%fragment("jsv8_define_class_template", "templates")
%{SWIGV8_$jsmangledname = SWIGV8_CreateClassTemplate("$jsname" , $jsctor);%}
%fragment("jsv8_create_class_instance", "templates") %{
v8::Handle<v8::Object> class_$jsmangledname = SWIGV8_$jsmangledname->GetFunction();%}
%fragment("jsv8_create_class_instance", "templates")
%{v8::Handle<v8::Object> class_$jsmangledname = SWIGV8_$jsmangledname->GetFunction();%}
%fragment("jsv8_inherit", "templates") %{
SWIGV8_$jsmangledname->Inherit(SWIGV8_$jsbaseclass);%}
%fragment("jsv8_inherit", "templates")
%{SWIGV8_$jsmangledname->Inherit(SWIGV8_$jsbaseclass);%}
%fragment("jsv8_register_class", "templates") %{
$jsparent->Set(v8::String::NewSymbol("$jsname"), class_$jsmangledname);%}
%fragment("jsv8_register_class", "templates")
%{$jsparent->Set(v8::String::NewSymbol("$jsname"), class_$jsmangledname);%}
%fragment("jsv8_create_namespace", "templates") %{
v8::Handle<v8::ObjectTemplate> $jsmangledname = v8::ObjectTemplate::New();%}
%fragment("jsv8_create_namespace", "templates")
%{v8::Handle<v8::ObjectTemplate> $jsmangledname = v8::ObjectTemplate::New();%}
%fragment("jsv8_register_member_function", "templates") %{
SWIGV8_AddMemberFunction(SWIGV8_$jsmangledname, "$jsname", $jswrapper);%}
%fragment("jsv8_register_member_function", "templates")
%{SWIGV8_AddMemberFunction(SWIGV8_$jsmangledname, "$jsname", $jswrapper);%}
%fragment("jsv8_register_static_function", "templates") %{
SWIGV8_AddGlobalFunction($jsparent, "$jsname", $jswrapper);%}
%fragment("jsv8_register_static_function", "templates")
%{SWIGV8_AddGlobalFunction(SWIGV8_$jsparent, "$jsname", $jswrapper);%}
%fragment("jsv8_register_member_variable", "templates") %{
SWIGV8_AddMemberVariable(SWIGV8_$jsmangledname, "$jsname", $jsgetter, $jssetter);%}
%fragment("jsv8_register_member_variable", "templates")
%{SWIGV8_AddMemberVariable(SWIGV8_$jsmangledname, "$jsname", $jsgetter, $jssetter);%}
%fragment("jsv8_register_static_variable", "templates") %{
SWIGV8_AddGlobalVariable($jsparent, "$jsname", $jsgetter, $jssetter);%}
%fragment("jsv8_register_static_variable", "templates")
%{SWIGV8_AddGlobalVariable(SWIGV8_$jsparent, "$jsname", $jsgetter, $jssetter);%}
%fragment("jsv8_register_namespace", "templates") %{
$jsparent->Set(v8::String::NewSymbol("$jsname", $jsmangledname->NewInstance()));%}
%fragment("JS_initializer", "templates") %{
%fragment("jsv8_register_namespace", "templates")
%{$jsparent->Set(v8::String::NewSymbol("$jsname"), $jsmangledname->NewInstance());%}
%fragment("JS_initializer", "templates")
%{
extern "C" {
void $jsname_initialize(v8::Handle<v8::Context> context)
@ -115,12 +122,12 @@ void $jsname_initialize(v8::Handle<v8::Context> context)
/* setup inheritances */
$jsv8inheritance
/* class instances */
$jsv8classinstances
/* add static class functions and variables */
$jsv8staticwrappers
/* class instances */
$jsv8classinstances
/* register classes */
$jsv8registerclasses