Compatibility changes for V8 7.4 support (#142)

Compatibility changes for V8 7.4 support (#142)

  • Replace uses of CreateDefaultPlatform with NewDefaultPlatform

Use of platform::CreateDefaultPlatform has been deprecated[1][2] in favour of NewDefaultPlatform. This commit changes the method invocation and changes the type of the result to std::unique_ptr.

[1] [cleanup] use unique_ptr for the DefaultPlatform · v8/v8@ffee558 · GitHub ffee558e14e28fc8b1f9a3c10ea3615e0d686c7b - v8/v8 - Git at Google https://chromium-review.googlesource.com/c/v8/v8/+/755033/ [2] [api] Remove several deprecated methods · v8/v8@cbd8f42 · GitHub cbd8f4269f91e8ade38876092b433bda9ddb89a9 - v8/v8 - Git at Google https://chromium-review.googlesource.com/c/1460952

  • Remove use of deprecated non-context version of Function::Call

The use of the non-maybe version of Function::Call has been deprecated for a while now[1][2]. This commit replaces calls to it with calls to the Maybe version and adds unwrapping.

[1] convert Function and Promise to maybe · v8/v8@66969fb · GitHub 66969fb2ad6161d2d1da87cdd6fb50e1e6c970e5 - v8/v8 - Git at Google Issue 993883002: convert Function and Promise to maybe - Code Review

[2] [api] Remove several deprecated methods · v8/v8@cbd8f42 · GitHub cbd8f4269f91e8ade38876092b433bda9ddb89a9 - v8/v8 - Git at Google https://chromium-review.googlesource.com/c/v8/v8/+/1460952

  • Remove use of the deprecated non-maybe FunctionTemplate::GetFunction API

The mentioned method has been deprecated for a while[1][2]. This commit replaces its use with use of the Maybe version and adds unwrapping.

[1] convert most remaining api functions needing context to maybes · v8/v8@5234d99 · GitHub 5234d9977d637668e66b9e2e9f0456c6f97f749e - v8/v8 - Git at Google Issue 993223003: convert most remaining api functions needing context to maybes - Code Review

[2] [Cleanup] Delete deprecated FunctionTemplate::GetFunction API. · v8/v8@6f5e805 · GitHub 6f5e8052847fc41df98a1e8f19211f399c6afc18 - v8/v8 - Git at Google https://chromium-review.googlesource.com/c/v8/v8/+/1450115

diff --git a/ext/mini_racer_extension/mini_racer_extension.cc b/ext/mini_racer_extension/mini_racer_extension.cc
index 688bce0..33da606 100644
--- a/ext/mini_racer_extension/mini_racer_extension.cc
+++ b/ext/mini_racer_extension/mini_racer_extension.cc
@@ -152,7 +152,7 @@ static VALUE rb_mJSON;
 static VALUE rb_cFailedV8Conversion;
 static VALUE rb_cDateTime = Qnil;
 
-static Platform* current_platform = NULL;
+static std::unique_ptr<Platform> current_platform = NULL;
 static std::mutex platform_lock;
 
 static VALUE rb_platform_set_flag_as_str(VALUE _klass, VALUE flag_as_str) {
@@ -189,8 +189,8 @@ static void init_v8() {
 
     if (current_platform == NULL) {
         V8::InitializeICU();
-        current_platform = platform::CreateDefaultPlatform();
-        V8::InitializePlatform(current_platform);
+        current_platform = platform::NewDefaultPlatform();
+        V8::InitializePlatform(current_platform.get());
         V8::Initialize();
     }
 
@@ -241,7 +241,7 @@ static void prepare_result(MaybeLocal<Value> v8res,
             Local<Object> object = local_value->ToObject(context).ToLocalChecked();
             const unsigned argc = 1;
             Local<Value> argv[argc] = { object };
-            MaybeLocal<Value> json = stringify->Call(JSON, argc, argv);
+            MaybeLocal<Value> json = stringify->Call(context, JSON, argc, argv);
 
             if (json.IsEmpty()) {
                 evalRes.executed = false;
@@ -1086,8 +1086,10 @@ static VALUE rb_external_function_notify_v8(VALUE self) {
         Local<Context> context = context_info->context->Get(isolate);
         Context::Scope context_scope(context);
 
-        Local<String> v8_str = String::NewFromUtf8(isolate, RSTRING_PTR(name),
-                              NewStringType::kNormal, (int)RSTRING_LEN(name)).ToLocalChecked();
+        Local<String> v8_str =
+            String::NewFromUtf8(isolate, RSTRING_PTR(name),
+                                NewStringType::kNormal, (int)RSTRING_LEN(name))
+                .ToLocalChecked();
 
         // copy self so we can access from v8 external
         VALUE* self_copy;
@@ -1097,24 +1099,35 @@ static VALUE rb_external_function_notify_v8(VALUE self) {
         Local<Value> external = External::New(isolate, self_copy);
 
         if (parent_object == Qnil) {
-            context->Global()->Set(v8_str, FunctionTemplate::New(isolate, ruby_callback, external)->GetFunction());
-        } else {
+            context->Global()->Set(
+                v8_str, FunctionTemplate::New(isolate, ruby_callback, external)
+                            ->GetFunction(context)
+                            .ToLocalChecked());
 
-            Local<String> eval = String::NewFromUtf8(isolate, RSTRING_PTR(parent_object_eval),
-                                  NewStringType::kNormal, (int)RSTRING_LEN(parent_object_eval)).ToLocalChecked();
+        } else {
+            Local<String> eval =
+                String::NewFromUtf8(isolate, RSTRING_PTR(parent_object_eval),
+                                    NewStringType::kNormal,
+                                    (int)RSTRING_LEN(parent_object_eval))
+                    .ToLocalChecked();
 
             MaybeLocal<Script> parsed_script = Script::Compile(context, eval);
             if (parsed_script.IsEmpty()) {
-            parse_error = true;
+                parse_error = true;
             } else {
-                MaybeLocal<Value> maybe_value = parsed_script.ToLocalChecked()->Run(context);
+                MaybeLocal<Value> maybe_value =
+                    parsed_script.ToLocalChecked()->Run(context);
                 attach_error = true;
 
                 if (!maybe_value.IsEmpty()) {
                     Local<Value> value = maybe_value.ToLocalChecked();
-                    if (value->IsObject()){
-                    value.As<Object>()->Set(v8_str, FunctionTemplate::New(isolate, ruby_callback, external)->GetFunction());
-                    attach_error = false;
+                    if (value->IsObject()) {
+                        value.As<Object>()->Set(
+                            v8_str, FunctionTemplate::New(
+                                        isolate, ruby_callback, external)
+                                        ->GetFunction(context)
+                                        .ToLocalChecked());
+                        attach_error = false;
                     }
                 }
             }

GitHub sha: a3cfe312