Commit 37245cec authored by yukishiino's avatar yukishiino Committed by Commit bot

Revert of binding: Removes Document::wrap that must be equivalent to...

Revert of binding: Removes Document::wrap that must be equivalent to Node::wrap. (patchset #5 id:100001 of https://codereview.chromium.org/2525313004/ )

Reason for revert:
CHECK(!frame->document()->containsWrapper()); in WindowProxy::updateDocumentProperty() is causing crashes at several places.

Original issue's description:
> binding: Removes Document::wrap that must be equivalent to Node::wrap.
>
> Removes unnecessary Document::wrap and associateWithWrapper.
> The special code in these functions were made in order to keep
> WindowProxy::m_document updated and consistent with toV8(document).
> But we no longer rely on the hack, and we can remove the dead code.
>
> BUG=
>
> Committed: https://crrev.com/87dc599743f71d33466ac56a8db5a53c5f6ce46c
> Cr-Commit-Position: refs/heads/master@{#435226}

TBR=haraken@chromium.org
# Skipping CQ checks because original CL landed less than 1 days ago.
NOPRESUBMIT=true
NOTREECHECKS=true
NOTRY=true
BUG=669968

Review-Url: https://codereview.chromium.org/2538403002
Cr-Commit-Position: refs/heads/master@{#435565}
parent ebad851c
......@@ -33,7 +33,6 @@
#include "bindings/core/v8/ConditionalFeatures.h"
#include "bindings/core/v8/DOMWrapperWorld.h"
#include "bindings/core/v8/ScriptController.h"
#include "bindings/core/v8/ToV8.h"
#include "bindings/core/v8/V8Binding.h"
#include "bindings/core/v8/V8DOMActivityLogger.h"
#include "bindings/core/v8/V8Document.h"
......@@ -74,6 +73,11 @@
namespace blink {
static void checkDocumentWrapper(v8::Local<v8::Object> wrapper,
Document* document) {
ASSERT(V8Document::toImpl(wrapper) == document);
}
WindowProxy* WindowProxy::create(v8::Isolate* isolate,
Frame* frame,
DOMWrapperWorld& world) {
......@@ -420,24 +424,33 @@ bool WindowProxy::setupWindowPrototypeChain() {
return true;
}
void WindowProxy::updateDocumentWrapper(v8::Local<v8::Object> wrapper) {
ASSERT(m_world->isMainWorld());
m_document.set(m_isolate, wrapper);
}
void WindowProxy::updateDocumentProperty() {
DCHECK(m_world->isMainWorld());
if (!m_world->isMainWorld())
return;
if (m_frame->isRemoteFrame())
if (m_frame->isRemoteFrame()) {
return;
}
ScriptState::Scope scope(m_scriptState.get());
v8::Local<v8::Context> context = m_scriptState->context();
LocalFrame* frame = toLocalFrame(m_frame);
// In the main world, the window.document attribute must be set right after
// the initialization of the Window or right after the installation of a new
// document, thus this must be the first time of the wrapper instantiation of
// the document.
CHECK(!frame->document()->containsWrapper());
v8::Local<v8::Value> documentWrapper =
toV8(frame->document(), context->Global(), m_isolate);
DCHECK(documentWrapper->IsObject());
m_document.set(m_isolate, documentWrapper.As<v8::Object>());
toV8(frame->document(), context->Global(), context->GetIsolate());
if (documentWrapper.IsEmpty())
return;
ASSERT(documentWrapper == m_document.newLocal(m_isolate) ||
m_document.isEmpty());
if (m_document.isEmpty())
updateDocumentWrapper(v8::Local<v8::Object>::Cast(documentWrapper));
checkDocumentWrapper(m_document.newLocal(m_isolate), frame->document());
ASSERT(documentWrapper->IsObject());
// Update cached accessor.
CHECK(V8PrivateProperty::getWindowDocumentCachedAccessor(m_isolate).set(
......@@ -505,7 +518,7 @@ void WindowProxy::setSecurityToken(SecurityOrigin* origin) {
}
void WindowProxy::updateDocument() {
DCHECK(m_world->isMainWorld());
ASSERT(m_world->isMainWorld());
if (!isGlobalInitialized())
return;
if (!isContextInitialized())
......@@ -562,31 +575,24 @@ static void getter(v8::Local<v8::Name> property,
v8SetReturnValue(info, value);
}
void WindowProxy::checkDocumentWrapper(v8::Local<v8::Object> wrapper,
Document* document) const {
DCHECK(!wrapper.IsEmpty());
DCHECK_EQ(V8Document::toImpl(wrapper), document);
DCHECK(wrapper ==
toV8(document, m_globalProxy.newLocal(m_isolate), m_isolate));
}
void WindowProxy::namedItemAdded(HTMLDocument* document,
const AtomicString& name) {
DCHECK(m_world->isMainWorld());
ASSERT(m_world->isMainWorld());
if (!isContextInitialized() || !m_scriptState->contextIsValid())
return;
ScriptState::Scope scope(m_scriptState.get());
v8::Local<v8::Object> documentWrapper = m_document.newLocal(m_isolate);
checkDocumentWrapper(documentWrapper, document);
documentWrapper->SetAccessor(m_isolate->GetCurrentContext(),
v8String(m_isolate, name), getter);
ASSERT(!m_document.isEmpty());
v8::Local<v8::Context> context = m_scriptState->context();
v8::Local<v8::Object> documentHandle = m_document.newLocal(m_isolate);
checkDocumentWrapper(documentHandle, document);
documentHandle->SetAccessor(context, v8String(m_isolate, name), getter);
}
void WindowProxy::namedItemRemoved(HTMLDocument* document,
const AtomicString& name) {
DCHECK(m_world->isMainWorld());
ASSERT(m_world->isMainWorld());
if (!isContextInitialized())
return;
......@@ -595,10 +601,11 @@ void WindowProxy::namedItemRemoved(HTMLDocument* document,
return;
ScriptState::Scope scope(m_scriptState.get());
v8::Local<v8::Object> documentWrapper = m_document.newLocal(m_isolate);
checkDocumentWrapper(documentWrapper, document);
documentWrapper->Delete(m_isolate->GetCurrentContext(),
v8String(m_isolate, name));
ASSERT(!m_document.isEmpty());
v8::Local<v8::Object> documentHandle = m_document.newLocal(m_isolate);
checkDocumentWrapper(documentHandle, document);
documentHandle->Delete(m_isolate->GetCurrentContext(),
v8String(m_isolate, name));
}
void WindowProxy::updateSecurityOrigin(SecurityOrigin* origin) {
......
......@@ -44,7 +44,6 @@
namespace blink {
class Document;
class Frame;
class HTMLDocument;
class SecurityOrigin;
......@@ -117,8 +116,6 @@ class WindowProxy final : public GarbageCollectedFinalized<WindowProxy> {
// DOMWindow object. Also does some more Window-specific initialization.
bool setupWindowPrototypeChain();
void checkDocumentWrapper(v8::Local<v8::Object> wrapper, Document*) const;
Member<Frame> m_frame;
v8::Isolate* m_isolate;
RefPtr<ScriptState> m_scriptState;
......
......@@ -6345,6 +6345,38 @@ void Document::platformColorsChanged() {
styleEngine().platformColorsChanged();
}
v8::Local<v8::Object> Document::wrap(v8::Isolate* isolate,
v8::Local<v8::Object> creationContext) {
DCHECK(!DOMDataStore::containsWrapper(this, isolate));
const WrapperTypeInfo* wrapperType = wrapperTypeInfo();
if (frame() && frame()->script().initializeMainWorld()) {
// initializeMainWorld may have created a wrapper for the object, retry from
// the start.
v8::Local<v8::Object> wrapper = DOMDataStore::getWrapper(this, isolate);
if (!wrapper.IsEmpty())
return wrapper;
}
v8::Local<v8::Object> wrapper =
V8DOMWrapper::createWrapper(isolate, creationContext, wrapperType);
DCHECK(!wrapper.IsEmpty());
return associateWithWrapper(isolate, wrapperType, wrapper);
}
v8::Local<v8::Object> Document::associateWithWrapper(
v8::Isolate* isolate,
const WrapperTypeInfo* wrapperType,
v8::Local<v8::Object> wrapper) {
wrapper = V8DOMWrapper::associateObjectWithWrapper(isolate, this, wrapperType,
wrapper);
DOMWrapperWorld& world = DOMWrapperWorld::current(isolate);
if (world.isMainWorld() && frame())
frame()->script().windowProxy(world)->updateDocumentWrapper(wrapper);
return wrapper;
}
bool Document::isSecureContext(
String& errorMessage,
const SecureContextCheck privilegeContextCheck) const {
......
......@@ -1245,6 +1245,13 @@ class CORE_EXPORT Document : public ContainerNode,
DOMTimerCoordinator* timers() final;
v8::Local<v8::Object> wrap(v8::Isolate*,
v8::Local<v8::Object> creationContext) override;
WARN_UNUSED_RESULT v8::Local<v8::Object> associateWithWrapper(
v8::Isolate*,
const WrapperTypeInfo*,
v8::Local<v8::Object> wrapper) override;
HostsUsingFeatures::Value& HostsUsingFeaturesValue() {
return m_hostsUsingFeaturesValue;
}
......
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