From ba32e0e23de3543027c82a896521cf7556e26540 Mon Sep 17 00:00:00 2001 From: Andrey Volk Date: Thu, 29 Jun 2017 01:05:19 +0300 Subject: [PATCH] FS-10435 [mod_v8] Update mod_v8 to support future v8 engine version change --- .../languages/mod_v8/include/javascript.hpp | 13 ++++++ src/mod/languages/mod_v8/mod_v8.cpp | 23 ++++++++++ src/mod/languages/mod_v8/src/fsglobal.cpp | 4 ++ src/mod/languages/mod_v8/src/jsbase.cpp | 23 ++++++++++ src/mod/languages/mod_v8/src/jsmain.cpp | 43 ++++++++++++++++++- 5 files changed, 105 insertions(+), 1 deletion(-) diff --git a/src/mod/languages/mod_v8/include/javascript.hpp b/src/mod/languages/mod_v8/include/javascript.hpp index a465bf6ea9..28c8c30c44 100644 --- a/src/mod/languages/mod_v8/include/javascript.hpp +++ b/src/mod/languages/mod_v8/include/javascript.hpp @@ -33,6 +33,10 @@ #include #include +#if defined(V8_MAJOR_VERSION) && V8_MAJOR_VERSION >=5 +#include +#include +#endif #include #include @@ -202,7 +206,11 @@ private: JSMain *js; /* The "owner" of this instance */ /* The callback that happens when the V8 GC cleans up object instances */ +#if defined(V8_MAJOR_VERSION) && V8_MAJOR_VERSION >=5 + static void WeakCallback(const v8::WeakCallbackInfo& data); +#else static void WeakCallback(const v8::WeakCallbackData& data); +#endif /* Internal basic constructor when creating a new instance from JS. It will call the actual user code inside */ static void CreateInstance(const v8::FunctionCallbackInfo& args); @@ -305,7 +313,12 @@ public: const std::string ExecuteScript(const std::string& filename, bool *resultIsError); const std::string ExecuteString(const std::string& scriptData, const std::string& fileName, bool *resultIsError); +#if defined(V8_MAJOR_VERSION) && V8_MAJOR_VERSION >=5 + static void Initialize(v8::Platform **platform); /* Initialize the V8 engine */ +#else static void Initialize(); /* Initialize the V8 engine */ +#endif + static void Dispose(); /* Deinitialize the V8 engine */ static void Include(const v8::FunctionCallbackInfo& args); /* Adds functionality to include another JavaScript from the running script */ diff --git a/src/mod/languages/mod_v8/mod_v8.cpp b/src/mod/languages/mod_v8/mod_v8.cpp index 499ee390c9..6523051de8 100644 --- a/src/mod/languages/mod_v8/mod_v8.cpp +++ b/src/mod/languages/mod_v8/mod_v8.cpp @@ -120,6 +120,9 @@ typedef struct { switch_event_node_t *event_node; set *event_handlers; char *xml_handler; +#if defined(V8_MAJOR_VERSION) && V8_MAJOR_VERSION >=5 + v8::Platform *v8platform; +#endif } mod_v8_global_t; static mod_v8_global_t globals = { 0 }; @@ -651,12 +654,23 @@ static int v8_parse_and_execute(switch_core_session_t *session, const char *inpu free(path); } // Create a string containing the JavaScript source code. +#if defined(V8_MAJOR_VERSION) && V8_MAJOR_VERSION >=5 + ScriptCompiler::Source *source = new ScriptCompiler::Source(String::NewFromUtf8(isolate, script_data)); +#else Handle source = String::NewFromUtf8(isolate, script_data); +#endif TryCatch try_catch; // Compile the source code. +#if defined(V8_MAJOR_VERSION) && V8_MAJOR_VERSION >=5 + v8::ScriptCompiler::CompileOptions options = v8::ScriptCompiler::kNoCompileOptions; + Handle v8_script = v8::ScriptCompiler::Compile(context, source, options).ToLocalChecked(); + //Handle v8_script = v8::ScriptCompiler::Compile(context, source,/* String::NewFromUtf8(isolate, script_file),*/ v8::ScriptCompiler::kProduceCodeCache).ToLocalChecked(); + //source->GetCachedData(); +#else Handle