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

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

Issue 1003043002: bindings: Use Maybe APIs in V8ScriptRunner (part 1) (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 5 years, 9 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
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 166 matching lines...) Expand 10 before | Expand all | Expand 10 after
177 177
178 if (!m_disableEvalPending.isEmpty()) { 178 if (!m_disableEvalPending.isEmpty()) {
179 m_scriptState->context()->AllowCodeGenerationFromStrings(false); 179 m_scriptState->context()->AllowCodeGenerationFromStrings(false);
180 m_scriptState->context()->SetErrorMessageForCodeGenerationFromStrings(v8 String(isolate(), m_disableEvalPending)); 180 m_scriptState->context()->SetErrorMessageForCodeGenerationFromStrings(v8 String(isolate(), m_disableEvalPending));
181 m_disableEvalPending = String(); 181 m_disableEvalPending = String();
182 } 182 }
183 183
184 v8::TryCatch block; 184 v8::TryCatch block;
185 185
186 v8::Handle<v8::String> scriptString = v8String(isolate(), script); 186 v8::Handle<v8::String> scriptString = v8String(isolate(), script);
187 v8::Handle<v8::Script> compiledScript = V8ScriptRunner::compileScript(script String, fileName, String(), scriptStartPosition, isolate(), nullptr, nullptr, ca cheHandler, SharableCrossOrigin, v8CacheOptions); 187 v8::Local<v8::Script> compiledScript;
188 v8::Local<v8::Value> result = V8ScriptRunner::runCompiledScript(isolate(), c ompiledScript, &m_workerGlobalScope); 188 v8::MaybeLocal<v8::Value> maybeResult;
189 if (V8ScriptRunner::compileScript(scriptString, fileName, String(), scriptSt artPosition, isolate(), nullptr, nullptr, cacheHandler, SharableCrossOrigin, v8C acheOptions).ToLocal(&compiledScript))
190 maybeResult = V8ScriptRunner::runCompiledScript(isolate(), compiledScrip t, &m_workerGlobalScope);
189 191
190 if (!block.CanContinue()) { 192 if (!block.CanContinue()) {
191 forbidExecution(); 193 forbidExecution();
192 return ScriptValue(); 194 return ScriptValue();
193 } 195 }
194 196
195 if (block.HasCaught()) { 197 if (block.HasCaught()) {
196 v8::Local<v8::Message> message = block.Message(); 198 v8::Local<v8::Message> message = block.Message();
197 m_globalScopeExecutionState->hadException = true; 199 m_globalScopeExecutionState->hadException = true;
198 m_globalScopeExecutionState->errorMessage = toCoreString(message->Get()) ; 200 m_globalScopeExecutionState->errorMessage = toCoreString(message->Get()) ;
199 m_globalScopeExecutionState->lineNumber = message->GetLineNumber(); 201 m_globalScopeExecutionState->lineNumber = message->GetLineNumber();
200 m_globalScopeExecutionState->columnNumber = message->GetStartColumn() + 1; 202 m_globalScopeExecutionState->columnNumber = message->GetStartColumn() + 1;
201 TOSTRING_DEFAULT(V8StringResource<>, sourceURL, message->GetScriptOrigin ().ResourceName(), ScriptValue()); 203 TOSTRING_DEFAULT(V8StringResource<>, sourceURL, message->GetScriptOrigin ().ResourceName(), ScriptValue());
202 m_globalScopeExecutionState->sourceURL = sourceURL; 204 m_globalScopeExecutionState->sourceURL = sourceURL;
203 m_globalScopeExecutionState->exception = ScriptValue(m_scriptState.get() , block.Exception()); 205 m_globalScopeExecutionState->exception = ScriptValue(m_scriptState.get() , block.Exception());
204 block.Reset(); 206 block.Reset();
205 } else { 207 } else {
206 m_globalScopeExecutionState->hadException = false; 208 m_globalScopeExecutionState->hadException = false;
207 } 209 }
208 210
209 if (result.IsEmpty() || result->IsUndefined()) 211 v8::Local<v8::Value> result;
212 if (!maybeResult.ToLocal(&result) || result->IsUndefined())
210 return ScriptValue(); 213 return ScriptValue();
211 214
212 return ScriptValue(m_scriptState.get(), result); 215 return ScriptValue(m_scriptState.get(), result);
213 } 216 }
214 217
215 bool WorkerScriptController::evaluate(const ScriptSourceCode& sourceCode, RefPtr WillBeRawPtr<ErrorEvent>* errorEvent, CachedMetadataHandler* cacheHandler, V8Cac heOptions v8CacheOptions) 218 bool WorkerScriptController::evaluate(const ScriptSourceCode& sourceCode, RefPtr WillBeRawPtr<ErrorEvent>* errorEvent, CachedMetadataHandler* cacheHandler, V8Cac heOptions v8CacheOptions)
216 { 219 {
217 if (isExecutionForbidden()) 220 if (isExecutionForbidden())
218 return false; 221 return false;
219 222
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
282 285
283 void WorkerScriptController::rethrowExceptionFromImportedScript(PassRefPtrWillBe RawPtr<ErrorEvent> errorEvent, ExceptionState& exceptionState) 286 void WorkerScriptController::rethrowExceptionFromImportedScript(PassRefPtrWillBe RawPtr<ErrorEvent> errorEvent, ExceptionState& exceptionState)
284 { 287 {
285 const String& errorMessage = errorEvent->message(); 288 const String& errorMessage = errorEvent->message();
286 if (m_globalScopeExecutionState) 289 if (m_globalScopeExecutionState)
287 m_globalScopeExecutionState->m_errorEventFromImportedScript = errorEvent ; 290 m_globalScopeExecutionState->m_errorEventFromImportedScript = errorEvent ;
288 exceptionState.rethrowV8Exception(V8ThrowException::createGeneralError(isola te(), errorMessage)); 291 exceptionState.rethrowV8Exception(V8ThrowException::createGeneralError(isola te(), errorMessage));
289 } 292 }
290 293
291 } // namespace blink 294 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698