Commit 38b6a765 authored by Clemens Hammacher's avatar Clemens Hammacher Committed by Commit Bot

Pass v8::Extension objects via unique_ptr

The raw-pointer API will be deprecated soon. Switch all uses in chrome
to the new API expecting a unique_ptr.

R=adamk@chromium.org, jochen@chromium.org

Bug: v8:8725
Change-Id: If08fc3b655b5bc2c2bf3d81bd5788a98385e3568
Reviewed-on: https://chromium-review.googlesource.com/c/1447652Reviewed-by: default avatarJochen Eisinger <jochen@chromium.org>
Commit-Queue: Clemens Hammacher <clemensh@chromium.org>
Cr-Commit-Position: refs/heads/master@{#629127}
parent 1a783b68
...@@ -79,8 +79,8 @@ class BenchmarkingWrapper : public v8::Extension { ...@@ -79,8 +79,8 @@ class BenchmarkingWrapper : public v8::Extension {
} }
}; };
v8::Extension* BenchmarkingExtension::Get() { std::unique_ptr<v8::Extension> BenchmarkingExtension::Get() {
return new BenchmarkingWrapper(); return std::make_unique<BenchmarkingWrapper>();
} }
} // namespace extensions_v8 } // namespace extensions_v8
...@@ -5,6 +5,8 @@ ...@@ -5,6 +5,8 @@
#ifndef CHROME_RENDERER_BENCHMARKING_EXTENSION_H_ #ifndef CHROME_RENDERER_BENCHMARKING_EXTENSION_H_
#define CHROME_RENDERER_BENCHMARKING_EXTENSION_H_ #define CHROME_RENDERER_BENCHMARKING_EXTENSION_H_
#include <memory>
namespace v8 { namespace v8 {
class Extension; class Extension;
} }
...@@ -16,7 +18,7 @@ namespace extensions_v8 { ...@@ -16,7 +18,7 @@ namespace extensions_v8 {
// name is to distinguish it from the built-in V8 Profiler. // name is to distinguish it from the built-in V8 Profiler.
class BenchmarkingExtension { class BenchmarkingExtension {
public: public:
static v8::Extension* Get(); static std::unique_ptr<v8::Extension> Get();
}; };
} // namespace extensions_v8 } // namespace extensions_v8
......
...@@ -404,8 +404,8 @@ class LoadTimesExtensionWrapper : public v8::Extension { ...@@ -404,8 +404,8 @@ class LoadTimesExtensionWrapper : public v8::Extension {
} }
}; };
v8::Extension* LoadTimesExtension::Get() { std::unique_ptr<v8::Extension> LoadTimesExtension::Get() {
return new LoadTimesExtensionWrapper(); return std::make_unique<LoadTimesExtensionWrapper>();
} }
} // namespace extensions_v8 } // namespace extensions_v8
...@@ -8,6 +8,8 @@ ...@@ -8,6 +8,8 @@
#ifndef CHROME_RENDERER_LOADTIMES_EXTENSION_BINDINGS_H_ #ifndef CHROME_RENDERER_LOADTIMES_EXTENSION_BINDINGS_H_
#define CHROME_RENDERER_LOADTIMES_EXTENSION_BINDINGS_H_ #define CHROME_RENDERER_LOADTIMES_EXTENSION_BINDINGS_H_
#include <memory>
namespace v8 { namespace v8 {
class Extension; class Extension;
} }
...@@ -16,7 +18,7 @@ namespace extensions_v8 { ...@@ -16,7 +18,7 @@ namespace extensions_v8 {
class LoadTimesExtension { class LoadTimesExtension {
public: public:
static v8::Extension* Get(); static std::unique_ptr<v8::Extension> Get();
}; };
} // namespace extensions_v8 } // namespace extensions_v8
......
...@@ -108,8 +108,8 @@ class NetBenchmarkingWrapper : public v8::Extension { ...@@ -108,8 +108,8 @@ class NetBenchmarkingWrapper : public v8::Extension {
} }
}; };
v8::Extension* NetBenchmarkingExtension::Get() { std::unique_ptr<v8::Extension> NetBenchmarkingExtension::Get() {
return new NetBenchmarkingWrapper(); return std::make_unique<NetBenchmarkingWrapper>();
} }
} // namespace extensions_v8 } // namespace extensions_v8
...@@ -5,6 +5,8 @@ ...@@ -5,6 +5,8 @@
#ifndef CHROME_RENDERER_NET_BENCHMARKING_EXTENSION_H_ #ifndef CHROME_RENDERER_NET_BENCHMARKING_EXTENSION_H_
#define CHROME_RENDERER_NET_BENCHMARKING_EXTENSION_H_ #define CHROME_RENDERER_NET_BENCHMARKING_EXTENSION_H_
#include <memory>
namespace v8 { namespace v8 {
class Extension; class Extension;
} }
...@@ -13,7 +15,7 @@ namespace extensions_v8 { ...@@ -13,7 +15,7 @@ namespace extensions_v8 {
class NetBenchmarkingExtension { class NetBenchmarkingExtension {
public: public:
static v8::Extension* Get(); static std::unique_ptr<v8::Extension> Get();
}; };
} // namespace extensions_v8 } // namespace extensions_v8
......
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
#include <stddef.h> #include <stddef.h>
#include <stdint.h> #include <stdint.h>
#include <memory>
#include "base/callback.h" #include "base/callback.h"
#include "base/memory/shared_memory.h" #include "base/memory/shared_memory.h"
...@@ -81,7 +82,7 @@ class CONTENT_EXPORT RenderThread : virtual public ChildThread { ...@@ -81,7 +82,7 @@ class CONTENT_EXPORT RenderThread : virtual public ChildThread {
size_t buffer_size) = 0; size_t buffer_size) = 0;
// Registers the given V8 extension with WebKit. // Registers the given V8 extension with WebKit.
virtual void RegisterExtension(v8::Extension* extension) = 0; virtual void RegisterExtension(std::unique_ptr<v8::Extension> extension) = 0;
// Post task to all worker threads. Returns number of workers. // Post task to all worker threads. Returns number of workers.
virtual int PostTaskToAllWebWorkers(const base::Closure& closure) = 0; virtual int PostTaskToAllWebWorkers(const base::Closure& closure) = 0;
......
...@@ -4,6 +4,8 @@ ...@@ -4,6 +4,8 @@
#include "content/public/test/mock_render_thread.h" #include "content/public/test/mock_render_thread.h"
#include <memory>
#include "base/logging.h" #include "base/logging.h"
#include "base/single_thread_task_runner.h" #include "base/single_thread_task_runner.h"
#include "base/threading/thread_task_runner_handle.h" #include "base/threading/thread_task_runner_handle.h"
...@@ -197,8 +199,9 @@ MockRenderThread::HostAllocateSharedMemoryBuffer(size_t buffer_size) { ...@@ -197,8 +199,9 @@ MockRenderThread::HostAllocateSharedMemoryBuffer(size_t buffer_size) {
return std::unique_ptr<base::SharedMemory>(shared_buf.release()); return std::unique_ptr<base::SharedMemory>(shared_buf.release());
} }
void MockRenderThread::RegisterExtension(v8::Extension* extension) { void MockRenderThread::RegisterExtension(
blink::WebScriptController::RegisterExtension(extension); std::unique_ptr<v8::Extension> extension) {
blink::WebScriptController::RegisterExtension(std::move(extension));
} }
int MockRenderThread::PostTaskToAllWebWorkers(const base::Closure& closure) { int MockRenderThread::PostTaskToAllWebWorkers(const base::Closure& closure) {
......
...@@ -72,7 +72,7 @@ class MockRenderThread : public RenderThread { ...@@ -72,7 +72,7 @@ class MockRenderThread : public RenderThread {
void RecordComputedAction(const std::string& action) override; void RecordComputedAction(const std::string& action) override;
std::unique_ptr<base::SharedMemory> HostAllocateSharedMemoryBuffer( std::unique_ptr<base::SharedMemory> HostAllocateSharedMemoryBuffer(
size_t buffer_size) override; size_t buffer_size) override;
void RegisterExtension(v8::Extension* extension) override; void RegisterExtension(std::unique_ptr<v8::Extension> extension) override;
int PostTaskToAllWebWorkers(const base::Closure& closure) override; int PostTaskToAllWebWorkers(const base::Closure& closure) override;
bool ResolveProxy(const GURL& url, std::string* proxy_list) override; bool ResolveProxy(const GURL& url, std::string* proxy_list) override;
base::WaitableEvent* GetShutdownEvent() override; base::WaitableEvent* GetShutdownEvent() override;
......
...@@ -1276,8 +1276,9 @@ RenderThreadImpl::HostAllocateSharedMemoryBuffer(size_t size) { ...@@ -1276,8 +1276,9 @@ RenderThreadImpl::HostAllocateSharedMemoryBuffer(size_t size) {
return ChildThreadImpl::AllocateSharedMemory(size); return ChildThreadImpl::AllocateSharedMemory(size);
} }
void RenderThreadImpl::RegisterExtension(v8::Extension* extension) { void RenderThreadImpl::RegisterExtension(
WebScriptController::RegisterExtension(extension); std::unique_ptr<v8::Extension> extension) {
WebScriptController::RegisterExtension(std::move(extension));
} }
int RenderThreadImpl::PostTaskToAllWebWorkers(const base::Closure& closure) { int RenderThreadImpl::PostTaskToAllWebWorkers(const base::Closure& closure) {
......
...@@ -204,7 +204,7 @@ class CONTENT_EXPORT RenderThreadImpl ...@@ -204,7 +204,7 @@ class CONTENT_EXPORT RenderThreadImpl
ResourceDispatcherDelegate* delegate) override; ResourceDispatcherDelegate* delegate) override;
std::unique_ptr<base::SharedMemory> HostAllocateSharedMemoryBuffer( std::unique_ptr<base::SharedMemory> HostAllocateSharedMemoryBuffer(
size_t buffer_size) override; size_t buffer_size) override;
void RegisterExtension(v8::Extension* extension) override; void RegisterExtension(std::unique_ptr<v8::Extension> extension) override;
int PostTaskToAllWebWorkers(const base::Closure& closure) override; int PostTaskToAllWebWorkers(const base::Closure& closure) override;
bool ResolveProxy(const GURL& url, std::string* proxy_list) override; bool ResolveProxy(const GURL& url, std::string* proxy_list) override;
base::WaitableEvent* GetShutdownEvent() override; base::WaitableEvent* GetShutdownEvent() override;
......
...@@ -223,7 +223,9 @@ class ExtensionImpl : public v8::Extension { ...@@ -223,7 +223,9 @@ class ExtensionImpl : public v8::Extension {
} // namespace } // namespace
// static // static
v8::Extension* SafeBuiltins::CreateV8Extension() { return new ExtensionImpl(); } std::unique_ptr<v8::Extension> SafeBuiltins::CreateV8Extension() {
return std::make_unique<ExtensionImpl>();
}
SafeBuiltins::SafeBuiltins(ScriptContext* context) : context_(context) {} SafeBuiltins::SafeBuiltins(ScriptContext* context) : context_(context) {}
......
...@@ -5,6 +5,8 @@ ...@@ -5,6 +5,8 @@
#ifndef EXTENSIONS_RENDERER_SAFE_BUILTINS_H_ #ifndef EXTENSIONS_RENDERER_SAFE_BUILTINS_H_
#define EXTENSIONS_RENDERER_SAFE_BUILTINS_H_ #define EXTENSIONS_RENDERER_SAFE_BUILTINS_H_
#include <memory>
#include "base/macros.h" #include "base/macros.h"
#include "v8/include/v8.h" #include "v8/include/v8.h"
...@@ -16,7 +18,7 @@ class ScriptContext; ...@@ -16,7 +18,7 @@ class ScriptContext;
class SafeBuiltins { class SafeBuiltins {
public: public:
// Creates the v8::Extension which manages SafeBuiltins instances. // Creates the v8::Extension which manages SafeBuiltins instances.
static v8::Extension* CreateV8Extension(); static std::unique_ptr<v8::Extension> CreateV8Extension();
explicit SafeBuiltins(ScriptContext* context); explicit SafeBuiltins(ScriptContext* context);
~SafeBuiltins(); ~SafeBuiltins();
......
...@@ -4,6 +4,9 @@ ...@@ -4,6 +4,9 @@
#include "extensions/renderer/test_v8_extension_configuration.h" #include "extensions/renderer/test_v8_extension_configuration.h"
#include <memory>
#include <utility>
#include "base/lazy_instance.h" #include "base/lazy_instance.h"
#include "extensions/renderer/safe_builtins.h" #include "extensions/renderer/safe_builtins.h"
#include "v8/include/v8.h" #include "v8/include/v8.h"
...@@ -18,12 +21,11 @@ base::LazyInstance<TestV8ExtensionConfiguration>::Leaky ...@@ -18,12 +21,11 @@ base::LazyInstance<TestV8ExtensionConfiguration>::Leaky
} // namespace } // namespace
TestV8ExtensionConfiguration::TestV8ExtensionConfiguration() TestV8ExtensionConfiguration::TestV8ExtensionConfiguration()
: safe_builtins_(SafeBuiltins::CreateV8Extension()), : v8_extension_configuration_(
v8_extension_names_(1, safe_builtins_->name()), new v8::ExtensionConfiguration(1, &v8_extension_name_)) {
v8_extension_configuration_(new v8::ExtensionConfiguration( auto safe_builtins = SafeBuiltins::CreateV8Extension();
static_cast<int>(v8_extension_names_.size()), v8_extension_name_ = safe_builtins->name();
v8_extension_names_.data())) { v8::RegisterExtension(std::move(safe_builtins));
v8::RegisterExtension(safe_builtins_.get());
} }
TestV8ExtensionConfiguration::~TestV8ExtensionConfiguration() {} TestV8ExtensionConfiguration::~TestV8ExtensionConfiguration() {}
......
...@@ -27,8 +27,7 @@ class TestV8ExtensionConfiguration { ...@@ -27,8 +27,7 @@ class TestV8ExtensionConfiguration {
static v8::ExtensionConfiguration* GetConfiguration(); static v8::ExtensionConfiguration* GetConfiguration();
private: private:
std::unique_ptr<v8::Extension> safe_builtins_; const char* v8_extension_name_;
std::vector<const char*> v8_extension_names_;
std::unique_ptr<v8::ExtensionConfiguration> v8_extension_configuration_; std::unique_ptr<v8::ExtensionConfiguration> v8_extension_configuration_;
DISALLOW_COPY_AND_ASSIGN(TestV8ExtensionConfiguration); DISALLOW_COPY_AND_ASSIGN(TestV8ExtensionConfiguration);
......
...@@ -31,6 +31,8 @@ ...@@ -31,6 +31,8 @@
#ifndef THIRD_PARTY_BLINK_PUBLIC_WEB_WEB_SCRIPT_CONTROLLER_H_ #ifndef THIRD_PARTY_BLINK_PUBLIC_WEB_WEB_SCRIPT_CONTROLLER_H_
#define THIRD_PARTY_BLINK_PUBLIC_WEB_WEB_SCRIPT_CONTROLLER_H_ #define THIRD_PARTY_BLINK_PUBLIC_WEB_WEB_SCRIPT_CONTROLLER_H_
#include <memory>
#include "third_party/blink/public/platform/web_common.h" #include "third_party/blink/public/platform/web_common.h"
namespace v8 { namespace v8 {
...@@ -42,9 +44,8 @@ namespace blink { ...@@ -42,9 +44,8 @@ namespace blink {
class WebScriptController { class WebScriptController {
public: public:
// Registers a v8 extension to be available on webpages. Will only affect // Registers a v8 extension to be available on webpages. Will only affect
// v8 contexts initialized after this call. Takes ownership of the // v8 contexts initialized after this call.
// v8::Extension object passed. BLINK_EXPORT static void RegisterExtension(std::unique_ptr<v8::Extension>);
BLINK_EXPORT static void RegisterExtension(v8::Extension*);
private: private:
WebScriptController() = delete; WebScriptController() = delete;
......
...@@ -32,6 +32,9 @@ ...@@ -32,6 +32,9 @@
#include "third_party/blink/renderer/bindings/core/v8/script_controller.h" #include "third_party/blink/renderer/bindings/core/v8/script_controller.h"
#include <memory>
#include <utility>
#include "third_party/blink/public/web/web_settings.h" #include "third_party/blink/public/web/web_settings.h"
#include "third_party/blink/renderer/bindings/core/v8/referrer_script_info.h" #include "third_party/blink/renderer/bindings/core/v8/referrer_script_info.h"
#include "third_party/blink/renderer/bindings/core/v8/script_source_code.h" #include "third_party/blink/renderer/bindings/core/v8/script_source_code.h"
...@@ -181,13 +184,14 @@ Vector<const char*>& RegisteredExtensionNames() { ...@@ -181,13 +184,14 @@ Vector<const char*>& RegisteredExtensionNames() {
} // namespace } // namespace
void ScriptController::RegisterExtensionIfNeeded(v8::Extension* extension) { void ScriptController::RegisterExtensionIfNeeded(
std::unique_ptr<v8::Extension> extension) {
for (const auto* extension_name : RegisteredExtensionNames()) { for (const auto* extension_name : RegisteredExtensionNames()) {
if (!strcmp(extension_name, extension->name())) if (!strcmp(extension_name, extension->name()))
return; return;
} }
RegisteredExtensionNames().push_back(extension->name()); RegisteredExtensionNames().push_back(extension->name());
v8::RegisterExtension(extension); v8::RegisterExtension(std::move(extension));
} }
v8::ExtensionConfiguration ScriptController::ExtensionsFor( v8::ExtensionConfiguration ScriptController::ExtensionsFor(
......
...@@ -31,6 +31,8 @@ ...@@ -31,6 +31,8 @@
#ifndef THIRD_PARTY_BLINK_RENDERER_BINDINGS_CORE_V8_SCRIPT_CONTROLLER_H_ #ifndef THIRD_PARTY_BLINK_RENDERER_BINDINGS_CORE_V8_SCRIPT_CONTROLLER_H_
#define THIRD_PARTY_BLINK_RENDERER_BINDINGS_CORE_V8_SCRIPT_CONTROLLER_H_ #define THIRD_PARTY_BLINK_RENDERER_BINDINGS_CORE_V8_SCRIPT_CONTROLLER_H_
#include <memory>
#include "third_party/blink/renderer/bindings/core/v8/sanitize_script_errors.h" #include "third_party/blink/renderer/bindings/core/v8/sanitize_script_errors.h"
#include "third_party/blink/renderer/bindings/core/v8/script_source_location_type.h" #include "third_party/blink/renderer/bindings/core/v8/script_source_location_type.h"
#include "third_party/blink/renderer/bindings/core/v8/window_proxy_manager.h" #include "third_party/blink/renderer/bindings/core/v8/window_proxy_manager.h"
...@@ -144,9 +146,8 @@ class CORE_EXPORT ScriptController final ...@@ -144,9 +146,8 @@ class CORE_EXPORT ScriptController final
void ClearForClose(); void ClearForClose();
// Registers a v8 extension to be available on webpages. Will only // Registers a v8 extension to be available on webpages. Will only
// affect v8 contexts initialized after this call. Takes ownership of // affect v8 contexts initialized after this call.
// the v8::Extension object passed. static void RegisterExtensionIfNeeded(std::unique_ptr<v8::Extension>);
static void RegisterExtensionIfNeeded(v8::Extension*);
static v8::ExtensionConfiguration ExtensionsFor(const ExecutionContext*); static v8::ExtensionConfiguration ExtensionsFor(const ExecutionContext*);
private: private:
......
...@@ -34,8 +34,9 @@ ...@@ -34,8 +34,9 @@
namespace blink { namespace blink {
void WebScriptController::RegisterExtension(v8::Extension* extension) { void WebScriptController::RegisterExtension(
ScriptController::RegisterExtensionIfNeeded(extension); std::unique_ptr<v8::Extension> extension) {
ScriptController::RegisterExtensionIfNeeded(std::move(extension));
} }
} // namespace blink } // namespace blink
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment