Commit afc2a8c1 authored by rtoy's avatar rtoy Committed by Commit bot

Move close() from BaseAudioContext to AudioContext

OfflineAudioContext cannot be closed so it makes more sense to have
close() be defined on AudioContext instead of BaseAudioContext.

This is a very minor tweak to the API, so no Blink intent submitted.

Spec issue: https://github.com/WebAudio/web-audio-api/issues/948
Resolved:   https://github.com/WebAudio/web-audio-api/issues/974
Chrome feature: https://www.chromestatus.com/feature/5683205155848192

BUG=647261
TEST=audiocontext-close.html

Review-Url: https://codereview.chromium.org/2345693002
Cr-Commit-Position: refs/heads/master@{#419244}
parent 7e41d4be
......@@ -125,6 +125,7 @@ interface AudioBufferSourceNode : AudioSourceNode
setter onended
interface AudioContext : BaseAudioContext
attribute @@toStringTag
method close
method constructor
interface AudioDestinationNode : AudioNode
attribute @@toStringTag
......@@ -6236,6 +6237,7 @@ interface XSLTProcessor
method transformToFragment
interface webkitAudioContext : BaseAudioContext
attribute @@toStringTag
method close
method constructor
interface webkitIDBCursor
attribute @@toStringTag
......
......@@ -33,10 +33,7 @@ PASS Closing context again correctly rejected promise.
PASS context.destination is null
PASS offline = new OfflineAudioContext(1, 1000, 48000) did not throw exception.
PASS offline.state is "suspended"
PASS Closing offline context correctly rejected: InvalidAccessError: cannot close an OfflineAudioContext.
PASS Closing offline context again correctly rejected
PASS offline.startRendering() did not throw exception.
PASS event.target.state is "closed"
PASS offline.close is undefined.
PASS successfullyParsed is true
TEST COMPLETE
......
......@@ -114,47 +114,11 @@
// Task: test offline context (1).
audit.defineTask('test-offline-context-1', function (done) {
// For an offline context, just check that if we try to close the context,
// nothing happens except that the promise returned by close() is rejected.
// For an offline context, verify that close is not defined.
shouldNotThrow("offline = new OfflineAudioContext(1, 1000, 48000)");
shouldBeEqualToString("offline.state", "suspended");
offline.close().then(
function () {
testFailed("Closing offline context erroneously resolved");
},
function (e) {
if (e.name === "InvalidAccessError") {
testPassed("Closing offline context correctly rejected: " + e);
} else {
testFailed("Closing offline context correctly rejected but expected InvalidAccessError, not: " + e);
}
}
).then(done);
});
// Task: test offline context (2).
audit.defineTask('test-offline-context-2', function (done) {
// Try closing again
offline.close().then(
function () {
testFailed("Closing offline context again erroneously resolved");
},
function () {
testPassed("Closing offline context again correctly rejected");
}
).then(
function () {
// Render the context, and check for a valid state
offline.oncomplete = function (event) {
shouldBeEqualToString("event.target.state", "closed");
done();
};
shouldNotThrow("offline.startRendering()");
}
);
shouldBeUndefined("offline.close");
done();
});
audit.defineTask('finish-test', function (done) {
......@@ -162,14 +126,7 @@
finishJSTest();
});
audit.runTasks(
'test-online-context-1',
'test-online-context-2',
'test-online-context-3',
'test-offline-context-1',
'test-offline-context-2',
'finish-test'
);
audit.runTasks();
successfullyParsed = true;
</script>
......
......@@ -160,6 +160,7 @@ interface AudioBufferSourceNode : AudioSourceNode
setter onended
interface AudioContext : BaseAudioContext
attribute @@toStringTag
method close
method constructor
interface AudioDestinationNode : AudioNode
attribute @@toStringTag
......@@ -7374,6 +7375,7 @@ interface XSLTProcessor
method transformToFragment
interface webkitAudioContext : BaseAudioContext
attribute @@toStringTag
method close
method constructor
interface webkitIDBCursor
attribute @@toStringTag
......
......@@ -26,7 +26,7 @@ public:
~AudioContext() override;
DECLARE_VIRTUAL_TRACE();
ScriptPromise closeContext(ScriptState*) final;
ScriptPromise closeContext(ScriptState*);
bool isContextClosed() const final;
ScriptPromise suspendContext(ScriptState*) final;
......
......@@ -32,6 +32,9 @@
NoInterfaceObject,
RaisesException=Constructor,
] interface AudioContext : BaseAudioContext {
// Close
[MeasureAs=AudioContextClose, CallWith=ScriptState, ImplementedAs=closeContext] Promise<void> close();
// Sources
// TODO(rtoy): The following methods should be here instead of in BaseAudioContext:
//
......
......@@ -176,9 +176,6 @@ public:
PeriodicWave* createPeriodicWave(DOMFloat32Array* real, DOMFloat32Array* imag, ExceptionState&);
PeriodicWave* createPeriodicWave(DOMFloat32Array* real, DOMFloat32Array* imag, const PeriodicWaveConstraints&, ExceptionState&);
// Close
virtual ScriptPromise closeContext(ScriptState*) = 0;
// Suspend
virtual ScriptPromise suspendContext(ScriptState*) = 0;
......
......@@ -56,9 +56,6 @@ enum AudioContextState {
[RaisesException, MeasureAs=AudioContextCreateChannelSplitter] ChannelSplitterNode createChannelSplitter(optional unsigned long numberOfOutputs);
[RaisesException, MeasureAs=AudioContextCreateChannelMerger] ChannelMergerNode createChannelMerger(optional unsigned long numberOfInputs);
// Close
[MeasureAs=AudioContextClose, CallWith=ScriptState, ImplementedAs=closeContext] Promise<void> close();
// Pause/resume
[MeasureAs=AudioContextSuspend, CallWith=ScriptState, ImplementedAs=suspendContext] Promise<void> suspend();
[MeasureAs=AudioContextResume, CallWith=ScriptState, ImplementedAs=resumeContext] Promise<void> resume();
......
......@@ -199,15 +199,6 @@ ScriptPromise OfflineAudioContext::startOfflineRendering(ScriptState* scriptStat
return m_completeResolver->promise();
}
ScriptPromise OfflineAudioContext::closeContext(ScriptState* scriptState)
{
return ScriptPromise::rejectWithDOMException(
scriptState,
DOMException::create(
InvalidAccessError,
"cannot close an OfflineAudioContext."));
}
ScriptPromise OfflineAudioContext::suspendContext(ScriptState* scriptState)
{
// This CANNOT be called on OfflineAudioContext; this is only to implement
......
......@@ -47,7 +47,6 @@ public:
ScriptPromise startOfflineRendering(ScriptState*);
ScriptPromise closeContext(ScriptState*) final;
ScriptPromise suspendContext(ScriptState*, double);
ScriptPromise resumeContext(ScriptState*) final;
......
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