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/public/browser/render_process_host.h"
#include "content/public/browser/render_view_host.h"
#include "gin/converter.h"
#include "native_mate/dictionary.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,
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();
if (render_view_host) {

View file

@ -359,7 +359,7 @@ void DestroyGlobalHandle(v8::Isolate* isolate,
if (!global_handle.IsEmpty()) {
v8::Local<v8::Value> local_handle = global_handle.Get(isolate);
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);
if (!ptr)
return;

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -277,8 +277,9 @@ v8::Local<v8::Context> RendererClientBase::GetContext(
return frame->MainWorldScriptContext();
}
v8::Local<v8::Value> RunScript(v8::Local<v8::Context> context,
v8::Local<v8::String> source) {
v8::Local<v8::Value> RendererClientBase::RunScript(
v8::Local<v8::Context> context,
v8::Local<v8::String> source) {
auto maybe_script = v8::Script::Compile(context, source);
v8::Local<v8::Script> 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::Isolate* isolate) const;
// 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);
protected: