From e98a6592463b2f0c0f10f5725e381b2d6589d982 Mon Sep 17 00:00:00 2001 From: Richard Date: Tue, 12 Aug 2014 23:05:14 -0500 Subject: [PATCH] Fixes for v8 3.21.17 (0x032117) --- Lib/javascript/v8/javascriptcode.swg | 45 +++++++++++++ Lib/javascript/v8/javascriptcomplex.swg | 13 ++++ Lib/javascript/v8/javascripthelpers.swg | 5 ++ Lib/javascript/v8/javascriptinit.swg | 5 ++ Lib/javascript/v8/javascriptrun.swg | 59 ++++++++++++++--- Tools/javascript/v8_shell.cxx | 88 ++++++++++++++++++++----- 6 files changed, 190 insertions(+), 25 deletions(-) diff --git a/Lib/javascript/v8/javascriptcode.swg b/Lib/javascript/v8/javascriptcode.swg index a3eb94daf..85e26d5f3 100644 --- a/Lib/javascript/v8/javascriptcode.swg +++ b/Lib/javascript/v8/javascriptcode.swg @@ -9,7 +9,12 @@ %fragment("js_ctor", "templates") %{ SwigV8ReturnValue $jswrapper(const SwigV8Arguments& args) { +#if (SWIG_V8_VERSION < 0x032117) v8::HandleScope scope; +#else + v8::HandleScope scope(v8::Isolate::GetCurrent()); +#endif + v8::Handle self = args.Holder(); $jslocals if(args.Length() != $jsargcount) SWIG_exception_fail(SWIG_ERROR, "Illegal number of arguments for $jswrapper."); @@ -32,7 +37,12 @@ fail: %fragment ("js_veto_ctor", "templates") %{ SwigV8ReturnValue $jswrapper(const SwigV8Arguments& args) { +#if (SWIG_V8_VERSION < 0x032117) v8::HandleScope scope; +#else + v8::HandleScope scope(v8::Isolate::GetCurrent()); +#endif + SWIG_exception(SWIG_ERROR, "Class $jsname can not be instantiated"); SWIGV8_RETURN(v8::Undefined()); } @@ -47,7 +57,12 @@ SwigV8ReturnValue $jswrapper(const SwigV8Arguments& args) { %fragment ("js_ctor_dispatcher", "templates") %{ SwigV8ReturnValue $jswrapper(const SwigV8Arguments& args) { +#if (SWIG_V8_VERSION < 0x032117) v8::HandleScope scope; +#else + v8::HandleScope scope(v8::Isolate::GetCurrent()); +#endif + OverloadErrorHandler errorHandler; v8::Handle self; @@ -72,7 +87,12 @@ fail: * ----------------------------------------------------------------------------- */ %fragment("js_overloaded_ctor", "templates") %{ SwigV8ReturnValue $jswrapper(const SwigV8Arguments& args, V8ErrorHandler& SWIGV8_ErrorHandler) { +#if (SWIG_V8_VERSION < 0x032117) v8::HandleScope scope; +#else + v8::HandleScope scope(v8::Isolate::GetCurrent()); +#endif + v8::Handle self = args.Holder(); $jslocals if(args.Length() != $jsargcount) SWIG_exception_fail(SWIG_ERROR, "Illegal number of arguments for $jswrapper."); @@ -201,7 +221,12 @@ void $jswrapper(v8::Isolate *isolate, v8::Persistent< v8::Object > * object, SWI %fragment("js_getter", "templates") %{ SwigV8ReturnValue $jswrapper(v8::Local property, const SwigV8PropertyCallbackInfo& info) { +#if (SWIG_V8_VERSION < 0x032117) v8::HandleScope scope; +#else + v8::HandleScope scope(v8::Isolate::GetCurrent()); +#endif + v8::Handle jsresult; $jslocals $jscode @@ -223,7 +248,12 @@ fail: %{ void $jswrapper(v8::Local property, v8::Local value, const SwigV8PropertyCallbackInfoVoid& info) { +#if (SWIG_V8_VERSION < 0x032117) v8::HandleScope scope; +#else + v8::HandleScope scope(v8::Isolate::GetCurrent()); +#endif + $jslocals $jscode goto fail; @@ -241,7 +271,12 @@ fail: %fragment("js_function", "templates") %{ SwigV8ReturnValue $jswrapper(const SwigV8Arguments& args) { +#if (SWIG_V8_VERSION < 0x032117) v8::HandleScope scope; +#else + v8::HandleScope scope(v8::Isolate::GetCurrent()); +#endif + v8::Handle jsresult; $jslocals if(args.Length() != $jsargcount) SWIG_exception_fail(SWIG_ERROR, "Illegal number of arguments for $jswrapper."); @@ -265,7 +300,12 @@ fail: %fragment("js_function_dispatcher", "templates") %{ SwigV8ReturnValue $jswrapper(const SwigV8Arguments& args) { +#if (SWIG_V8_VERSION < 0x032117) v8::HandleScope scope; +#else + v8::HandleScope scope(v8::Isolate::GetCurrent()); +#endif + v8::Handle jsresult; OverloadErrorHandler errorHandler; $jscode @@ -288,7 +328,12 @@ fail: %{ SwigV8ReturnValue $jswrapper(const SwigV8Arguments& args, V8ErrorHandler& SWIGV8_ErrorHandler) { +#if (SWIG_V8_VERSION < 0x032117) v8::HandleScope scope; +#else + v8::HandleScope scope(v8::Isolate::GetCurrent()); +#endif + v8::Handle jsresult; $jslocals $jscode diff --git a/Lib/javascript/v8/javascriptcomplex.swg b/Lib/javascript/v8/javascriptcomplex.swg index 70c5baffb..88573c2f2 100644 --- a/Lib/javascript/v8/javascriptcomplex.swg +++ b/Lib/javascript/v8/javascriptcomplex.swg @@ -15,7 +15,12 @@ SWIGINTERNINLINE v8::Handle SWIG_From_dec(Type)(%ifcplusplus(const Type&, Type) c) { +#if (SWIG_V8_VERSION < 0x032117) v8::HandleScope scope; +#else + v8::HandleScope scope(v8::Isolate::GetCurrent()); +#endif + v8::Local vals = v8::Array::New(2); vals->Set(0, SWIG_From(double)(Real(c))); @@ -33,7 +38,11 @@ SWIG_From_dec(Type)(%ifcplusplus(const Type&, Type) c) SWIGINTERN int SWIG_AsVal_dec(Type) (v8::Handle o, Type* val) { +#if (SWIG_V8_VERSION < 0x032117) v8::HandleScope scope; +#else + v8::HandleScope scope(v8::Isolate::GetCurrent()); +#endif if (o->IsArray()) { v8::Handle array = v8::Handle::Cast(o); @@ -75,7 +84,11 @@ SWIG_AsVal_dec(Type) (v8::Handle o, Type* val) SWIGINTERN int SWIG_AsVal_dec(Type) (v8::Handle o, Type* val) { +#if (SWIG_V8_VERSION < 0x032117) v8::HandleScope scope; +#else + v8::HandleScope scope(v8::Isolate::GetCurrent()); +#endif if (o->IsArray()) { v8::Handle array = v8::Handle::Cast(o); diff --git a/Lib/javascript/v8/javascripthelpers.swg b/Lib/javascript/v8/javascripthelpers.swg index ac352796e..630946d07 100644 --- a/Lib/javascript/v8/javascripthelpers.swg +++ b/Lib/javascript/v8/javascripthelpers.swg @@ -17,7 +17,12 @@ typedef v8::PropertyCallbackInfo SwigV8PropertyCallbackInfoVoid; * Creates a class template for a class with specified initialization function. */ SWIGRUNTIME v8::Handle SWIGV8_CreateClassTemplate(const char* symbol) { +#if (SWIG_V8_VERSION < 0x032117) v8::HandleScope scope; +#else + v8::HandleScope scope(v8::Isolate::GetCurrent()); +#endif + v8::Local class_templ = v8::FunctionTemplate::New(); class_templ->SetClassName(v8::String::NewSymbol(symbol)); diff --git a/Lib/javascript/v8/javascriptinit.swg b/Lib/javascript/v8/javascriptinit.swg index 651a39144..97b273dc1 100644 --- a/Lib/javascript/v8/javascriptinit.swg +++ b/Lib/javascript/v8/javascriptinit.swg @@ -61,7 +61,12 @@ void SWIGV8_INIT (v8::Handle exports, v8::Handle /*modul { SWIG_InitializeModule(static_cast(&exports)); +#if (SWIG_V8_VERSION < 0x032117) v8::HandleScope scope; +#else + v8::HandleScope scope(v8::Isolate::GetCurrent()); +#endif + v8::Handle exports_obj = exports; %} diff --git a/Lib/javascript/v8/javascriptrun.swg b/Lib/javascript/v8/javascriptrun.swg index 50e4c5b87..311902378 100644 --- a/Lib/javascript/v8/javascriptrun.swg +++ b/Lib/javascript/v8/javascriptrun.swg @@ -117,7 +117,11 @@ public: v8::Persistent SWIGV8_SWIGTYPE_Proxy_class_templ; int SWIG_V8_ConvertInstancePtr(v8::Handle objRef, void** ptr, swig_type_info *info, int flags) { +#if (SWIG_V8_VERSION < 0x032117) v8::HandleScope scope; +#else + v8::HandleScope scope(v8::Isolate::GetCurrent()); +#endif if(objRef->InternalFieldCount() < 1) return SWIG_ERROR; @@ -239,7 +243,12 @@ void SWIGV8_SetPrivateData(v8::Handle obj, void* ptr, swig_type_info } int SWIG_V8_ConvertPtr(v8::Handle valRef, void** ptr, swig_type_info *info, int flags) { +#if (SWIG_V8_VERSION < 0x032117) v8::HandleScope scope; +#else + v8::HandleScope scope(v8::Isolate::GetCurrent()); +#endif + /* special case: JavaScript null => C NULL pointer */ if(valRef->IsNull()) { *ptr=0; @@ -253,7 +262,12 @@ int SWIG_V8_ConvertPtr(v8::Handle valRef, void** ptr, swig_type_info } v8::Handle SWIG_V8_NewPointerObj(void *ptr, swig_type_info *info, int flags) { +#if (SWIG_V8_VERSION < 0x032117) v8::HandleScope scope; +#else + v8::HandleScope scope(v8::Isolate::GetCurrent()); +#endif + v8::Handle class_templ; if (ptr == NULL) { @@ -293,12 +307,14 @@ v8::Handle SWIG_V8_NewPointerObj(void *ptr, swig_type_info *info, int #define SWIG_GetInstancePtr(obj, ptr) SWIG_V8_GetInstancePtr(obj, ptr) -#if (SWIG_V8_VERSION < 0x031903) -v8::Handle _SWIGV8_wrap_equals(const v8::Arguments &args) { -#else -void _SWIGV8_wrap_equals(const v8::FunctionCallbackInfo& args) { -#endif +SwigV8ReturnValue _SWIGV8_wrap_equals(const SwigV8Arguments &args) { + +#if (SWIG_V8_VERSION < 0x032117) v8::HandleScope scope; +#else + v8::HandleScope scope(v8::Isolate::GetCurrent()); +#endif + v8::Handle jsresult; void *arg1 = (void *) 0 ; void *arg2 = (void *) 0 ; @@ -326,12 +342,14 @@ fail: SWIGV8_RETURN(v8::Undefined()); } -#if (SWIG_V8_VERSION < 0x031903) -v8::Handle _wrap_getCPtr(const v8::Arguments &args) { -#else -void _wrap_getCPtr(const v8::FunctionCallbackInfo& args) { -#endif +SwigV8ReturnValue _wrap_getCPtr(const SwigV8Arguments &args) { + +#if (SWIG_V8_VERSION < 0x032117) v8::HandleScope scope; +#else + v8::HandleScope scope(v8::Isolate::GetCurrent()); +#endif + v8::Handle jsresult; void *arg1 = (void *) 0 ; long result; @@ -372,7 +390,13 @@ public: SWIGRUNTIMEINLINE int SwigV8Packed_Check(v8::Handle valRef) { + +#if (SWIG_V8_VERSION < 0x032117) v8::HandleScope scope; +#else + v8::HandleScope scope(v8::Isolate::GetCurrent()); +#endif + v8::Handle objRef = valRef->ToObject(); if(objRef->InternalFieldCount() < 1) return false; v8::Handle flag = objRef->GetHiddenValue(v8::String::New("__swig__packed_data__")); @@ -382,7 +406,13 @@ int SwigV8Packed_Check(v8::Handle valRef) { SWIGRUNTIME swig_type_info* SwigV8Packed_UnpackData(v8::Handle valRef, void *ptr, size_t size) { if (SwigV8Packed_Check(valRef)) { + +#if (SWIG_V8_VERSION < 0x032117) v8::HandleScope scope; +#else + v8::HandleScope scope(v8::Isolate::GetCurrent()); +#endif + SwigV8PackedData *sobj; v8::Handle objRef = valRef->ToObject(); @@ -445,7 +475,11 @@ void _wrap_SwigV8PackedData_delete(v8::Isolate *isolate, v8::Persistent< v8::Obj SWIGRUNTIME v8::Handle SWIGV8_NewPackedObj(void *data, size_t size, swig_type_info *type) { +#if (SWIG_V8_VERSION < 0x032117) v8::HandleScope scope; +#else + v8::HandleScope scope(v8::Isolate::GetCurrent()); +#endif SwigV8PackedData* cdata = new SwigV8PackedData(data, size, type); v8::Handle obj = v8::Object::New(); @@ -497,7 +531,12 @@ v8::Handle SWIGV8_NewPackedObj(void *data, size_t size, swig_type_inf SWIGRUNTIME v8::Handle SWIGV8_AppendOutput(v8::Handle result, v8::Handle obj) { +#if (SWIG_V8_VERSION < 0x032117) v8::HandleScope scope; +#else + v8::HandleScope scope(v8::Isolate::GetCurrent()); +#endif + if (result->IsUndefined()) { result = v8::Array::New(); } diff --git a/Tools/javascript/v8_shell.cxx b/Tools/javascript/v8_shell.cxx index cf3836369..b8d777856 100644 --- a/Tools/javascript/v8_shell.cxx +++ b/Tools/javascript/v8_shell.cxx @@ -11,6 +11,22 @@ typedef int (*V8ExtensionInitializer) (v8::Handle module); +// Note: these typedefs and defines are used to deal with v8 API changes since version 3.19.00 + +#if (V8_VERSION < 0x031903) +typedef v8::Handle SwigV8ReturnValue; +typedef v8::Arguments SwigV8Arguments; +typedef v8::AccessorInfo SwigV8PropertyCallbackInfo; +#define SWIGV8_RETURN(val) return scope.Close(val) +#define SWIGV8_RETURN_INFO(val, info) return scope.Close(val) +#else +typedef void SwigV8ReturnValue; +typedef v8::FunctionCallbackInfo SwigV8Arguments; +typedef v8::PropertyCallbackInfo SwigV8PropertyCallbackInfo; +#define SWIGV8_RETURN(val) args.GetReturnValue().Set(val); return +#define SWIGV8_RETURN_INFO(val, info) info.GetReturnValue().Set(val); return +#endif + class V8Shell: public JSShell { public: @@ -43,13 +59,13 @@ private: void ReportException(v8::TryCatch* handler); - static v8::Handle Print(const v8::Arguments& args); + static SwigV8ReturnValue Print(const SwigV8Arguments& args); - static v8::Handle Require(const v8::Arguments& args); + static SwigV8ReturnValue Require(const SwigV8Arguments& args); - static v8::Handle Quit(const v8::Arguments& args); + static SwigV8ReturnValue Quit(const SwigV8Arguments& args); - static v8::Handle Version(const v8::Arguments& args); + static SwigV8ReturnValue Version(const SwigV8Arguments& args); static const char* ToCString(const v8::String::Utf8Value& value); @@ -69,7 +85,11 @@ V8Shell::~V8Shell() {} bool V8Shell::RunScript(const std::string& scriptPath) { std::string source = ReadFile(scriptPath); +#if (V8_VERSION < 0x032117) v8::HandleScope scope; +#else + v8::HandleScope scope(v8::Isolate::GetCurrent()); +#endif #if (V8_VERSION < 0x031900) v8::Persistent context = CreateShellContext(); @@ -113,7 +133,12 @@ bool V8Shell::RunScript(const std::string& scriptPath) { } bool V8Shell::RunShell() { +#if (V8_VERSION < 0x032117) v8::HandleScope scope; +#else + v8::HandleScope scope(v8::Isolate::GetCurrent()); +#endif + #if (V8_VERSION < 0x031900) v8::Persistent context = CreateShellContext(); @@ -166,7 +191,13 @@ bool V8Shell::InitializeEngine() { } bool V8Shell::ExecuteScript(const std::string& source, const std::string& name) { - v8::HandleScope handle_scope; +#if (V8_VERSION < 0x032117) + v8::HandleScope scope; +#else + v8::HandleScope scope(v8::Isolate::GetCurrent()); +#endif + + v8::TryCatch try_catch; v8::Handle script = v8::Script::Compile(v8::String::New(source.c_str()), v8::String::New(name.c_str())); @@ -197,7 +228,12 @@ v8::Persistent V8Shell::CreateShellContext() { #else v8::Local V8Shell::CreateShellContext() { #endif + +#if (V8_VERSION < 0x032117) v8::HandleScope scope; +#else + v8::HandleScope scope(v8::Isolate::GetCurrent()); +#endif // Create a template for the global object. v8::Handle global = v8::ObjectTemplate::New(); @@ -224,7 +260,12 @@ v8::Local V8Shell::CreateShellContext() { v8::Handle V8Shell::Import(const std::string& module_path) { +#if (V8_VERSION < 0x032117) v8::HandleScope scope; +#else + v8::HandleScope scope(v8::Isolate::GetCurrent()); +#endif + HANDLE library; std::string module_name = LoadModule(module_path, &library); @@ -243,10 +284,16 @@ v8::Handle V8Shell::Import(const std::string& module_path) return scope.Close(module); } -v8::Handle V8Shell::Print(const v8::Arguments& args) { +SwigV8ReturnValue V8Shell::Print(const SwigV8Arguments& args) { bool first = true; for (int i = 0; i < args.Length(); i++) { - v8::HandleScope handle_scope; + +#if (V8_VERSION < 0x032117) + v8::HandleScope scope; +#else + v8::HandleScope scope(v8::Isolate::GetCurrent()); +#endif + if (first) { first = false; } else { @@ -258,11 +305,16 @@ v8::Handle V8Shell::Print(const v8::Arguments& args) { } printf("\n"); fflush(stdout); - return v8::Undefined(); + SWIGV8_RETURN(v8::Undefined()); } -v8::Handle V8Shell::Require(const v8::Arguments& args) { +SwigV8ReturnValue V8Shell::Require(const SwigV8Arguments& args) { +#if (V8_VERSION < 0x032117) v8::HandleScope scope; +#else + v8::HandleScope scope(v8::Isolate::GetCurrent()); +#endif + if (args.Length() != 1) { printf("Illegal arguments for `require`"); @@ -279,23 +331,29 @@ v8::Handle V8Shell::Require(const v8::Arguments& args) { v8::Handle module = _this->Import(moduleName); - return scope.Close(module); + SWIGV8_RETURN(module); } -v8::Handle V8Shell::Quit(const v8::Arguments& args) { +SwigV8ReturnValue V8Shell::Quit(const SwigV8Arguments& args) { int exit_code = args[0]->Int32Value(); fflush(stdout); fflush(stderr); exit(exit_code); - return v8::Undefined(); + SWIGV8_RETURN(v8::Undefined()); } -v8::Handle V8Shell::Version(const v8::Arguments& args) { - return v8::String::New(v8::V8::GetVersion()); +SwigV8ReturnValue V8Shell::Version(const SwigV8Arguments& args) { + SWIGV8_RETURN(v8::String::New(v8::V8::GetVersion())); } void V8Shell::ReportException(v8::TryCatch* try_catch) { - v8::HandleScope handle_scope; +#if (V8_VERSION < 0x032117) + v8::HandleScope scope; +#else + v8::HandleScope scope(v8::Isolate::GetCurrent()); +#endif + + v8::String::Utf8Value exception(try_catch->Exception()); const char* exception_string = V8Shell::ToCString(exception); v8::Handle message = try_catch->Message();