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 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
189 | 189 |
190 V8DOMWrapper::associateObjectWithWrapper(m_isolate, &m_workerGlobalScope, wr
apperTypeInfo, jsWorkerGlobalScope); | 190 V8DOMWrapper::associateObjectWithWrapper(m_isolate, &m_workerGlobalScope, wr
apperTypeInfo, jsWorkerGlobalScope); |
191 | 191 |
192 // Insert the object instance as the prototype of the shadow object. | 192 // Insert the object instance as the prototype of the shadow object. |
193 v8::Handle<v8::Object> globalObject = v8::Handle<v8::Object>::Cast(m_scriptS
tate->context()->Global()->GetPrototype()); | 193 v8::Handle<v8::Object> globalObject = v8::Handle<v8::Object>::Cast(m_scriptS
tate->context()->Global()->GetPrototype()); |
194 globalObject->SetPrototype(jsWorkerGlobalScope); | 194 globalObject->SetPrototype(jsWorkerGlobalScope); |
195 | 195 |
196 return true; | 196 return true; |
197 } | 197 } |
198 | 198 |
199 ScriptValue WorkerScriptController::evaluate(const String& script, const String&
fileName, const TextPosition& scriptStartPosition) | 199 ScriptValue WorkerScriptController::evaluate(const String& script, const String&
fileName, const TextPosition& scriptStartPosition, CachedMetadataHandler* cache
Handler, V8CacheOptions v8CacheOptions) |
200 { | 200 { |
201 if (!initializeContextIfNeeded()) | 201 if (!initializeContextIfNeeded()) |
202 return ScriptValue(); | 202 return ScriptValue(); |
203 | 203 |
204 ScriptState::Scope scope(m_scriptState.get()); | 204 ScriptState::Scope scope(m_scriptState.get()); |
205 | 205 |
206 if (!m_disableEvalPending.isEmpty()) { | 206 if (!m_disableEvalPending.isEmpty()) { |
207 m_scriptState->context()->AllowCodeGenerationFromStrings(false); | 207 m_scriptState->context()->AllowCodeGenerationFromStrings(false); |
208 m_scriptState->context()->SetErrorMessageForCodeGenerationFromStrings(v8
String(m_isolate, m_disableEvalPending)); | 208 m_scriptState->context()->SetErrorMessageForCodeGenerationFromStrings(v8
String(m_isolate, m_disableEvalPending)); |
209 m_disableEvalPending = String(); | 209 m_disableEvalPending = String(); |
210 } | 210 } |
211 | 211 |
212 v8::TryCatch block; | 212 v8::TryCatch block; |
213 | 213 |
214 v8::Handle<v8::String> scriptString = v8String(m_isolate, script); | 214 v8::Handle<v8::String> scriptString = v8String(m_isolate, script); |
215 v8::Handle<v8::Script> compiledScript = V8ScriptRunner::compileScript(script
String, fileName, scriptStartPosition, 0, 0, m_isolate); | 215 v8::Handle<v8::Script> compiledScript = V8ScriptRunner::compileScript(script
String, fileName, scriptStartPosition, m_isolate, nullptr, nullptr, cacheHandler
, SharableCrossOrigin, v8CacheOptions); |
216 v8::Local<v8::Value> result = V8ScriptRunner::runCompiledScript(m_isolate, c
ompiledScript, &m_workerGlobalScope); | 216 v8::Local<v8::Value> result = V8ScriptRunner::runCompiledScript(m_isolate, c
ompiledScript, &m_workerGlobalScope); |
217 | 217 |
218 if (!block.CanContinue()) { | 218 if (!block.CanContinue()) { |
219 m_workerGlobalScope.script()->forbidExecution(); | 219 m_workerGlobalScope.script()->forbidExecution(); |
220 return ScriptValue(); | 220 return ScriptValue(); |
221 } | 221 } |
222 | 222 |
223 if (block.HasCaught()) { | 223 if (block.HasCaught()) { |
224 v8::Local<v8::Message> message = block.Message(); | 224 v8::Local<v8::Message> message = block.Message(); |
225 m_globalScopeExecutionState->hadException = true; | 225 m_globalScopeExecutionState->hadException = true; |
226 m_globalScopeExecutionState->errorMessage = toCoreString(message->Get())
; | 226 m_globalScopeExecutionState->errorMessage = toCoreString(message->Get())
; |
227 m_globalScopeExecutionState->lineNumber = message->GetLineNumber(); | 227 m_globalScopeExecutionState->lineNumber = message->GetLineNumber(); |
228 m_globalScopeExecutionState->columnNumber = message->GetStartColumn() +
1; | 228 m_globalScopeExecutionState->columnNumber = message->GetStartColumn() +
1; |
229 TOSTRING_DEFAULT(V8StringResource<>, sourceURL, message->GetScriptOrigin
().ResourceName(), ScriptValue()); | 229 TOSTRING_DEFAULT(V8StringResource<>, sourceURL, message->GetScriptOrigin
().ResourceName(), ScriptValue()); |
230 m_globalScopeExecutionState->sourceURL = sourceURL; | 230 m_globalScopeExecutionState->sourceURL = sourceURL; |
231 m_globalScopeExecutionState->exception = ScriptValue(m_scriptState.get()
, block.Exception()); | 231 m_globalScopeExecutionState->exception = ScriptValue(m_scriptState.get()
, block.Exception()); |
232 block.Reset(); | 232 block.Reset(); |
233 } else { | 233 } else { |
234 m_globalScopeExecutionState->hadException = false; | 234 m_globalScopeExecutionState->hadException = false; |
235 } | 235 } |
236 | 236 |
237 if (result.IsEmpty() || result->IsUndefined()) | 237 if (result.IsEmpty() || result->IsUndefined()) |
238 return ScriptValue(); | 238 return ScriptValue(); |
239 | 239 |
240 return ScriptValue(m_scriptState.get(), result); | 240 return ScriptValue(m_scriptState.get(), result); |
241 } | 241 } |
242 | 242 |
243 bool WorkerScriptController::evaluate(const ScriptSourceCode& sourceCode, RefPtr
WillBeRawPtr<ErrorEvent>* errorEvent) | 243 bool WorkerScriptController::evaluate(const ScriptSourceCode& sourceCode, RefPtr
WillBeRawPtr<ErrorEvent>* errorEvent, CachedMetadataHandler* cacheHandler, V8Cac
heOptions v8CacheOptions) |
244 { | 244 { |
245 if (isExecutionForbidden()) | 245 if (isExecutionForbidden()) |
246 return false; | 246 return false; |
247 | 247 |
248 WorkerGlobalScopeExecutionState state(this); | 248 WorkerGlobalScopeExecutionState state(this); |
249 evaluate(sourceCode.source(), sourceCode.url().string(), sourceCode.startPos
ition()); | 249 evaluate(sourceCode.source(), sourceCode.url().string(), sourceCode.startPos
ition(), cacheHandler, v8CacheOptions); |
250 if (state.hadException) { | 250 if (state.hadException) { |
251 if (errorEvent) { | 251 if (errorEvent) { |
252 if (state.m_errorEventFromImportedScript) { | 252 if (state.m_errorEventFromImportedScript) { |
253 // Propagate inner error event outwards. | 253 // Propagate inner error event outwards. |
254 *errorEvent = state.m_errorEventFromImportedScript.release(); | 254 *errorEvent = state.m_errorEventFromImportedScript.release(); |
255 return false; | 255 return false; |
256 } | 256 } |
257 if (m_workerGlobalScope.shouldSanitizeScriptError(state.sourceURL, N
otSharableCrossOrigin)) | 257 if (m_workerGlobalScope.shouldSanitizeScriptError(state.sourceURL, N
otSharableCrossOrigin)) |
258 *errorEvent = ErrorEvent::createSanitizedError(m_world.get()); | 258 *errorEvent = ErrorEvent::createSanitizedError(m_world.get()); |
259 else | 259 else |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
311 | 311 |
312 void WorkerScriptController::rethrowExceptionFromImportedScript(PassRefPtrWillBe
RawPtr<ErrorEvent> errorEvent, ExceptionState& exceptionState) | 312 void WorkerScriptController::rethrowExceptionFromImportedScript(PassRefPtrWillBe
RawPtr<ErrorEvent> errorEvent, ExceptionState& exceptionState) |
313 { | 313 { |
314 const String& errorMessage = errorEvent->message(); | 314 const String& errorMessage = errorEvent->message(); |
315 if (m_globalScopeExecutionState) | 315 if (m_globalScopeExecutionState) |
316 m_globalScopeExecutionState->m_errorEventFromImportedScript = errorEvent
; | 316 m_globalScopeExecutionState->m_errorEventFromImportedScript = errorEvent
; |
317 exceptionState.rethrowV8Exception(V8ThrowException::createGeneralError(m_iso
late, errorMessage)); | 317 exceptionState.rethrowV8Exception(V8ThrowException::createGeneralError(m_iso
late, errorMessage)); |
318 } | 318 } |
319 | 319 |
320 } // namespace blink | 320 } // namespace blink |
OLD | NEW |