Skip to content

Commit

Permalink
Revert of Revert of ServiceWorker: throw when close() or terminate() …
Browse files Browse the repository at this point in the history
…called (patchset #1 of https://codereview.chromium.org/515323002/)

Reason for revert:
The CL reverted by this patchset was not responsible for the breakage. Re-landing.

Original issue's description:
> Revert of ServiceWorker: throw when close() or terminate() called (patchset #3 of https://codereview.chromium.org/505063002/)
> 
> Reason for revert:
> Break compilation on various bots. Maybe Win only.
> 
> Original issue's description:
> > ServiceWorker: throw when close() or terminate() called
> > 
> > Per spec:
> > * ServiceWorker#terminate() should throw InvalidAccessError
> > * ServiceWorkerGlobalScope#close() should throw InvalidAccessError
> > 
> > ... since the behaviors inherited from the base interfaces are not
> > supported.
> > 
> > Spec: slightlyoff.github.io/ServiceWorker/spec/service_worker/index.html
> > 
> > BUG=398318
> > 
> > Committed: https://src.chromium.org/viewvc/blink?view=rev&revision=181049
> 
> [email protected],[email protected]
> NOTREECHECKS=true
> NOTRY=true
> BUG=398318
> 
> Committed: https://src.chromium.org/viewvc/blink?view=rev&revision=181050

[email protected],[email protected]
NOTREECHECKS=true
NOTRY=true
BUG=398318

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

git-svn-id: svn://svn.chromium.org/blink/trunk@181057 bbb929c8-8fbe-4397-9dbb-9b2b20218538
  • Loading branch information
inexorabletash committed Aug 28, 2014
1 parent 18b6af9 commit 5547e68
Show file tree
Hide file tree
Showing 13 changed files with 76 additions and 7 deletions.
1 change: 1 addition & 0 deletions LayoutTests/http/tests/serviceworker/interfaces.html
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
{
scriptURL: 'string',
state: 'string',
terminate: 'function',
onstatechange: EVENT_HANDLER
});
return registration.unregister();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ self.onmessage = function(e) {

function quit(port) {
port.postMessage('quit');
self.close();
}

function doFetchTwiceTest(port) {
Expand Down Expand Up @@ -92,4 +91,4 @@ function doTextTest(port) {
doJSONTest(port);
});
});
}
}
17 changes: 12 additions & 5 deletions LayoutTests/http/tests/serviceworker/resources/fetch-worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,19 @@ var testTargets = [
];

function doNextFetchTest(port) {

function runInfiniteFetchLoop() {
fetch('dummy.html')
.then(function() { runInfiniteFetchLoop(); });
}

if (testTargets.length == 0) {
port.postMessage('quit');
// Destroying the execution context while fetch is happening should not cause a crash.
fetch('dummy.html').then(function() {}).catch(function() {});
self.close();
return;
// Destroying the execution context while fetch is happening
// should not cause a crash.
runInfiniteFetchLoop();

port.postMessage('quit');
return;
}
var target = testTargets.shift();
fetch(target)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ test(function() {
{
scope: 'string',
clients: 'object',
close: 'function',

onactivate: EVENT_HANDLER,
onfetch: EVENT_HANDLER,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
importScripts('interfaces.js');
importScripts('worker-test-harness.js');

test(function() {
assert_throws({name: 'InvalidAccessError'}, function() {
self.close();
});
}, 'ServiceWorkerGlobalScope close operation');
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<!DOCTYPE html>
<title>ServiceWorkerGlobalScope: close operation</title>
<script src="../resources/testharness.js"></script>
<script src="../resources/testharnessreport.js"></script>
<script src="resources/test-helpers.js"></script>
<script>

service_worker_test(
'resources/serviceworkerglobalscope-close-worker.js',
'ServiceWorkerGlobalScope: close operation');

</script>
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<!DOCTYPE html>
<title>ServiceWorker object: terminate operation</title>
<script src="../resources/testharness.js"></script>
<script src="../resources/testharnessreport.js"></script>
<script src="resources/test-helpers.js"></script>
<script>

async_test(function(t) {
var worker = 'resources/empty-worker.js';
var scope = 'resources/blank.html';
service_worker_unregister_and_register(t, worker, scope)
.then(t.step_func(function(registration) {
return wait_for_update(t, registration);
}))
.then(t.step_func(function(worker) {
assert_throws({name: 'InvalidAccessError'}, function() {
worker.terminate();
});
return service_worker_unregister_and_done(t, scope);
}))
.catch(t.step_func(function(e) { throw e; }));
}, 'Verify the terminate operation');

</script>
5 changes: 5 additions & 0 deletions Source/modules/serviceworkers/ServiceWorker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,11 @@ void ServiceWorker::postMessage(ExecutionContext*, PassRefPtr<SerializedScriptVa
m_outerWorker->postMessage(messageString, webChannels.leakPtr());
}

void ServiceWorker::terminate(ExceptionState& exceptionState)
{
exceptionState.throwDOMException(InvalidAccessError, "Not supported.");
}

bool ServiceWorker::isReady()
{
return m_proxyState == Ready;
Expand Down
1 change: 1 addition & 0 deletions Source/modules/serviceworkers/ServiceWorker.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ class ServiceWorker FINAL : public AbstractWorker, public WebServiceWorkerProxy
static void dispose(WebType*);

void postMessage(ExecutionContext*, PassRefPtr<SerializedScriptValue> message, const MessagePortArray*, ExceptionState&);
void terminate(ExceptionState&);

String scriptURL() const;
const AtomicString& state() const;
Expand Down
2 changes: 2 additions & 0 deletions Source/modules/serviceworkers/ServiceWorker.idl
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ enum ServiceWorkerState {
// FIXME: Should inherit this from Worker.
[Custom, RaisesException] void postMessage(SerializedScriptValue message, optional sequence<Transferable> transfer);

[RaisesException] void terminate();

readonly attribute ScalarValueString scriptURL;
readonly attribute ServiceWorkerState state;

Expand Down
5 changes: 5 additions & 0 deletions Source/modules/serviceworkers/ServiceWorkerGlobalScope.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,11 @@ PassRefPtrWillBeRawPtr<ServiceWorkerClients> ServiceWorkerGlobalScope::clients()
return m_clients;
}

void ServiceWorkerGlobalScope::close(ExceptionState& exceptionState)
{
exceptionState.throwDOMException(InvalidAccessError, "Not supported.");
}

const AtomicString& ServiceWorkerGlobalScope::interfaceName() const
{
return EventTargetNames::ServiceWorkerGlobalScope;
Expand Down
2 changes: 2 additions & 0 deletions Source/modules/serviceworkers/ServiceWorkerGlobalScope.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ class ServiceWorkerGlobalScope FINAL : public WorkerGlobalScope {
ScriptPromise fetch(ScriptState*, const String&);
ScriptPromise fetch(ScriptState*, const String&, const Dictionary&);

void close(ExceptionState&);

// EventTarget
virtual const AtomicString& interfaceName() const OVERRIDE;

Expand Down
2 changes: 2 additions & 0 deletions Source/modules/serviceworkers/ServiceWorkerGlobalScope.idl
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@
[CallWith=ScriptState] Promise fetch(DOMString request, optional Dictionary requestInitDict);
[CallWith=ScriptState] Promise fetch(Request request, optional Dictionary requestInitDict);

[RaisesException] void close();

attribute EventHandler onactivate;
attribute EventHandler onfetch;
attribute EventHandler oninstall;
Expand Down

0 comments on commit 5547e68

Please sign in to comment.