Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(139)

Unified Diff: third_party/WebKit/Source/bindings/core/v8/V8Binding.cpp

Issue 2794023002: Move ScriptState::forWorld/ScriptState::forMainWorld (Part 1) (Closed)
Patch Set: Code review changes Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/Source/bindings/core/v8/V8Binding.cpp
diff --git a/third_party/WebKit/Source/bindings/core/v8/V8Binding.cpp b/third_party/WebKit/Source/bindings/core/v8/V8Binding.cpp
index 8c526ddc3e6488b4beabc536932930fe04babae6..57025848b7dc45285bef5145025ab70619dbdbbe 100644
--- a/third_party/WebKit/Source/bindings/core/v8/V8Binding.cpp
+++ b/third_party/WebKit/Source/bindings/core/v8/V8Binding.cpp
@@ -786,6 +786,20 @@ void toFlexibleArrayBufferView(v8::Isolate* isolate,
result.setSmall(storage, length);
}
+static ScriptState* toScriptStateImpl(LocalFrame* frame,
+ DOMWrapperWorld& world) {
+ if (!frame)
+ return nullptr;
+ v8::Local<v8::Context> context = toV8ContextEvenIfDetached(frame, world);
+ if (context.IsEmpty())
+ return nullptr;
+ ScriptState* scriptState = ScriptState::from(context);
+ if (!scriptState->contextIsValid())
+ return nullptr;
+ DCHECK_EQ(frame, toLocalFrameIfNotDetached(context));
+ return scriptState;
+}
+
v8::Local<v8::Context> toV8Context(ExecutionContext* context,
DOMWrapperWorld& world) {
ASSERT(context);
@@ -803,17 +817,10 @@ v8::Local<v8::Context> toV8Context(ExecutionContext* context,
}
v8::Local<v8::Context> toV8Context(LocalFrame* frame, DOMWrapperWorld& world) {
- if (!frame)
+ ScriptState* scriptState = toScriptStateImpl(frame, world);
+ if (!scriptState)
return v8::Local<v8::Context>();
- v8::Local<v8::Context> context = toV8ContextEvenIfDetached(frame, world);
- if (context.IsEmpty())
- return v8::Local<v8::Context>();
- ScriptState* scriptState = ScriptState::from(context);
- if (scriptState->contextIsValid()) {
- DCHECK_EQ(frame, toLocalFrameIfNotDetached(context));
- return scriptState->context();
- }
- return v8::Local<v8::Context>();
+ return scriptState->context();
}
v8::Local<v8::Context> toV8ContextEvenIfDetached(LocalFrame* frame,
@@ -822,6 +829,15 @@ v8::Local<v8::Context> toV8ContextEvenIfDetached(LocalFrame* frame,
return frame->windowProxy(world)->contextIfInitialized();
}
+ScriptState* toScriptState(LocalFrame* frame, DOMWrapperWorld& world) {
+ v8::HandleScope handleScope(toIsolate(frame));
+ return toScriptStateImpl(frame, world);
+}
+
+ScriptState* toScriptStateForMainWorld(LocalFrame* frame) {
+ return toScriptState(frame, DOMWrapperWorld::mainWorld());
+}
+
bool isValidEnum(const String& value,
const char** validValues,
size_t length,

Powered by Google App Engine
This is Rietveld 408576698