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

Side by Side Diff: Source/bindings/v8/WorkerScriptController.cpp

Issue 22467005: Correctly attribute exceptions thrown inside a Worker's imported scripts. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: tests. Created 7 years, 4 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 | Annotate | Revision Log
« no previous file with comments | « Source/bindings/v8/WorkerScriptController.h ('k') | Source/core/workers/WorkerGlobalScope.cpp » ('j') | 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 149 matching lines...) Expand 10 before | Expand all | Expand 10 after
160 return ScriptValue(); 160 return ScriptValue();
161 } 161 }
162 162
163 if (block.HasCaught()) { 163 if (block.HasCaught()) {
164 v8::Local<v8::Message> message = block.Message(); 164 v8::Local<v8::Message> message = block.Message();
165 state->hadException = true; 165 state->hadException = true;
166 state->errorMessage = toWebCoreString(message->Get()); 166 state->errorMessage = toWebCoreString(message->Get());
167 state->lineNumber = message->GetLineNumber(); 167 state->lineNumber = message->GetLineNumber();
168 state->columnNumber = message->GetStartColumn(); 168 state->columnNumber = message->GetStartColumn();
169 state->sourceURL = toWebCoreString(message->GetScriptResourceName()); 169 state->sourceURL = toWebCoreString(message->GetScriptResourceName());
170 if (m_workerGlobalScope->shouldSanitizeScriptError(state->sourceURL, Not SharableCrossOrigin))
171 state->exception = throwError(v8GeneralError, "Script error.", m_iso late);
do-not-use 2013/08/08 07:23:46 It feels bad to stop initializing state->exception
172 else
173 state->exception = ScriptValue(block.Exception());
174
175 block.Reset(); 170 block.Reset();
176 } else 171 } else
177 state->hadException = false; 172 state->hadException = false;
178 173
179 if (result.IsEmpty() || result->IsUndefined()) 174 if (result.IsEmpty() || result->IsUndefined())
180 return ScriptValue(); 175 return ScriptValue();
181 176
182 return ScriptValue(result); 177 return ScriptValue(result);
183 } 178 }
184 179
185 void WorkerScriptController::evaluate(const ScriptSourceCode& sourceCode, Script Value* exception) 180 void WorkerScriptController::evaluate(const ScriptSourceCode& sourceCode, RefPtr <ErrorEvent>* errorEvent)
186 { 181 {
187 if (isExecutionForbidden()) 182 if (isExecutionForbidden())
188 return; 183 return;
189 184
190 WorkerGlobalScopeExecutionState state; 185 WorkerGlobalScopeExecutionState state;
191 evaluate(sourceCode.source(), sourceCode.url().string(), sourceCode.startPos ition(), &state); 186 evaluate(sourceCode.source(), sourceCode.url().string(), sourceCode.startPos ition(), &state);
192 if (state.hadException) { 187 if (state.hadException) {
193 if (exception) { 188 if (errorEvent) {
194 *exception = state.exception; 189 *errorEvent = m_workerGlobalScope->shouldSanitizeScriptError(state.s ourceURL, NotSharableCrossOrigin) ?
190 ErrorEvent::createSanitizedError() : ErrorEvent::create(state.er rorMessage, state.sourceURL, state.lineNumber, state.columnNumber);
195 } else { 191 } else {
196 RefPtr<ErrorEvent> event = ErrorEvent::create(state.errorMessage, st ate.sourceURL, state.lineNumber, state.columnNumber); 192 ASSERT(!m_workerGlobalScope->shouldSanitizeScriptError(state.sourceU RL, NotSharableCrossOrigin));
193 RefPtr<ErrorEvent> event = m_errorEventFromImportedScript ? m_errorE ventFromImportedScript.release() : ErrorEvent::create(state.errorMessage, state. sourceURL, state.lineNumber, state.columnNumber);
194 m_errorEventFromImportedScript.clear();
197 m_workerGlobalScope->reportException(event, 0, NotSharableCrossOrigi n); 195 m_workerGlobalScope->reportException(event, 0, NotSharableCrossOrigi n);
198 } 196 }
199 } 197 }
200 } 198 }
201 199
202 void WorkerScriptController::scheduleExecutionTermination() 200 void WorkerScriptController::scheduleExecutionTermination()
203 { 201 {
204 // The mutex provides a memory barrier to ensure that once 202 // The mutex provides a memory barrier to ensure that once
205 // termination is scheduled, isExecutionTerminating will 203 // termination is scheduled, isExecutionTerminating will
206 // accurately reflect that state when called from another thread. 204 // accurately reflect that state when called from another thread.
(...skipping 21 matching lines...) Expand all
228 { 226 {
229 ASSERT(m_workerGlobalScope->isContextThread()); 227 ASSERT(m_workerGlobalScope->isContextThread());
230 return m_executionForbidden; 228 return m_executionForbidden;
231 } 229 }
232 230
233 void WorkerScriptController::disableEval(const String& errorMessage) 231 void WorkerScriptController::disableEval(const String& errorMessage)
234 { 232 {
235 m_disableEvalPending = errorMessage; 233 m_disableEvalPending = errorMessage;
236 } 234 }
237 235
238 void WorkerScriptController::setException(const ScriptValue& exception) 236 void WorkerScriptController::rethrowExceptionFromImportedScript(PassRefPtr<Error Event> errorEvent)
239 { 237 {
240 throwError(exception.v8Value()); 238 m_errorEventFromImportedScript = errorEvent;
239 throwError(V8ThrowException::createError(v8GeneralError, m_errorEventFromImp ortedScript->message(), m_isolate));
241 } 240 }
242 241
243 WorkerScriptController* WorkerScriptController::controllerForContext() 242 WorkerScriptController* WorkerScriptController::controllerForContext()
244 { 243 {
245 // Happens on frame destruction, check otherwise GetCurrent() will crash. 244 // Happens on frame destruction, check otherwise GetCurrent() will crash.
246 if (!v8::Context::InContext()) 245 if (!v8::Context::InContext())
247 return 0; 246 return 0;
248 v8::Handle<v8::Context> context = v8::Context::GetCurrent(); 247 v8::Handle<v8::Context> context = v8::Context::GetCurrent();
249 v8::Handle<v8::Object> global = context->Global(); 248 v8::Handle<v8::Object> global = context->Global();
250 global = global->FindInstanceInPrototypeChain(V8WorkerGlobalScope::GetTempla te(context->GetIsolate(), WorkerWorld)); 249 global = global->FindInstanceInPrototypeChain(V8WorkerGlobalScope::GetTempla te(context->GetIsolate(), WorkerWorld));
251 // Return 0 if the current executing context is not the worker context. 250 // Return 0 if the current executing context is not the worker context.
252 if (global.IsEmpty()) 251 if (global.IsEmpty())
253 return 0; 252 return 0;
254 WorkerGlobalScope* workerGlobalScope = V8WorkerGlobalScope::toNative(global) ; 253 WorkerGlobalScope* workerGlobalScope = V8WorkerGlobalScope::toNative(global) ;
255 return workerGlobalScope->script(); 254 return workerGlobalScope->script();
256 } 255 }
257 256
258 } // namespace WebCore 257 } // namespace WebCore
OLDNEW
« no previous file with comments | « Source/bindings/v8/WorkerScriptController.h ('k') | Source/core/workers/WorkerGlobalScope.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698