From 54c2bbeda8ee583d2e22062ff2689915eb57b863 Mon Sep 17 00:00:00 2001 From: Mike Jerris Date: Thu, 3 May 2018 16:16:08 -0400 Subject: [PATCH] FS-11047: [build] support v8 6.6 fixes from Andrey Volk --- .../languages/mod_v8/include/javascript.hpp | 2 +- src/mod/languages/mod_v8/mod_v8.cpp | 4 ++-- src/mod/languages/mod_v8/src/jsbase.cpp | 19 ++++++------------- src/mod/languages/mod_v8/src/jsmain.cpp | 8 ++++---- 4 files changed, 13 insertions(+), 20 deletions(-) diff --git a/src/mod/languages/mod_v8/include/javascript.hpp b/src/mod/languages/mod_v8/include/javascript.hpp index 5650ad18e1..a080a508de 100644 --- a/src/mod/languages/mod_v8/include/javascript.hpp +++ b/src/mod/languages/mod_v8/include/javascript.hpp @@ -127,7 +127,7 @@ /* Macro for basic script state check (to know if the script is being terminated), should be called before calling any callback actual code */ #define JS_CHECK_SCRIPT_STATE() \ - if (v8::V8::IsExecutionTerminating(info.GetIsolate())) return;\ + if (info.GetIsolate()->IsExecutionTerminating()) return;\ if (JSMain::GetScriptInstanceFromIsolate(info.GetIsolate()) && JSMain::GetScriptInstanceFromIsolate(info.GetIsolate())->GetForcedTermination()) return /* Macro for easy unlocking an isolate on a long running c call */ diff --git a/src/mod/languages/mod_v8/mod_v8.cpp b/src/mod/languages/mod_v8/mod_v8.cpp index 636b93e5ac..9d1d8a9b91 100644 --- a/src/mod/languages/mod_v8/mod_v8.cpp +++ b/src/mod/languages/mod_v8/mod_v8.cpp @@ -645,7 +645,7 @@ static int v8_parse_and_execute(switch_core_session_t *session, const char *inpu isolate->SetData(0, js); // New global template - Handle global = ObjectTemplate::New(); + Handle global = ObjectTemplate::New(isolate); if (global.IsEmpty()) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Failed to create JS global object template\n"); @@ -793,7 +793,7 @@ static int v8_parse_and_execute(switch_core_session_t *session, const char *inpu free(path); } - TryCatch try_catch; + TryCatch try_catch(isolate); // Compile the source code. #if defined(V8_MAJOR_VERSION) && V8_MAJOR_VERSION >=5 diff --git a/src/mod/languages/mod_v8/src/jsbase.cpp b/src/mod/languages/mod_v8/src/jsbase.cpp index 4fd320f439..9e8b2032a5 100644 --- a/src/mod/languages/mod_v8/src/jsbase.cpp +++ b/src/mod/languages/mod_v8/src/jsbase.cpp @@ -153,17 +153,9 @@ void JSBase::CreateInstance(const v8::FunctionCallbackInfo& args) autoDestroy = args[1]->BooleanValue(); } else { // Create a new C++ instance -#if defined(V8_MAJOR_VERSION) && V8_MAJOR_VERSION >=5 - Isolate *isolate = args.GetIsolate(); - v8::Local context = isolate->GetCurrentContext(); - v8::Local key = String::NewFromUtf8(isolate, "constructor_method"); - v8::Local privateKey = v8::Private::ForApi(isolate, key); - Handle ex; - v8::MaybeLocal hiddenValue = args.Callee()->GetPrivate(context, privateKey); - if (!hiddenValue.IsEmpty()) { - ex = Handle::Cast(hiddenValue.ToLocalChecked()); - } -#else +#if defined(V8_MAJOR_VERSION) && V8_MAJOR_VERSION >=6 + Handle ex = Handle::Cast(args.Data()); +#else Handle ex = Handle::Cast(args.Callee()->GetHiddenValue(String::NewFromUtf8(args.GetIsolate(), "constructor_method"))); #endif @@ -232,13 +224,14 @@ void JSBase::Register(Isolate *isolate, const js_class_definition_t *desc) void JSBase::RegisterInstance(Isolate *isolate, string name, bool autoDestroy) { // Get the context's global scope (that's where we'll put the constructor) - Handle global = isolate->GetCurrentContext()->Global(); + Local context = isolate->GetCurrentContext(); + Handle global = context->Global(); Local func = Local::Cast(global->Get(v8::String::NewFromUtf8(isolate, this->GetJSClassName().c_str()))); // Add the C++ instance as an argument, so it won't try to create another one. Handle args[] = { External::New(isolate, this), Boolean::New(isolate, autoDestroy) }; - Handle newObj = func->NewInstance(2, args); + Handle newObj = func->NewInstance(context, 2, args).ToLocalChecked(); // Add the instance to JavaScript. if (name.size() > 0) { diff --git a/src/mod/languages/mod_v8/src/jsmain.cpp b/src/mod/languages/mod_v8/src/jsmain.cpp index e162460df2..86fed7b27f 100644 --- a/src/mod/languages/mod_v8/src/jsmain.cpp +++ b/src/mod/languages/mod_v8/src/jsmain.cpp @@ -209,7 +209,7 @@ const string JSMain::GetExceptionInfo(Isolate* isolate, TryCatch* try_catch) ss << " "; } - int end = message->GetEndColumn(); + int32_t end = message->GetEndColumn(isolate->GetCurrentContext()).FromMaybe(0); for (int i = start; i < end; i++) { ss << "^"; @@ -292,7 +292,7 @@ const string JSMain::ExecuteString(const string& scriptData, const string& fileN isolate->SetData(0, this); - Handle global = ObjectTemplate::New(); + Handle global = ObjectTemplate::New(isolate); global->Set(String::NewFromUtf8(isolate, "include"), FunctionTemplate::New(isolate, Include)); global->Set(String::NewFromUtf8(isolate, "require"), FunctionTemplate::New(isolate, Include)); global->Set(String::NewFromUtf8(isolate, "log"), FunctionTemplate::New(isolate, Log)); @@ -323,7 +323,7 @@ const string JSMain::ExecuteString(const string& scriptData, const string& fileN inst->obj->RegisterInstance(isolate, inst->name, inst->auto_destroy); } - TryCatch try_catch; + TryCatch try_catch(isolate); // Compile the source code. #if defined(V8_MAJOR_VERSION) && V8_MAJOR_VERSION >=5 @@ -583,7 +583,7 @@ void JSMain::ExitScript(Isolate *isolate, const char *msg) js->forcedTerminationScriptFile = GetStackInfo(isolate, &js->forcedTerminationLineNumber); } - V8::TerminateExecution(isolate); + isolate->TerminateExecution(); } char *JSMain::GetStackInfo(Isolate *isolate, int *lineNumber)