chore: fix v8 deprecation warnings

This commit is contained in:
deepak1556 2018-11-29 07:25:03 +05:30
parent f8418554a3
commit e1336d8453
14 changed files with 86 additions and 65 deletions

View file

@ -20,6 +20,7 @@
#include "content/browser/renderer_host/render_widget_host_impl.h" #include "content/browser/renderer_host/render_widget_host_impl.h"
#include "content/public/browser/render_process_host.h" #include "content/public/browser/render_process_host.h"
#include "content/public/browser/render_view_host.h" #include "content/public/browser/render_view_host.h"
#include "gin/converter.h"
#include "native_mate/dictionary.h" #include "native_mate/dictionary.h"
#include "ui/gl/gpu_switching_manager.h" #include "ui/gl/gpu_switching_manager.h"
@ -311,7 +312,7 @@ void BrowserWindow::SetBrowserView(v8::Local<v8::Value> value) {
void BrowserWindow::SetVibrancy(v8::Isolate* isolate, void BrowserWindow::SetVibrancy(v8::Isolate* isolate,
v8::Local<v8::Value> value) { v8::Local<v8::Value> value) {
std::string type = mate::V8ToString(value); std::string type = gin::V8ToString(isolate, value);
auto* render_view_host = web_contents()->GetRenderViewHost(); auto* render_view_host = web_contents()->GetRenderViewHost();
if (render_view_host) { if (render_view_host) {

View file

@ -359,7 +359,7 @@ void DestroyGlobalHandle(v8::Isolate* isolate,
if (!global_handle.IsEmpty()) { if (!global_handle.IsEmpty()) {
v8::Local<v8::Value> local_handle = global_handle.Get(isolate); v8::Local<v8::Value> local_handle = global_handle.Get(isolate);
if (local_handle->IsObject()) { if (local_handle->IsObject()) {
v8::Local<v8::Object> object = local_handle->ToObject(); v8::Local<v8::Object> object = local_handle->ToObject(isolate);
void* ptr = object->GetAlignedPointerFromInternalField(0); void* ptr = object->GetAlignedPointerFromInternalField(0);
if (!ptr) if (!ptr)
return; return;

View file

@ -20,6 +20,7 @@
#include "atom/common/native_mate_converters/value_converter.h" #include "atom/common/native_mate_converters/value_converter.h"
#include "atom/common/options_switches.h" #include "atom/common/options_switches.h"
#include "electron/buildflags/buildflags.h" #include "electron/buildflags/buildflags.h"
#include "gin/converter.h"
#include "native_mate/handle.h" #include "native_mate/handle.h"
#include "native_mate/persistent_dictionary.h" #include "native_mate/persistent_dictionary.h"
@ -643,7 +644,8 @@ void TopLevelWindow::SetFocusable(bool focusable) {
void TopLevelWindow::SetMenu(v8::Isolate* isolate, v8::Local<v8::Value> value) { void TopLevelWindow::SetMenu(v8::Isolate* isolate, v8::Local<v8::Value> value) {
mate::Handle<Menu> menu; mate::Handle<Menu> menu;
if (value->IsObject() && if (value->IsObject() &&
mate::V8ToString(value->ToObject()->GetConstructorName()) == "Menu" && gin::V8ToString(
isolate, value->ToObject(isolate)->GetConstructorName()) == "Menu" &&
mate::ConvertFromV8(isolate, value, &menu) && !menu.IsEmpty()) { mate::ConvertFromV8(isolate, value, &menu) && !menu.IsEmpty()) {
menu_.Reset(isolate, menu.ToV8()); menu_.Reset(isolate, menu.ToV8());
window_->SetMenu(menu->model()); window_->SetMenu(menu->model());
@ -740,7 +742,7 @@ void TopLevelWindow::SetAutoHideCursor(bool auto_hide) {
void TopLevelWindow::SetVibrancy(v8::Isolate* isolate, void TopLevelWindow::SetVibrancy(v8::Isolate* isolate,
v8::Local<v8::Value> value) { v8::Local<v8::Value> value) {
std::string type = mate::V8ToString(value); std::string type = gin::V8ToString(isolate, value);
window_->SetVibrancy(type); window_->SetVibrancy(type);
} }

View file

@ -103,7 +103,8 @@ class EventEmitter : public Wrappable<T> {
v8::HandleScope handle_scope(isolate()); v8::HandleScope handle_scope(isolate());
EmitEvent(isolate(), GetWrapper(), name, event, args...); EmitEvent(isolate(), GetWrapper(), name, event, args...);
return event->Get(StringToV8(isolate(), "defaultPrevented")) return event->Get(StringToV8(isolate(), "defaultPrevented"))
->BooleanValue(); ->BooleanValue(isolate()->GetCurrentContext())
.ToChecked();
} }
DISALLOW_COPY_AND_ASSIGN(EventEmitter); DISALLOW_COPY_AND_ASSIGN(EventEmitter);

View file

@ -131,7 +131,7 @@ void InitAsarSupport(v8::Isolate* isolate,
result = asar_init->Run(context).ToLocalChecked(); result = asar_init->Run(context).ToLocalChecked();
// Initialize asar support. // Initialize asar support.
CHECK(result->IsFunction()); DCHECK(result->IsFunction());
v8::Local<v8::Value> args[] = { v8::Local<v8::Value> args[] = {
source, source,

View file

@ -12,6 +12,7 @@
#include "base/strings/string_util.h" #include "base/strings/string_util.h"
#include "base/strings/utf_string_conversions.h" #include "base/strings/utf_string_conversions.h"
#include "content/public/browser/native_web_keyboard_event.h" #include "content/public/browser/native_web_keyboard_event.h"
#include "gin/converter.h"
#include "native_mate/dictionary.h" #include "native_mate/dictionary.h"
#include "third_party/blink/public/platform/web_input_event.h" #include "third_party/blink/public/platform/web_input_event.h"
#include "third_party/blink/public/platform/web_mouse_event.h" #include "third_party/blink/public/platform/web_mouse_event.h"
@ -41,7 +42,7 @@ struct Converter<base::char16> {
static bool FromV8(v8::Isolate* isolate, static bool FromV8(v8::Isolate* isolate,
v8::Handle<v8::Value> val, v8::Handle<v8::Value> val,
base::char16* out) { base::char16* out) {
base::string16 code = base::UTF8ToUTF16(V8ToString(val)); base::string16 code = base::UTF8ToUTF16(gin::V8ToString(isolate, val));
if (code.length() != 1) if (code.length() != 1)
return false; return false;
*out = code[0]; *out = code[0];
@ -54,7 +55,7 @@ struct Converter<blink::WebInputEvent::Type> {
static bool FromV8(v8::Isolate* isolate, static bool FromV8(v8::Isolate* isolate,
v8::Handle<v8::Value> val, v8::Handle<v8::Value> val,
blink::WebInputEvent::Type* out) { blink::WebInputEvent::Type* out) {
std::string type = base::ToLowerASCII(V8ToString(val)); std::string type = base::ToLowerASCII(gin::V8ToString(isolate, val));
if (type == "mousedown") if (type == "mousedown")
*out = blink::WebInputEvent::kMouseDown; *out = blink::WebInputEvent::kMouseDown;
else if (type == "mouseup") else if (type == "mouseup")
@ -92,7 +93,7 @@ struct Converter<blink::WebMouseEvent::Button> {
static bool FromV8(v8::Isolate* isolate, static bool FromV8(v8::Isolate* isolate,
v8::Handle<v8::Value> val, v8::Handle<v8::Value> val,
blink::WebMouseEvent::Button* out) { blink::WebMouseEvent::Button* out) {
std::string button = base::ToLowerASCII(V8ToString(val)); std::string button = base::ToLowerASCII(gin::V8ToString(isolate, val));
if (button == "left") if (button == "left")
*out = blink::WebMouseEvent::Button::kLeft; *out = blink::WebMouseEvent::Button::kLeft;
else if (button == "middle") else if (button == "middle")
@ -110,7 +111,7 @@ struct Converter<blink::WebInputEvent::Modifiers> {
static bool FromV8(v8::Isolate* isolate, static bool FromV8(v8::Isolate* isolate,
v8::Handle<v8::Value> val, v8::Handle<v8::Value> val,
blink::WebInputEvent::Modifiers* out) { blink::WebInputEvent::Modifiers* out) {
std::string modifier = base::ToLowerASCII(V8ToString(val)); std::string modifier = base::ToLowerASCII(gin::V8ToString(isolate, val));
if (modifier == "shift") if (modifier == "shift")
*out = blink::WebInputEvent::kShiftKey; *out = blink::WebInputEvent::kShiftKey;
else if (modifier == "control" || modifier == "ctrl") else if (modifier == "control" || modifier == "ctrl")
@ -516,7 +517,7 @@ bool Converter<blink::WebReferrerPolicy>::FromV8(
v8::Isolate* isolate, v8::Isolate* isolate,
v8::Handle<v8::Value> val, v8::Handle<v8::Value> val,
blink::WebReferrerPolicy* out) { blink::WebReferrerPolicy* out) {
std::string policy = base::ToLowerASCII(V8ToString(val)); std::string policy = base::ToLowerASCII(gin::V8ToString(isolate, val));
if (policy == "default") if (policy == "default")
*out = blink::kWebReferrerPolicyDefault; *out = blink::kWebReferrerPolicyDefault;
else if (policy == "unsafe-url") else if (policy == "unsafe-url")

View file

@ -46,7 +46,7 @@ bool GetIPCObject(v8::Isolate* isolate,
return false; return false;
if (value.IsEmpty() || !value->IsObject()) if (value.IsEmpty() || !value->IsObject())
return false; return false;
*ipc = value->ToObject(); *ipc = value->ToObject(isolate);
return true; return true;
} }

View file

@ -198,12 +198,13 @@ void AtomRendererClient::SetupMainWorldOverrides(
std::string left = "(function (binding, require) {\n"; std::string left = "(function (binding, require) {\n";
std::string right = "\n})"; std::string right = "\n})";
auto source = v8::String::Concat( auto source = v8::String::Concat(
mate::ConvertToV8(isolate, left)->ToString(), isolate, mate::ConvertToV8(isolate, left)->ToString(isolate),
v8::String::Concat(node::isolated_bundle_value.ToStringChecked(isolate), v8::String::Concat(isolate,
mate::ConvertToV8(isolate, right)->ToString())); node::isolated_bundle_value.ToStringChecked(isolate),
mate::ConvertToV8(isolate, right)->ToString(isolate)));
auto result = RunScript(context, source); auto result = RunScript(context, source);
CHECK(result->IsFunction()); DCHECK(result->IsFunction());
auto binding = v8::Object::New(isolate); auto binding = v8::Object::New(isolate);
api::Initialize(binding, v8::Null(isolate), context, nullptr); api::Initialize(binding, v8::Null(isolate), context, nullptr);

View file

@ -19,6 +19,7 @@
#include "base/path_service.h" #include "base/path_service.h"
#include "base/process/process_handle.h" #include "base/process/process_handle.h"
#include "content/public/renderer/render_frame.h" #include "content/public/renderer/render_frame.h"
#include "gin/converter.h"
#include "native_mate/dictionary.h" #include "native_mate/dictionary.h"
#include "third_party/blink/public/web/blink.h" #include "third_party/blink/public/web/blink.h"
#include "third_party/blink/public/web/web_document.h" #include "third_party/blink/public/web/web_document.h"
@ -52,7 +53,7 @@ v8::Local<v8::Object> GetModuleCache(v8::Isolate* isolate) {
global.SetHidden(kModuleCacheKey, cache); global.SetHidden(kModuleCacheKey, cache);
} }
return cache->ToObject(); return cache->ToObject(isolate);
} }
// adapted from node.cc // adapted from node.cc
@ -60,7 +61,7 @@ v8::Local<v8::Value> GetBinding(v8::Isolate* isolate,
v8::Local<v8::String> key, v8::Local<v8::String> key,
mate::Arguments* margs) { mate::Arguments* margs) {
v8::Local<v8::Object> exports; v8::Local<v8::Object> exports;
std::string module_key = mate::V8ToString(key); std::string module_key = gin::V8ToString(isolate, key);
mate::Dictionary cache(isolate, GetModuleCache(isolate)); mate::Dictionary cache(isolate, GetModuleCache(isolate));
if (cache.Get(module_key.c_str(), &exports)) { if (cache.Get(module_key.c_str(), &exports)) {
@ -85,6 +86,12 @@ v8::Local<v8::Value> GetBinding(v8::Isolate* isolate,
return exports; return exports;
} }
v8::Local<v8::Value> CreatePreloadScript(v8::Isolate* isolate,
v8::Local<v8::String> preloadSrc) {
return RendererClientBase::RunScript(isolate->GetCurrentContext(),
preloadSrc);
}
class AtomSandboxedRenderFrameObserver : public AtomRenderFrameObserver { class AtomSandboxedRenderFrameObserver : public AtomRenderFrameObserver {
public: public:
AtomSandboxedRenderFrameObserver(content::RenderFrame* render_frame, AtomSandboxedRenderFrameObserver(content::RenderFrame* render_frame,
@ -134,7 +141,7 @@ void AtomSandboxedRendererClient::InitializeBindings(
auto* isolate = context->GetIsolate(); auto* isolate = context->GetIsolate();
mate::Dictionary b(isolate, binding); mate::Dictionary b(isolate, binding);
b.SetMethod("get", GetBinding); b.SetMethod("get", GetBinding);
b.SetMethod("createPreloadScript", RunScript); b.SetMethod("createPreloadScript", CreatePreloadScript);
mate::Dictionary process = mate::Dictionary::CreateEmpty(isolate); mate::Dictionary process = mate::Dictionary::CreateEmpty(isolate);
b.Set("process", process); b.Set("process", process);
@ -184,12 +191,13 @@ void AtomSandboxedRendererClient::DidCreateScriptContext(
std::string right = "\n})"; std::string right = "\n})";
// Compile the wrapper and run it to get the function object // Compile the wrapper and run it to get the function object
auto source = v8::String::Concat( auto source = v8::String::Concat(
mate::ConvertToV8(isolate, left)->ToString(), isolate, mate::ConvertToV8(isolate, left)->ToString(isolate),
v8::String::Concat(node::preload_bundle_value.ToStringChecked(isolate), v8::String::Concat(isolate,
mate::ConvertToV8(isolate, right)->ToString())); node::preload_bundle_value.ToStringChecked(isolate),
mate::ConvertToV8(isolate, right)->ToString(isolate)));
auto result = RunScript(context, source); auto result = RunScript(context, source);
CHECK(result->IsFunction()); DCHECK(result->IsFunction());
// Create and initialize the binding object // Create and initialize the binding object
auto binding = v8::Object::New(isolate); auto binding = v8::Object::New(isolate);
InitializeBindings(binding, context); InitializeBindings(binding, context);
@ -218,7 +226,7 @@ void AtomSandboxedRendererClient::InvokeIpcCallback(
const std::string& callback_name, const std::string& callback_name,
std::vector<v8::Handle<v8::Value>> args) { std::vector<v8::Handle<v8::Value>> args) {
auto* isolate = context->GetIsolate(); auto* isolate = context->GetIsolate();
auto binding_key = mate::ConvertToV8(isolate, kIpcKey)->ToString(); auto binding_key = mate::ConvertToV8(isolate, kIpcKey)->ToString(isolate);
auto private_binding_key = v8::Private::ForApi(isolate, binding_key); auto private_binding_key = v8::Private::ForApi(isolate, binding_key);
auto global_object = context->Global(); auto global_object = context->Global();
v8::Local<v8::Value> value; v8::Local<v8::Value> value;
@ -226,8 +234,9 @@ void AtomSandboxedRendererClient::InvokeIpcCallback(
return; return;
if (value.IsEmpty() || !value->IsObject()) if (value.IsEmpty() || !value->IsObject())
return; return;
auto binding = value->ToObject(); auto binding = value->ToObject(isolate);
auto callback_key = mate::ConvertToV8(isolate, callback_name)->ToString(); auto callback_key =
mate::ConvertToV8(isolate, callback_name)->ToString(isolate);
auto callback_value = binding->Get(callback_key); auto callback_value = binding->Get(callback_key);
DCHECK(callback_value->IsFunction()); // set by sandboxed_renderer/init.js DCHECK(callback_value->IsFunction()); // set by sandboxed_renderer/init.js
auto callback = v8::Handle<v8::Function>::Cast(callback_value); auto callback = v8::Handle<v8::Function>::Cast(callback_value);

View file

@ -277,8 +277,9 @@ v8::Local<v8::Context> RendererClientBase::GetContext(
return frame->MainWorldScriptContext(); return frame->MainWorldScriptContext();
} }
v8::Local<v8::Value> RunScript(v8::Local<v8::Context> context, v8::Local<v8::Value> RendererClientBase::RunScript(
v8::Local<v8::String> source) { v8::Local<v8::Context> context,
v8::Local<v8::String> source) {
auto maybe_script = v8::Script::Compile(context, source); auto maybe_script = v8::Script::Compile(context, source);
v8::Local<v8::Script> script; v8::Local<v8::Script> script;
if (!maybe_script.ToLocal(&script)) if (!maybe_script.ToLocal(&script))

View file

@ -40,7 +40,7 @@ class RendererClientBase : public content::ContentRendererClient {
v8::Local<v8::Context> GetContext(blink::WebLocalFrame* frame, v8::Local<v8::Context> GetContext(blink::WebLocalFrame* frame,
v8::Isolate* isolate) const; v8::Isolate* isolate) const;
// Executes a given v8 Script // Executes a given v8 Script
inline v8::Local<v8::Value> RunScript(v8::Local<v8::Context> context, static v8::Local<v8::Value> RunScript(v8::Local<v8::Context> context,
v8::Local<v8::String> source); v8::Local<v8::String> source);
protected: protected:

View file

@ -10,17 +10,33 @@ using v8::Array;
using v8::Boolean; using v8::Boolean;
using v8::External; using v8::External;
using v8::Function; using v8::Function;
using v8::Int32;
using v8::Integer; using v8::Integer;
using v8::Isolate; using v8::Isolate;
using v8::Local; using v8::Local;
using v8::Maybe;
using v8::MaybeLocal;
using v8::Number; using v8::Number;
using v8::Object; using v8::Object;
using v8::Promise; using v8::Promise;
using v8::String; using v8::String;
using v8::Uint32;
using v8::Value; using v8::Value;
namespace mate { namespace mate {
namespace {
template <typename T, typename U>
bool FromMaybe(Maybe<T> maybe, U* out) {
if (maybe.IsNothing())
return false;
*out = static_cast<U>(maybe.FromJust());
return true;
}
} // namespace
Local<Value> Converter<bool>::ToV8(Isolate* isolate, bool val) { Local<Value> Converter<bool>::ToV8(Isolate* isolate, bool val) {
return v8::Boolean::New(isolate, val); return v8::Boolean::New(isolate, val);
} }
@ -28,7 +44,7 @@ Local<Value> Converter<bool>::ToV8(Isolate* isolate, bool val) {
bool Converter<bool>::FromV8(Isolate* isolate, Local<Value> val, bool* out) { bool Converter<bool>::FromV8(Isolate* isolate, Local<Value> val, bool* out) {
if (!val->IsBoolean()) if (!val->IsBoolean())
return false; return false;
*out = val->BooleanValue(); *out = val.As<Boolean>()->Value();
return true; return true;
} }
@ -43,8 +59,7 @@ bool Converter<unsigned long>::FromV8(Isolate* isolate,
unsigned long* out) { unsigned long* out) {
if (!val->IsNumber()) if (!val->IsNumber())
return false; return false;
*out = val->IntegerValue(); return FromMaybe(val->IntegerValue(isolate->GetCurrentContext()), out);
return true;
} }
#endif #endif
@ -57,7 +72,7 @@ bool Converter<int32_t>::FromV8(Isolate* isolate,
int32_t* out) { int32_t* out) {
if (!val->IsInt32()) if (!val->IsInt32())
return false; return false;
*out = val->Int32Value(); *out = val.As<Int32>()->Value();
return true; return true;
} }
@ -70,7 +85,7 @@ bool Converter<uint32_t>::FromV8(Isolate* isolate,
uint32_t* out) { uint32_t* out) {
if (!val->IsUint32()) if (!val->IsUint32())
return false; return false;
*out = val->Uint32Value(); *out = val.As<Uint32>()->Value();
return true; return true;
} }
@ -85,8 +100,7 @@ bool Converter<int64_t>::FromV8(Isolate* isolate,
return false; return false;
// Even though IntegerValue returns int64_t, JavaScript cannot represent // Even though IntegerValue returns int64_t, JavaScript cannot represent
// the full precision of int64_t, which means some rounding might occur. // the full precision of int64_t, which means some rounding might occur.
*out = val->IntegerValue(); return FromMaybe(val->IntegerValue(isolate->GetCurrentContext()), out);
return true;
} }
Local<Value> Converter<uint64_t>::ToV8(Isolate* isolate, uint64_t val) { Local<Value> Converter<uint64_t>::ToV8(Isolate* isolate, uint64_t val) {
@ -98,8 +112,7 @@ bool Converter<uint64_t>::FromV8(Isolate* isolate,
uint64_t* out) { uint64_t* out) {
if (!val->IsNumber()) if (!val->IsNumber())
return false; return false;
*out = static_cast<uint64_t>(val->IntegerValue()); return FromMaybe(val->IntegerValue(isolate->GetCurrentContext()), out);
return true;
} }
Local<Value> Converter<float>::ToV8(Isolate* isolate, float val) { Local<Value> Converter<float>::ToV8(Isolate* isolate, float val) {
@ -109,7 +122,7 @@ Local<Value> Converter<float>::ToV8(Isolate* isolate, float val) {
bool Converter<float>::FromV8(Isolate* isolate, Local<Value> val, float* out) { bool Converter<float>::FromV8(Isolate* isolate, Local<Value> val, float* out) {
if (!val->IsNumber()) if (!val->IsNumber())
return false; return false;
*out = static_cast<float>(val->NumberValue()); *out = static_cast<float>(val.As<Number>()->Value());
return true; return true;
} }
@ -122,7 +135,7 @@ bool Converter<double>::FromV8(Isolate* isolate,
double* out) { double* out) {
if (!val->IsNumber()) if (!val->IsNumber())
return false; return false;
*out = val->NumberValue(); *out = val.As<Number>()->Value();
return true; return true;
} }
@ -147,9 +160,10 @@ bool Converter<std::string>::FromV8(Isolate* isolate,
if (!val->IsString()) if (!val->IsString())
return false; return false;
Local<String> str = Local<String>::Cast(val); Local<String> str = Local<String>::Cast(val);
int length = str->Utf8Length(); int length = str->Utf8Length(isolate);
out->resize(length); out->resize(length);
str->WriteUtf8(&(*out)[0], length, NULL, String::NO_NULL_TERMINATION); str->WriteUtf8(isolate, &(*out)[0], length, NULL,
String::NO_NULL_TERMINATION);
return true; return true;
} }
@ -245,13 +259,4 @@ v8::Local<v8::String> StringToSymbol(v8::Isolate* isolate,
static_cast<uint32_t>(val.length())); static_cast<uint32_t>(val.length()));
} }
std::string V8ToString(v8::Local<v8::Value> value) {
if (value.IsEmpty())
return std::string();
std::string result;
if (!ConvertFromV8(NULL, value, &result))
return std::string();
return result;
}
} // namespace mate } // namespace mate

View file

@ -11,6 +11,7 @@
#include <vector> #include <vector>
#include "base/strings/string_piece.h" #include "base/strings/string_piece.h"
#include "gin/converter.h"
#include "v8/include/v8.h" #include "v8/include/v8.h"
namespace mate { namespace mate {
@ -136,8 +137,6 @@ struct Converter<std::string> {
v8::Local<v8::String> StringToSymbol(v8::Isolate* isolate, v8::Local<v8::String> StringToSymbol(v8::Isolate* isolate,
const base::StringPiece& input); const base::StringPiece& input);
std::string V8ToString(v8::Local<v8::Value> value);
template <> template <>
struct Converter<v8::Local<v8::Function>> { struct Converter<v8::Local<v8::Function>> {
static v8::Local<v8::Value> ToV8(v8::Isolate* isolate, static v8::Local<v8::Value> ToV8(v8::Isolate* isolate,
@ -276,13 +275,14 @@ struct Converter<std::map<std::string, T>> {
if (!val->IsObject()) if (!val->IsObject())
return false; return false;
v8::Local<v8::Object> dict = val->ToObject(); v8::Local<v8::Context> context = isolate->GetCurrentContext();
v8::Local<v8::Object> dict = val->ToObject(context).ToLocalChecked();
v8::Local<v8::Array> keys = dict->GetOwnPropertyNames(); v8::Local<v8::Array> keys = dict->GetOwnPropertyNames();
for (uint32_t i = 0; i < keys->Length(); ++i) { for (uint32_t i = 0; i < keys->Length(); ++i) {
v8::Local<v8::Value> key = keys->Get(i); v8::Local<v8::Value> key = keys->Get(i);
T value; T value;
if (Converter<T>::FromV8(isolate, dict->Get(key), &value)) if (Converter<T>::FromV8(isolate, dict->Get(key), &value))
(*out)[V8ToString(key)] = std::move(value); (*out)[gin::V8ToString(isolate, key)] = std::move(value);
} }
return true; return true;
} }

View file

@ -13,15 +13,13 @@ namespace mate {
// Currently we don't have a mechanism for retaining a mate::Wrappable object // Currently we don't have a mechanism for retaining a mate::Wrappable object
// in the C++ heap because strong references from C++ to V8 can cause memory // in the C++ heap because strong references from C++ to V8 can cause memory
// leaks. // leaks.
template<typename T> template <typename T>
class Handle { class Handle {
public: public:
Handle() : object_(NULL) {} Handle() : object_(NULL) {}
Handle(v8::Local<v8::Object> wrapper, T* object) Handle(v8::Local<v8::Object> wrapper, T* object)
: wrapper_(wrapper), : wrapper_(wrapper), object_(object) {}
object_(object) {
}
bool IsEmpty() const { return !object_; } bool IsEmpty() const { return !object_; }
@ -39,13 +37,14 @@ class Handle {
T* object_; T* object_;
}; };
template<typename T> template <typename T>
struct Converter<mate::Handle<T> > { struct Converter<mate::Handle<T>> {
static v8::Local<v8::Value> ToV8(v8::Isolate* isolate, static v8::Local<v8::Value> ToV8(v8::Isolate* isolate,
const mate::Handle<T>& val) { const mate::Handle<T>& val) {
return val.ToV8(); return val.ToV8();
} }
static bool FromV8(v8::Isolate* isolate, v8::Local<v8::Value> val, static bool FromV8(v8::Isolate* isolate,
v8::Local<v8::Value> val,
mate::Handle<T>* out) { mate::Handle<T>* out) {
T* object = NULL; T* object = NULL;
if (val->IsNull() || val->IsUndefined()) { if (val->IsNull() || val->IsUndefined()) {
@ -55,14 +54,15 @@ struct Converter<mate::Handle<T> > {
if (!Converter<T*>::FromV8(isolate, val, &object)) { if (!Converter<T*>::FromV8(isolate, val, &object)) {
return false; return false;
} }
*out = mate::Handle<T>(val->ToObject(), object); v8::Local<v8::Context> context = isolate->GetCurrentContext();
*out = mate::Handle<T>(val->ToObject(context).ToLocalChecked(), object);
return true; return true;
} }
}; };
// This function is a convenient way to create a handle from a raw pointer // This function is a convenient way to create a handle from a raw pointer
// without having to write out the type of the object explicitly. // without having to write out the type of the object explicitly.
template<typename T> template <typename T>
mate::Handle<T> CreateHandle(v8::Isolate* isolate, T* object) { mate::Handle<T> CreateHandle(v8::Isolate* isolate, T* object) {
return mate::Handle<T>(object->GetWrapper(), object); return mate::Handle<T>(object->GetWrapper(), object);
} }