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 64% |
copy from third_party/WebKit/Source/bindings/core/v8/WorkerScriptController.cpp |
copy to third_party/WebKit/Source/bindings/core/v8/GlobalScopeScriptController.cpp |
index 24f0e63375363b04af39b0a748c91bbe594c833a..bc283e3df0ae3364ef463bb46906eac7a7939322 100644 |
--- a/third_party/WebKit/Source/bindings/core/v8/WorkerScriptController.cpp |
+++ b/third_party/WebKit/Source/bindings/core/v8/GlobalScopeScriptController.cpp |
@@ -28,7 +28,7 @@ |
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
*/ |
-#include "bindings/core/v8/WorkerScriptController.h" |
+#include "bindings/core/v8/GlobalScopeScriptController.h" |
#include "bindings/core/v8/ScriptSourceCode.h" |
#include "bindings/core/v8/ScriptValue.h" |
@@ -45,31 +45,29 @@ |
#include "core/inspector/ScriptCallStack.h" |
#include "core/inspector/WorkerThreadDebugger.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::ExecutionState final { |
kinuko
2015/12/24 04:45:51
nit: this renaming change could be probably landed
|
STACK_ALLOCATED(); |
public: |
- explicit WorkerGlobalScopeExecutionState(WorkerScriptController* controller) |
+ explicit ExecutionState(GlobalScopeScriptController* controller) |
: hadException(false) |
, lineNumber(0) |
, columnNumber(0) |
, m_controller(controller) |
- , m_outerState(controller->m_globalScopeExecutionState) |
+ , m_outerState(controller->m_executionState) |
{ |
- m_controller->m_globalScopeExecutionState = this; |
+ m_controller->m_executionState = this; |
} |
- ~WorkerGlobalScopeExecutionState() |
+ ~ExecutionState() |
{ |
- m_controller->m_globalScopeExecutionState = m_outerState; |
+ m_controller->m_executionState = m_outerState; |
} |
DEFINE_INLINE_TRACE() |
@@ -86,43 +84,37 @@ public: |
ScriptValue exception; |
RefPtrWillBeMember<ErrorEvent> m_errorEventFromImportedScript; |
- // A WorkerGlobalScopeExecutionState context is stack allocated by |
- // WorkerScriptController::evaluate(), with the contoller using it |
+ // A ExecutionState context is stack allocated by |
+ // GlobalScopeScriptController::evaluate(), with the contoller using it |
// during script evaluation. To handle nested evaluate() uses, |
- // WorkerGlobalScopeExecutionStates are chained together; |
+ // ExecutionStates 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 |
- // and the previous one restored (see above dtor.) |
+ // GlobalScopeScriptController's ExecutionState 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; |
+ ExecutionState* 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) |
- , m_executionForbidden(false) |
+GlobalScopeScriptController::GlobalScopeScriptController(v8::Isolate* isolate) |
+ : m_executionForbidden(false) |
, m_executionScheduledToTerminate(false) |
, m_rejectedPromises(RejectedPromises::create()) |
- , m_globalScopeExecutionState(0) |
+ , m_executionState(0) |
{ |
ASSERT(isolate); |
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(); |
@@ -131,13 +123,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(); |
+ didStopRunLoop(); |
if (isContextInitialized()) |
m_scriptState->disposePerContextData(); |
} |
-bool WorkerScriptController::initializeContextIfNeeded() |
+bool GlobalScopeScriptController::initializeContextIfNeeded() |
{ |
v8::HandleScope handleScope(isolate()); |
@@ -156,29 +148,26 @@ 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> isolatedGlobalScopeConstructor = m_scriptState->perContextData()->constructorForType(wrapperTypeInfo); |
+ if (isolatedGlobalScopeConstructor.IsEmpty()) |
return false; |
- v8::Local<v8::Object> jsWorkerGlobalScope; |
- if (!V8ObjectConstructor::newInstance(isolate(), workerGlobalScopeConstructor).ToLocal(&jsWorkerGlobalScope)) { |
+ |
+ v8::Local<v8::Object> jsGlobalScope; |
+ if (!V8ObjectConstructor::newInstance(isolate(), isolatedGlobalScopeConstructor).ToLocal(&jsGlobalScope)) { |
m_scriptState->disposePerContextData(); |
return false; |
} |
- jsWorkerGlobalScope = V8DOMWrapper::associateObjectWithWrapper(isolate(), m_workerGlobalScope, wrapperTypeInfo, jsWorkerGlobalScope); |
+ jsGlobalScope = associateGlobalScopeWithWrapper(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)); |
-} |
- |
-v8::Isolate* WorkerScriptController::isolate() const |
-{ |
- return m_workerGlobalScope->thread()->isolate(); |
+ return v8CallBoolean(globalObject->SetPrototype(context, jsGlobalScope)); |
} |
-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(); |
@@ -196,7 +185,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 = runCompiledScript(compiledScript); |
if (!block.CanContinue()) { |
forbidExecution(); |
@@ -205,22 +194,22 @@ ScriptValue WorkerScriptController::evaluate(const String& script, const String& |
if (block.HasCaught()) { |
v8::Local<v8::Message> message = block.Message(); |
- m_globalScopeExecutionState->hadException = true; |
- m_globalScopeExecutionState->errorMessage = toCoreString(message->Get()); |
- if (v8Call(message->GetLineNumber(m_scriptState->context()), m_globalScopeExecutionState->lineNumber) |
- && v8Call(message->GetStartColumn(m_scriptState->context()), m_globalScopeExecutionState->columnNumber)) { |
- ++m_globalScopeExecutionState->columnNumber; |
+ m_executionState->hadException = true; |
+ m_executionState->errorMessage = toCoreString(message->Get()); |
+ if (v8Call(message->GetLineNumber(m_scriptState->context()), m_executionState->lineNumber) |
+ && v8Call(message->GetStartColumn(m_scriptState->context()), m_executionState->columnNumber)) { |
+ ++m_executionState->columnNumber; |
} else { |
- m_globalScopeExecutionState->lineNumber = 0; |
- m_globalScopeExecutionState->columnNumber = 0; |
+ m_executionState->lineNumber = 0; |
+ m_executionState->columnNumber = 0; |
} |
TOSTRING_DEFAULT(V8StringResource<>, sourceURL, message->GetScriptOrigin().ResourceName(), ScriptValue()); |
- m_globalScopeExecutionState->sourceURL = sourceURL; |
- m_globalScopeExecutionState->exception = ScriptValue(m_scriptState.get(), block.Exception()); |
+ m_executionState->sourceURL = sourceURL; |
+ m_executionState->exception = ScriptValue(m_scriptState.get(), block.Exception()); |
block.Reset(); |
} else { |
- m_globalScopeExecutionState->hadException = false; |
+ m_executionState->hadException = false; |
} |
v8::Local<v8::Value> result; |
@@ -230,12 +219,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); |
+ ExecutionState state(this); |
evaluate(sourceCode.source(), sourceCode.url().string(), sourceCode.startPosition(), cacheHandler, v8CacheOptions); |
if (isExecutionForbidden()) |
return false; |
@@ -246,26 +235,26 @@ bool WorkerScriptController::evaluate(const ScriptSourceCode& sourceCode, RefPtr |
*errorEvent = state.m_errorEventFromImportedScript.release(); |
return false; |
} |
- if (m_workerGlobalScope->shouldSanitizeScriptError(state.sourceURL, NotSharableCrossOrigin)) |
+ if (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(!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); |
+ 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 |
@@ -274,41 +263,40 @@ 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(isContextThread()); |
m_executionForbidden = true; |
} |
-bool WorkerScriptController::isExecutionForbidden() const |
+bool GlobalScopeScriptController::isExecutionForbidden() const |
{ |
- ASSERT(m_workerGlobalScope->isContextThread()); |
+ ASSERT(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) |
- m_globalScopeExecutionState->m_errorEventFromImportedScript = errorEvent; |
+ if (m_executionState) |
+ m_executionState->m_errorEventFromImportedScript = errorEvent; |
exceptionState.rethrowV8Exception(V8ThrowException::createGeneralError(isolate(), errorMessage)); |
} |
-DEFINE_TRACE(WorkerScriptController) |
+DEFINE_TRACE(GlobalScopeScriptController) |
{ |
- visitor->trace(m_workerGlobalScope); |
visitor->trace(m_rejectedPromises); |
} |