Better v8 version handling.
You should start to specify a version on command line, e.g.,
swig -javascript -v8 -DSWIG_V8_VERSION=0x032007
This commit is contained in:
parent
5228c0eeab
commit
a48438c562
3 changed files with 168 additions and 100 deletions
|
|
@ -1,7 +1,20 @@
|
|||
%insert(runtime) %{
|
||||
|
||||
// Note: since 3.19 there are new CallBack types, since 03.21.9 the old ones have been removed
|
||||
#if SWIG_V8_VERSION < 0x031900
|
||||
typedef v8::InvocationCallback SwigV8FunctionCallback;
|
||||
typedef v8::AccessorGetter SwigV8AccessorGetterCallback;
|
||||
typedef v8::AccessorSetter SwigV8AccessorSetterCallback;
|
||||
typedef v8::AccessorInfo SwigV8PropertyCallbackInfoVoid;
|
||||
#else
|
||||
typedef v8::FunctionCallback SwigV8FunctionCallback;
|
||||
typedef v8::AccessorGetterCallback SwigV8AccessorGetterCallback;
|
||||
typedef v8::AccessorSetterCallback SwigV8AccessorSetterCallback;
|
||||
typedef v8::PropertyCallbackInfo<void> SwigV8PropertyCallbackInfoVoid;
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Creates a class template for a class with specified initialization function.
|
||||
* Creates a class template for a class with specified initialization function.
|
||||
*/
|
||||
v8::Handle<v8::FunctionTemplate> SWIGV8_CreateClassTemplate(const char* symbol) {
|
||||
v8::HandleScope scope;
|
||||
|
|
@ -15,44 +28,49 @@ v8::Handle<v8::FunctionTemplate> SWIGV8_CreateClassTemplate(const char* symbol)
|
|||
}
|
||||
|
||||
/**
|
||||
* Registers a class method with given name for a given class template.
|
||||
* Registers a class method with given name for a given class template.
|
||||
*/
|
||||
void SWIGV8_AddMemberFunction(v8::Handle<v8::FunctionTemplate> class_templ, const char* symbol, v8::FunctionCallback _func) {
|
||||
void SWIGV8_AddMemberFunction(v8::Handle<v8::FunctionTemplate> class_templ, const char* symbol,
|
||||
SwigV8FunctionCallback _func) {
|
||||
v8::Handle<v8::ObjectTemplate> proto_templ = class_templ->PrototypeTemplate();
|
||||
proto_templ->Set(v8::String::NewSymbol(symbol), v8::FunctionTemplate::New(_func));
|
||||
proto_templ->Set(v8::String::NewSymbol(symbol), v8::FunctionTemplate::New(_func));
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers a class property with given name for a given class template.
|
||||
* Registers a class property with given name for a given class template.
|
||||
*/
|
||||
void SWIGV8_AddMemberVariable(v8::Handle<v8::FunctionTemplate> class_templ, const char* symbol, v8::AccessorGetterCallback getter, v8::AccessorSetterCallback setter) {
|
||||
void SWIGV8_AddMemberVariable(v8::Handle<v8::FunctionTemplate> class_templ, const char* symbol,
|
||||
SwigV8AccessorGetterCallback getter, SwigV8AccessorSetterCallback setter) {
|
||||
v8::Handle<v8::ObjectTemplate> proto_templ = class_templ->InstanceTemplate();
|
||||
proto_templ->SetAccessor(v8::String::NewSymbol(symbol), getter, setter);
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers a class method with given name for a given object.
|
||||
* Registers a class method with given name for a given object.
|
||||
*/
|
||||
void SWIGV8_AddStaticFunction(v8::Handle<v8::Object> obj, const char* symbol, const v8::FunctionCallback& _func) {
|
||||
void SWIGV8_AddStaticFunction(v8::Handle<v8::Object> obj, const char* symbol,
|
||||
const SwigV8FunctionCallback& _func) {
|
||||
obj->Set(v8::String::NewSymbol(symbol), v8::FunctionTemplate::New(_func)->GetFunction());
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers a class method with given name for a given object.
|
||||
* Registers a class method with given name for a given object.
|
||||
*/
|
||||
void SWIGV8_AddStaticVariable(v8::Handle<v8::Object> obj, const char* symbol, v8::AccessorGetterCallback getter, v8::AccessorSetterCallback setter) {
|
||||
void SWIGV8_AddStaticVariable(v8::Handle<v8::Object> obj, const char* symbol,
|
||||
SwigV8AccessorGetterCallback getter, SwigV8AccessorSetterCallback setter) {
|
||||
obj->SetAccessor(v8::String::NewSymbol(symbol), getter, setter);
|
||||
}
|
||||
|
||||
void JS_veto_set_variable(v8::Local<v8::String> property, v8::Local<v8::Value> value, const v8::PropertyCallbackInfo<void>& info)
|
||||
void JS_veto_set_variable(v8::Local<v8::String> property, v8::Local<v8::Value> value,
|
||||
const SwigV8PropertyCallbackInfoVoid& info)
|
||||
{
|
||||
char buffer[256];
|
||||
char msg[512];
|
||||
int res;
|
||||
|
||||
|
||||
property->WriteUtf8(buffer, 256);
|
||||
res = sprintf(msg, "Tried to write read-only variable: %s.", buffer);
|
||||
|
||||
|
||||
if(res<0) {
|
||||
SWIG_exception(SWIG_ERROR, "Tried to write read-only variable.");
|
||||
} else {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue