- Revision
- 135208
- Author
- [email protected]
- Date
- 2012-11-19 16:21:20 -0800 (Mon, 19 Nov 2012)
Log Message
[V8] Simplify V8DOMWindowShell::getEntered
https://bugs.webkit.org/show_bug.cgi?id=102156
Reviewed by Eric Seidel.
This patch is an incremental step towards merging
V8DOMWrapper::getCachedWrapper(Node*) with the general case for looking
up DOM wrappers. In order to merge with the general case, we need to
get down to calling v8::Context::GetCurrent once, which means we need
to factor the call to v8::Context::GetEntered out of V8DOMWindowShell.
As a side-benefit to this change, we can remove some redundant checks
for isolatedWorldsExist and v8::Context::InContext from callers of
V8DOMWindowShell::getEntered, including in getCachedWrapper.
* bindings/v8/DOMDataStore.cpp:
(WebCore::DOMDataStore::current):
* bindings/v8/ScriptController.cpp:
(WebCore::ScriptController::shouldBypassMainWorldContentSecurityPolicy):
(WebCore::ScriptController::currentWorldContext):
* bindings/v8/V8DOMWindowShell.h:
(WebCore::V8DOMWindowShell::isolated):
(WebCore::V8DOMWindowShell::perContextData):
(WebCore::V8DOMWindowShell::world):
(V8DOMWindowShell):
* bindings/v8/V8DOMWrapper.h:
(WebCore::V8DOMWrapper::getCachedWrapper):
* bindings/v8/WorldContextHandle.cpp:
(WebCore::WorldContextHandle::WorldContextHandle):
* bindings/v8/custom/V8DocumentCustom.cpp:
(WebCore::V8Document::dispatchWrapCustom):
* bindings/v8/custom/V8HTMLDocumentCustom.cpp:
(WebCore::V8HTMLDocument::dispatchWrapCustom):
* bindings/v8/custom/V8SVGDocumentCustom.cpp:
(WebCore::V8SVGDocument::dispatchWrapCustom):
* bindings/v8/custom/V8XMLHttpRequestConstructor.cpp:
(WebCore::V8XMLHttpRequest::constructorCallback):
Modified Paths
Diff
Modified: trunk/Source/WebCore/ChangeLog (135207 => 135208)
--- trunk/Source/WebCore/ChangeLog 2012-11-20 00:03:51 UTC (rev 135207)
+++ trunk/Source/WebCore/ChangeLog 2012-11-20 00:21:20 UTC (rev 135208)
@@ -1,3 +1,43 @@
+2012-11-19 Adam Barth <[email protected]>
+
+ [V8] Simplify V8DOMWindowShell::getEntered
+ https://bugs.webkit.org/show_bug.cgi?id=102156
+
+ Reviewed by Eric Seidel.
+
+ This patch is an incremental step towards merging
+ V8DOMWrapper::getCachedWrapper(Node*) with the general case for looking
+ up DOM wrappers. In order to merge with the general case, we need to
+ get down to calling v8::Context::GetCurrent once, which means we need
+ to factor the call to v8::Context::GetEntered out of V8DOMWindowShell.
+
+ As a side-benefit to this change, we can remove some redundant checks
+ for isolatedWorldsExist and v8::Context::InContext from callers of
+ V8DOMWindowShell::getEntered, including in getCachedWrapper.
+
+ * bindings/v8/DOMDataStore.cpp:
+ (WebCore::DOMDataStore::current):
+ * bindings/v8/ScriptController.cpp:
+ (WebCore::ScriptController::shouldBypassMainWorldContentSecurityPolicy):
+ (WebCore::ScriptController::currentWorldContext):
+ * bindings/v8/V8DOMWindowShell.h:
+ (WebCore::V8DOMWindowShell::isolated):
+ (WebCore::V8DOMWindowShell::perContextData):
+ (WebCore::V8DOMWindowShell::world):
+ (V8DOMWindowShell):
+ * bindings/v8/V8DOMWrapper.h:
+ (WebCore::V8DOMWrapper::getCachedWrapper):
+ * bindings/v8/WorldContextHandle.cpp:
+ (WebCore::WorldContextHandle::WorldContextHandle):
+ * bindings/v8/custom/V8DocumentCustom.cpp:
+ (WebCore::V8Document::dispatchWrapCustom):
+ * bindings/v8/custom/V8HTMLDocumentCustom.cpp:
+ (WebCore::V8HTMLDocument::dispatchWrapCustom):
+ * bindings/v8/custom/V8SVGDocumentCustom.cpp:
+ (WebCore::V8SVGDocument::dispatchWrapCustom):
+ * bindings/v8/custom/V8XMLHttpRequestConstructor.cpp:
+ (WebCore::V8XMLHttpRequest::constructorCallback):
+
2012-11-19 Kentaro Hara <[email protected]>
Rename idlDocument::classes to idlDocument::interfaces in the IDL parser
Modified: trunk/Source/WebCore/bindings/v8/DOMDataStore.cpp (135207 => 135208)
--- trunk/Source/WebCore/bindings/v8/DOMDataStore.cpp 2012-11-20 00:03:51 UTC (rev 135207)
+++ trunk/Source/WebCore/bindings/v8/DOMDataStore.cpp 2012-11-20 00:21:20 UTC (rev 135208)
@@ -57,9 +57,9 @@
V8PerIsolateData* data = "" ? V8PerIsolateData::from(isolate) : V8PerIsolateData::current();
if (UNLIKELY(!!data->domDataStore()))
return data->domDataStore();
- V8DOMWindowShell* context = V8DOMWindowShell::getEntered();
- if (UNLIKELY(!!context))
- return context->world()->isolatedWorldDOMDataStore();
+ V8DOMWindowShell* shell = V8DOMWindowShell::isolated(v8::Context::GetEntered());
+ if (UNLIKELY(!!shell))
+ return shell->world()->isolatedWorldDOMDataStore();
return &mainWorldDOMDataStore;
}
Modified: trunk/Source/WebCore/bindings/v8/ScriptController.cpp (135207 => 135208)
--- trunk/Source/WebCore/bindings/v8/ScriptController.cpp 2012-11-20 00:03:51 UTC (rev 135207)
+++ trunk/Source/WebCore/bindings/v8/ScriptController.cpp 2012-11-20 00:21:20 UTC (rev 135208)
@@ -423,8 +423,8 @@
bool ScriptController::shouldBypassMainWorldContentSecurityPolicy()
{
- if (V8DOMWindowShell* isolatedWorldShell = V8DOMWindowShell::getEntered())
- return isolatedWorldShell->world()->isolatedWorldHasContentSecurityPolicy();
+ if (DOMWrapperWorld* world = worldForEnteredContextIfIsolated())
+ return world->isolatedWorldHasContentSecurityPolicy();
return false;
}
@@ -442,11 +442,13 @@
v8::Local<v8::Context> ScriptController::currentWorldContext()
{
- if (V8DOMWindowShell* isolatedShell = V8DOMWindowShell::getEntered()) {
- v8::Persistent<v8::Context> context = isolatedShell->context();
- if (context.IsEmpty() || m_frame != toFrameIfNotDetached(context))
+ if (v8::Context::InContext()) {
+ v8::Handle<v8::Context> context = v8::Context::GetEntered();
+ if (V8DOMWindowShell::isolated(context)) {
+ if (m_frame == toFrameIfNotDetached(context))
+ return v8::Local<v8::Context>::New(context);
return v8::Local<v8::Context>();
- return v8::Local<v8::Context>::New(context);
+ }
}
return v8::Local<v8::Context>::New(windowShell(mainThreadNormalWorld())->context());
}
Modified: trunk/Source/WebCore/bindings/v8/V8Binding.h (135207 => 135208)
--- trunk/Source/WebCore/bindings/v8/V8Binding.h 2012-11-20 00:03:51 UTC (rev 135207)
+++ trunk/Source/WebCore/bindings/v8/V8Binding.h 2012-11-20 00:21:20 UTC (rev 135208)
@@ -379,6 +379,16 @@
// a context, if the window is currently being displayed in the Frame.
Frame* toFrameIfNotDetached(v8::Handle<v8::Context>);
+ inline DOMWrapperWorld* worldForEnteredContextIfIsolated()
+ {
+ if (!v8::Context::InContext())
+ return 0;
+ V8DOMWindowShell* shell = V8DOMWindowShell::isolated(v8::Context::GetEntered());
+ if (!shell)
+ return 0;
+ return shell->world();
+ }
+
// If the current context causes out of memory, _javascript_ setting
// is disabled and it returns true.
bool handleOutOfMemory();
Modified: trunk/Source/WebCore/bindings/v8/V8DOMWindowShell.h (135207 => 135208)
--- trunk/Source/WebCore/bindings/v8/V8DOMWindowShell.h 2012-11-20 00:03:51 UTC (rev 135207)
+++ trunk/Source/WebCore/bindings/v8/V8DOMWindowShell.h 2012-11-20 00:21:20 UTC (rev 135208)
@@ -80,29 +80,16 @@
void destroyGlobal();
- V8PerContextData* perContextData() { return m_perContextData.get(); }
-
- DOMWrapperWorld* world() { return m_world.get(); }
-
- // Returns the isolated world associated with
- // v8::Context::GetEntered(). Because worlds are isolated, the entire
- // _javascript_ call stack should be from the same isolated world.
- // Returns 0 if the entered context is from the main world.
- //
- // FIXME: Consider edge cases with DOM mutation events that might
- // violate this invariant.
- //
- // FIXME: This is poorly named after the deletion of isolated contexts.
- static V8DOMWindowShell* getEntered()
+ static V8DOMWindowShell* isolated(v8::Handle<v8::Context> context)
{
- if (!DOMWrapperWorld::isolatedWorldsExist())
- return 0;
- if (!v8::Context::InContext())
- return 0;
- return static_cast<V8DOMWindowShell*>(v8::Context::GetEntered()->GetAlignedPointerFromEmbedderData(v8ContextIsolatedWindowShell));
+ return static_cast<V8DOMWindowShell*>(context->GetAlignedPointerFromEmbedderData(v8ContextIsolatedWindowShell));
}
+ V8PerContextData* perContextData() { return m_perContextData.get(); }
+ DOMWrapperWorld* world() { return m_world.get(); }
+
void destroyIsolatedShell();
+
private:
V8DOMWindowShell(Frame*, PassRefPtr<DOMWrapperWorld>);
Modified: trunk/Source/WebCore/bindings/v8/V8DOMWrapper.h (135207 => 135208)
--- trunk/Source/WebCore/bindings/v8/V8DOMWrapper.h 2012-11-20 00:03:51 UTC (rev 135207)
+++ trunk/Source/WebCore/bindings/v8/V8DOMWrapper.h 2012-11-20 00:21:20 UTC (rev 135208)
@@ -115,14 +115,15 @@
static v8::Handle<v8::Object> getCachedWrapper(Node* node)
{
ASSERT(isMainThread());
- if (LIKELY(!DOMWrapperWorld::isolatedWorldsExist()))
+ if (LIKELY(!DOMWrapperWorld::isolatedWorldsExist()) || !v8::Context::InContext())
return node->wrapper();
- V8DOMWindowShell* context = V8DOMWindowShell::getEntered();
- if (LIKELY(!context))
+ v8::Handle<v8::Context> context = v8::Context::GetEntered();
+ V8DOMWindowShell* shell = V8DOMWindowShell::isolated(context);
+ if (LIKELY(!shell))
return node->wrapper();
- return context->world()->isolatedWorldDOMDataStore()->get(node);
+ return shell->world()->isolatedWorldDOMDataStore()->get(node);
}
private:
Modified: trunk/Source/WebCore/bindings/v8/WorldContextHandle.cpp (135207 => 135208)
--- trunk/Source/WebCore/bindings/v8/WorldContextHandle.cpp 2012-11-20 00:03:51 UTC (rev 135207)
+++ trunk/Source/WebCore/bindings/v8/WorldContextHandle.cpp 2012-11-20 00:21:20 UTC (rev 135208)
@@ -44,27 +44,21 @@
if (worldToUse == UseMainWorld || worldToUse == UseWorkerWorld)
return;
-#if ENABLE(WORKERS)
- // FIXME We are duplicating a lot of effort here checking the context for the worker and for the isolated world.
if (v8::Context::InContext()) {
v8::Handle<v8::Context> context = v8::Context::GetCurrent();
- if (!context.IsEmpty()) {
- if (UNLIKELY(!V8DOMWrapper::isWrapperOfType(toInnerGlobalObject(context), &V8DOMWindow::info))) {
- m_worldToUse = UseWorkerWorld;
- return;
- }
+#if ENABLE(WORKERS)
+ if (UNLIKELY(!V8DOMWrapper::isWrapperOfType(toInnerGlobalObject(context), &V8DOMWindow::info))) {
+ m_worldToUse = UseWorkerWorld;
+ return;
}
- }
#endif
-
- V8DOMWindowShell* shell = V8DOMWindowShell::getEntered();
- if (LIKELY(!shell)) {
- m_worldToUse = UseMainWorld;
- return;
+ if (V8DOMWindowShell::isolated(context)) {
+ m_context = SharedPersistent<v8::Context>::create(context);
+ return;
+ }
}
- ASSERT(!shell->context().IsEmpty());
- m_context = SharedPersistent<v8::Context>::create(shell->context());
+ m_worldToUse = UseMainWorld;
}
v8::Local<v8::Context> WorldContextHandle::adjustedContext(ScriptController* script) const
Modified: trunk/Source/WebCore/bindings/v8/custom/V8DocumentCustom.cpp (135207 => 135208)
--- trunk/Source/WebCore/bindings/v8/custom/V8DocumentCustom.cpp 2012-11-20 00:03:51 UTC (rev 135207)
+++ trunk/Source/WebCore/bindings/v8/custom/V8DocumentCustom.cpp 2012-11-20 00:21:20 UTC (rev 135208)
@@ -107,7 +107,7 @@
v8::Handle<v8::Object> wrapper = V8Document::createWrapper(impl, creationContext, isolate);
if (wrapper.IsEmpty())
return wrapper;
- if (!V8DOMWindowShell::getEntered()) {
+ if (!worldForEnteredContextIfIsolated()) {
if (Frame* frame = impl->frame())
frame->script()->windowShell(mainThreadNormalWorld())->updateDocumentWrapper(wrapper);
}
Modified: trunk/Source/WebCore/bindings/v8/custom/V8HTMLDocumentCustom.cpp (135207 => 135208)
--- trunk/Source/WebCore/bindings/v8/custom/V8HTMLDocumentCustom.cpp 2012-11-20 00:03:51 UTC (rev 135207)
+++ trunk/Source/WebCore/bindings/v8/custom/V8HTMLDocumentCustom.cpp 2012-11-20 00:21:20 UTC (rev 135208)
@@ -174,7 +174,7 @@
v8::Handle<v8::Object> wrapper = V8HTMLDocument::createWrapper(impl, creationContext, isolate);
if (wrapper.IsEmpty())
return wrapper;
- if (!V8DOMWindowShell::getEntered()) {
+ if (!worldForEnteredContextIfIsolated()) {
if (Frame* frame = impl->frame())
frame->script()->windowShell(mainThreadNormalWorld())->updateDocumentWrapper(wrapper);
}
Modified: trunk/Source/WebCore/bindings/v8/custom/V8SVGDocumentCustom.cpp (135207 => 135208)
--- trunk/Source/WebCore/bindings/v8/custom/V8SVGDocumentCustom.cpp 2012-11-20 00:03:51 UTC (rev 135207)
+++ trunk/Source/WebCore/bindings/v8/custom/V8SVGDocumentCustom.cpp 2012-11-20 00:21:20 UTC (rev 135208)
@@ -44,7 +44,7 @@
v8::Handle<v8::Object> wrapper = V8SVGDocument::createWrapper(impl, creationContext, isolate);
if (wrapper.IsEmpty())
return wrapper;
- if (!V8DOMWindowShell::getEntered()) {
+ if (!worldForEnteredContextIfIsolated()) {
if (Frame* frame = impl->frame())
frame->script()->windowShell(mainThreadNormalWorld())->updateDocumentWrapper(wrapper);
}
Modified: trunk/Source/WebCore/bindings/v8/custom/V8XMLHttpRequestConstructor.cpp (135207 => 135208)
--- trunk/Source/WebCore/bindings/v8/custom/V8XMLHttpRequestConstructor.cpp 2012-11-20 00:03:51 UTC (rev 135207)
+++ trunk/Source/WebCore/bindings/v8/custom/V8XMLHttpRequestConstructor.cpp 2012-11-20 00:21:20 UTC (rev 135208)
@@ -55,8 +55,10 @@
ScriptExecutionContext* context = getScriptExecutionContext();
RefPtr<SecurityOrigin> securityOrigin;
- if (V8DOMWindowShell* isolatedWorldShell = V8DOMWindowShell::getEntered())
- securityOrigin = isolatedWorldShell->world()->isolatedWorldSecurityOrigin();
+ if (context->isDocument()) {
+ if (DOMWrapperWorld* world = worldForEnteredContextIfIsolated())
+ securityOrigin = world->isolatedWorldSecurityOrigin();
+ }
RefPtr<XMLHttpRequest> xmlHttpRequest = XMLHttpRequest::create(context, securityOrigin);