bool WorkerScriptController::evaluate(const ScriptSourceCode& sourceCode, RefPtrWillBeRawPtr<ErrorEvent>* errorEvent, CachedMetadataHandler* cacheHandler, V8CacheOptions v8CacheOptions) { if (isExecutionForbidden()) return false; WorkerGlobalScopeExecutionState state(this); evaluate(sourceCode.source(), sourceCode.url().string(), sourceCode.startPosition(), cacheHandler, v8CacheOptions); if (isExecutionForbidden()) return false; if (state.hadException) { if (errorEvent) { if (state.m_errorEventFromImportedScript) { // Propagate inner error event outwards. *errorEvent = state.m_errorEventFromImportedScript.release(); return false; } if (m_workerGlobalScope.shouldSanitizeScriptError(state.sourceURL, NotSharableCrossOrigin)) *errorEvent = ErrorEvent::createSanitizedError(m_world.get()); else *errorEvent = ErrorEvent::create(state.errorMessage, state.sourceURL, state.lineNumber, state.columnNumber, m_world.get()); V8ErrorHandler::storeExceptionOnErrorEventWrapper(isolate(), errorEvent->get(), state.exception.v8Value(), m_scriptState->context()->Global()); } else { ASSERT(!m_workerGlobalScope.shouldSanitizeScriptError(state.sourceURL, NotSharableCrossOrigin)); RefPtrWillBeRawPtr<ErrorEvent> event = nullptr; if (state.m_errorEventFromImportedScript) event = state.m_errorEventFromImportedScript.release(); else event = ErrorEvent::create(state.errorMessage, state.sourceURL, state.lineNumber, state.columnNumber, m_world.get()); m_workerGlobalScope.reportException(event, 0, nullptr, NotSharableCrossOrigin); } return false; } return true; }
void WorkerScriptController::evaluate(const ScriptSourceCode& sourceCode, ScriptValue* exception) { if (isExecutionForbidden()) return; WorkerContextExecutionState state; m_proxy->evaluate(sourceCode.source(), sourceCode.url().string(), sourceCode.startPosition(), &state); if (state.hadException) { if (exception) *exception = state.exception; else m_workerContext->reportException(state.errorMessage, state.lineNumber, state.sourceURL, 0); } }
bool WorkerOrWorkletScriptController::evaluate( const ScriptSourceCode& sourceCode, ErrorEvent** errorEvent, CachedMetadataHandler* cacheHandler, V8CacheOptions v8CacheOptions) { if (isExecutionForbidden()) return false; ExecutionState state(this); evaluate(sourceCode.source(), sourceCode.url().getString(), sourceCode.startPosition(), cacheHandler, v8CacheOptions); if (isExecutionForbidden()) return false; if (state.hadException) { if (errorEvent) { if (state.m_errorEventFromImportedScript) { // Propagate inner error event outwards. *errorEvent = state.m_errorEventFromImportedScript.release(); return false; } if (m_globalScope->shouldSanitizeScriptError(state.m_location->url(), NotSharableCrossOrigin)) *errorEvent = ErrorEvent::createSanitizedError(m_world.get()); else *errorEvent = ErrorEvent::create( state.errorMessage, state.m_location->clone(), m_world.get()); V8ErrorHandler::storeExceptionOnErrorEventWrapper( m_scriptState.get(), *errorEvent, state.exception.v8Value(), m_scriptState->context()->Global()); } else { DCHECK(!m_globalScope->shouldSanitizeScriptError(state.m_location->url(), NotSharableCrossOrigin)); ErrorEvent* event = nullptr; if (state.m_errorEventFromImportedScript) event = state.m_errorEventFromImportedScript.release(); else event = ErrorEvent::create(state.errorMessage, state.m_location->clone(), m_world.get()); m_globalScope->dispatchErrorEvent(event, NotSharableCrossOrigin); } return false; } return true; }
void WorkerScriptController::evaluate(const ScriptSourceCode& sourceCode, RefPtr<ErrorEvent>* errorEvent) { if (isExecutionForbidden()) return; WorkerGlobalScopeExecutionState state; evaluate(sourceCode.source(), sourceCode.url().string(), sourceCode.startPosition(), &state); if (state.hadException) { if (errorEvent) { *errorEvent = m_workerGlobalScope.shouldSanitizeScriptError(state.sourceURL, NotSharableCrossOrigin) ? ErrorEvent::createSanitizedError(nullptr) : ErrorEvent::create(state.errorMessage, state.sourceURL, state.lineNumber, state.columnNumber, nullptr); V8ErrorHandler::storeExceptionOnErrorEventWrapper(errorEvent->get(), state.exception.v8Value(), isolate()); } else { ASSERT(!m_workerGlobalScope.shouldSanitizeScriptError(state.sourceURL, NotSharableCrossOrigin)); RefPtr<ErrorEvent> event = m_errorEventFromImportedScript ? m_errorEventFromImportedScript.release() : ErrorEvent::create(state.errorMessage, state.sourceURL, state.lineNumber, state.columnNumber, nullptr); m_workerGlobalScope.reportException(event, nullptr, NotSharableCrossOrigin); } } }
v8::Local<v8::Value> V8Proxy::evaluate(const ScriptSourceCode& source, Node* node) { ASSERT(v8::Context::InContext()); V8GCController::checkMemoryUsage(); InspectorInstrumentationCookie cookie = InspectorInstrumentation::willEvaluateScript(m_frame, source.url().isNull() ? String() : source.url().string(), source.startLine()); v8::Local<v8::Value> result; { // Isolate exceptions that occur when compiling and executing // the code. These exceptions should not interfere with // javascript code we might evaluate from C++ when returning // from here. v8::TryCatch tryCatch; tryCatch.SetVerbose(true); // Compile the script. v8::Local<v8::String> code = v8ExternalString(source.source()); #if PLATFORM(CHROMIUM) TRACE_EVENT_BEGIN0("v8", "v8.compile"); #endif OwnPtr<v8::ScriptData> scriptData = precompileScript(code, source.cachedScript()); // NOTE: For compatibility with WebCore, ScriptSourceCode's line starts at // 1, whereas v8 starts at 0. v8::Handle<v8::Script> script = compileScript(code, source.url(), source.startPosition(), scriptData.get()); #if PLATFORM(CHROMIUM) TRACE_EVENT_END0("v8", "v8.compile"); TRACE_EVENT0("v8", "v8.run"); #endif result = runScript(script); } InspectorInstrumentation::didEvaluateScript(cookie); return result; }
v8::Local<v8::Value> ScriptController::compileAndRunScript(const ScriptSourceCode& source) { ASSERT(v8::Context::InContext()); V8GCController::checkMemoryUsage(); InspectorInstrumentationCookie cookie = InspectorInstrumentation::willEvaluateScript(m_frame, source.url().isNull() ? String() : source.url().string(), source.startLine()); v8::Local<v8::Value> result; { // Isolate exceptions that occur when compiling and executing // the code. These exceptions should not interfere with // javascript code we might evaluate from C++ when returning // from here. v8::TryCatch tryCatch; tryCatch.SetVerbose(true); // Compile the script. v8::Handle<v8::String> code = v8String(source.source(), m_isolate); TRACE_EVENT_BEGIN0("v8", "v8.compile"); OwnPtr<v8::ScriptData> scriptData = ScriptSourceCode::precompileScript(code, source.cachedScript()); // NOTE: For compatibility with WebCore, ScriptSourceCode's line starts at // 1, whereas v8 starts at 0. v8::Handle<v8::Script> script = ScriptSourceCode::compileScript(code, source.url(), source.startPosition(), scriptData.get(), m_isolate); TRACE_EVENT_END0("v8", "v8.compile"); TRACE_EVENT0("v8", "v8.run"); // Keep Frame (and therefore ScriptController) alive. RefPtr<Frame> protect(m_frame); result = V8ScriptRunner::runCompiledScript(script, m_frame->document()); ASSERT(!tryCatch.HasCaught() || result.IsEmpty()); } InspectorInstrumentation::didEvaluateScript(cookie); return result; }
v8::Local<v8::Value> V8Proxy::evaluate(const ScriptSourceCode& source, Node* node) { ASSERT(v8::Context::InContext()); V8GCController::checkMemoryUsage(); InspectorInstrumentationCookie cookie = InspectorInstrumentation::willEvaluateScript(m_frame, source.url().isNull() ? String() : source.url().string(), source.startLine()); v8::Local<v8::Value> result; { // Isolate exceptions that occur when compiling and executing // the code. These exceptions should not interfere with // javascript code we might evaluate from C++ when returning // from here. v8::TryCatch tryCatch; tryCatch.SetVerbose(true); // Compile the script. v8::Local<v8::String> code = v8ExternalString(source.source()); #if PLATFORM(CHROMIUM) PlatformBridge::traceEventBegin("v8.compile", node, ""); #endif OwnPtr<v8::ScriptData> scriptData = precompileScript(code, source.cachedScript()); // NOTE: For compatibility with WebCore, ScriptSourceCode's line starts at // 1, whereas v8 starts at 0. v8::Handle<v8::Script> script = compileScript(code, source.url(), WTF::toZeroBasedTextPosition(source.startPosition()), scriptData.get()); #if PLATFORM(CHROMIUM) PlatformBridge::traceEventEnd("v8.compile", node, ""); PlatformBridge::traceEventBegin("v8.run", node, ""); #endif // Set inlineCode to true for <a href="javascript:doSomething()"> // and false for <script>doSomething</script>. We make a rough guess at // this based on whether the script source has a URL. result = runScript(script, source.url().string().isNull()); } #if PLATFORM(CHROMIUM) PlatformBridge::traceEventEnd("v8.run", node, ""); #endif InspectorInstrumentation::didEvaluateScript(cookie); return result; }
v8::Local<v8::Value> ScriptController::executeScriptAndReturnValue(v8::Handle<v8::Context> context, const ScriptSourceCode& source, AccessControlStatus corsStatus) { v8::Context::Scope scope(context); InspectorInstrumentationCookie cookie = InspectorInstrumentation::willEvaluateScript(m_frame, source.url().isNull() ? String() : source.url().string(), source.startLine()); v8::Local<v8::Value> result; { // Isolate exceptions that occur when compiling and executing // the code. These exceptions should not interfere with // javascript code we might evaluate from C++ when returning // from here. v8::TryCatch tryCatch; tryCatch.SetVerbose(true); v8::Handle<v8::String> code = v8String(m_isolate, source.source()); OwnPtr<v8::ScriptData> scriptData = V8ScriptRunner::precompileScript(code, source.resource()); // NOTE: For compatibility with WebCore, ScriptSourceCode's line starts at // 1, whereas v8 starts at 0. v8::Handle<v8::Script> script = V8ScriptRunner::compileScript(code, source.url(), source.startPosition(), scriptData.get(), m_isolate, corsStatus); // Keep LocalFrame (and therefore ScriptController) alive. RefPtr<LocalFrame> protect(m_frame); result = V8ScriptRunner::runCompiledScript(script, m_frame->document(), m_isolate); ASSERT(!tryCatch.HasCaught() || result.IsEmpty()); } InspectorInstrumentation::didEvaluateScript(cookie); return result; }
v8::Local<v8::Value> ScriptController::executeScriptAndReturnValue(v8::Local<v8::Context> context, const ScriptSourceCode& source, AccessControlStatus accessControlStatus, double* compilationFinishTime) { TRACE_EVENT1("devtools.timeline", "EvaluateScript", "data", InspectorEvaluateScriptEvent::data(frame(), source.url().getString(), source.startPosition())); InspectorInstrumentation::NativeBreakpoint nativeBreakpoint(frame()->document(), "scriptFirstStatement", false); v8::Local<v8::Value> result; { V8CacheOptions v8CacheOptions(V8CacheOptionsDefault); if (frame()->settings()) v8CacheOptions = frame()->settings()->v8CacheOptions(); if (source.resource() && !source.resource()->response().cacheStorageCacheName().isNull()) { switch (frame()->settings()->v8CacheStrategiesForCacheStorage()) { case V8CacheStrategiesForCacheStorage::None: v8CacheOptions = V8CacheOptionsNone; break; case V8CacheStrategiesForCacheStorage::Normal: v8CacheOptions = V8CacheOptionsCode; break; case V8CacheStrategiesForCacheStorage::Default: case V8CacheStrategiesForCacheStorage::Aggressive: v8CacheOptions = V8CacheOptionsAlways; break; } } // Isolate exceptions that occur when compiling and executing // the code. These exceptions should not interfere with // javascript code we might evaluate from C++ when returning // from here. v8::TryCatch tryCatch(isolate()); tryCatch.SetVerbose(true); v8::Local<v8::Script> script; if (!v8Call(V8ScriptRunner::compileScript(source, isolate(), accessControlStatus, v8CacheOptions), script, tryCatch)) return result; if (compilationFinishTime) { *compilationFinishTime = WTF::monotonicallyIncreasingTime(); } if (!v8Call(V8ScriptRunner::runCompiledScript(isolate(), script, frame()->document()), result, tryCatch)) return result; } TRACE_EVENT_INSTANT1(TRACE_DISABLED_BY_DEFAULT("devtools.timeline"), "UpdateCounters", TRACE_EVENT_SCOPE_THREAD, "data", InspectorUpdateCountersEvent::data()); return result; }
v8::Local<v8::Script> V8ScriptRunner::compileScript(const ScriptSourceCode& source, v8::Isolate* isolate, AccessControlStatus corsStatus) { return compileScript(v8String(isolate, source.source()), source.url(), source.startPosition(), source.resource(), isolate, corsStatus); }
v8::Local<v8::Value> ScriptController::executeScriptAndReturnValue(v8::Local<v8::Context> context, const ScriptSourceCode& source, AccessControlStatus accessControlStatus, double* compilationFinishTime) { TRACE_EVENT1("devtools.timeline", "EvaluateScript", "data", InspectorEvaluateScriptEvent::data(frame(), source.url().string(), source.startPosition())); InspectorInstrumentation::willEvaluateScript(frame()->document()); v8::Local<v8::Value> result; { V8CacheOptions v8CacheOptions(V8CacheOptionsDefault); if (frame()->settings()) v8CacheOptions = frame()->settings()->v8CacheOptions(); // Isolate exceptions that occur when compiling and executing // the code. These exceptions should not interfere with // javascript code we might evaluate from C++ when returning // from here. v8::TryCatch tryCatch; tryCatch.SetVerbose(true); v8::Local<v8::Script> script; if (!v8Call(V8ScriptRunner::compileScript(source, isolate(), accessControlStatus, v8CacheOptions), script, tryCatch)) return result; if (compilationFinishTime) { *compilationFinishTime = WTF::monotonicallyIncreasingTime(); } // Keep LocalFrame (and therefore ScriptController) alive. RefPtrWillBeRawPtr<LocalFrame> protect(frame()); if (!v8Call(V8ScriptRunner::runCompiledScript(isolate(), script, frame()->document()), result, tryCatch)) return result; } TRACE_EVENT_INSTANT1(TRACE_DISABLED_BY_DEFAULT("devtools.timeline"), "UpdateCounters", TRACE_EVENT_SCOPE_THREAD, "data", InspectorUpdateCountersEvent::data()); return result; }
v8::MaybeLocal<v8::Script> V8ScriptRunner::compileScript(const ScriptSourceCode& source, v8::Isolate* isolate, AccessControlStatus corsStatus, V8CacheOptions cacheOptions) { if (source.source().length() >= v8::String::kMaxLength) { V8ThrowException::throwGeneralError(isolate, "Source file too large."); return v8::Local<v8::Script>(); } return compileScript(v8String(isolate, source.source()), source.url(), source.sourceMapUrl(), source.startPosition(), isolate, source.resource(), source.streamer(), source.resource() ? source.resource()->cacheHandler() : nullptr, corsStatus, cacheOptions); }