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

Side by Side Diff: third_party/WebKit/Source/bindings/core/v8/WorkerScriptController.cpp

Issue 1550533002: Rename WorkerGlobalScopeExecutionState to ExecutionState. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 12 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 unified diff | Download patch
« no previous file with comments | « third_party/WebKit/Source/bindings/core/v8/WorkerScriptController.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
47 #include "core/workers/SharedWorkerGlobalScope.h" 47 #include "core/workers/SharedWorkerGlobalScope.h"
48 #include "core/workers/WorkerGlobalScope.h" 48 #include "core/workers/WorkerGlobalScope.h"
49 #include "core/workers/WorkerObjectProxy.h" 49 #include "core/workers/WorkerObjectProxy.h"
50 #include "core/workers/WorkerThread.h" 50 #include "core/workers/WorkerThread.h"
51 #include "platform/heap/ThreadState.h" 51 #include "platform/heap/ThreadState.h"
52 #include "public/platform/Platform.h" 52 #include "public/platform/Platform.h"
53 #include <v8.h> 53 #include <v8.h>
54 54
55 namespace blink { 55 namespace blink {
56 56
57 class WorkerScriptController::WorkerGlobalScopeExecutionState final { 57 class WorkerScriptController::ExecutionState final {
58 STACK_ALLOCATED(); 58 STACK_ALLOCATED();
59 public: 59 public:
60 explicit WorkerGlobalScopeExecutionState(WorkerScriptController* controller) 60 explicit ExecutionState(WorkerScriptController* controller)
61 : hadException(false) 61 : hadException(false)
62 , lineNumber(0) 62 , lineNumber(0)
63 , columnNumber(0) 63 , columnNumber(0)
64 , m_controller(controller) 64 , m_controller(controller)
65 , m_outerState(controller->m_globalScopeExecutionState) 65 , m_outerState(controller->m_executionState)
66 { 66 {
67 m_controller->m_globalScopeExecutionState = this; 67 m_controller->m_executionState = this;
68 } 68 }
69 69
70 ~WorkerGlobalScopeExecutionState() 70 ~ExecutionState()
71 { 71 {
72 m_controller->m_globalScopeExecutionState = m_outerState; 72 m_controller->m_executionState = m_outerState;
73 } 73 }
74 74
75 DEFINE_INLINE_TRACE() 75 DEFINE_INLINE_TRACE()
76 { 76 {
77 visitor->trace(m_errorEventFromImportedScript); 77 visitor->trace(m_errorEventFromImportedScript);
78 visitor->trace(m_controller); 78 visitor->trace(m_controller);
79 } 79 }
80 80
81 bool hadException; 81 bool hadException;
82 String errorMessage; 82 String errorMessage;
83 int lineNumber; 83 int lineNumber;
84 int columnNumber; 84 int columnNumber;
85 String sourceURL; 85 String sourceURL;
86 ScriptValue exception; 86 ScriptValue exception;
87 RefPtrWillBeMember<ErrorEvent> m_errorEventFromImportedScript; 87 RefPtrWillBeMember<ErrorEvent> m_errorEventFromImportedScript;
88 88
89 // A WorkerGlobalScopeExecutionState context is stack allocated by 89 // A ExecutionState context is stack allocated by
90 // WorkerScriptController::evaluate(), with the contoller using it 90 // WorkerScriptController::evaluate(), with the contoller using it
91 // during script evaluation. To handle nested evaluate() uses, 91 // during script evaluation. To handle nested evaluate() uses,
92 // WorkerGlobalScopeExecutionStates are chained together; 92 // ExecutionStates are chained together;
93 // |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
94 // (or 0, if outermost.) Upon return from evaluate(), the 94 // (or 0, if outermost.) Upon return from evaluate(), the
95 // WorkerScriptController's WorkerGlobalScopeExecutionState is popped 95 // WorkerScriptController's ExecutionState is popped and the previous one
96 // and the previous one restored (see above dtor.) 96 // restored (see above dtor.)
97 // 97 //
98 // 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"
99 // and its fields will be traced when scanning the stack. 99 // and its fields will be traced when scanning the stack.
100 RawPtrWillBeMember<WorkerScriptController> m_controller; 100 RawPtrWillBeMember<WorkerScriptController> m_controller;
101 WorkerGlobalScopeExecutionState* m_outerState; 101 ExecutionState* m_outerState;
102 }; 102 };
103 103
104 PassOwnPtrWillBeRawPtr<WorkerScriptController> WorkerScriptController::create(Wo rkerGlobalScope* workerGlobalScope, v8::Isolate* isolate) 104 PassOwnPtrWillBeRawPtr<WorkerScriptController> WorkerScriptController::create(Wo rkerGlobalScope* workerGlobalScope, v8::Isolate* isolate)
105 { 105 {
106 return adoptPtrWillBeNoop(new WorkerScriptController(workerGlobalScope, isol ate)); 106 return adoptPtrWillBeNoop(new WorkerScriptController(workerGlobalScope, isol ate));
107 } 107 }
108 108
109 WorkerScriptController::WorkerScriptController(WorkerGlobalScope* workerGlobalSc ope, v8::Isolate* isolate) 109 WorkerScriptController::WorkerScriptController(WorkerGlobalScope* workerGlobalSc ope, v8::Isolate* isolate)
110 : m_workerGlobalScope(workerGlobalScope) 110 : m_workerGlobalScope(workerGlobalScope)
111 , m_executionForbidden(false) 111 , m_executionForbidden(false)
112 , m_executionScheduledToTerminate(false) 112 , m_executionScheduledToTerminate(false)
113 , m_rejectedPromises(RejectedPromises::create()) 113 , m_rejectedPromises(RejectedPromises::create())
114 , m_globalScopeExecutionState(0) 114 , m_executionState(0)
115 { 115 {
116 ASSERT(isolate); 116 ASSERT(isolate);
117 m_world = DOMWrapperWorld::create(isolate, WorkerWorldId); 117 m_world = DOMWrapperWorld::create(isolate, WorkerWorldId);
118 } 118 }
119 119
120 WorkerScriptController::~WorkerScriptController() 120 WorkerScriptController::~WorkerScriptController()
121 { 121 {
122 ASSERT(!m_rejectedPromises); 122 ASSERT(!m_rejectedPromises);
123 } 123 }
124 124
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
198 if (v8Call(V8ScriptRunner::compileScript(script, fileName, String(), scriptS tartPosition, isolate(), cacheHandler, SharableCrossOrigin, v8CacheOptions), com piledScript, block)) 198 if (v8Call(V8ScriptRunner::compileScript(script, fileName, String(), scriptS tartPosition, isolate(), cacheHandler, SharableCrossOrigin, v8CacheOptions), com piledScript, block))
199 maybeResult = V8ScriptRunner::runCompiledScript(isolate(), compiledScrip t, m_workerGlobalScope); 199 maybeResult = V8ScriptRunner::runCompiledScript(isolate(), compiledScrip t, m_workerGlobalScope);
200 200
201 if (!block.CanContinue()) { 201 if (!block.CanContinue()) {
202 forbidExecution(); 202 forbidExecution();
203 return ScriptValue(); 203 return ScriptValue();
204 } 204 }
205 205
206 if (block.HasCaught()) { 206 if (block.HasCaught()) {
207 v8::Local<v8::Message> message = block.Message(); 207 v8::Local<v8::Message> message = block.Message();
208 m_globalScopeExecutionState->hadException = true; 208 m_executionState->hadException = true;
209 m_globalScopeExecutionState->errorMessage = toCoreString(message->Get()) ; 209 m_executionState->errorMessage = toCoreString(message->Get());
210 if (v8Call(message->GetLineNumber(m_scriptState->context()), m_globalSco peExecutionState->lineNumber) 210 if (v8Call(message->GetLineNumber(m_scriptState->context()), m_execution State->lineNumber)
211 && v8Call(message->GetStartColumn(m_scriptState->context()), m_globa lScopeExecutionState->columnNumber)) { 211 && v8Call(message->GetStartColumn(m_scriptState->context()), m_execu tionState->columnNumber)) {
212 ++m_globalScopeExecutionState->columnNumber; 212 ++m_executionState->columnNumber;
213 } else { 213 } else {
214 m_globalScopeExecutionState->lineNumber = 0; 214 m_executionState->lineNumber = 0;
215 m_globalScopeExecutionState->columnNumber = 0; 215 m_executionState->columnNumber = 0;
216 } 216 }
217 217
218 TOSTRING_DEFAULT(V8StringResource<>, sourceURL, message->GetScriptOrigin ().ResourceName(), ScriptValue()); 218 TOSTRING_DEFAULT(V8StringResource<>, sourceURL, message->GetScriptOrigin ().ResourceName(), ScriptValue());
219 m_globalScopeExecutionState->sourceURL = sourceURL; 219 m_executionState->sourceURL = sourceURL;
220 m_globalScopeExecutionState->exception = ScriptValue(m_scriptState.get() , block.Exception()); 220 m_executionState->exception = ScriptValue(m_scriptState.get(), block.Exc eption());
221 block.Reset(); 221 block.Reset();
222 } else { 222 } else {
223 m_globalScopeExecutionState->hadException = false; 223 m_executionState->hadException = false;
224 } 224 }
225 225
226 v8::Local<v8::Value> result; 226 v8::Local<v8::Value> result;
227 if (!maybeResult.ToLocal(&result) || result->IsUndefined()) 227 if (!maybeResult.ToLocal(&result) || result->IsUndefined())
228 return ScriptValue(); 228 return ScriptValue();
229 229
230 return ScriptValue(m_scriptState.get(), result); 230 return ScriptValue(m_scriptState.get(), result);
231 } 231 }
232 232
233 bool WorkerScriptController::evaluate(const ScriptSourceCode& sourceCode, RefPtr WillBeRawPtr<ErrorEvent>* errorEvent, CachedMetadataHandler* cacheHandler, V8Cac heOptions v8CacheOptions) 233 bool WorkerScriptController::evaluate(const ScriptSourceCode& sourceCode, RefPtr WillBeRawPtr<ErrorEvent>* errorEvent, CachedMetadataHandler* cacheHandler, V8Cac heOptions v8CacheOptions)
234 { 234 {
235 if (isExecutionForbidden()) 235 if (isExecutionForbidden())
236 return false; 236 return false;
237 237
238 WorkerGlobalScopeExecutionState state(this); 238 ExecutionState state(this);
239 evaluate(sourceCode.source(), sourceCode.url().string(), sourceCode.startPos ition(), cacheHandler, v8CacheOptions); 239 evaluate(sourceCode.source(), sourceCode.url().string(), sourceCode.startPos ition(), cacheHandler, v8CacheOptions);
240 if (isExecutionForbidden()) 240 if (isExecutionForbidden())
241 return false; 241 return false;
242 if (state.hadException) { 242 if (state.hadException) {
243 if (errorEvent) { 243 if (errorEvent) {
244 if (state.m_errorEventFromImportedScript) { 244 if (state.m_errorEventFromImportedScript) {
245 // Propagate inner error event outwards. 245 // Propagate inner error event outwards.
246 *errorEvent = state.m_errorEventFromImportedScript.release(); 246 *errorEvent = state.m_errorEventFromImportedScript.release();
247 return false; 247 return false;
248 } 248 }
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
294 } 294 }
295 295
296 void WorkerScriptController::disableEval(const String& errorMessage) 296 void WorkerScriptController::disableEval(const String& errorMessage)
297 { 297 {
298 m_disableEvalPending = errorMessage; 298 m_disableEvalPending = errorMessage;
299 } 299 }
300 300
301 void WorkerScriptController::rethrowExceptionFromImportedScript(PassRefPtrWillBe RawPtr<ErrorEvent> errorEvent, ExceptionState& exceptionState) 301 void WorkerScriptController::rethrowExceptionFromImportedScript(PassRefPtrWillBe RawPtr<ErrorEvent> errorEvent, ExceptionState& exceptionState)
302 { 302 {
303 const String& errorMessage = errorEvent->message(); 303 const String& errorMessage = errorEvent->message();
304 if (m_globalScopeExecutionState) 304 if (m_executionState)
305 m_globalScopeExecutionState->m_errorEventFromImportedScript = errorEvent ; 305 m_executionState->m_errorEventFromImportedScript = errorEvent;
306 exceptionState.rethrowV8Exception(V8ThrowException::createGeneralError(isola te(), errorMessage)); 306 exceptionState.rethrowV8Exception(V8ThrowException::createGeneralError(isola te(), errorMessage));
307 } 307 }
308 308
309 DEFINE_TRACE(WorkerScriptController) 309 DEFINE_TRACE(WorkerScriptController)
310 { 310 {
311 visitor->trace(m_workerGlobalScope); 311 visitor->trace(m_workerGlobalScope);
312 visitor->trace(m_rejectedPromises); 312 visitor->trace(m_rejectedPromises);
313 } 313 }
314 314
315 } // namespace blink 315 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/bindings/core/v8/WorkerScriptController.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698