Index: third_party/WebKit/Source/bindings/core/v8/IsolatedScriptController.cpp |
diff --git a/third_party/WebKit/Source/bindings/core/v8/WorkerScriptController.cpp b/third_party/WebKit/Source/bindings/core/v8/IsolatedScriptController.cpp |
similarity index 71% |
rename from third_party/WebKit/Source/bindings/core/v8/WorkerScriptController.cpp |
rename to third_party/WebKit/Source/bindings/core/v8/IsolatedScriptController.cpp |
index 4f5668bf9bac4d8d91e89fcb6f4d67ec90a335e4..7c7c5fd12c886a9a3d4b9655e0a92da2040afdff 100644 |
--- a/third_party/WebKit/Source/bindings/core/v8/WorkerScriptController.cpp |
+++ b/third_party/WebKit/Source/bindings/core/v8/IsolatedScriptController.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/IsolatedScriptController.h" |
#include "bindings/core/v8/ScriptSourceCode.h" |
#include "bindings/core/v8/ScriptValue.h" |
@@ -54,10 +54,10 @@ |
namespace blink { |
-class WorkerScriptController::ExecutionState final { |
+class IsolatedScriptController::ExecutionState final { |
STACK_ALLOCATED(); |
public: |
- explicit ExecutionState(WorkerScriptController* controller) |
+ explicit ExecutionState(IsolatedScriptController* controller) |
: hadException(false) |
, lineNumber(0) |
, columnNumber(0) |
@@ -87,42 +87,45 @@ public: |
RefPtrWillBeMember<ErrorEvent> m_errorEventFromImportedScript; |
// A ExecutionState context is stack allocated by |
- // WorkerScriptController::evaluate(), with the contoller using it |
+ // IsolatedScriptController::evaluate(), with the contoller using it |
// during script evaluation. To handle nested evaluate() uses, |
// 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 ExecutionState is popped and the previous one |
- // restored (see above dtor.) |
+ // IsolatedScriptController'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; |
+ RawPtrWillBeMember<IsolatedScriptController> m_controller; |
ExecutionState* m_outerState; |
}; |
-PassOwnPtrWillBeRawPtr<WorkerScriptController> WorkerScriptController::create(WorkerGlobalScope* workerGlobalScope, v8::Isolate* isolate) |
+PassOwnPtrWillBeRawPtr<IsolatedScriptController> IsolatedScriptController::create(ExecutionContext* executionContext, ScriptWrappable* scriptWrappable, v8::Isolate* isolate) |
{ |
- return adoptPtrWillBeNoop(new WorkerScriptController(workerGlobalScope, isolate)); |
+ return adoptPtrWillBeNoop(new IsolatedScriptController(executionContext, scriptWrappable, isolate)); |
} |
-WorkerScriptController::WorkerScriptController(WorkerGlobalScope* workerGlobalScope, v8::Isolate* isolate) |
- : m_workerGlobalScope(workerGlobalScope) |
+IsolatedScriptController::IsolatedScriptController(ExecutionContext* executionContext, ScriptWrappable* scriptWrappable, v8::Isolate* isolate) |
+ : m_executionContext(executionContext) |
+ , m_scriptWrappable(scriptWrappable) |
+ , m_isolate(isolate) |
, m_executionForbidden(false) |
, m_executionScheduledToTerminate(false) |
, m_rejectedPromises(RejectedPromises::create()) |
, m_executionState(0) |
{ |
+ ASSERT(executionContext->isWorkerGlobalScope() || executionContext->isWorkletGlobalScope()); |
ASSERT(isolate); |
m_world = DOMWrapperWorld::create(isolate, WorkerWorldId); |
} |
-WorkerScriptController::~WorkerScriptController() |
+IsolatedScriptController::~IsolatedScriptController() |
{ |
ASSERT(!m_rejectedPromises); |
} |
-void WorkerScriptController::dispose() |
+void IsolatedScriptController::dispose() |
{ |
m_rejectedPromises->dispose(); |
m_rejectedPromises.release(); |
@@ -133,14 +136,14 @@ void WorkerScriptController::dispose() |
m_scriptState->disposePerContextData(); |
} |
-bool WorkerScriptController::initializeContextIfNeeded() |
+bool IsolatedScriptController::initializeContextIfNeeded() |
{ |
- v8::HandleScope handleScope(isolate()); |
+ v8::HandleScope handleScope(m_isolate); |
if (isContextInitialized()) |
return true; |
- v8::Local<v8::Context> context = v8::Context::New(isolate()); |
+ v8::Local<v8::Context> context = v8::Context::New(m_isolate); |
if (context.IsEmpty()) |
return false; |
@@ -152,29 +155,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 = m_scriptWrappable->wrapperTypeInfo(); |
+ |
+ 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(m_isolate, isolatedGlobalScopeConstructor).ToLocal(&jsGlobalScope)) { |
m_scriptState->disposePerContextData(); |
return false; |
} |
- jsWorkerGlobalScope = V8DOMWrapper::associateObjectWithWrapper(isolate(), m_workerGlobalScope, wrapperTypeInfo, jsWorkerGlobalScope); |
+ jsGlobalScope = V8DOMWrapper::associateObjectWithWrapper(m_isolate, m_scriptWrappable, 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 IsolatedScriptController::evaluate(const String& script, const String& fileName, const TextPosition& scriptStartPosition, CachedMetadataHandler* cacheHandler, V8CacheOptions v8CacheOptions) |
{ |
if (!initializeContextIfNeeded()) |
return ScriptValue(); |
@@ -183,16 +183,16 @@ ScriptValue WorkerScriptController::evaluate(const String& script, const String& |
if (!m_disableEvalPending.isEmpty()) { |
m_scriptState->context()->AllowCodeGenerationFromStrings(false); |
- m_scriptState->context()->SetErrorMessageForCodeGenerationFromStrings(v8String(isolate(), m_disableEvalPending)); |
+ m_scriptState->context()->SetErrorMessageForCodeGenerationFromStrings(v8String(m_isolate, m_disableEvalPending)); |
m_disableEvalPending = String(); |
} |
- v8::TryCatch block(isolate()); |
+ v8::TryCatch block(m_isolate); |
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); |
+ if (v8Call(V8ScriptRunner::compileScript(script, fileName, String(), scriptStartPosition, m_isolate, cacheHandler, SharableCrossOrigin, v8CacheOptions), compiledScript, block)) |
+ maybeResult = V8ScriptRunner::runCompiledScript(m_isolate, compiledScript, m_executionContext); |
if (!block.CanContinue()) { |
forbidExecution(); |
@@ -226,7 +226,7 @@ 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 IsolatedScriptController::evaluate(const ScriptSourceCode& sourceCode, RefPtrWillBeRawPtr<ErrorEvent>* errorEvent, CachedMetadataHandler* cacheHandler, V8CacheOptions v8CacheOptions) |
{ |
if (isExecutionForbidden()) |
return false; |
@@ -242,26 +242,26 @@ bool WorkerScriptController::evaluate(const ScriptSourceCode& sourceCode, RefPtr |
*errorEvent = state.m_errorEventFromImportedScript.release(); |
return false; |
} |
- if (m_workerGlobalScope->shouldSanitizeScriptError(state.sourceURL, NotSharableCrossOrigin)) |
+ if (m_executionContext->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_executionContext->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_executionContext->reportException(event, 0, nullptr, NotSharableCrossOrigin); |
} |
return false; |
} |
return true; |
} |
-void WorkerScriptController::willScheduleExecutionTermination() |
+void IsolatedScriptController::willScheduleExecutionTermination() |
{ |
// The mutex provides a memory barrier to ensure that once |
// termination is scheduled, isExecutionTerminating will |
@@ -270,41 +270,40 @@ void WorkerScriptController::willScheduleExecutionTermination() |
m_executionScheduledToTerminate = true; |
} |
-bool WorkerScriptController::isExecutionTerminating() const |
+bool IsolatedScriptController::isExecutionTerminating() const |
{ |
// See comments in willScheduleExecutionTermination regarding mutex usage. |
MutexLocker locker(m_scheduledTerminationMutex); |
return m_executionScheduledToTerminate; |
} |
-void WorkerScriptController::forbidExecution() |
+void IsolatedScriptController::forbidExecution() |
{ |
- ASSERT(m_workerGlobalScope->isContextThread()); |
+ ASSERT(m_executionContext->isContextThread()); |
m_executionForbidden = true; |
} |
-bool WorkerScriptController::isExecutionForbidden() const |
+bool IsolatedScriptController::isExecutionForbidden() const |
{ |
- ASSERT(m_workerGlobalScope->isContextThread()); |
+ ASSERT(m_executionContext->isContextThread()); |
return m_executionForbidden; |
} |
-void WorkerScriptController::disableEval(const String& errorMessage) |
+void IsolatedScriptController::disableEval(const String& errorMessage) |
{ |
m_disableEvalPending = errorMessage; |
} |
-void WorkerScriptController::rethrowExceptionFromImportedScript(PassRefPtrWillBeRawPtr<ErrorEvent> errorEvent, ExceptionState& exceptionState) |
+void IsolatedScriptController::rethrowExceptionFromImportedScript(PassRefPtrWillBeRawPtr<ErrorEvent> errorEvent, ExceptionState& exceptionState) |
{ |
const String& errorMessage = errorEvent->message(); |
if (m_executionState) |
m_executionState->m_errorEventFromImportedScript = errorEvent; |
- exceptionState.rethrowV8Exception(V8ThrowException::createGeneralError(isolate(), errorMessage)); |
+ exceptionState.rethrowV8Exception(V8ThrowException::createGeneralError(m_isolate, errorMessage)); |
} |
-DEFINE_TRACE(WorkerScriptController) |
+DEFINE_TRACE(IsolatedScriptController) |
{ |
- visitor->trace(m_workerGlobalScope); |
haraken
2016/01/05 06:08:06
You need to keep this code, otherwise the oilpan b
ikilpatrick
2016/01/07 22:47:34
Done.
|
visitor->trace(m_rejectedPromises); |
} |