Add support for static member variables and functions to v8 module.
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/oliverb-javascript-v8@13759 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
parent
e8dd979d16
commit
32a32633ba
3 changed files with 63 additions and 14 deletions
|
|
@ -16,6 +16,12 @@ void ${MODULE}_Initialize(v8::Handle<v8::Context> context)
|
||||||
/* setup inheritances */
|
/* setup inheritances */
|
||||||
${PART_INHERITANCE}
|
${PART_INHERITANCE}
|
||||||
|
|
||||||
|
/* class instances */
|
||||||
|
${PART_CLASS_INSTANCES}
|
||||||
|
|
||||||
|
/* add static class functions and variables */
|
||||||
|
${PART_STATIC_WRAPPERS}
|
||||||
|
|
||||||
/* register classes */
|
/* register classes */
|
||||||
${PART_REGISTER_CLASSES}
|
${PART_REGISTER_CLASSES}
|
||||||
|
|
||||||
|
|
@ -29,11 +35,14 @@ v8::Persistent<v8::FunctionTemplate> SWIGV8_${NAME_MANGLED};%}
|
||||||
%fragment("v8_define_class_template", "templates") %{
|
%fragment("v8_define_class_template", "templates") %{
|
||||||
SWIGV8_${NAME_MANGLED} = SWIGV8_CreateClassTemplate("${NAME_UNQUALIFIED}" , ${NAME_MANGLED}_new);%}
|
SWIGV8_${NAME_MANGLED} = SWIGV8_CreateClassTemplate("${NAME_UNQUALIFIED}" , ${NAME_MANGLED}_new);%}
|
||||||
|
|
||||||
|
%fragment("v8_create_class_instance", "templates") %{
|
||||||
|
v8::Handle<v8::Object> class_${NAME_MANGLED} = SWIGV8_${NAME_MANGLED}->GetFunction();%}
|
||||||
|
|
||||||
%fragment("v8_inherit", "templates") %{
|
%fragment("v8_inherit", "templates") %{
|
||||||
SWIGV8_${NAME_MANGLED}->Inherit(SWIGV8_${BASE_CLASS});%}
|
SWIGV8_${NAME_MANGLED}->Inherit(SWIGV8_${BASE_CLASS});%}
|
||||||
|
|
||||||
%fragment("v8_register_class", "templates") %{
|
%fragment("v8_register_class", "templates") %{
|
||||||
${CONTEXT}->Set(v8::String::NewSymbol("${NAME_UNQUALIFIED}", SWIGV8_${NAME_MANGLED}->GetFunction()));%}
|
${CONTEXT}->Set(v8::String::NewSymbol("${NAME_UNQUALIFIED}"), class_${NAME_MANGLED});%}
|
||||||
|
|
||||||
%fragment("v8_ctor_wrapper", "templates") %{
|
%fragment("v8_ctor_wrapper", "templates") %{
|
||||||
v8::Handle<v8::Value> ${NAME_MANGLED}_new(const v8::Arguments& args) {
|
v8::Handle<v8::Value> ${NAME_MANGLED}_new(const v8::Arguments& args) {
|
||||||
|
|
|
||||||
|
|
@ -9,6 +9,7 @@
|
||||||
#define V8_INITIALIZER "v8_initializer"
|
#define V8_INITIALIZER "v8_initializer"
|
||||||
#define V8_DECL_CLASSTEMPLATE "v8_declare_class_template"
|
#define V8_DECL_CLASSTEMPLATE "v8_declare_class_template"
|
||||||
#define V8_DEFINE_CLASSTEMPLATE "v8_define_class_template"
|
#define V8_DEFINE_CLASSTEMPLATE "v8_define_class_template"
|
||||||
|
#define V8_CREATE_CLASS_INSTANCE "v8_create_class_instance"
|
||||||
#define V8_INHERIT "v8_inherit"
|
#define V8_INHERIT "v8_inherit"
|
||||||
#define V8_REGISTER_CLASS "v8_register_class"
|
#define V8_REGISTER_CLASS "v8_register_class"
|
||||||
#define V8_CTOR_WRAPPER "v8_ctor_wrapper"
|
#define V8_CTOR_WRAPPER "v8_ctor_wrapper"
|
||||||
|
|
@ -42,6 +43,8 @@
|
||||||
#define KW_CLASS_TEMPLATES "${PART_CLASS_TEMPLATES}"
|
#define KW_CLASS_TEMPLATES "${PART_CLASS_TEMPLATES}"
|
||||||
#define KW_WRAPPERS "${PART_WRAPPERS}"
|
#define KW_WRAPPERS "${PART_WRAPPERS}"
|
||||||
#define KW_INHERITANCE "${PART_INHERITANCE}"
|
#define KW_INHERITANCE "${PART_INHERITANCE}"
|
||||||
|
#define KW_CLASS_INSTANCES "${PART_CLASS_INSTANCES}"
|
||||||
|
#define KW_STATIC_WRAPPERS "${PART_STATIC_WRAPPERS}"
|
||||||
#define KW_REGISTER_CLASSES "${PART_REGISTER_CLASSES}"
|
#define KW_REGISTER_CLASSES "${PART_REGISTER_CLASSES}"
|
||||||
#define KW_REGISTER_NS "${PART_REGISTER_NS}"
|
#define KW_REGISTER_NS "${PART_REGISTER_NS}"
|
||||||
|
|
||||||
|
|
@ -86,6 +89,8 @@ int V8Emitter::Initialize(Node *n)
|
||||||
f_init_class_templates = NewString("");
|
f_init_class_templates = NewString("");
|
||||||
f_init_wrappers = NewString("");
|
f_init_wrappers = NewString("");
|
||||||
f_init_inheritance = NewString("");
|
f_init_inheritance = NewString("");
|
||||||
|
f_init_class_instances = NewString("");
|
||||||
|
f_init_static_wrappers = NewString("");
|
||||||
f_init_register_classes = NewString("");
|
f_init_register_classes = NewString("");
|
||||||
f_init_register_namespaces = NewString("");
|
f_init_register_namespaces = NewString("");
|
||||||
|
|
||||||
|
|
@ -116,6 +121,8 @@ int V8Emitter::Dump(Node *n)
|
||||||
.Replace(KW_CLASS_TEMPLATES, f_init_class_templates)
|
.Replace(KW_CLASS_TEMPLATES, f_init_class_templates)
|
||||||
.Replace(KW_WRAPPERS, f_init_wrappers)
|
.Replace(KW_WRAPPERS, f_init_wrappers)
|
||||||
.Replace(KW_INHERITANCE, f_init_inheritance)
|
.Replace(KW_INHERITANCE, f_init_inheritance)
|
||||||
|
.Replace(KW_CLASS_INSTANCES, f_init_class_instances)
|
||||||
|
.Replace(KW_STATIC_WRAPPERS, f_init_static_wrappers)
|
||||||
.Replace(KW_REGISTER_CLASSES, f_init_register_classes)
|
.Replace(KW_REGISTER_CLASSES, f_init_register_classes)
|
||||||
.Replace(KW_REGISTER_NS, f_init_register_namespaces);
|
.Replace(KW_REGISTER_NS, f_init_register_namespaces);
|
||||||
Wrapper_pretty_print(initializer.str(), f_wrap_cpp);
|
Wrapper_pretty_print(initializer.str(), f_wrap_cpp);
|
||||||
|
|
@ -125,6 +132,7 @@ int V8Emitter::Dump(Node *n)
|
||||||
|
|
||||||
int V8Emitter::Close()
|
int V8Emitter::Close()
|
||||||
{
|
{
|
||||||
|
/* strings */
|
||||||
Delete(f_runtime);
|
Delete(f_runtime);
|
||||||
Delete(f_header);
|
Delete(f_header);
|
||||||
Delete(f_class_templates);
|
Delete(f_class_templates);
|
||||||
|
|
@ -133,8 +141,12 @@ int V8Emitter::Close()
|
||||||
Delete(f_init_class_templates);
|
Delete(f_init_class_templates);
|
||||||
Delete(f_init_wrappers);
|
Delete(f_init_wrappers);
|
||||||
Delete(f_init_inheritance);
|
Delete(f_init_inheritance);
|
||||||
|
Delete(f_init_class_instances);
|
||||||
|
Delete(f_init_static_wrappers);
|
||||||
Delete(f_init_register_classes);
|
Delete(f_init_register_classes);
|
||||||
Delete(f_init_register_namespaces);
|
Delete(f_init_register_namespaces);
|
||||||
|
|
||||||
|
/* files */
|
||||||
::Close(f_wrap_cpp);
|
::Close(f_wrap_cpp);
|
||||||
Delete(f_wrap_cpp);
|
Delete(f_wrap_cpp);
|
||||||
|
|
||||||
|
|
@ -210,9 +222,13 @@ int V8Emitter::EnterClass(Node *n)
|
||||||
|
|
||||||
// emit definition of v8 class template
|
// emit definition of v8 class template
|
||||||
Template t_def_class(GetTemplate(V8_DEFINE_CLASSTEMPLATE));
|
Template t_def_class(GetTemplate(V8_DEFINE_CLASSTEMPLATE));
|
||||||
t_def_class.Replace(KW_MANGLED_NAME, current_classname_mangled)
|
t_def_class.Replace(KW_MANGLED_NAME, current_classname_mangled)
|
||||||
.Replace(KW_UNQUALIFIED_NAME, current_classname_unqualified);
|
.Replace(KW_UNQUALIFIED_NAME, current_classname_unqualified);
|
||||||
Printv(f_init_class_templates, t_def_class.str(), 0);
|
Printv(f_init_class_templates, t_def_class.str(), 0);
|
||||||
|
|
||||||
|
Template t_class_instance(GetTemplate(V8_CREATE_CLASS_INSTANCE));
|
||||||
|
t_class_instance.Replace(KW_MANGLED_NAME, current_classname_mangled);
|
||||||
|
Printv(f_init_class_instances, t_class_instance.str(), 0);
|
||||||
|
|
||||||
return SWIG_OK;
|
return SWIG_OK;
|
||||||
}
|
}
|
||||||
|
|
@ -262,14 +278,25 @@ int V8Emitter::EnterVariable(Node* n)
|
||||||
|
|
||||||
int V8Emitter::ExitVariable(Node* n)
|
int V8Emitter::ExitVariable(Node* n)
|
||||||
{
|
{
|
||||||
|
|
||||||
if(GetFlag(n, "ismember")) {
|
if(GetFlag(n, "ismember")) {
|
||||||
Template t_register(GetTemplate(V8_REGISTER_MEMBER_VARIABLE));
|
if(Equal(Getattr(n, "storage"), "static")) {
|
||||||
t_register.Replace(KW_CLASSNAME_MANGLED, current_classname_mangled)
|
Template t_register(GetTemplate(V8_REGISTER_GLOBAL_VARIABLE));
|
||||||
.Replace(KW_UNQUALIFIED_NAME, current_variable_unqualified)
|
String *class_instance = NewString("");
|
||||||
.Replace(KW_GETTER, current_getter)
|
Printf(class_instance, "class_%s", current_classname_mangled);
|
||||||
.Replace(KW_SETTER, current_setter);
|
t_register.Replace(KW_CONTEXT, class_instance)
|
||||||
Printv(f_init_wrappers, t_register.str(), 0);
|
.Replace(KW_UNQUALIFIED_NAME, current_variable_unqualified)
|
||||||
|
.Replace(KW_GETTER, current_getter)
|
||||||
|
.Replace(KW_SETTER, current_setter);
|
||||||
|
Printv(f_init_static_wrappers, t_register.str(), 0);
|
||||||
|
Delete(class_instance);
|
||||||
|
} else {
|
||||||
|
Template t_register(GetTemplate(V8_REGISTER_MEMBER_VARIABLE));
|
||||||
|
t_register.Replace(KW_CLASSNAME_MANGLED, current_classname_mangled)
|
||||||
|
.Replace(KW_UNQUALIFIED_NAME, current_variable_unqualified)
|
||||||
|
.Replace(KW_GETTER, current_getter)
|
||||||
|
.Replace(KW_SETTER, current_setter);
|
||||||
|
Printv(f_init_wrappers, t_register.str(), 0);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
Template t_register(GetTemplate(V8_REGISTER_GLOBAL_VARIABLE));
|
Template t_register(GetTemplate(V8_REGISTER_GLOBAL_VARIABLE));
|
||||||
t_register.Replace(KW_CONTEXT, current_context)
|
t_register.Replace(KW_CONTEXT, current_context)
|
||||||
|
|
@ -305,11 +332,22 @@ int V8Emitter::ExitFunction(Node* n)
|
||||||
{
|
{
|
||||||
// register the function at the specific context
|
// register the function at the specific context
|
||||||
if(GetFlag(n, "ismember")) {
|
if(GetFlag(n, "ismember")) {
|
||||||
Template t_register(GetTemplate(V8_REGISTER_MEMBER_FUNCTION));
|
if(Equal(Getattr(n, "storage"), "static")) {
|
||||||
t_register.Replace(KW_CLASSNAME_MANGLED, current_classname_mangled)
|
Template t_register(GetTemplate(V8_REGISTER_GLOBAL_FUNCTION));
|
||||||
.Replace(KW_UNQUALIFIED_NAME, current_function_unqualified)
|
String *class_instance = NewString("");
|
||||||
.Replace(KW_MANGLED_NAME, Getattr(n, "wrap:name"));
|
Printf(class_instance, "class_%s", current_classname_mangled);
|
||||||
Printv(f_init_wrappers, t_register.str(), "\n", 0);
|
t_register.Replace(KW_CONTEXT, class_instance)
|
||||||
|
.Replace(KW_UNQUALIFIED_NAME, current_function_unqualified)
|
||||||
|
.Replace(KW_MANGLED_NAME, Getattr(n, "wrap:name"));
|
||||||
|
Printv(f_init_static_wrappers, t_register.str(), 0);
|
||||||
|
Delete(class_instance);
|
||||||
|
} else {
|
||||||
|
Template t_register(GetTemplate(V8_REGISTER_MEMBER_FUNCTION));
|
||||||
|
t_register.Replace(KW_CLASSNAME_MANGLED, current_classname_mangled)
|
||||||
|
.Replace(KW_UNQUALIFIED_NAME, current_function_unqualified)
|
||||||
|
.Replace(KW_MANGLED_NAME, Getattr(n, "wrap:name"));
|
||||||
|
Printv(f_init_wrappers, t_register.str(), "\n", 0);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
Template t_register(GetTemplate(V8_REGISTER_GLOBAL_FUNCTION));
|
Template t_register(GetTemplate(V8_REGISTER_GLOBAL_FUNCTION));
|
||||||
t_register.Replace(KW_CONTEXT, current_context)
|
t_register.Replace(KW_CONTEXT, current_context)
|
||||||
|
|
|
||||||
|
|
@ -62,6 +62,8 @@ private:
|
||||||
File *f_init_class_templates;
|
File *f_init_class_templates;
|
||||||
File *f_init_wrappers;
|
File *f_init_wrappers;
|
||||||
File *f_init_inheritance;
|
File *f_init_inheritance;
|
||||||
|
File *f_init_class_instances;
|
||||||
|
File *f_init_static_wrappers;
|
||||||
File *f_init_register_classes;
|
File *f_init_register_classes;
|
||||||
File *f_init_register_namespaces;
|
File *f_init_register_namespaces;
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue