From e3d07c237045cae94fd106c6ea038499f89fc1c0 Mon Sep 17 00:00:00 2001 From: Ben Murdoch Date: Thu, 24 Mar 2016 15:59:32 +0000 Subject: Fixup libpac for V8 4.9.385.28 DO NOT MERGE. Change-Id: I6f9011826b2a170c60890bed1cced7182e8b0551 (cherry picked from commit 1c9888ab57e000ecde4446df364a8b6a09ee4aa3) Bug: 31987131 Bug: 29178923 --- Android.mk | 2 +- src/proxy_resolver_v8.cc | 24 +++++++++++++++++++++--- src/proxy_resolver_v8.h | 1 + 3 files changed, 23 insertions(+), 4 deletions(-) diff --git a/Android.mk b/Android.mk index d25755f..e8a2b26 100644 --- a/Android.mk +++ b/Android.mk @@ -23,7 +23,7 @@ LOCAL_C_INCLUDES += $(LOCAL_PATH)/src $(LOCAL_PATH)/../v8 LOCAL_STATIC_LIBRARIES := libv8 -LOCAL_SHARED_LIBRARIES := libutils liblog +LOCAL_SHARED_LIBRARIES := libutils liblog libicuuc libicui18n LOCAL_CXX_STL := libc++ diff --git a/src/proxy_resolver_v8.cc b/src/proxy_resolver_v8.cc index 533ef88..f978694 100644 --- a/src/proxy_resolver_v8.cc +++ b/src/proxy_resolver_v8.cc @@ -160,7 +160,7 @@ android::String16 V8StringToUTF16(v8::Handle s) { char16_t* buf = new char16_t[len + 1]; s->Write(reinterpret_cast(buf), 0, len); android::String16 ret(buf, len); - delete buf; + delete[] buf; return ret; } @@ -343,6 +343,17 @@ bool IsInNetEx(const std::string& ip_address, const std::string& ip_prefix) { } // namespace +class ArrayBufferAllocator : public v8::ArrayBuffer::Allocator { + public: + virtual void* Allocate(size_t length) { + void* data = AllocateUninitialized(length); + return data == NULL ? data : memset(data, 0, length); + } + virtual void* AllocateUninitialized(size_t length) { return malloc(length); } + virtual void Free(void* data, size_t) { free(data); } +}; + + // ProxyResolverV8::Context --------------------------------------------------- class ProxyResolverV8::Context { @@ -701,15 +712,18 @@ class ProxyResolverV8::Context { // ProxyResolverV8 ------------------------------------------------------------ +bool ProxyResolverV8::initialized_for_this_process_ = false; + ProxyResolverV8::ProxyResolverV8( ProxyResolverJSBindings* custom_js_bindings, ProxyErrorListener* error_listener) : context_(NULL), js_bindings_(custom_js_bindings), error_listener_(error_listener) { - if (v8::V8::GetCurrentPlatform() == NULL) { + if (!initialized_for_this_process_) { v8::Platform* platform = v8::platform::CreateDefaultPlatform(); v8::V8::InitializePlatform(platform); v8::V8::Initialize(); + initialized_for_this_process_ = true; } } @@ -749,7 +763,11 @@ int ProxyResolverV8::SetPacScript(const android::String16& script_data) { return ERR_PAC_SCRIPT_FAILED; // Try parsing the PAC script. - context_ = new Context(js_bindings_, error_listener_, v8::Isolate::New()); + ArrayBufferAllocator allocator; + v8::Isolate::CreateParams create_params; + create_params.array_buffer_allocator = &allocator; + + context_ = new Context(js_bindings_, error_listener_, v8::Isolate::New(create_params)); int rv; if ((rv = context_->InitV8(script_data)) != OK) { context_ = NULL; diff --git a/src/proxy_resolver_v8.h b/src/proxy_resolver_v8.h index 13a1bd8..9b74e29 100644 --- a/src/proxy_resolver_v8.h +++ b/src/proxy_resolver_v8.h @@ -71,6 +71,7 @@ class ProxyResolverV8 { ProxyResolverJSBindings* js_bindings_; ProxyErrorListener* error_listener_; + static bool initialized_for_this_process_; }; } // namespace net -- cgit v1.2.3