Index: third_party/WebKit/Source/bindings/core/v8/GlobalScopeScriptController.cpp |
diff --git a/third_party/WebKit/Source/bindings/core/v8/WorkerScriptController.cpp b/third_party/WebKit/Source/bindings/core/v8/GlobalScopeScriptController.cpp |
similarity index 73% |
copy from third_party/WebKit/Source/bindings/core/v8/WorkerScriptController.cpp |
copy to third_party/WebKit/Source/bindings/core/v8/GlobalScopeScriptController.cpp |
index c8c4c4e037ce4d22ce49e5135f004d2bda5f80a4..8a01c0ac8a8e982d26ae035946c689f9932cdd29 100644 |
--- a/third_party/WebKit/Source/bindings/core/v8/WorkerScriptController.cpp |
+++ b/third_party/WebKit/Source/bindings/core/v8/GlobalScopeScriptController.cpp |
@@ -29,8 +29,7 @@ |
*/ |
#include "config.h" |
- |
-#include "bindings/core/v8/WorkerScriptController.h" |
+#include "bindings/core/v8/GlobalScopeScriptController.h" |
#include "bindings/core/v8/ScriptSourceCode.h" |
#include "bindings/core/v8/ScriptValue.h" |
@@ -46,20 +45,19 @@ |
#include "core/frame/DOMTimer.h" |
#include "core/inspector/ScriptCallStack.h" |
#include "core/inspector/WorkerThreadDebugger.h" |
+#include "core/workers/AbstractGlobalScope.h" |
#include "core/workers/SharedWorkerGlobalScope.h" |
-#include "core/workers/WorkerGlobalScope.h" |
#include "core/workers/WorkerObjectProxy.h" |
-#include "core/workers/WorkerThread.h" |
#include "platform/heap/ThreadState.h" |
#include "public/platform/Platform.h" |
#include <v8.h> |
namespace blink { |
-class WorkerScriptController::WorkerGlobalScopeExecutionState final { |
+class GlobalScopeScriptController::GlobalScopeExecutionState final { |
STACK_ALLOCATED(); |
public: |
- explicit WorkerGlobalScopeExecutionState(WorkerScriptController* controller) |
+ explicit GlobalScopeExecutionState(GlobalScopeScriptController* controller) |
: hadException(false) |
, lineNumber(0) |
, columnNumber(0) |
@@ -69,7 +67,7 @@ public: |
m_controller->m_globalScopeExecutionState = this; |
} |
- ~WorkerGlobalScopeExecutionState() |
+ ~GlobalScopeExecutionState() |
{ |
m_controller->m_globalScopeExecutionState = m_outerState; |
} |
@@ -88,28 +86,23 @@ public: |
ScriptValue exception; |
RefPtrWillBeMember<ErrorEvent> m_errorEventFromImportedScript; |
- // A WorkerGlobalScopeExecutionState context is stack allocated by |
- // WorkerScriptController::evaluate(), with the contoller using it |
+ // A GlobalScopeExecutionState context is stack allocated by |
+ // GlobalScopeScriptController::evaluate(), with the contoller using it |
// during script evaluation. To handle nested evaluate() uses, |
- // WorkerGlobalScopeExecutionStates are chained together; |
+ // GlobalScopeExecutionStates are chained together; |
// |m_outerState| keeps a pointer to the context object one level out |
// (or 0, if outermost.) Upon return from evaluate(), the |
- // WorkerScriptController's WorkerGlobalScopeExecutionState is popped |
+ // GlobalScopeScriptController's GlobalScopeExecutionState is popped |
// and the previous one restored (see above dtor.) |
// |
// With Oilpan, |m_outerState| isn't traced. It'll be "up the stack" |
// and its fields will be traced when scanning the stack. |
- RawPtrWillBeMember<WorkerScriptController> m_controller; |
- WorkerGlobalScopeExecutionState* m_outerState; |
+ RawPtrWillBeMember<GlobalScopeScriptController> m_controller; |
+ GlobalScopeExecutionState* m_outerState; |
}; |
-PassOwnPtrWillBeRawPtr<WorkerScriptController> WorkerScriptController::create(WorkerGlobalScope* workerGlobalScope, v8::Isolate* isolate) |
-{ |
- return adoptPtrWillBeNoop(new WorkerScriptController(workerGlobalScope, isolate)); |
-} |
- |
-WorkerScriptController::WorkerScriptController(WorkerGlobalScope* workerGlobalScope, v8::Isolate* isolate) |
- : m_workerGlobalScope(workerGlobalScope) |
+GlobalScopeScriptController::GlobalScopeScriptController(AbstractGlobalScope* abstractGlobalScope, v8::Isolate* isolate) |
+ : m_abstractGlobalScope(abstractGlobalScope) |
, m_executionForbidden(false) |
, m_executionScheduledToTerminate(false) |
, m_rejectedPromises(RejectedPromises::create()) |
@@ -119,12 +112,12 @@ WorkerScriptController::WorkerScriptController(WorkerGlobalScope* workerGlobalSc |
m_world = DOMWrapperWorld::create(isolate, WorkerWorldId); |
} |
-WorkerScriptController::~WorkerScriptController() |
+GlobalScopeScriptController::~GlobalScopeScriptController() |
{ |
ASSERT(!m_rejectedPromises); |
} |
-void WorkerScriptController::dispose() |
+void GlobalScopeScriptController::dispose() |
{ |
m_rejectedPromises->dispose(); |
m_rejectedPromises.release(); |
@@ -133,13 +126,13 @@ void WorkerScriptController::dispose() |
// The corresponding call to didStartRunLoop() is in WorkerThread::initialize(). |
// See http://webkit.org/b/83104#c14 for why this is here. |
- m_workerGlobalScope->thread()->didStopRunLoop(); |
+ m_abstractGlobalScope->didStopRunLoop(); |
if (isContextInitialized()) |
m_scriptState->disposePerContextData(); |
} |
-bool WorkerScriptController::initializeContextIfNeeded() |
+bool GlobalScopeScriptController::initializeContextIfNeeded() |
{ |
v8::HandleScope handleScope(isolate()); |
@@ -158,29 +151,31 @@ bool WorkerScriptController::initializeContextIfNeeded() |
WorkerThreadDebugger::setContextDebugData(context); |
// Create a new JS object and use it as the prototype for the shadow global object. |
- const WrapperTypeInfo* wrapperTypeInfo = m_workerGlobalScope->wrapperTypeInfo(); |
- v8::Local<v8::Function> workerGlobalScopeConstructor = m_scriptState->perContextData()->constructorForType(wrapperTypeInfo); |
- if (workerGlobalScopeConstructor.IsEmpty()) |
+ const WrapperTypeInfo* wrapperTypeInfo = wrapperTypeInfoForGlobalScope(); |
+ |
+ v8::Local<v8::Function> abstractGlobalScopeConstructor = m_scriptState->perContextData()->constructorForType(wrapperTypeInfo); |
+ if (abstractGlobalScopeConstructor.IsEmpty()) |
return false; |
- v8::Local<v8::Object> jsWorkerGlobalScope; |
- if (!V8ObjectConstructor::newInstance(isolate(), workerGlobalScopeConstructor).ToLocal(&jsWorkerGlobalScope)) { |
+ |
+ v8::Local<v8::Object> jsGlobalScope; |
+ if (!V8ObjectConstructor::newInstance(isolate(), abstractGlobalScopeConstructor).ToLocal(&jsGlobalScope)) { |
m_scriptState->disposePerContextData(); |
return false; |
} |
- jsWorkerGlobalScope = V8DOMWrapper::associateObjectWithWrapper(isolate(), m_workerGlobalScope, wrapperTypeInfo, jsWorkerGlobalScope); |
+ jsGlobalScope = associateGlobalScopeWithWrapper(isolate(), wrapperTypeInfo, jsGlobalScope); |
// Insert the object instance as the prototype of the shadow object. |
v8::Local<v8::Object> globalObject = v8::Local<v8::Object>::Cast(m_scriptState->context()->Global()->GetPrototype()); |
- return v8CallBoolean(globalObject->SetPrototype(context, jsWorkerGlobalScope)); |
+ return v8CallBoolean(globalObject->SetPrototype(context, jsGlobalScope)); |
} |
-v8::Isolate* WorkerScriptController::isolate() const |
+v8::Isolate* GlobalScopeScriptController::isolate() const |
{ |
- return m_workerGlobalScope->thread()->isolate(); |
+ return m_abstractGlobalScope->isolate(); |
} |
-ScriptValue WorkerScriptController::evaluate(const String& script, const String& fileName, const TextPosition& scriptStartPosition, CachedMetadataHandler* cacheHandler, V8CacheOptions v8CacheOptions) |
+ScriptValue GlobalScopeScriptController::evaluate(const String& script, const String& fileName, const TextPosition& scriptStartPosition, CachedMetadataHandler* cacheHandler, V8CacheOptions v8CacheOptions) |
{ |
if (!initializeContextIfNeeded()) |
return ScriptValue(); |
@@ -198,7 +193,7 @@ ScriptValue WorkerScriptController::evaluate(const String& script, const String& |
v8::Local<v8::Script> compiledScript; |
v8::MaybeLocal<v8::Value> maybeResult; |
if (v8Call(V8ScriptRunner::compileScript(script, fileName, String(), scriptStartPosition, isolate(), cacheHandler, SharableCrossOrigin, v8CacheOptions), compiledScript, block)) |
- maybeResult = V8ScriptRunner::runCompiledScript(isolate(), compiledScript, m_workerGlobalScope); |
+ maybeResult = V8ScriptRunner::runCompiledScript(isolate(), compiledScript, m_abstractGlobalScope); |
if (!block.CanContinue()) { |
forbidExecution(); |
@@ -232,12 +227,12 @@ ScriptValue WorkerScriptController::evaluate(const String& script, const String& |
return ScriptValue(m_scriptState.get(), result); |
} |
-bool WorkerScriptController::evaluate(const ScriptSourceCode& sourceCode, RefPtrWillBeRawPtr<ErrorEvent>* errorEvent, CachedMetadataHandler* cacheHandler, V8CacheOptions v8CacheOptions) |
+bool GlobalScopeScriptController::evaluate(const ScriptSourceCode& sourceCode, RefPtrWillBeRawPtr<ErrorEvent>* errorEvent, CachedMetadataHandler* cacheHandler, V8CacheOptions v8CacheOptions) |
{ |
if (isExecutionForbidden()) |
return false; |
- WorkerGlobalScopeExecutionState state(this); |
+ GlobalScopeExecutionState state(this); |
evaluate(sourceCode.source(), sourceCode.url().string(), sourceCode.startPosition(), cacheHandler, v8CacheOptions); |
if (isExecutionForbidden()) |
return false; |
@@ -248,26 +243,26 @@ bool WorkerScriptController::evaluate(const ScriptSourceCode& sourceCode, RefPtr |
*errorEvent = state.m_errorEventFromImportedScript.release(); |
return false; |
} |
- if (m_workerGlobalScope->shouldSanitizeScriptError(state.sourceURL, NotSharableCrossOrigin)) |
+ if (m_abstractGlobalScope->shouldSanitizeScriptError(state.sourceURL, NotSharableCrossOrigin)) |
*errorEvent = ErrorEvent::createSanitizedError(m_world.get()); |
else |
*errorEvent = ErrorEvent::create(state.errorMessage, state.sourceURL, state.lineNumber, state.columnNumber, m_world.get()); |
V8ErrorHandler::storeExceptionOnErrorEventWrapper(m_scriptState.get(), errorEvent->get(), state.exception.v8Value(), m_scriptState->context()->Global()); |
} else { |
- ASSERT(!m_workerGlobalScope->shouldSanitizeScriptError(state.sourceURL, NotSharableCrossOrigin)); |
+ ASSERT(!m_abstractGlobalScope->shouldSanitizeScriptError(state.sourceURL, NotSharableCrossOrigin)); |
RefPtrWillBeRawPtr<ErrorEvent> event = nullptr; |
if (state.m_errorEventFromImportedScript) |
event = state.m_errorEventFromImportedScript.release(); |
else |
event = ErrorEvent::create(state.errorMessage, state.sourceURL, state.lineNumber, state.columnNumber, m_world.get()); |
- m_workerGlobalScope->reportException(event, 0, nullptr, NotSharableCrossOrigin); |
+ m_abstractGlobalScope->reportException(event, 0, nullptr, NotSharableCrossOrigin); |
} |
return false; |
} |
return true; |
} |
-void WorkerScriptController::willScheduleExecutionTermination() |
+void GlobalScopeScriptController::willScheduleExecutionTermination() |
{ |
// The mutex provides a memory barrier to ensure that once |
// termination is scheduled, isExecutionTerminating will |
@@ -276,31 +271,31 @@ void WorkerScriptController::willScheduleExecutionTermination() |
m_executionScheduledToTerminate = true; |
} |
-bool WorkerScriptController::isExecutionTerminating() const |
+bool GlobalScopeScriptController::isExecutionTerminating() const |
{ |
// See comments in willScheduleExecutionTermination regarding mutex usage. |
MutexLocker locker(m_scheduledTerminationMutex); |
return m_executionScheduledToTerminate; |
} |
-void WorkerScriptController::forbidExecution() |
+void GlobalScopeScriptController::forbidExecution() |
{ |
- ASSERT(m_workerGlobalScope->isContextThread()); |
+ ASSERT(m_abstractGlobalScope->isContextThread()); |
m_executionForbidden = true; |
} |
-bool WorkerScriptController::isExecutionForbidden() const |
+bool GlobalScopeScriptController::isExecutionForbidden() const |
{ |
- ASSERT(m_workerGlobalScope->isContextThread()); |
+ ASSERT(m_abstractGlobalScope->isContextThread()); |
return m_executionForbidden; |
} |
-void WorkerScriptController::disableEval(const String& errorMessage) |
+void GlobalScopeScriptController::disableEval(const String& errorMessage) |
{ |
m_disableEvalPending = errorMessage; |
} |
-void WorkerScriptController::rethrowExceptionFromImportedScript(PassRefPtrWillBeRawPtr<ErrorEvent> errorEvent, ExceptionState& exceptionState) |
+void GlobalScopeScriptController::rethrowExceptionFromImportedScript(PassRefPtrWillBeRawPtr<ErrorEvent> errorEvent, ExceptionState& exceptionState) |
{ |
const String& errorMessage = errorEvent->message(); |
if (m_globalScopeExecutionState) |
@@ -308,9 +303,9 @@ void WorkerScriptController::rethrowExceptionFromImportedScript(PassRefPtrWillBe |
exceptionState.rethrowV8Exception(V8ThrowException::createGeneralError(isolate(), errorMessage)); |
} |
-DEFINE_TRACE(WorkerScriptController) |
+DEFINE_TRACE(GlobalScopeScriptController) |
{ |
- visitor->trace(m_workerGlobalScope); |
+ visitor->trace(m_abstractGlobalScope); |
visitor->trace(m_rejectedPromises); |
} |