From f4420b449f93854df371544b2de329c7ce3dc7ae Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Sun, 14 May 2017 19:25:07 +0900 Subject: [PATCH] Use v8::ArrayBuffer::Allocator inside Node --- atom/browser/javascript_environment.cc | 31 +---------- atom/browser/javascript_environment.h | 9 ---- atom/node/osfhandle.cc | 13 ----- atom/node/osfhandle.h | 6 --- atom/renderer/atom_renderer_client.cc | 2 - atom/renderer/node_array_buffer_bridge.cc | 66 ----------------------- atom/renderer/node_array_buffer_bridge.h | 15 ------ filenames.gypi | 2 - script/lib/config.py | 2 +- vendor/libchromiumcontent | 2 +- vendor/node | 2 +- 11 files changed, 5 insertions(+), 145 deletions(-) delete mode 100644 atom/renderer/node_array_buffer_bridge.cc delete mode 100644 atom/renderer/node_array_buffer_bridge.h diff --git a/atom/browser/javascript_environment.cc b/atom/browser/javascript_environment.cc index d13b95597..b7e3aae20 100644 --- a/atom/browser/javascript_environment.cc +++ b/atom/browser/javascript_environment.cc @@ -10,40 +10,13 @@ #include "base/message_loop/message_loop.h" #include "base/threading/thread_task_runner_handle.h" #include "content/public/common/content_switches.h" +#include "gin/array_buffer.h" #include "gin/v8_initializer.h" -#if defined(OS_WIN) -#include "atom/node/osfhandle.h" -#endif - #include "atom/common/node_includes.h" namespace atom { -void* ArrayBufferAllocator::Allocate(size_t length) { -#if defined(OS_WIN) - return node::ArrayBufferCalloc(length); -#else - return calloc(1, length); -#endif -} - -void* ArrayBufferAllocator::AllocateUninitialized(size_t length) { -#if defined(OS_WIN) - return node::ArrayBufferMalloc(length); -#else - return malloc(length); -#endif -} - -void ArrayBufferAllocator::Free(void* data, size_t length) { -#if defined(OS_WIN) - node::ArrayBufferFree(data, length); -#else - free(data); -#endif -} - JavascriptEnvironment::JavascriptEnvironment() : initialized_(Initialize()), isolate_holder_(base::ThreadTaskRunnerHandle::Get()), @@ -73,7 +46,7 @@ bool JavascriptEnvironment::Initialize() { gin::IsolateHolder::Initialize(gin::IsolateHolder::kNonStrictMode, gin::IsolateHolder::kStableV8Extras, - &allocator_); + gin::ArrayBufferAllocator::SharedInstance()); return true; } diff --git a/atom/browser/javascript_environment.h b/atom/browser/javascript_environment.h index 75d1629f6..43a7295f9 100644 --- a/atom/browser/javascript_environment.h +++ b/atom/browser/javascript_environment.h @@ -14,14 +14,6 @@ class Environment; namespace atom { -// ArrayBuffer's allocator, used on Chromium's side. -class ArrayBufferAllocator : public v8::ArrayBuffer::Allocator { - public: - void* Allocate(size_t length) override; - void* AllocateUninitialized(size_t length) override; - void Free(void* data, size_t length) override; -}; - // Manage the V8 isolate and context automatically. class JavascriptEnvironment { public: @@ -39,7 +31,6 @@ class JavascriptEnvironment { bool Initialize(); bool initialized_; - ArrayBufferAllocator allocator_; gin::IsolateHolder isolate_holder_; v8::Isolate* isolate_; v8::Isolate::Scope isolate_scope_; diff --git a/atom/node/osfhandle.cc b/atom/node/osfhandle.cc index f21f55a79..4d49d7227 100644 --- a/atom/node/osfhandle.cc +++ b/atom/node/osfhandle.cc @@ -27,7 +27,6 @@ #include "third_party/icu/source/i18n/unicode/uregex.h" #include "third_party/icu/source/i18n/unicode/uspoof.h" #include "third_party/icu/source/i18n/unicode/usearch.h" -#include "util-inl.h" #include "v8-profiler.h" #include "v8-inspector.h" @@ -41,18 +40,6 @@ int close(int fd) { return _close(fd); } -void* ArrayBufferCalloc(size_t length) { - return UncheckedCalloc(length); -} - -void* ArrayBufferMalloc(size_t length) { - return UncheckedMalloc(length); -} - -void ArrayBufferFree(void* data, size_t length) { - return ::free(data); -} - void ReferenceSymbols() { // Following symbols are used by electron.exe but got stripped by compiler, // by using the symbols we can force compiler to keep the objects in node.dll, diff --git a/atom/node/osfhandle.h b/atom/node/osfhandle.h index 58f87198a..1427bb895 100644 --- a/atom/node/osfhandle.h +++ b/atom/node/osfhandle.h @@ -21,12 +21,6 @@ namespace node { __declspec(dllexport) int open_osfhandle(intptr_t osfhandle, int flags); __declspec(dllexport) int close(int fd); -// Memory allocation functions from Node's module, used by ArrayBuffer allocator -// to make sure memories are allocated and freed with the same allocator. -__declspec(dllexport) void* ArrayBufferCalloc(size_t length); -__declspec(dllexport) void* ArrayBufferMalloc(size_t length); -__declspec(dllexport) void ArrayBufferFree(void* data, size_t length); - // A trick to force referencing symbols. __declspec(dllexport) void ReferenceSymbols(); diff --git a/atom/renderer/atom_renderer_client.cc b/atom/renderer/atom_renderer_client.cc index 393b86403..b03ec6c6f 100644 --- a/atom/renderer/atom_renderer_client.cc +++ b/atom/renderer/atom_renderer_client.cc @@ -16,7 +16,6 @@ #include "atom/renderer/api/atom_api_renderer_ipc.h" #include "atom/renderer/atom_render_frame_observer.h" #include "atom/renderer/atom_render_view_observer.h" -#include "atom/renderer/node_array_buffer_bridge.h" #include "atom/renderer/web_worker_observer.h" #include "base/command_line.h" #include "content/public/renderer/render_frame.h" @@ -51,7 +50,6 @@ AtomRendererClient::~AtomRendererClient() { } void AtomRendererClient::RenderThreadStarted() { - OverrideNodeArrayBuffer(); RendererClientBase::RenderThreadStarted(); } diff --git a/atom/renderer/node_array_buffer_bridge.cc b/atom/renderer/node_array_buffer_bridge.cc deleted file mode 100644 index 14e84d639..000000000 --- a/atom/renderer/node_array_buffer_bridge.cc +++ /dev/null @@ -1,66 +0,0 @@ -// Copyright (c) 2015 GitHub, Inc. -// Use of this source code is governed by the MIT license that can be -// found in the LICENSE file. - -#include "atom/renderer/node_array_buffer_bridge.h" - -#include "atom/common/node_includes.h" -#include "base/macros.h" -#include "native_mate/converter.h" -#include "third_party/WebKit/public/web/WebArrayBuffer.h" -#include "third_party/WebKit/public/web/WebArrayBufferConverter.h" - -namespace atom { - -namespace { - -// global.Uint8Array; -v8::Local GetUint8ArrayConstructor( - v8::Isolate* isolate, v8::Local context) { - v8::Local constructor = context->Global()->Get( - mate::StringToV8(isolate, "Uint8Array")); - return v8::Local::Cast(constructor); -} - -// new ArrayBuffer(size); -v8::Local BlinkArrayBufferNew( - v8::Isolate* isolate, size_t size) { - blink::WebArrayBuffer buffer = blink::WebArrayBuffer::create(size, 1); - return v8::Local::Cast( - blink::WebArrayBufferConverter::toV8Value( - &buffer, isolate->GetCurrentContext()->Global(), isolate)); -} - -// new ArrayBuffer(data, size); -v8::Local BlinkArrayBufferNewWith( - v8::Isolate* isolate, void* data, size_t size) { - blink::WebArrayBuffer buffer = blink::WebArrayBuffer::createExternal( - data, size); - return v8::Local::Cast( - blink::WebArrayBufferConverter::toV8Value( - &buffer, isolate->GetCurrentContext()->Global(), isolate)); -} - -// new Uint8Array(array_buffer, offset, size); -v8::Local BlinkUint8ArrayNew( - v8::Local ab, size_t offset, size_t size) { - // Use the DOM's Uint8Array constructor to create Uint8Array. - v8::Local context = ab->CreationContext(); - v8::Isolate* isolate = context->GetIsolate(); - v8::Local constructor = - GetUint8ArrayConstructor(isolate, context); - v8::Local args[] = { - ab, mate::ConvertToV8(isolate, offset), mate::ConvertToV8(isolate, size) - }; - return v8::Local::Cast(constructor->NewInstance( - context, node::arraysize(args), args).ToLocalChecked()); -} - -} // namespace - -void OverrideNodeArrayBuffer() { - node::Buffer::SetArrayBufferCreator( - BlinkArrayBufferNew, BlinkArrayBufferNewWith, BlinkUint8ArrayNew); -} - -} // namespace atom diff --git a/atom/renderer/node_array_buffer_bridge.h b/atom/renderer/node_array_buffer_bridge.h deleted file mode 100644 index 61d180699..000000000 --- a/atom/renderer/node_array_buffer_bridge.h +++ /dev/null @@ -1,15 +0,0 @@ -// Copyright (c) 2015 GitHub, Inc. -// Use of this source code is governed by the MIT license that can be -// found in the LICENSE file. - -#ifndef ATOM_RENDERER_NODE_ARRAY_BUFFER_BRIDGE_H_ -#define ATOM_RENDERER_NODE_ARRAY_BUFFER_BRIDGE_H_ - -namespace atom { - -// Override Node's ArrayBuffer with DOM's ArrayBuffer. -void OverrideNodeArrayBuffer(); - -} // namespace atom - -#endif // ATOM_RENDERER_NODE_ARRAY_BUFFER_BRIDGE_H_ diff --git a/filenames.gypi b/filenames.gypi index 570d20ab1..63b46cb40 100644 --- a/filenames.gypi +++ b/filenames.gypi @@ -491,8 +491,6 @@ 'atom/renderer/atom_sandboxed_renderer_client.h', 'atom/renderer/guest_view_container.cc', 'atom/renderer/guest_view_container.h', - 'atom/renderer/node_array_buffer_bridge.cc', - 'atom/renderer/node_array_buffer_bridge.h', 'atom/renderer/preferences_manager.cc', 'atom/renderer/preferences_manager.h', 'atom/renderer/renderer_client_base.cc', diff --git a/script/lib/config.py b/script/lib/config.py index 4a55bf1fb..330a14acc 100644 --- a/script/lib/config.py +++ b/script/lib/config.py @@ -9,7 +9,7 @@ import sys BASE_URL = os.getenv('LIBCHROMIUMCONTENT_MIRROR') or \ 'https://s3.amazonaws.com/github-janky-artifacts/libchromiumcontent' LIBCHROMIUMCONTENT_COMMIT = os.getenv('LIBCHROMIUMCONTENT_COMMIT') or \ - 'ecc5298428a02f8acb9af285c75e1491715ae4dd' + '549af32d00045c7b9dbb2760c090586c8d3a2638' PLATFORM = { 'cygwin': 'win32', diff --git a/vendor/libchromiumcontent b/vendor/libchromiumcontent index ecc529842..549af32d0 160000 --- a/vendor/libchromiumcontent +++ b/vendor/libchromiumcontent @@ -1 +1 @@ -Subproject commit ecc5298428a02f8acb9af285c75e1491715ae4dd +Subproject commit 549af32d00045c7b9dbb2760c090586c8d3a2638 diff --git a/vendor/node b/vendor/node index 3cdf4532c..dfa72e2c7 160000 --- a/vendor/node +++ b/vendor/node @@ -1 +1 @@ -Subproject commit 3cdf4532cf3da20af37e57cbbd59eb860be233aa +Subproject commit dfa72e2c73e0442d27746e0f8716d0427f7f9b27