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& ...@@ -238,10 +238,10 @@ ScriptValue WorkerScriptController::evaluate(const String& script, const String&
return ScriptValue(m_scriptState.get(), result); 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()) if (isExecutionForbidden())
return; return false;
WorkerGlobalScopeExecutionState state(this); WorkerGlobalScopeExecutionState state(this);
evaluate(sourceCode.source(), sourceCode.url().string(), sourceCode.startPosition()); evaluate(sourceCode.source(), sourceCode.url().string(), sourceCode.startPosition());
...@@ -250,7 +250,7 @@ void WorkerScriptController::evaluate(const ScriptSourceCode& sourceCode, RefPtr ...@@ -250,7 +250,7 @@ void WorkerScriptController::evaluate(const ScriptSourceCode& sourceCode, RefPtr
if (state.m_errorEventFromImportedScript) { if (state.m_errorEventFromImportedScript) {
// Propagate inner error event outwards. // Propagate inner error event outwards.
*errorEvent = state.m_errorEventFromImportedScript.release(); *errorEvent = state.m_errorEventFromImportedScript.release();
return; return false;
} }
if (m_workerGlobalScope.shouldSanitizeScriptError(state.sourceURL, NotSharableCrossOrigin)) if (m_workerGlobalScope.shouldSanitizeScriptError(state.sourceURL, NotSharableCrossOrigin))
*errorEvent = ErrorEvent::createSanitizedError(m_world.get()); *errorEvent = ErrorEvent::createSanitizedError(m_world.get());
...@@ -266,7 +266,9 @@ void WorkerScriptController::evaluate(const ScriptSourceCode& sourceCode, RefPtr ...@@ -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()); event = ErrorEvent::create(state.errorMessage, state.sourceURL, state.lineNumber, state.columnNumber, m_world.get());
m_workerGlobalScope.reportException(event, 0, nullptr, NotSharableCrossOrigin); m_workerGlobalScope.reportException(event, 0, nullptr, NotSharableCrossOrigin);
} }
return false;
} }
return true;
} }
void WorkerScriptController::scheduleExecutionTermination() void WorkerScriptController::scheduleExecutionTermination()
......
...@@ -52,7 +52,9 @@ public: ...@@ -52,7 +52,9 @@ public:
bool isExecutionForbidden() const; bool isExecutionForbidden() const;
bool isExecutionTerminating() 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 // Prevents future JavaScript execution. See
// scheduleExecutionTermination, isExecutionForbidden. // scheduleExecutionTermination, isExecutionForbidden.
......
...@@ -63,6 +63,7 @@ public: ...@@ -63,6 +63,7 @@ public:
virtual void reportException(const String& errorMessage, int lineNumber, int columnNumber, const String& sourceURL) override; virtual void reportException(const String& errorMessage, int lineNumber, int columnNumber, const String& sourceURL) override;
virtual void reportConsoleMessage(PassRefPtrWillBeRawPtr<ConsoleMessage>) override; virtual void reportConsoleMessage(PassRefPtrWillBeRawPtr<ConsoleMessage>) override;
virtual void postMessageToPageInspector(const String&) override; virtual void postMessageToPageInspector(const String&) override;
virtual void didEvaluateWorkerScript(bool success) override { };
virtual void workerGlobalScopeStarted(WorkerGlobalScope*) override { } virtual void workerGlobalScopeStarted(WorkerGlobalScope*) override { }
virtual void workerGlobalScopeClosed() override; virtual void workerGlobalScopeClosed() override;
virtual void workerThreadTerminated() override; virtual void workerThreadTerminated() override;
......
...@@ -40,7 +40,7 @@ namespace blink { ...@@ -40,7 +40,7 @@ namespace blink {
class ConsoleMessage; class ConsoleMessage;
class WorkerGlobalScope; class WorkerGlobalScope;
// APIs used by workers to report console activity. // APIs used by workers to report console and worker activity.
class WorkerReportingProxy { class WorkerReportingProxy {
public: public:
virtual ~WorkerReportingProxy() { } virtual ~WorkerReportingProxy() { }
...@@ -49,6 +49,10 @@ public: ...@@ -49,6 +49,10 @@ public:
virtual void reportConsoleMessage(PassRefPtrWillBeRawPtr<ConsoleMessage>) = 0; virtual void reportConsoleMessage(PassRefPtrWillBeRawPtr<ConsoleMessage>) = 0;
virtual void postMessageToPageInspector(const String&) = 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. // Invoked when the new WorkerGlobalScope is started.
virtual void workerGlobalScopeStarted(WorkerGlobalScope*) = 0; virtual void workerGlobalScopeStarted(WorkerGlobalScope*) = 0;
......
...@@ -320,8 +320,9 @@ void WorkerThread::initialize() ...@@ -320,8 +320,9 @@ void WorkerThread::initialize()
if (!script->isExecutionForbidden()) if (!script->isExecutionForbidden())
script->initializeContextIfNeeded(); script->initializeContextIfNeeded();
InspectorInstrumentation::willEvaluateWorkerScript(workerGlobalScope(), startMode); InspectorInstrumentation::willEvaluateWorkerScript(workerGlobalScope(), startMode);
script->evaluate(ScriptSourceCode(sourceCode, scriptURL)); bool success = script->evaluate(ScriptSourceCode(sourceCode, scriptURL));
m_workerGlobalScope->didEvaluateWorkerScript(); m_workerGlobalScope->didEvaluateWorkerScript();
m_workerReportingProxy.didEvaluateWorkerScript(success);
postInitialize(); postInitialize();
......
...@@ -143,6 +143,11 @@ void ServiceWorkerGlobalScopeProxy::postMessageToPageInspector(const String& mes ...@@ -143,6 +143,11 @@ void ServiceWorkerGlobalScopeProxy::postMessageToPageInspector(const String& mes
m_document.postInspectorTask(createCrossThreadTask(&WebEmbeddedWorkerImpl::postMessageToPageInspector, &m_embeddedWorker, message)); m_document.postInspectorTask(createCrossThreadTask(&WebEmbeddedWorkerImpl::postMessageToPageInspector, &m_embeddedWorker, message));
} }
void ServiceWorkerGlobalScopeProxy::didEvaluateWorkerScript(bool success)
{
m_client.didEvaluateWorkerScript(success);
}
void ServiceWorkerGlobalScopeProxy::workerGlobalScopeStarted(WorkerGlobalScope* workerGlobalScope) void ServiceWorkerGlobalScopeProxy::workerGlobalScopeStarted(WorkerGlobalScope* workerGlobalScope)
{ {
ASSERT(!m_workerGlobalScope); ASSERT(!m_workerGlobalScope);
......
...@@ -80,6 +80,7 @@ public: ...@@ -80,6 +80,7 @@ public:
virtual void reportException(const String& errorMessage, int lineNumber, int columnNumber, const String& sourceURL) override; virtual void reportException(const String& errorMessage, int lineNumber, int columnNumber, const String& sourceURL) override;
virtual void reportConsoleMessage(PassRefPtrWillBeRawPtr<ConsoleMessage>) override; virtual void reportConsoleMessage(PassRefPtrWillBeRawPtr<ConsoleMessage>) override;
virtual void postMessageToPageInspector(const String&) override; virtual void postMessageToPageInspector(const String&) override;
virtual void didEvaluateWorkerScript(bool success) override;
virtual void workerGlobalScopeStarted(WorkerGlobalScope*) override; virtual void workerGlobalScopeStarted(WorkerGlobalScope*) override;
virtual void workerGlobalScopeClosed() override; virtual void workerGlobalScopeClosed() override;
virtual void willDestroyWorkerGlobalScope() override; virtual void willDestroyWorkerGlobalScope() override;
......
...@@ -75,6 +75,7 @@ public: ...@@ -75,6 +75,7 @@ public:
const WTF::String&, int, int, const WTF::String&) override; const WTF::String&, int, int, const WTF::String&) override;
virtual void reportConsoleMessage(PassRefPtrWillBeRawPtr<ConsoleMessage>) override; virtual void reportConsoleMessage(PassRefPtrWillBeRawPtr<ConsoleMessage>) override;
virtual void postMessageToPageInspector(const WTF::String&) override; virtual void postMessageToPageInspector(const WTF::String&) override;
virtual void didEvaluateWorkerScript(bool success) override { };
virtual void workerGlobalScopeStarted(WorkerGlobalScope*) override; virtual void workerGlobalScopeStarted(WorkerGlobalScope*) override;
virtual void workerGlobalScopeClosed() override; virtual void workerGlobalScopeClosed() override;
virtual void workerThreadTerminated() override; virtual void workerThreadTerminated() override;
......
...@@ -94,6 +94,10 @@ public: ...@@ -94,6 +94,10 @@ public:
// This is called on the main thread. // This is called on the main thread.
virtual void workerContextFailedToStart() { } 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. // Called when the WorkerGlobalScope had an error or an exception.
virtual void reportException(const WebString& errorMessage, int lineNumber, int columnNumber, const WebString& sourceURL) { } 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