diff --git a/CHANGELOG b/CHANGELOG index c664a49c..729bbb41 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,3 +1,9 @@ +- Unreleased + + - FIX: Compatiblity fixes for V8 7 and above @ignisf + - FIX: Memory leak in gc_callback @messense + - IMPROVEMENT: Added example of sourcemap support @ianks + - 02-11-2018 - 0.2.4 diff --git a/LICENSE.txt b/LICENSE.txt index 109b204f..87a6bf90 100644 --- a/LICENSE.txt +++ b/LICENSE.txt @@ -1,6 +1,6 @@ The MIT License (MIT) -Copyright (c) 2016 TODO: Write your name +Copyright (c) 2016-2019, the mini_racer project authors. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/ext/mini_racer_extension/mini_racer_extension.cc b/ext/mini_racer_extension/mini_racer_extension.cc index e2c11212..dad8f20b 100644 --- a/ext/mini_racer_extension/mini_racer_extension.cc +++ b/ext/mini_racer_extension/mini_racer_extension.cc @@ -230,13 +230,13 @@ static void prepare_result(MaybeLocal v8res, Local local_value = v8res.ToLocalChecked(); if ((local_value->IsObject() || local_value->IsArray()) && !local_value->IsDate() && !local_value->IsFunction()) { - Local JSON = context->Global()->Get( - String::NewFromUtf8(isolate, "JSON"))->ToObject(); + Local JSON = context->Global()->Get(String::NewFromUtf8(isolate, "JSON")) + ->ToObject(context).ToLocalChecked(); Local stringify = JSON->Get(v8::String::NewFromUtf8(isolate, "stringify")) .As(); - Local object = local_value->ToObject(); + Local object = local_value->ToObject(context).ToLocalChecked(); const unsigned argc = 1; Local argv[argc] = { object }; MaybeLocal json = stringify->Call(JSON, argc, argv); @@ -274,7 +274,7 @@ static void prepare_result(MaybeLocal v8res, } len = snprintf(buf, sizeof(buf), "%s at %s:%i:%i", *String::Utf8Value(isolate, message->Get()), - *String::Utf8Value(isolate, message->GetScriptResourceName()->ToString()), + *String::Utf8Value(isolate, message->GetScriptResourceName()->ToString(context).ToLocalChecked()), line, column); @@ -293,7 +293,8 @@ static void prepare_result(MaybeLocal v8res, } if (!trycatch.StackTrace(context).IsEmpty()) { evalRes.backtrace = new Persistent(); - evalRes.backtrace->Reset(isolate, trycatch.StackTrace(context).ToLocalChecked()->ToString()); + evalRes.backtrace->Reset(isolate, + trycatch.StackTrace(context).ToLocalChecked()->ToString(context).ToLocalChecked()); } } } @@ -373,11 +374,11 @@ static VALUE convert_v8_to_ruby(Isolate* isolate, Local context, } if (value->IsInt32()) { - return INT2FIX(value->Int32Value()); + return INT2FIX(value->Int32Value(context).ToChecked()); } if (value->IsNumber()) { - return rb_float_new(value->NumberValue()); + return rb_float_new(value->NumberValue(context).ToChecked()); } if (value->IsTrue()) { @@ -418,7 +419,7 @@ static VALUE convert_v8_to_ruby(Isolate* isolate, Local context, VALUE rb_hash = rb_hash_new(); TryCatch trycatch(isolate); - Local object = value->ToObject(); + Local object = value->ToObject(context).ToLocalChecked(); auto maybe_props = object->GetOwnPropertyNames(context); if (!maybe_props.IsEmpty()) { Local props = maybe_props.ToLocalChecked(); @@ -441,8 +442,8 @@ static VALUE convert_v8_to_ruby(Isolate* isolate, Local context, return rb_hash; } - Local rstr = value->ToString(); - return rb_enc_str_new(*String::Utf8Value(isolate, rstr), rstr->Utf8Length(), rb_enc_find("utf-8")); + Local rstr = value->ToString(context).ToLocalChecked(); + return rb_enc_str_new(*String::Utf8Value(isolate, rstr), rstr->Utf8Length(isolate), rb_enc_find("utf-8")); } static VALUE convert_v8_to_ruby(Isolate* isolate, @@ -463,7 +464,7 @@ static VALUE convert_v8_to_ruby(Isolate* isolate, Local::New(isolate, value)); } -static Local convert_ruby_to_v8(Isolate* isolate, VALUE value) { +static Local convert_ruby_to_v8(Isolate* isolate, Local context, VALUE value) { EscapableHandleScope scope(isolate); Local array; @@ -497,7 +498,7 @@ static Local convert_ruby_to_v8(Isolate* isolate, VALUE value) { length = RARRAY_LEN(value); array = Array::New(isolate, (int)length); for(i=0; iSet(i, convert_ruby_to_v8(isolate, rb_ary_entry(value, i))); + array->Set(i, convert_ruby_to_v8(isolate, context, rb_ary_entry(value, i))); } return scope.Escape(array); case T_HASH: @@ -506,8 +507,8 @@ static Local convert_ruby_to_v8(Isolate* isolate, VALUE value) { length = RARRAY_LEN(hash_as_array); for(i=0; iSet(convert_ruby_to_v8(isolate, rb_ary_entry(pair, 0)), - convert_ruby_to_v8(isolate, rb_ary_entry(pair, 1))); + object->Set(convert_ruby_to_v8(isolate, context, rb_ary_entry(pair, 0)), + convert_ruby_to_v8(isolate, context, rb_ary_entry(pair, 1))); } return scope.Escape(object); case T_SYMBOL: @@ -522,7 +523,7 @@ static Local convert_ruby_to_v8(Isolate* isolate, VALUE value) { value = rb_funcall(value, rb_intern("to_time"), 0); } value = rb_funcall(value, rb_intern("to_f"), 0); - return scope.Escape(Date::New(isolate, NUM2DBL(value) * 1000)); + return scope.Escape(Date::New(context, NUM2DBL(value) * 1000).ToLocalChecked()); } case T_OBJECT: case T_CLASS: @@ -538,7 +539,6 @@ static Local convert_ruby_to_v8(Isolate* isolate, VALUE value) { default: return scope.Escape(String::NewFromUtf8(isolate, "Undefined Conversion")); } - } static void unblock_eval(void *ptr) { @@ -546,6 +546,91 @@ static void unblock_eval(void *ptr) { eval->context_info->isolate_info->interrupted = true; } +/* + * The implementations of the run_extra_code(), create_snapshot_data_blob() and + * warm_up_snapshot_data_blob() functions have been derived from V8's test suite. + */ +bool run_extra_code(Isolate *isolate, Local context, + const char *utf8_source, const char *name) { + Context::Scope context_scope(context); + TryCatch try_catch(isolate); + Local source_string; + if (!String::NewFromUtf8(isolate, utf8_source, + NewStringType::kNormal) + .ToLocal(&source_string)) { + return false; + } + Local resource_name = + String::NewFromUtf8(isolate, name, NewStringType::kNormal) + .ToLocalChecked(); + ScriptOrigin origin(resource_name); + ScriptCompiler::Source source(source_string, origin); + Local