Skip to content

Commit

Permalink
Add comments to v8 code templates.
Browse files Browse the repository at this point in the history
  • Loading branch information
oliver7654 committed Sep 8, 2012
1 parent b3e0054 commit b7a359c
Show file tree
Hide file tree
Showing 2 changed files with 167 additions and 6 deletions.
8 changes: 8 additions & 0 deletions Lib/javascript/jsc/javascriptcode.swg
Expand Up @@ -60,6 +60,14 @@ JSObjectRef $jswrapper(JSContextRef context, JSObjectRef ctorObject,
}
%}

/* -----------------------------------------------------------------------------
* js_overloaded_ctor: template for wrapping a ctor.
* - $jswrapper: wrapper of called ctor
* - $jslocals: locals part of wrapper
* - $jscode: code part of wrapper
* - $jsargcount: number of arguments
* - $jsmangledtype: mangled type of class
* ----------------------------------------------------------------------------- */
%fragment ("js_overloaded_ctor", "templates")
%{
JSObjectRef $jswrapper(JSContextRef context, JSObjectRef thisObject, size_t argc, const JSValueRef argv[], JSValueRef* exception)
Expand Down
165 changes: 159 additions & 6 deletions Lib/javascript/v8/javascriptcode.swg
@@ -1,3 +1,11 @@
/* -----------------------------------------------------------------------------
* js_ctor: template for wrapping a ctor.
* - $jswrapper: wrapper of called ctor
* - $jslocals: locals part of wrapper
* - $jscode: code part of wrapper
* - $jsargcount: number of arguments
* - $jsmangledtype: mangled type of class
* ----------------------------------------------------------------------------- */
%fragment("js_ctor", "templates") %{
v8::Handle<v8::Value> $jswrapper(const v8::Arguments& args) {
v8::HandleScope scope;
Expand All @@ -15,6 +23,11 @@ fail:
}
%}

/* -----------------------------------------------------------------------------
* js_veto_ctor: a vetoing ctor for abstract classes
* - $jswrapper: name of wrapper
* - $jsname: class name
* ----------------------------------------------------------------------------- */
%fragment ("js_veto_ctor", "templates")
%{
v8::Handle<v8::Value> $jswrapper(const v8::Arguments& args) {
Expand All @@ -24,6 +37,12 @@ v8::Handle<v8::Value> $jswrapper(const v8::Arguments& args) {
}
%}

/* -----------------------------------------------------------------------------
* js_ctor_dispatcher: dispatcher for overloaded constructors
* - $jswrapper: name of wrapper
* - $jsname: class name
* - $jsdispatchcases: part containing code for dispatching
* ----------------------------------------------------------------------------- */
%fragment ("js_ctor_dispatcher", "templates")
%{
v8::Handle<v8::Value> $jswrapper(const v8::Arguments& args) {
Expand All @@ -42,6 +61,14 @@ fail:
}
%}

/* -----------------------------------------------------------------------------
* js_overloaded_ctor: template for wrapping a ctor.
* - $jswrapper: wrapper of called ctor
* - $jslocals: locals part of wrapper
* - $jscode: code part of wrapper
* - $jsargcount: number of arguments
* - $jsmangledtype: mangled type of class
* ----------------------------------------------------------------------------- */
%fragment("js_overloaded_ctor", "templates") %{
v8::Handle<v8::Value> $jswrapper(const v8::Arguments& args, V8ErrorHandler& SWIGV8_ErrorHandler) {
v8::HandleScope scope;
Expand All @@ -59,6 +86,13 @@ fail:
}
%}

/* -----------------------------------------------------------------------------
* js_ctor_dispatch_case: template for a dispatch case for calling an overloaded ctor.
* - $jsargcount: number of arguments of called ctor
* - $jswrapper: wrapper of called ctor
*
* Note: a try-catch-like mechanism is used to switch cases
* ----------------------------------------------------------------------------- */
%fragment ("js_ctor_dispatch_case", "templates")
%{
if(args.Length() == $jsargcount) {
Expand All @@ -70,6 +104,11 @@ fail:
}
%}

/* -----------------------------------------------------------------------------
* js_dtor: template for a destructor wrapper
* - $jsmangledname: mangled class name
* - $jstype: class type
* ----------------------------------------------------------------------------- */
%fragment ("js_dtor", "templates")
%{
void $jswrapper(v8::Persistent< v8::Value > object, void *parameter) {
Expand All @@ -82,7 +121,12 @@ void $jswrapper(v8::Persistent< v8::Value > object, void *parameter) {
}
%}


/* -----------------------------------------------------------------------------
* js_getter: template for getter function wrappers
* - $jswrapper: wrapper function name
* - $jslocals: locals part of wrapper
* - $jscode: code part of wrapper
* ----------------------------------------------------------------------------- */
%fragment("js_getter", "templates")
%{
v8::Handle<v8::Value> $jswrapper(v8::Local<v8::String> property, const v8::AccessorInfo& info) {
Expand All @@ -97,6 +141,12 @@ fail:
}
%}

/* -----------------------------------------------------------------------------
* js_setter: template for setter function wrappers
* - $jswrapper: wrapper function name
* - $jslocals: locals part of wrapper
* - $jscode: code part of wrapper
* ----------------------------------------------------------------------------- */
%fragment("js_setter", "templates")
%{
void $jswrapper(v8::Local<v8::String> property, v8::Local<v8::Value> value, const v8::AccessorInfo& info) {
Expand All @@ -109,6 +159,12 @@ fail:
}
%}

/* -----------------------------------------------------------------------------
* js_function: template for function wrappers
* - $jswrapper: wrapper function name
* - $jslocals: locals part of wrapper
* - $jscode: code part of wrapper
* ----------------------------------------------------------------------------- */
%fragment("js_function", "templates")
%{
v8::Handle<v8::Value> $jswrapper(const v8::Arguments &args) {
Expand All @@ -125,6 +181,13 @@ fail:
}
%}

/* -----------------------------------------------------------------------------
* js_function_dispatcher: template for a function dispatcher for overloaded functions
* - $jswrapper: wrapper function name
* - $jsname: name of the wrapped function
* - $jslocals: locals part of wrapper
* - $jscode: code part of wrapper
* ----------------------------------------------------------------------------- */
%fragment("js_function_dispatcher", "templates")
%{
v8::Handle<v8::Value> $jswrapper(const v8::Arguments &args) {
Expand All @@ -141,6 +204,12 @@ fail:
}
%}

/* -----------------------------------------------------------------------------
* js_overloaded_function: template for a overloaded function
* - $jswrapper: wrapper function name
* - $jslocals: locals part of wrapper
* - $jscode: code part of wrapper
* ----------------------------------------------------------------------------- */
%fragment ("js_overloaded_function", "templates")
%{
v8::Handle<v8::Value> $jswrapper(const v8::Arguments &args, V8ErrorHandler& SWIGV8_ErrorHandler)
Expand All @@ -156,6 +225,12 @@ fail:
}
%}

/* -----------------------------------------------------------------------------
* js_function_dispatch_case: template for a case used in the function dispatcher
* - $jswrapper: wrapper function name
* - $jsargcount: number of arguments of overloaded function
* - $jscode: code part of wrapper
* ----------------------------------------------------------------------------- */
%fragment ("js_function_dispatch_case", "templates")
%{
if(args.Length() == $jsargcount) {
Expand All @@ -167,11 +242,21 @@ fail:
}
%}

/* -----------------------------------------------------------------------------
* jsv8_declare_class_template: template for a class template declaration.
* - $jsmangledname: mangled class name
* ----------------------------------------------------------------------------- */
%fragment("jsv8_declare_class_template", "templates")
%{
SWIGV8_ClientData $jsmangledname_clientData;
%}

/* -----------------------------------------------------------------------------
* jsv8_define_class_template: template for a class template definition.
* - $jsmangledname: mangled class name
* - $jsmangledtype: mangled class type
* - $jsdtor: the dtor wrapper
* ----------------------------------------------------------------------------- */
%fragment("jsv8_define_class_template", "templates")
%{
v8::Handle<v8::FunctionTemplate> $jsmangledname_class = SWIGV8_CreateClassTemplate("$jsmangledname");
Expand All @@ -180,11 +265,21 @@ fail:
SWIGTYPE$jsmangledtype->clientdata = &$jsmangledname_clientData;
%}

/* -----------------------------------------------------------------------------
* jsv8_inherit: template for an class inherit statement.
* - $jsmangledname: mangled class name
* - $jsbaseclass: mangled name of the base class
* ----------------------------------------------------------------------------- */
%fragment("jsv8_inherit", "templates")
%{
$jsmangledname_class->Inherit($jsbaseclass_class);
%}

/* -----------------------------------------------------------------------------
* jsv8_create_class_instance: template for creating an class object.
* - $jsname: class name
* - $jsmangledname: mangled class name
* ----------------------------------------------------------------------------- */
%fragment("jsv8_create_class_instance", "templates")
%{
v8::Handle<v8::FunctionTemplate> $jsmangledname_class_0 = SWIGV8_CreateClassTemplate("$jsname");
Expand All @@ -194,41 +289,99 @@ fail:
v8::Handle<v8::Object> $jsmangledname_obj = $jsmangledname_class_0->GetFunction();
%}

/* -----------------------------------------------------------------------------
* jsv8_register_class: template for a statement that registers a class in a parent namespace.
* - $jsname: class name
* - $jsmangledname: mangled class name
* - $jsparent: mangled name of parent namespace
* ----------------------------------------------------------------------------- */
%fragment("jsv8_register_class", "templates")
%{
$jsparent_obj->Set(v8::String::NewSymbol("$jsname"), $jsmangledname_obj);
%}

/* -----------------------------------------------------------------------------
* jsv8_create_namespace: template for a statement that creates a namespace object.
* - $jsmangledname: mangled namespace name
* ----------------------------------------------------------------------------- */
%fragment("jsv8_create_namespace", "templates")
%{
v8::Handle<v8::Object> $jsmangledname_obj = v8::Object::New();
%}

/* -----------------------------------------------------------------------------
* jsv8_register_namespace: template for a statement that registers a namespace in a parent namespace.
* - $jsname: name of namespace
* - $jsmangledname: mangled name of namespace
* - $jsparent: mangled name of parent namespace
* ----------------------------------------------------------------------------- */
%fragment("jsv8_register_namespace", "templates")
%{
$jsparent_obj->Set(v8::String::NewSymbol("$jsname"), $jsmangledname_obj);
%}

/* -----------------------------------------------------------------------------
* jsv8_register_member_function: template for a statement that registers a member function.
* - $jsmangledname: mangled class name
* - $jsname: name of the function
* - $jswrapper: wrapper of the member function
* ----------------------------------------------------------------------------- */
%fragment("jsv8_register_member_function", "templates")
%{
SWIGV8_AddMemberFunction($jsmangledname_class, "$jsname", $jswrapper);
%}

/* -----------------------------------------------------------------------------
* jsv8_register_member_variable: template for a statement that registers a member variable.
* - $jsmangledname: mangled class name
* - $jsname: name of the function
* - $jsgetter: wrapper of the getter function
* - $jssetter: wrapper of the setter function
* ----------------------------------------------------------------------------- */
%fragment("jsv8_register_member_variable", "templates")
%{
SWIGV8_AddMemberVariable($jsmangledname_class, "$jsname", $jsgetter, $jssetter);
%}

/* -----------------------------------------------------------------------------
* jsv8_register_static_function: template for a statement that registers a static class function.
* - $jsname: function name
* - $jswrapper: wrapper of the function
* - $jsparent: mangled name of parent namespace
*
* Note: this template is also used for global functions.
* ----------------------------------------------------------------------------- */
%fragment("jsv8_register_static_function", "templates")
%{
SWIGV8_AddStaticFunction($jsparent_obj, "$jsname", $jswrapper);
%}

/* -----------------------------------------------------------------------------
* jsv8_register_static_variable: template for a statement that registers a static variable.
* - $jsname: variable name
* - $jsparent: mangled name of parent namespace
* - $jsgetter: wrapper of the getter function
* - $jssetter: wrapper of the setter function
*
* Note: this template is also used for global variables.
* ----------------------------------------------------------------------------- */
%fragment("jsv8_register_static_variable", "templates")
%{
SWIGV8_AddStaticVariable($jsparent_obj, "$jsname", $jsgetter, $jssetter);
%}

%fragment("jsv8_register_namespace", "templates")
%{
$jsparent_obj->Set(v8::String::NewSymbol("$jsname"), $jsmangledname_obj);
%}

/* -----------------------------------------------------------------------------
* js_initializer: template for the module initializer function
* - $jsname: module name
* - $jsv8nspaces: part with code creating namespace objects
* - $jsv8classtemplates: part with code creating class templates
* - $jsv8wrappers: part with code that registers wrapper functions
* - $jsv8inheritance: part with inherit statements
* - $jsv8classinstances: part with code creating class objects
* - $jsv8staticwrappers: part with code adding static functions to class objects
* - $jsv8registerclasses: part with code that registers class objects in namespaces
* - $jsv8registernspaces: part with code that registers namespaces in parent namespaces
* ----------------------------------------------------------------------------- */
%fragment("js_initializer", "templates")
%{
extern "C" {
Expand Down

0 comments on commit b7a359c

Please sign in to comment.