From c713deb1e8f7246f7ad39e8523b9014c7a05bd51 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Sat, 28 Jun 2014 19:31:23 +0800 Subject: [PATCH] Upgrade to new V8 APIs. --- atom/browser/api/atom_api_menu.cc | 106 ++++++++++-------- atom/common/chrome_version.h | 28 ++--- .../string16_converter.h | 4 +- atom/common/node_includes.h | 6 +- vendor/native_mate | 2 +- 5 files changed, 82 insertions(+), 64 deletions(-) diff --git a/atom/browser/api/atom_api_menu.cc b/atom/browser/api/atom_api_menu.cc index a76d77b0..d93d84fd 100644 --- a/atom/browser/api/atom_api_menu.cc +++ b/atom/browser/api/atom_api_menu.cc @@ -20,26 +20,23 @@ namespace api { namespace { // Call method of delegate object. -v8::Handle CallDelegate(v8::Handle default_value, +v8::Handle CallDelegate(v8::Isolate* isolate, + v8::Handle default_value, v8::Handle menu, const char* method, int command_id) { - v8::Locker locker(node_isolate); - v8::HandleScope handle_scope(node_isolate); - - v8::Handle delegate = menu->Get(v8::String::New("delegate")); + v8::Handle delegate = menu->Get( + MATE_STRING_NEW(isolate, "delegate")); if (!delegate->IsObject()) return default_value; v8::Handle function = v8::Handle::Cast( - delegate->ToObject()->Get(v8::String::New(method))); + delegate->ToObject()->Get(MATE_STRING_NEW(isolate, method))); if (!function->IsFunction()) return default_value; - v8::Handle argv = v8::Integer::New(command_id); - - return handle_scope.Close( - function->Call(v8::Context::GetCurrent()->Global(), 1, &argv)); + v8::Handle argv = MATE_INTEGER_NEW(isolate, command_id); + return function->Call(isolate->GetCurrentContext()->Global(), 1, &argv); } } // namespace @@ -53,38 +50,46 @@ Menu::~Menu() { } bool Menu::IsCommandIdChecked(int command_id) const { - v8::Locker locker(node_isolate); - v8::HandleScope handle_scope(node_isolate); - return CallDelegate(v8::False(), - const_cast(this)->GetWrapper(node_isolate), + v8::Isolate* isolate = v8::Isolate::GetCurrent(); + v8::Locker locker(isolate); + v8::HandleScope handle_scope(isolate); + return CallDelegate(isolate, + MATE_FALSE(isolate), + const_cast(this)->GetWrapper(isolate), "isCommandIdChecked", command_id)->BooleanValue(); } bool Menu::IsCommandIdEnabled(int command_id) const { - v8::Locker locker(node_isolate); - v8::HandleScope handle_scope(node_isolate); - return CallDelegate(v8::True(), - const_cast(this)->GetWrapper(node_isolate), + v8::Isolate* isolate = v8::Isolate::GetCurrent(); + v8::Locker locker(isolate); + v8::HandleScope handle_scope(isolate); + return CallDelegate(isolate, + MATE_TRUE(isolate), + const_cast(this)->GetWrapper(isolate), "isCommandIdEnabled", command_id)->BooleanValue(); } bool Menu::IsCommandIdVisible(int command_id) const { - v8::Locker locker(node_isolate); - v8::HandleScope handle_scope(node_isolate); - return CallDelegate(v8::True(), - const_cast(this)->GetWrapper(node_isolate), + v8::Isolate* isolate = v8::Isolate::GetCurrent(); + v8::Locker locker(isolate); + v8::HandleScope handle_scope(isolate); + return CallDelegate(isolate, + MATE_TRUE(isolate), + const_cast(this)->GetWrapper(isolate), "isCommandIdVisible", command_id)->BooleanValue(); } bool Menu::GetAcceleratorForCommandId(int command_id, ui::Accelerator* accelerator) { - v8::Locker locker(node_isolate); - v8::HandleScope handle_scope(node_isolate); - v8::Handle shortcut = CallDelegate(v8::Undefined(), - GetWrapper(node_isolate), + v8::Isolate* isolate = v8::Isolate::GetCurrent(); + v8::Locker locker(isolate); + v8::HandleScope handle_scope(isolate); + v8::Handle shortcut = CallDelegate(isolate, + MATE_UNDEFINED(isolate), + GetWrapper(isolate), "getAcceleratorForCommandId", command_id); if (shortcut->IsString()) { @@ -96,20 +101,24 @@ bool Menu::GetAcceleratorForCommandId(int command_id, } bool Menu::IsItemForCommandIdDynamic(int command_id) const { - v8::Locker locker(node_isolate); - v8::HandleScope handle_scope(node_isolate); - return CallDelegate(v8::False(), - const_cast(this)->GetWrapper(node_isolate), + v8::Isolate* isolate = v8::Isolate::GetCurrent(); + v8::Locker locker(isolate); + v8::HandleScope handle_scope(isolate); + return CallDelegate(isolate, + MATE_FALSE(isolate), + const_cast(this)->GetWrapper(isolate), "isItemForCommandIdDynamic", command_id)->BooleanValue(); } string16 Menu::GetLabelForCommandId(int command_id) const { - v8::Locker locker(node_isolate); - v8::HandleScope handle_scope(node_isolate); + v8::Isolate* isolate = v8::Isolate::GetCurrent(); + v8::Locker locker(isolate); + v8::HandleScope handle_scope(isolate); v8::Handle result = CallDelegate( - v8::False(), - const_cast(this)->GetWrapper(node_isolate), + isolate, + MATE_FALSE(isolate), + const_cast(this)->GetWrapper(isolate), "getLabelForCommandId", command_id); string16 label; @@ -118,29 +127,34 @@ string16 Menu::GetLabelForCommandId(int command_id) const { } string16 Menu::GetSublabelForCommandId(int command_id) const { - v8::Locker locker(node_isolate); - v8::HandleScope handle_scope(node_isolate); + v8::Isolate* isolate = v8::Isolate::GetCurrent(); + v8::Locker locker(isolate); + v8::HandleScope handle_scope(isolate); v8::Handle result = CallDelegate( - v8::False(), - const_cast(this)->GetWrapper(node_isolate), + isolate, + MATE_FALSE(isolate), + const_cast(this)->GetWrapper(isolate), "getSubLabelForCommandId", command_id); string16 label; - mate::ConvertFromV8(node_isolate, result, &label); + mate::ConvertFromV8(isolate, result, &label); return label; } void Menu::ExecuteCommand(int command_id, int event_flags) { - v8::Locker locker(node_isolate); - v8::HandleScope handle_scope(node_isolate); - CallDelegate(v8::False(), GetWrapper(node_isolate), "executeCommand", - command_id); + v8::Isolate* isolate = v8::Isolate::GetCurrent(); + v8::Locker locker(isolate); + v8::HandleScope handle_scope(isolate); + CallDelegate(isolate, MATE_FALSE(isolate), GetWrapper(isolate), + "executeCommand", command_id); } void Menu::MenuWillShow(ui::SimpleMenuModel* source) { - v8::Locker locker(node_isolate); - v8::HandleScope handle_scope(node_isolate); - CallDelegate(v8::False(), GetWrapper(node_isolate), "menuWillShow", -1); + v8::Isolate* isolate = v8::Isolate::GetCurrent(); + v8::Locker locker(isolate); + v8::HandleScope handle_scope(isolate); + CallDelegate(isolate, MATE_FALSE(isolate), GetWrapper(isolate), + "menuWillShow", -1); } void Menu::InsertItemAt( diff --git a/atom/common/chrome_version.h b/atom/common/chrome_version.h index d0ebcb54..f6b1b8fe 100644 --- a/atom/common/chrome_version.h +++ b/atom/common/chrome_version.h @@ -1,14 +1,14 @@ -// Copyright (c) 2014 GitHub, Inc. All rights reserved. -// Use of this source code is governed by the MIT license that can be -// found in the LICENSE file. - -// This file is generated by script/bootstrap.py, you should never modify it -// by hand. - -#ifndef ATOM_COMMON_CHROME_VERSION_H_ -#define ATOM_COMMON_CHROME_VERSION_H_ - -#define CHROME_VERSION_STRING "31.0.1650.57" -#define CHROME_VERSION "v" CHROME_VERSION_STRING - -#endif // ATOM_COMMON_CHROME_VERSION_H_ +// Copyright (c) 2014 GitHub, Inc. All rights reserved. +// Use of this source code is governed by the MIT license that can be +// found in the LICENSE file. + +// This file is generated by script/bootstrap.py, you should never modify it +// by hand. + +#ifndef ATOM_COMMON_CHROME_VERSION_H_ +#define ATOM_COMMON_CHROME_VERSION_H_ + +#define CHROME_VERSION_STRING "35.0.1916.153" +#define CHROME_VERSION "v" CHROME_VERSION_STRING + +#endif // ATOM_COMMON_CHROME_VERSION_H_ diff --git a/atom/common/native_mate_converters/string16_converter.h b/atom/common/native_mate_converters/string16_converter.h index 172bed74..a171de5e 100644 --- a/atom/common/native_mate_converters/string16_converter.h +++ b/atom/common/native_mate_converters/string16_converter.h @@ -14,8 +14,8 @@ template<> struct Converter { static v8::Handle ToV8(v8::Isolate* isolate, const string16& val) { - return v8::String::New(reinterpret_cast(val.data()), - val.size()); + return MATE_STRING_NEW_FROM_UTF16( + isolate, reinterpret_cast(val.data()), val.size()); } static bool FromV8(v8::Isolate* isolate, v8::Handle val, diff --git a/atom/common/node_includes.h b/atom/common/node_includes.h index 9f544a12..680a211f 100644 --- a/atom/common/node_includes.h +++ b/atom/common/node_includes.h @@ -10,13 +10,17 @@ #undef CHECK #undef CHECK_EQ #undef CHECK_NE +#undef CHECK_GE +#undef CHECK_GT +#undef CHECK_LE +#undef CHECK_LT #undef DISALLOW_COPY_AND_ASSIGN +#undef debug_string // This is defined in OS X 10.9 SDK in AssertMacros.h. #include "vendor/node/src/env.h" #include "vendor/node/src/env-inl.h" #include "vendor/node/src/node.h" #include "vendor/node/src/node_buffer.h" #include "vendor/node/src/node_internals.h" -using node::node_isolate; namespace atom { // Defined in node_bindings.cc. diff --git a/vendor/native_mate b/vendor/native_mate index a5c4a2c7..c49cebac 160000 --- a/vendor/native_mate +++ b/vendor/native_mate @@ -1 +1 @@ -Subproject commit a5c4a2c7c64239ec5d007342f00f16f3981d6d80 +Subproject commit c49cebacb23149f82571b2ca691be7d9a345352c -- 2.43.0