| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2009, 2012 Google Inc. All rights reserved. | 2 * Copyright (C) 2009, 2012 Google Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
| 6 * met: | 6 * met: |
| 7 * | 7 * |
| 8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
| (...skipping 11 matching lines...) Expand all Loading... |
| 22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | 22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | 23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 29 */ | 29 */ |
| 30 | 30 |
| 31 #include "config.h" | 31 #include "config.h" |
| 32 | 32 #include "bindings/core/v8/GlobalScopeScriptController.h" |
| 33 #include "bindings/core/v8/WorkerScriptController.h" | |
| 34 | 33 |
| 35 #include "bindings/core/v8/ScriptSourceCode.h" | 34 #include "bindings/core/v8/ScriptSourceCode.h" |
| 36 #include "bindings/core/v8/ScriptValue.h" | 35 #include "bindings/core/v8/ScriptValue.h" |
| 37 #include "bindings/core/v8/V8DedicatedWorkerGlobalScope.h" | 36 #include "bindings/core/v8/V8DedicatedWorkerGlobalScope.h" |
| 38 #include "bindings/core/v8/V8ErrorHandler.h" | 37 #include "bindings/core/v8/V8ErrorHandler.h" |
| 39 #include "bindings/core/v8/V8Initializer.h" | 38 #include "bindings/core/v8/V8Initializer.h" |
| 40 #include "bindings/core/v8/V8ObjectConstructor.h" | 39 #include "bindings/core/v8/V8ObjectConstructor.h" |
| 41 #include "bindings/core/v8/V8ScriptRunner.h" | 40 #include "bindings/core/v8/V8ScriptRunner.h" |
| 42 #include "bindings/core/v8/V8SharedWorkerGlobalScope.h" | 41 #include "bindings/core/v8/V8SharedWorkerGlobalScope.h" |
| 43 #include "bindings/core/v8/V8WorkerGlobalScope.h" | 42 #include "bindings/core/v8/V8WorkerGlobalScope.h" |
| 44 #include "bindings/core/v8/WrapperTypeInfo.h" | 43 #include "bindings/core/v8/WrapperTypeInfo.h" |
| 45 #include "core/events/ErrorEvent.h" | 44 #include "core/events/ErrorEvent.h" |
| 46 #include "core/frame/DOMTimer.h" | 45 #include "core/frame/DOMTimer.h" |
| 47 #include "core/inspector/ScriptCallStack.h" | 46 #include "core/inspector/ScriptCallStack.h" |
| 48 #include "core/inspector/WorkerThreadDebugger.h" | 47 #include "core/inspector/WorkerThreadDebugger.h" |
| 48 #include "core/workers/AbstractGlobalScope.h" |
| 49 #include "core/workers/SharedWorkerGlobalScope.h" | 49 #include "core/workers/SharedWorkerGlobalScope.h" |
| 50 #include "core/workers/WorkerGlobalScope.h" | |
| 51 #include "core/workers/WorkerObjectProxy.h" | 50 #include "core/workers/WorkerObjectProxy.h" |
| 52 #include "core/workers/WorkerThread.h" | |
| 53 #include "platform/heap/ThreadState.h" | 51 #include "platform/heap/ThreadState.h" |
| 54 #include "public/platform/Platform.h" | 52 #include "public/platform/Platform.h" |
| 55 #include <v8.h> | 53 #include <v8.h> |
| 56 | 54 |
| 57 namespace blink { | 55 namespace blink { |
| 58 | 56 |
| 59 class WorkerScriptController::WorkerGlobalScopeExecutionState final { | 57 class GlobalScopeScriptController::GlobalScopeExecutionState final { |
| 60 STACK_ALLOCATED(); | 58 STACK_ALLOCATED(); |
| 61 public: | 59 public: |
| 62 explicit WorkerGlobalScopeExecutionState(WorkerScriptController* controller) | 60 explicit GlobalScopeExecutionState(GlobalScopeScriptController* controller) |
| 63 : hadException(false) | 61 : hadException(false) |
| 64 , lineNumber(0) | 62 , lineNumber(0) |
| 65 , columnNumber(0) | 63 , columnNumber(0) |
| 66 , m_controller(controller) | 64 , m_controller(controller) |
| 67 , m_outerState(controller->m_globalScopeExecutionState) | 65 , m_outerState(controller->m_globalScopeExecutionState) |
| 68 { | 66 { |
| 69 m_controller->m_globalScopeExecutionState = this; | 67 m_controller->m_globalScopeExecutionState = this; |
| 70 } | 68 } |
| 71 | 69 |
| 72 ~WorkerGlobalScopeExecutionState() | 70 ~GlobalScopeExecutionState() |
| 73 { | 71 { |
| 74 m_controller->m_globalScopeExecutionState = m_outerState; | 72 m_controller->m_globalScopeExecutionState = m_outerState; |
| 75 } | 73 } |
| 76 | 74 |
| 77 DEFINE_INLINE_TRACE() | 75 DEFINE_INLINE_TRACE() |
| 78 { | 76 { |
| 79 visitor->trace(m_errorEventFromImportedScript); | 77 visitor->trace(m_errorEventFromImportedScript); |
| 80 visitor->trace(m_controller); | 78 visitor->trace(m_controller); |
| 81 } | 79 } |
| 82 | 80 |
| 83 bool hadException; | 81 bool hadException; |
| 84 String errorMessage; | 82 String errorMessage; |
| 85 int lineNumber; | 83 int lineNumber; |
| 86 int columnNumber; | 84 int columnNumber; |
| 87 String sourceURL; | 85 String sourceURL; |
| 88 ScriptValue exception; | 86 ScriptValue exception; |
| 89 RefPtrWillBeMember<ErrorEvent> m_errorEventFromImportedScript; | 87 RefPtrWillBeMember<ErrorEvent> m_errorEventFromImportedScript; |
| 90 | 88 |
| 91 // A WorkerGlobalScopeExecutionState context is stack allocated by | 89 // A GlobalScopeExecutionState context is stack allocated by |
| 92 // WorkerScriptController::evaluate(), with the contoller using it | 90 // GlobalScopeScriptController::evaluate(), with the contoller using it |
| 93 // during script evaluation. To handle nested evaluate() uses, | 91 // during script evaluation. To handle nested evaluate() uses, |
| 94 // WorkerGlobalScopeExecutionStates are chained together; | 92 // GlobalScopeExecutionStates are chained together; |
| 95 // |m_outerState| keeps a pointer to the context object one level out | 93 // |m_outerState| keeps a pointer to the context object one level out |
| 96 // (or 0, if outermost.) Upon return from evaluate(), the | 94 // (or 0, if outermost.) Upon return from evaluate(), the |
| 97 // WorkerScriptController's WorkerGlobalScopeExecutionState is popped | 95 // GlobalScopeScriptController's GlobalScopeExecutionState is popped |
| 98 // and the previous one restored (see above dtor.) | 96 // and the previous one restored (see above dtor.) |
| 99 // | 97 // |
| 100 // With Oilpan, |m_outerState| isn't traced. It'll be "up the stack" | 98 // With Oilpan, |m_outerState| isn't traced. It'll be "up the stack" |
| 101 // and its fields will be traced when scanning the stack. | 99 // and its fields will be traced when scanning the stack. |
| 102 RawPtrWillBeMember<WorkerScriptController> m_controller; | 100 RawPtrWillBeMember<GlobalScopeScriptController> m_controller; |
| 103 WorkerGlobalScopeExecutionState* m_outerState; | 101 GlobalScopeExecutionState* m_outerState; |
| 104 }; | 102 }; |
| 105 | 103 |
| 106 PassOwnPtrWillBeRawPtr<WorkerScriptController> WorkerScriptController::create(Wo
rkerGlobalScope* workerGlobalScope, v8::Isolate* isolate) | 104 GlobalScopeScriptController::GlobalScopeScriptController(AbstractGlobalScope* ab
stractGlobalScope, v8::Isolate* isolate) |
| 107 { | 105 : m_abstractGlobalScope(abstractGlobalScope) |
| 108 return adoptPtrWillBeNoop(new WorkerScriptController(workerGlobalScope, isol
ate)); | |
| 109 } | |
| 110 | |
| 111 WorkerScriptController::WorkerScriptController(WorkerGlobalScope* workerGlobalSc
ope, v8::Isolate* isolate) | |
| 112 : m_workerGlobalScope(workerGlobalScope) | |
| 113 , m_executionForbidden(false) | 106 , m_executionForbidden(false) |
| 114 , m_executionScheduledToTerminate(false) | 107 , m_executionScheduledToTerminate(false) |
| 115 , m_rejectedPromises(RejectedPromises::create()) | 108 , m_rejectedPromises(RejectedPromises::create()) |
| 116 , m_globalScopeExecutionState(0) | 109 , m_globalScopeExecutionState(0) |
| 117 { | 110 { |
| 118 ASSERT(isolate); | 111 ASSERT(isolate); |
| 119 m_world = DOMWrapperWorld::create(isolate, WorkerWorldId); | 112 m_world = DOMWrapperWorld::create(isolate, WorkerWorldId); |
| 120 } | 113 } |
| 121 | 114 |
| 122 WorkerScriptController::~WorkerScriptController() | 115 GlobalScopeScriptController::~GlobalScopeScriptController() |
| 123 { | 116 { |
| 124 ASSERT(!m_rejectedPromises); | 117 ASSERT(!m_rejectedPromises); |
| 125 } | 118 } |
| 126 | 119 |
| 127 void WorkerScriptController::dispose() | 120 void GlobalScopeScriptController::dispose() |
| 128 { | 121 { |
| 129 m_rejectedPromises->dispose(); | 122 m_rejectedPromises->dispose(); |
| 130 m_rejectedPromises.release(); | 123 m_rejectedPromises.release(); |
| 131 | 124 |
| 132 m_world->dispose(); | 125 m_world->dispose(); |
| 133 | 126 |
| 134 // The corresponding call to didStartRunLoop() is in WorkerThread::initializ
e(). | 127 // The corresponding call to didStartRunLoop() is in WorkerThread::initializ
e(). |
| 135 // See http://webkit.org/b/83104#c14 for why this is here. | 128 // See http://webkit.org/b/83104#c14 for why this is here. |
| 136 m_workerGlobalScope->thread()->didStopRunLoop(); | 129 m_abstractGlobalScope->didStopRunLoop(); |
| 137 | 130 |
| 138 if (isContextInitialized()) | 131 if (isContextInitialized()) |
| 139 m_scriptState->disposePerContextData(); | 132 m_scriptState->disposePerContextData(); |
| 140 } | 133 } |
| 141 | 134 |
| 142 bool WorkerScriptController::initializeContextIfNeeded() | 135 bool GlobalScopeScriptController::initializeContextIfNeeded() |
| 143 { | 136 { |
| 144 v8::HandleScope handleScope(isolate()); | 137 v8::HandleScope handleScope(isolate()); |
| 145 | 138 |
| 146 if (isContextInitialized()) | 139 if (isContextInitialized()) |
| 147 return true; | 140 return true; |
| 148 | 141 |
| 149 v8::Local<v8::Context> context = v8::Context::New(isolate()); | 142 v8::Local<v8::Context> context = v8::Context::New(isolate()); |
| 150 if (context.IsEmpty()) | 143 if (context.IsEmpty()) |
| 151 return false; | 144 return false; |
| 152 | 145 |
| 153 m_scriptState = ScriptState::create(context, m_world); | 146 m_scriptState = ScriptState::create(context, m_world); |
| 154 | 147 |
| 155 ScriptState::Scope scope(m_scriptState.get()); | 148 ScriptState::Scope scope(m_scriptState.get()); |
| 156 | 149 |
| 157 // Name new context for debugging. | 150 // Name new context for debugging. |
| 158 WorkerThreadDebugger::setContextDebugData(context); | 151 WorkerThreadDebugger::setContextDebugData(context); |
| 159 | 152 |
| 160 // Create a new JS object and use it as the prototype for the shadow global
object. | 153 // Create a new JS object and use it as the prototype for the shadow global
object. |
| 161 const WrapperTypeInfo* wrapperTypeInfo = m_workerGlobalScope->wrapperTypeInf
o(); | 154 const WrapperTypeInfo* wrapperTypeInfo = wrapperTypeInfoForGlobalScope(); |
| 162 v8::Local<v8::Function> workerGlobalScopeConstructor = m_scriptState->perCon
textData()->constructorForType(wrapperTypeInfo); | 155 |
| 163 if (workerGlobalScopeConstructor.IsEmpty()) | 156 v8::Local<v8::Function> abstractGlobalScopeConstructor = m_scriptState->perC
ontextData()->constructorForType(wrapperTypeInfo); |
| 157 if (abstractGlobalScopeConstructor.IsEmpty()) |
| 164 return false; | 158 return false; |
| 165 v8::Local<v8::Object> jsWorkerGlobalScope; | 159 |
| 166 if (!V8ObjectConstructor::newInstance(isolate(), workerGlobalScopeConstructo
r).ToLocal(&jsWorkerGlobalScope)) { | 160 v8::Local<v8::Object> jsGlobalScope; |
| 161 if (!V8ObjectConstructor::newInstance(isolate(), abstractGlobalScopeConstruc
tor).ToLocal(&jsGlobalScope)) { |
| 167 m_scriptState->disposePerContextData(); | 162 m_scriptState->disposePerContextData(); |
| 168 return false; | 163 return false; |
| 169 } | 164 } |
| 170 | 165 |
| 171 jsWorkerGlobalScope = V8DOMWrapper::associateObjectWithWrapper(isolate(), m_
workerGlobalScope, wrapperTypeInfo, jsWorkerGlobalScope); | 166 jsGlobalScope = associateGlobalScopeWithWrapper(isolate(), wrapperTypeInfo,
jsGlobalScope); |
| 172 | 167 |
| 173 // Insert the object instance as the prototype of the shadow object. | 168 // Insert the object instance as the prototype of the shadow object. |
| 174 v8::Local<v8::Object> globalObject = v8::Local<v8::Object>::Cast(m_scriptSta
te->context()->Global()->GetPrototype()); | 169 v8::Local<v8::Object> globalObject = v8::Local<v8::Object>::Cast(m_scriptSta
te->context()->Global()->GetPrototype()); |
| 175 return v8CallBoolean(globalObject->SetPrototype(context, jsWorkerGlobalScope
)); | 170 return v8CallBoolean(globalObject->SetPrototype(context, jsGlobalScope)); |
| 176 } | 171 } |
| 177 | 172 |
| 178 v8::Isolate* WorkerScriptController::isolate() const | 173 v8::Isolate* GlobalScopeScriptController::isolate() const |
| 179 { | 174 { |
| 180 return m_workerGlobalScope->thread()->isolate(); | 175 return m_abstractGlobalScope->isolate(); |
| 181 } | 176 } |
| 182 | 177 |
| 183 ScriptValue WorkerScriptController::evaluate(const String& script, const String&
fileName, const TextPosition& scriptStartPosition, CachedMetadataHandler* cache
Handler, V8CacheOptions v8CacheOptions) | 178 ScriptValue GlobalScopeScriptController::evaluate(const String& script, const St
ring& fileName, const TextPosition& scriptStartPosition, CachedMetadataHandler*
cacheHandler, V8CacheOptions v8CacheOptions) |
| 184 { | 179 { |
| 185 if (!initializeContextIfNeeded()) | 180 if (!initializeContextIfNeeded()) |
| 186 return ScriptValue(); | 181 return ScriptValue(); |
| 187 | 182 |
| 188 ScriptState::Scope scope(m_scriptState.get()); | 183 ScriptState::Scope scope(m_scriptState.get()); |
| 189 | 184 |
| 190 if (!m_disableEvalPending.isEmpty()) { | 185 if (!m_disableEvalPending.isEmpty()) { |
| 191 m_scriptState->context()->AllowCodeGenerationFromStrings(false); | 186 m_scriptState->context()->AllowCodeGenerationFromStrings(false); |
| 192 m_scriptState->context()->SetErrorMessageForCodeGenerationFromStrings(v8
String(isolate(), m_disableEvalPending)); | 187 m_scriptState->context()->SetErrorMessageForCodeGenerationFromStrings(v8
String(isolate(), m_disableEvalPending)); |
| 193 m_disableEvalPending = String(); | 188 m_disableEvalPending = String(); |
| 194 } | 189 } |
| 195 | 190 |
| 196 v8::TryCatch block(isolate()); | 191 v8::TryCatch block(isolate()); |
| 197 | 192 |
| 198 v8::Local<v8::Script> compiledScript; | 193 v8::Local<v8::Script> compiledScript; |
| 199 v8::MaybeLocal<v8::Value> maybeResult; | 194 v8::MaybeLocal<v8::Value> maybeResult; |
| 200 if (v8Call(V8ScriptRunner::compileScript(script, fileName, String(), scriptS
tartPosition, isolate(), cacheHandler, SharableCrossOrigin, v8CacheOptions), com
piledScript, block)) | 195 if (v8Call(V8ScriptRunner::compileScript(script, fileName, String(), scriptS
tartPosition, isolate(), cacheHandler, SharableCrossOrigin, v8CacheOptions), com
piledScript, block)) |
| 201 maybeResult = V8ScriptRunner::runCompiledScript(isolate(), compiledScrip
t, m_workerGlobalScope); | 196 maybeResult = V8ScriptRunner::runCompiledScript(isolate(), compiledScrip
t, m_abstractGlobalScope); |
| 202 | 197 |
| 203 if (!block.CanContinue()) { | 198 if (!block.CanContinue()) { |
| 204 forbidExecution(); | 199 forbidExecution(); |
| 205 return ScriptValue(); | 200 return ScriptValue(); |
| 206 } | 201 } |
| 207 | 202 |
| 208 if (block.HasCaught()) { | 203 if (block.HasCaught()) { |
| 209 v8::Local<v8::Message> message = block.Message(); | 204 v8::Local<v8::Message> message = block.Message(); |
| 210 m_globalScopeExecutionState->hadException = true; | 205 m_globalScopeExecutionState->hadException = true; |
| 211 m_globalScopeExecutionState->errorMessage = toCoreString(message->Get())
; | 206 m_globalScopeExecutionState->errorMessage = toCoreString(message->Get())
; |
| (...skipping 13 matching lines...) Expand all Loading... |
| 225 m_globalScopeExecutionState->hadException = false; | 220 m_globalScopeExecutionState->hadException = false; |
| 226 } | 221 } |
| 227 | 222 |
| 228 v8::Local<v8::Value> result; | 223 v8::Local<v8::Value> result; |
| 229 if (!maybeResult.ToLocal(&result) || result->IsUndefined()) | 224 if (!maybeResult.ToLocal(&result) || result->IsUndefined()) |
| 230 return ScriptValue(); | 225 return ScriptValue(); |
| 231 | 226 |
| 232 return ScriptValue(m_scriptState.get(), result); | 227 return ScriptValue(m_scriptState.get(), result); |
| 233 } | 228 } |
| 234 | 229 |
| 235 bool WorkerScriptController::evaluate(const ScriptSourceCode& sourceCode, RefPtr
WillBeRawPtr<ErrorEvent>* errorEvent, CachedMetadataHandler* cacheHandler, V8Cac
heOptions v8CacheOptions) | 230 bool GlobalScopeScriptController::evaluate(const ScriptSourceCode& sourceCode, R
efPtrWillBeRawPtr<ErrorEvent>* errorEvent, CachedMetadataHandler* cacheHandler,
V8CacheOptions v8CacheOptions) |
| 236 { | 231 { |
| 237 if (isExecutionForbidden()) | 232 if (isExecutionForbidden()) |
| 238 return false; | 233 return false; |
| 239 | 234 |
| 240 WorkerGlobalScopeExecutionState state(this); | 235 GlobalScopeExecutionState state(this); |
| 241 evaluate(sourceCode.source(), sourceCode.url().string(), sourceCode.startPos
ition(), cacheHandler, v8CacheOptions); | 236 evaluate(sourceCode.source(), sourceCode.url().string(), sourceCode.startPos
ition(), cacheHandler, v8CacheOptions); |
| 242 if (isExecutionForbidden()) | 237 if (isExecutionForbidden()) |
| 243 return false; | 238 return false; |
| 244 if (state.hadException) { | 239 if (state.hadException) { |
| 245 if (errorEvent) { | 240 if (errorEvent) { |
| 246 if (state.m_errorEventFromImportedScript) { | 241 if (state.m_errorEventFromImportedScript) { |
| 247 // Propagate inner error event outwards. | 242 // Propagate inner error event outwards. |
| 248 *errorEvent = state.m_errorEventFromImportedScript.release(); | 243 *errorEvent = state.m_errorEventFromImportedScript.release(); |
| 249 return false; | 244 return false; |
| 250 } | 245 } |
| 251 if (m_workerGlobalScope->shouldSanitizeScriptError(state.sourceURL,
NotSharableCrossOrigin)) | 246 if (m_abstractGlobalScope->shouldSanitizeScriptError(state.sourceURL
, NotSharableCrossOrigin)) |
| 252 *errorEvent = ErrorEvent::createSanitizedError(m_world.get()); | 247 *errorEvent = ErrorEvent::createSanitizedError(m_world.get()); |
| 253 else | 248 else |
| 254 *errorEvent = ErrorEvent::create(state.errorMessage, state.sourc
eURL, state.lineNumber, state.columnNumber, m_world.get()); | 249 *errorEvent = ErrorEvent::create(state.errorMessage, state.sourc
eURL, state.lineNumber, state.columnNumber, m_world.get()); |
| 255 V8ErrorHandler::storeExceptionOnErrorEventWrapper(m_scriptState.get(
), errorEvent->get(), state.exception.v8Value(), m_scriptState->context()->Globa
l()); | 250 V8ErrorHandler::storeExceptionOnErrorEventWrapper(m_scriptState.get(
), errorEvent->get(), state.exception.v8Value(), m_scriptState->context()->Globa
l()); |
| 256 } else { | 251 } else { |
| 257 ASSERT(!m_workerGlobalScope->shouldSanitizeScriptError(state.sourceU
RL, NotSharableCrossOrigin)); | 252 ASSERT(!m_abstractGlobalScope->shouldSanitizeScriptError(state.sourc
eURL, NotSharableCrossOrigin)); |
| 258 RefPtrWillBeRawPtr<ErrorEvent> event = nullptr; | 253 RefPtrWillBeRawPtr<ErrorEvent> event = nullptr; |
| 259 if (state.m_errorEventFromImportedScript) | 254 if (state.m_errorEventFromImportedScript) |
| 260 event = state.m_errorEventFromImportedScript.release(); | 255 event = state.m_errorEventFromImportedScript.release(); |
| 261 else | 256 else |
| 262 event = ErrorEvent::create(state.errorMessage, state.sourceURL,
state.lineNumber, state.columnNumber, m_world.get()); | 257 event = ErrorEvent::create(state.errorMessage, state.sourceURL,
state.lineNumber, state.columnNumber, m_world.get()); |
| 263 m_workerGlobalScope->reportException(event, 0, nullptr, NotSharableC
rossOrigin); | 258 m_abstractGlobalScope->reportException(event, 0, nullptr, NotSharabl
eCrossOrigin); |
| 264 } | 259 } |
| 265 return false; | 260 return false; |
| 266 } | 261 } |
| 267 return true; | 262 return true; |
| 268 } | 263 } |
| 269 | 264 |
| 270 void WorkerScriptController::willScheduleExecutionTermination() | 265 void GlobalScopeScriptController::willScheduleExecutionTermination() |
| 271 { | 266 { |
| 272 // The mutex provides a memory barrier to ensure that once | 267 // The mutex provides a memory barrier to ensure that once |
| 273 // termination is scheduled, isExecutionTerminating will | 268 // termination is scheduled, isExecutionTerminating will |
| 274 // accurately reflect that state when called from another thread. | 269 // accurately reflect that state when called from another thread. |
| 275 MutexLocker locker(m_scheduledTerminationMutex); | 270 MutexLocker locker(m_scheduledTerminationMutex); |
| 276 m_executionScheduledToTerminate = true; | 271 m_executionScheduledToTerminate = true; |
| 277 } | 272 } |
| 278 | 273 |
| 279 bool WorkerScriptController::isExecutionTerminating() const | 274 bool GlobalScopeScriptController::isExecutionTerminating() const |
| 280 { | 275 { |
| 281 // See comments in willScheduleExecutionTermination regarding mutex usage. | 276 // See comments in willScheduleExecutionTermination regarding mutex usage. |
| 282 MutexLocker locker(m_scheduledTerminationMutex); | 277 MutexLocker locker(m_scheduledTerminationMutex); |
| 283 return m_executionScheduledToTerminate; | 278 return m_executionScheduledToTerminate; |
| 284 } | 279 } |
| 285 | 280 |
| 286 void WorkerScriptController::forbidExecution() | 281 void GlobalScopeScriptController::forbidExecution() |
| 287 { | 282 { |
| 288 ASSERT(m_workerGlobalScope->isContextThread()); | 283 ASSERT(m_abstractGlobalScope->isContextThread()); |
| 289 m_executionForbidden = true; | 284 m_executionForbidden = true; |
| 290 } | 285 } |
| 291 | 286 |
| 292 bool WorkerScriptController::isExecutionForbidden() const | 287 bool GlobalScopeScriptController::isExecutionForbidden() const |
| 293 { | 288 { |
| 294 ASSERT(m_workerGlobalScope->isContextThread()); | 289 ASSERT(m_abstractGlobalScope->isContextThread()); |
| 295 return m_executionForbidden; | 290 return m_executionForbidden; |
| 296 } | 291 } |
| 297 | 292 |
| 298 void WorkerScriptController::disableEval(const String& errorMessage) | 293 void GlobalScopeScriptController::disableEval(const String& errorMessage) |
| 299 { | 294 { |
| 300 m_disableEvalPending = errorMessage; | 295 m_disableEvalPending = errorMessage; |
| 301 } | 296 } |
| 302 | 297 |
| 303 void WorkerScriptController::rethrowExceptionFromImportedScript(PassRefPtrWillBe
RawPtr<ErrorEvent> errorEvent, ExceptionState& exceptionState) | 298 void GlobalScopeScriptController::rethrowExceptionFromImportedScript(PassRefPtrW
illBeRawPtr<ErrorEvent> errorEvent, ExceptionState& exceptionState) |
| 304 { | 299 { |
| 305 const String& errorMessage = errorEvent->message(); | 300 const String& errorMessage = errorEvent->message(); |
| 306 if (m_globalScopeExecutionState) | 301 if (m_globalScopeExecutionState) |
| 307 m_globalScopeExecutionState->m_errorEventFromImportedScript = errorEvent
; | 302 m_globalScopeExecutionState->m_errorEventFromImportedScript = errorEvent
; |
| 308 exceptionState.rethrowV8Exception(V8ThrowException::createGeneralError(isola
te(), errorMessage)); | 303 exceptionState.rethrowV8Exception(V8ThrowException::createGeneralError(isola
te(), errorMessage)); |
| 309 } | 304 } |
| 310 | 305 |
| 311 DEFINE_TRACE(WorkerScriptController) | 306 DEFINE_TRACE(GlobalScopeScriptController) |
| 312 { | 307 { |
| 313 visitor->trace(m_workerGlobalScope); | 308 visitor->trace(m_abstractGlobalScope); |
| 314 visitor->trace(m_rejectedPromises); | 309 visitor->trace(m_rejectedPromises); |
| 315 } | 310 } |
| 316 | 311 |
| 317 } // namespace blink | 312 } // namespace blink |
| OLD | NEW |