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

View file

@ -24,10 +24,12 @@ void SWIGV8_AddMemberFunction(v8::Handle<v8::FunctionTemplate> class_templ, cons
/**
* Registers a class method with given name for a given class template.
*/
void SWIGV8_AddGlobalFunction(v8::Handle<v8::ObjectTemplate> obj_templ, const char* symbol, v8::InvocationCallback _func) {
obj_templ->Set(v8::String::NewSymbol(symbol), v8::FunctionTemplate::New(_func)->GetFunction());
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.
*/
@ -39,7 +41,8 @@ void SWIGV8_AddMemberVariable(v8::Handle<v8::FunctionTemplate> class_templ, cons
/**
* Registers a class method with given name for a given class template.
*/
void SWIGV8_AddGlobalVariable(v8::Handle<v8::ObjectTemplate> obj_templ, const char* symbol, v8::AccessorGetter getter, v8::AccessorSetter setter) {
obj_templ->SetAccessor(v8::String::NewSymbol(symbol), getter, setter);
void SWIGV8_AddGlobalVariable(v8::Handle<v8::FunctionTemplate> class_templ, const char* symbol, v8::AccessorGetter getter, v8::AccessorSetter setter) {
v8::Handle<v8::ObjectTemplate> obj_templ = class_templ->InstanceTemplate();
obj_templ->SetAccessor(v8::String::NewSymbol(symbol), getter, setter);
}
%} // v8_helper_functions

View file

@ -24,7 +24,7 @@ typedef struct {
bool swigCMemOwn;
void *swigCObject;
swig_type_info *info;
}SWIG_PRV_DATA;
} SWIG_PRV_DATA;
%}
%insert(runtime) %{
@ -88,8 +88,27 @@ int SWIG_V8_ConvertPtr(v8::Handle<v8::Value> valRef, void** ptr, swig_type_info
}
v8::Handle<v8::Object> SWIG_V8_NewPointerObj(void *ptr, swig_type_info *info, int flags) {
// TODO: wrap ptr into an v8 object
return v8::Undefined();
v8::HandleScope scope;
v8::Local<v8::FunctionTemplate> class_templ;
if(info->clientdata == NULL) {
// TODO: get class template for unknown types
//class_templ = _SwigObject_classRef;
} else {
class_templ = *((v8::Local<v8::FunctionTemplate>*) info->clientdata);
}
v8::Handle<v8::ObjectTemplate> inst_templ = class_templ->InstanceTemplate();
v8::Local<v8::Object> result = inst_templ->NewInstance();
SWIG_PRV_DATA* cdata = (SWIG_PRV_DATA*) new SWIG_PRV_DATA;
cdata->swigCObject = ptr;
cdata->swigCMemOwn = (flags & SWIG_POINTER_OWN) ? 1 : 0;
cdata->info = info;
result->SetInternalField(0, v8::External::New(cdata));
return scope.Close(result);
}
#define SWIG_ConvertPtr(obj, ptr, info, flags) SWIG_V8_ConvertPtr(obj, ptr, info, flags)