Skip to content

Commit

Permalink
Compatibility changes for V8 7.4 support (#142)
Browse files Browse the repository at this point in the history
* 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] v8/v8@ffee558
    https://chromium.googlesource.com/v8/v8/+/ffee558e14e28fc8b1f9a3c10ea3615e0d686c7b
    https://chromium-review.googlesource.com/c/v8/v8/+/755033/
[2] v8/v8@cbd8f42
    https://chromium.googlesource.com/v8/v8/+/cbd8f4269f91e8ade38876092b433bda9ddb89a9
    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] v8/v8@66969fb
    https://chromium.googlesource.com/v8/v8/+/66969fb2ad6161d2d1da87cdd6fb50e1e6c970e5
    https://codereview.chromium.org/993883002

[2] v8/v8@cbd8f42
    https://chromium.googlesource.com/v8/v8/+/cbd8f4269f91e8ade38876092b433bda9ddb89a9
    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] v8/v8@5234d99
    https://chromium.googlesource.com/v8/v8/+/5234d9977d637668e66b9e2e9f0456c6f97f749e
    https://codereview.chromium.org/993223003

[2] v8/v8@6f5e805
    https://chromium.googlesource.com/v8/v8/+/6f5e8052847fc41df98a1e8f19211f399c6afc18
    https://chromium-review.googlesource.com/c/v8/v8/+/1450115
  • Loading branch information
ignisf authored and SamSaffron committed May 29, 2019
1 parent 38cd347 commit a3cfe31
Showing 1 changed file with 28 additions and 15 deletions.
43 changes: 28 additions & 15 deletions ext/mini_racer_extension/mini_racer_extension.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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();
}

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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;
}
}
}
Expand Down

0 comments on commit a3cfe31

Please sign in to comment.