%fragment("JS_ctordefn", "templates") %{ v8::Handle $jsmangledname_new(const v8::Arguments& args) { v8::HandleScope scope; v8::Handle self = args.Holder(); $jslocals $jscode self->SetInternalField(0, v8::External::New(result)); return scope.Close(self); goto fail; fail: return scope.Close(v8::Undefined); }%} %fragment("JS_getproperty", "templates") %{ v8::Handle $jsgetter(v8::Local property, const v8::AccessorInfo& info) { v8::HandleScope scope; v8::Handle jsresult; $jslocals $jscode return scope.Close(jsresult); goto fail; fail: return scope.Close(v8::Undefined()); }%} %fragment("JS_setproperty", "templates") %{ void $jssetter(v8::Local property, v8::Local value, const v8::AccessorInfo& info) { v8::HandleScope scope; $jslocals $jscode goto fail; fail: return; }%} %fragment("JS_functionwrapper", "templates") %{ v8::Handle $jswrapper(const v8::Arguments &args) { v8::HandleScope scope; v8::Handle jsresult; $jslocals $jscode return scope.Close(jsresult); goto fail; fail: return scope.Close(v8::Undefined()); }%} // TODO: implement ctor overloading properly! %fragment ("JS_mainctordefn", "templates") %{ // TODO: implement JS_mainctordefn %} %fragment ("JS_ctor_dispatch_case", "templates") %{ // TODO: implement JS_ctor_dispatch_case %} %fragment ("JS_destructordefn", "templates") %{ // TODO: implement JS_destructordefn %} %fragment("jsv8_declare_class_template", "templates") %{ v8::Persistent SWIGV8_$jsmangledname;%} %fragment("jsv8_define_class_template", "templates") %{ SWIGV8_$jsmangledname = SWIGV8_CreateClassTemplate("$jsname" , $jsmangledname_new);%} %fragment("jsv8_create_class_instance", "templates") %{ v8::Handle class_$jsmangledname = SWIGV8_$jsmangledname->GetFunction();%} %fragment("jsv8_inherit", "templates") %{ SWIGV8_$jsmangledname->Inherit(SWIGV8_$jsbaseclass);%} %fragment("jsv8_register_class", "templates") %{ $jsparent->Set(v8::String::NewSymbol("$jsname"), class_$jsmangledname);%} %fragment("jsv8_create_namespace", "templates") %{ v8::Handle $jsmangledname = v8::ObjectTemplate::New();%} %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_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_namespace", "templates") %{ $jsparent->Set(v8::String::NewSymbol("$jsname", $jsmangledname->NewInstance()));%} %fragment("JS_initializer", "templates") %{ extern "C" { void $jsname_initialize(v8::Handle context) { 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 /* class instances */ $jsv8classinstances /* add static class functions and variables */ $jsv8staticwrappers /* register classes */ $jsv8registerclasses /* create and register namespace objects */ $jsv8registernspaces } }%}