Commit 836f22e6 authored by nhiroki@chromium.org's avatar nhiroki@chromium.org

ServiceWorker: Registering a malformed script should fail [1/3]

Before this series of patches, registration succeeds even if the worker script
has a syntax error because the installing sequence does not check the result of
the script evaluation.

To enable the installing sequence to wait for the script evaluation, this adds
WorkerReportingProxy::didEvaluteWorkerScript() to be called when the
evaluation is completed and to propagate the result up to the Chromium-side.

Patch dependency:
[1] Blink: THIS PATCH
[2] Chromium: https://codereview.chromium.org/697593002/
[3] Blink: https://codereview.chromium.org/697833004/

BUG=426344
TEST=compile (test will be added by [3])

Review URL: https://codereview.chromium.org/692003002

git-svn-id: svn://svn.chromium.org/blink/trunk@184854 bbb929c8-8fbe-4397-9dbb-9b2b20218538
parent b411b603
......@@ -238,10 +238,10 @@ ScriptValue WorkerScriptController::evaluate(const String& script, const String&
return ScriptValue(m_scriptState.get(), result);
}
void WorkerScriptController::evaluate(const ScriptSourceCode& sourceCode, RefPtrWillBeRawPtr<ErrorEvent>* errorEvent)
bool WorkerScriptController::evaluate(const ScriptSourceCode& sourceCode, RefPtrWillBeRawPtr<ErrorEvent>* errorEvent)
{
if (isExecutionForbidden())
return;
return false;
WorkerGlobalScopeExecutionState state(this);
evaluate(sourceCode.source(), sourceCode.url().string(), sourceCode.startPosition());
......@@ -250,7 +250,7 @@ void WorkerScriptController::evaluate(const ScriptSourceCode& sourceCode, RefPtr
if (state.m_errorEventFromImportedScript) {
// Propagate inner error event outwards.
*errorEvent = state.m_errorEventFromImportedScript.release();
return;
return false;
}
if (m_workerGlobalScope.shouldSanitizeScriptError(state.sourceURL, NotSharableCrossOrigin))
*errorEvent = ErrorEvent::createSanitizedError(m_world.get());
......@@ -266,7 +266,9 @@ void WorkerScriptController::evaluate(const ScriptSourceCode& sourceCode, RefPtr
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::scheduleExecutionTermination()
......
......@@ -52,7 +52,9 @@ public:
bool isExecutionForbidden() const;
bool isExecutionTerminating() const;
void evaluate(const ScriptSourceCode&, RefPtrWillBeRawPtr<ErrorEvent>* = 0);
// Returns true if the evaluation completed with no uncaught exception.
bool evaluate(const ScriptSourceCode&, RefPtrWillBeRawPtr<ErrorEvent>* = 0);
// Prevents future JavaScript execution. See
// scheduleExecutionTermination, isExecutionForbidden.
......
......@@ -63,6 +63,7 @@ public:
virtual void reportException(const String& errorMessage, int lineNumber, int columnNumber, const String& sourceURL) override;
virtual void reportConsoleMessage(PassRefPtrWillBeRawPtr<ConsoleMessage>) override;
virtual void postMessageToPageInspector(const String&) override;
virtual void didEvaluateWorkerScript(bool success) override { };
virtual void workerGlobalScopeStarted(WorkerGlobalScope*) override { }
virtual void workerGlobalScopeClosed() override;
virtual void workerThreadTerminated() override;
......
......@@ -40,7 +40,7 @@ namespace blink {
class ConsoleMessage;
class WorkerGlobalScope;
// APIs used by workers to report console activity.
// APIs used by workers to report console and worker activity.
class WorkerReportingProxy {
public:
virtual ~WorkerReportingProxy() { }
......@@ -49,6 +49,10 @@ public:
virtual void reportConsoleMessage(PassRefPtrWillBeRawPtr<ConsoleMessage>) = 0;
virtual void postMessageToPageInspector(const String&) = 0;
// Invoked when the worker script is evaluated. |success| is true if the
// evaluation completed with no uncaught exception.
virtual void didEvaluateWorkerScript(bool success) = 0;
// Invoked when the new WorkerGlobalScope is started.
virtual void workerGlobalScopeStarted(WorkerGlobalScope*) = 0;
......
......@@ -320,8 +320,9 @@ void WorkerThread::initialize()
if (!script->isExecutionForbidden())
script->initializeContextIfNeeded();
InspectorInstrumentation::willEvaluateWorkerScript(workerGlobalScope(), startMode);
script->evaluate(ScriptSourceCode(sourceCode, scriptURL));
bool success = script->evaluate(ScriptSourceCode(sourceCode, scriptURL));
m_workerGlobalScope->didEvaluateWorkerScript();
m_workerReportingProxy.didEvaluateWorkerScript(success);
postInitialize();
......
......@@ -143,6 +143,11 @@ void ServiceWorkerGlobalScopeProxy::postMessageToPageInspector(const String& mes
m_document.postInspectorTask(createCrossThreadTask(&WebEmbeddedWorkerImpl::postMessageToPageInspector, &m_embeddedWorker, message));
}
void ServiceWorkerGlobalScopeProxy::didEvaluateWorkerScript(bool success)
{
m_client.didEvaluateWorkerScript(success);
}
void ServiceWorkerGlobalScopeProxy::workerGlobalScopeStarted(WorkerGlobalScope* workerGlobalScope)
{
ASSERT(!m_workerGlobalScope);
......
......@@ -80,6 +80,7 @@ public:
virtual void reportException(const String& errorMessage, int lineNumber, int columnNumber, const String& sourceURL) override;
virtual void reportConsoleMessage(PassRefPtrWillBeRawPtr<ConsoleMessage>) override;
virtual void postMessageToPageInspector(const String&) override;
virtual void didEvaluateWorkerScript(bool success) override;
virtual void workerGlobalScopeStarted(WorkerGlobalScope*) override;
virtual void workerGlobalScopeClosed() override;
virtual void willDestroyWorkerGlobalScope() override;
......
......@@ -75,6 +75,7 @@ public:
const WTF::String&, int, int, const WTF::String&) override;
virtual void reportConsoleMessage(PassRefPtrWillBeRawPtr<ConsoleMessage>) override;
virtual void postMessageToPageInspector(const WTF::String&) override;
virtual void didEvaluateWorkerScript(bool success) override { };
virtual void workerGlobalScopeStarted(WorkerGlobalScope*) override;
virtual void workerGlobalScopeClosed() override;
virtual void workerThreadTerminated() override;
......
......@@ -94,6 +94,10 @@ public:
// This is called on the main thread.
virtual void workerContextFailedToStart() { }
// Called when the worker script is evaluated. |success| is true if the
// evaluation completed with no uncaught exception.
virtual void didEvaluateWorkerScript(bool success) { }
// Called when the WorkerGlobalScope had an error or an exception.
virtual void reportException(const WebString& errorMessage, int lineNumber, int columnNumber, const WebString& sourceURL) { }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment