Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
Copy link
Copy Markdown
Contributor Author

@ignisf ignisf May 28, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@SamSaffron, check this out. The new platform API mandates the use of an std::unique_ptr.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh interesting!

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