Commit 168be21d authored by yukishiino's avatar yukishiino Committed by Commit bot

binding: Changes the association among global-proxy/global/worker-instance.

Since V8 now supports internal fields for the global proxy objects,
let's change the mappings among global proxy object / global object /
C++ instance in Blink.

With this CL, a global proxy object and C++ instance point to each
other, and a global object points to the C++ instance (without
reverse pointer).

BUG=675872

Review-Url: https://codereview.chromium.org/2620493002
Cr-Commit-Position: refs/heads/master@{#443515}
parent 87a6ab34
......@@ -5,11 +5,9 @@
#include "bindings/core/v8/ToV8.h"
#include "bindings/core/v8/WindowProxy.h"
#include "bindings/core/v8/WorkerOrWorkletScriptController.h"
#include "core/events/EventTarget.h"
#include "core/frame/DOMWindow.h"
#include "core/frame/Frame.h"
#include "core/workers/WorkerOrWorkletGlobalScope.h"
namespace blink {
......@@ -42,22 +40,4 @@ v8::Local<v8::Value> ToV8(EventTarget* impl,
return ToV8(static_cast<ScriptWrappable*>(impl), creationContext, isolate);
}
v8::Local<v8::Value> ToV8(WorkerOrWorkletGlobalScope* impl,
v8::Local<v8::Object> creationContext,
v8::Isolate* isolate) {
// Notice that we explicitly ignore creationContext because the
// WorkerOrWorkletGlobalScope has its own creationContext.
if (UNLIKELY(!impl))
return v8::Null(isolate);
WorkerOrWorkletScriptController* scriptController = impl->scriptController();
if (!scriptController)
return v8::Null(isolate);
v8::Local<v8::Object> global = scriptController->context()->Global();
ASSERT(!global.IsEmpty());
return global;
}
} // namespace blink
......@@ -25,7 +25,6 @@ namespace blink {
class DOMWindow;
class Dictionary;
class EventTarget;
class WorkerOrWorkletGlobalScope;
// ScriptWrappable
......@@ -57,7 +56,7 @@ inline v8::Local<v8::Value> ToV8(Node* impl,
return wrapper;
}
// Special versions for DOMWindow, WorkerOrWorkletGlobalScope and EventTarget
// Special versions for DOMWindow and EventTarget
CORE_EXPORT v8::Local<v8::Value> ToV8(DOMWindow*,
v8::Local<v8::Object> creationContext,
......@@ -65,9 +64,6 @@ CORE_EXPORT v8::Local<v8::Value> ToV8(DOMWindow*,
CORE_EXPORT v8::Local<v8::Value> ToV8(EventTarget*,
v8::Local<v8::Object> creationContext,
v8::Isolate*);
v8::Local<v8::Value> ToV8(WorkerOrWorkletGlobalScope*,
v8::Local<v8::Object> creationContext,
v8::Isolate*);
// Primitives
......
......@@ -64,8 +64,6 @@ class Frame;
class LocalDOMWindow;
class LocalFrame;
class NodeFilter;
class WorkerGlobalScope;
class WorkerOrWorkletGlobalScope;
class XPathNSResolver;
template <typename T>
......@@ -204,7 +202,7 @@ inline void v8SetReturnValue(const CallbackInfo& callbackInfo, Node* impl) {
v8SetReturnValue(callbackInfo, wrapper);
}
// Special versions for DOMWindow, WorkerGlobalScope and EventTarget
// Special versions for DOMWindow and EventTarget
template <typename CallbackInfo>
inline void v8SetReturnValue(const CallbackInfo& callbackInfo,
......@@ -220,14 +218,6 @@ inline void v8SetReturnValue(const CallbackInfo& callbackInfo,
callbackInfo.GetIsolate()));
}
template <typename CallbackInfo>
inline void v8SetReturnValue(const CallbackInfo& callbackInfo,
WorkerGlobalScope* impl) {
v8SetReturnValue(callbackInfo,
ToV8((WorkerOrWorkletGlobalScope*)impl,
callbackInfo.Holder(), callbackInfo.GetIsolate()));
}
template <typename CallbackInfo, typename T>
inline void v8SetReturnValue(const CallbackInfo& callbackInfo,
PassRefPtr<T> impl) {
......@@ -274,7 +264,7 @@ inline void v8SetReturnValueForMainWorld(const CallbackInfo& callbackInfo,
v8SetReturnValueForMainWorld(callbackInfo, ScriptWrappable::fromNode(impl));
}
// Special versions for DOMWindow, WorkerGlobalScope and EventTarget
// Special versions for DOMWindow and EventTarget
template <typename CallbackInfo>
inline void v8SetReturnValueForMainWorld(const CallbackInfo& callbackInfo,
......@@ -290,14 +280,6 @@ inline void v8SetReturnValueForMainWorld(const CallbackInfo& callbackInfo,
callbackInfo.GetIsolate()));
}
template <typename CallbackInfo>
inline void v8SetReturnValueForMainWorld(const CallbackInfo& callbackInfo,
WorkerGlobalScope* impl) {
v8SetReturnValue(callbackInfo,
ToV8((WorkerOrWorkletGlobalScope*)impl,
callbackInfo.Holder(), callbackInfo.GetIsolate()));
}
template <typename CallbackInfo, typename T>
inline void v8SetReturnValueForMainWorld(const CallbackInfo& callbackInfo,
PassRefPtr<T> impl) {
......@@ -336,7 +318,7 @@ inline void v8SetReturnValueFast(const CallbackInfo& callbackInfo,
v8SetReturnValue(callbackInfo, wrapper);
}
// Special versions for DOMWindow, WorkerGlobalScope and EventTarget
// Special versions for DOMWindow and EventTarget
template <typename CallbackInfo>
inline void v8SetReturnValueFast(const CallbackInfo& callbackInfo,
......@@ -354,15 +336,6 @@ inline void v8SetReturnValueFast(const CallbackInfo& callbackInfo,
callbackInfo.GetIsolate()));
}
template <typename CallbackInfo>
inline void v8SetReturnValueFast(const CallbackInfo& callbackInfo,
WorkerGlobalScope* impl,
const ScriptWrappable*) {
v8SetReturnValue(callbackInfo,
ToV8((WorkerOrWorkletGlobalScope*)impl,
callbackInfo.Holder(), callbackInfo.GetIsolate()));
}
template <typename CallbackInfo, typename T, typename Wrappable>
inline void v8SetReturnValueFast(const CallbackInfo& callbackInfo,
PassRefPtr<T> impl,
......
......@@ -180,16 +180,43 @@ bool WorkerOrWorkletScriptController::initializeContextIfNeeded() {
ScriptState::Scope scope(m_scriptState.get());
// Associate the global proxy object, the global object and the worker
// instance (C++ object) as follows.
//
// global proxy object <====> worker or worklet instance
// ^
// |
// global object --------+
//
// Per HTML spec, there is no corresponding object for workers to WindowProxy.
// However, V8 always creates the global proxy object, we associate these
// objects in the same manner as WindowProxy and Window.
//
// a) worker or worklet instance --> global proxy object
// As we shouldn't expose the global object to author scripts, we map the
// worker or worklet instance to the global proxy object.
// b) global proxy object --> worker or worklet instance
// Blink's callback functions are called by V8 with the global proxy object,
// we need to map the global proxy object to the worker or worklet instance.
// c) global object --> worker or worklet instance
// The global proxy object is NOT considered as a wrapper object of the
// worker or worklet instance because it's not an instance of
// v8::FunctionTemplate of worker or worklet, especially note that
// v8::Object::FindInstanceInPrototypeChain skips the global proxy object.
// Thus we need to map the global object to the worker or worklet instance.
// The global proxy object. Note this is not the global object.
v8::Local<v8::Object> globalProxy = context->Global();
V8DOMWrapper::setNativeInfo(m_isolate, globalProxy, wrapperTypeInfo,
scriptWrappable);
v8::Local<v8::Object> associatedWrapper =
V8DOMWrapper::associateObjectWithWrapper(
m_isolate, scriptWrappable, wrapperTypeInfo, globalProxy);
CHECK(globalProxy == associatedWrapper);
// The global object, aka worker/worklet wrapper object.
v8::Local<v8::Object> globalObject =
globalProxy->GetPrototype().As<v8::Object>();
globalObject = V8DOMWrapper::associateObjectWithWrapper(
m_isolate, scriptWrappable, wrapperTypeInfo, globalObject);
V8DOMWrapper::setNativeInfo(m_isolate, globalObject, wrapperTypeInfo,
scriptWrappable);
// All interfaces must be registered to V8PerContextData.
// So we explicitly call constructorForType for the global object.
......
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