Add initial Javascript V8 emitter implementation.
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/oliverb-javascript-v8@13743 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
parent
4bcfca05dd
commit
3c30e2d382
9 changed files with 857 additions and 1 deletions
58
Lib/javascript/v8/javascripthelpers.swg
Normal file
58
Lib/javascript/v8/javascripthelpers.swg
Normal file
|
|
@ -0,0 +1,58 @@
|
|||
|
||||
%insert(runtime) %{
|
||||
|
||||
/**
|
||||
* Creates a class template for a class without extra initialization function.
|
||||
*/
|
||||
v8::Persistent<v8::FunctionTemplate> SWIGV8_CreateClassTemplate(const char* symbol) {
|
||||
v8::Local<v8::FunctionTemplate> class_templ = v8::FunctionTemplate::New();
|
||||
class_templ->SetClassName(v8::String::NewSymbol(symbol));
|
||||
|
||||
v8::Handle<v8::ObjectTemplate> inst_templ = class_templ->InstanceTemplate();
|
||||
inst_templ->SetInternalFieldCount(1);
|
||||
|
||||
return v8::Persistent<v8::FunctionTemplate>::New(class_templ);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a class template for a class with specified initialization function.
|
||||
*/
|
||||
v8::Persistent<v8::FunctionTemplate> SWIGV8_CreateClassTemplate(const char* symbol, v8::InvocationCallback _func) {
|
||||
v8::Local<v8::FunctionTemplate> class_templ = v8::FunctionTemplate::New(_func);
|
||||
class_templ->SetClassName(v8::String::NewSymbol(symbol));
|
||||
|
||||
v8::Handle<v8::ObjectTemplate> inst_templ = class_templ->InstanceTemplate();
|
||||
inst_templ->SetInternalFieldCount(1);
|
||||
|
||||
return v8::Persistent<v8::FunctionTemplate>::New(class_templ);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the pimpl data of a V8 class.
|
||||
*/
|
||||
v8::Handle<v8::Value> V8GeneratorUtils::SetInstance(const v8::Arguments& args, void* data) {
|
||||
v8::HandleScope scope;
|
||||
|
||||
v8::Handle<v8::Object> self = args.Holder();
|
||||
self->SetInternalField(0, v8::External::New(data));
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers a class method with given name for a given class template.
|
||||
*/
|
||||
void V8GeneratorUtils::AddClassMethod(v8::Handle<v8::FunctionTemplate> class_templ, const char* symbol, v8::InvocationCallback _func) {
|
||||
v8::Handle<v8::ObjectTemplate> proto_templ = class_templ->PrototypeTemplate();
|
||||
proto_templ->Set(v8::String::NewSymbol(symbol), v8::FunctionTemplate::New(_func));
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers a class property with given name for a given class template.
|
||||
*/
|
||||
void V8GeneratorUtils::AddProperty(v8::Handle<v8::FunctionTemplate> class_templ, const char* varname, v8::AccessorGetter getter, v8::AccessorSetter setter) {
|
||||
v8::Handle<v8::ObjectTemplate> proto_templ = class_templ->InstanceTemplate();
|
||||
proto_templ->SetAccessor(v8::String::New(varname), getter, setter);
|
||||
}
|
||||
|
||||
%} // v8_helper_functions
|
||||
Loading…
Add table
Add a link
Reference in a new issue