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