Source code
Revision control
Copy as Markdown
Other Tools
Test Info:
- This WPT test may be referenced by the following Test IDs:
- /streams/writable-streams/properties.any.html - WPT Dashboard Interop Dashboard
- /streams/writable-streams/properties.any.serviceworker.html - WPT Dashboard Interop Dashboard
- /streams/writable-streams/properties.any.shadowrealm-in-dedicatedworker.html - WPT Dashboard Interop Dashboard
- /streams/writable-streams/properties.any.shadowrealm-in-shadowrealm.html - WPT Dashboard Interop Dashboard
- /streams/writable-streams/properties.any.shadowrealm-in-sharedworker.html - WPT Dashboard Interop Dashboard
- /streams/writable-streams/properties.any.shadowrealm-in-window.html - WPT Dashboard Interop Dashboard
- /streams/writable-streams/properties.any.sharedworker.html - WPT Dashboard Interop Dashboard
- /streams/writable-streams/properties.any.worker.html - WPT Dashboard Interop Dashboard
- /streams/writable-streams/properties.https.any.shadowrealm-in-audioworklet.html - WPT Dashboard Interop Dashboard
- /streams/writable-streams/properties.https.any.shadowrealm-in-serviceworker.html - WPT Dashboard Interop Dashboard
// META: global=window,worker,shadowrealm
'use strict';
const sinkMethods = {
start: {
length: 1,
trigger: () => Promise.resolve()
},
write: {
length: 2,
trigger: writer => writer.write()
},
close: {
length: 0,
trigger: writer => writer.close()
},
abort: {
length: 1,
trigger: writer => writer.abort()
}
};
for (const method in sinkMethods) {
const { length, trigger } = sinkMethods[method];
// Some semantic tests of how sink methods are called can be found in general.js, as well as in the test files
// specific to each method.
promise_test(() => {
let argCount;
const ws = new WritableStream({
[method](...args) {
argCount = args.length;
}
});
return Promise.resolve(trigger(ws.getWriter())).then(() => {
assert_equals(argCount, length, `${method} should be called with ${length} arguments`);
});
}, `sink method ${method} should be called with the right number of arguments`);
promise_test(() => {
let methodWasCalled = false;
function Sink() {}
Sink.prototype = {
[method]() {
methodWasCalled = true;
}
};
const ws = new WritableStream(new Sink());
return Promise.resolve(trigger(ws.getWriter())).then(() => {
assert_true(methodWasCalled, `${method} should be called`);
});
}, `sink method ${method} should be called even when it's located on the prototype chain`);
}