|
| 1 | +2020-10-07 Chris Dumez < [email protected]> |
| 2 | + |
| 3 | + Constructing a AudioWorkletNode should construct an AudioWorkletProcessor on the Worklet thread |
| 4 | + https://bugs.webkit.org/show_bug.cgi?id=217442 |
| 5 | + |
| 6 | + Reviewed by Geoffrey Garen. |
| 7 | + |
| 8 | + Constructing a AudioWorkletNode should construct an AudioWorkletProcessor on the Worklet thread: |
| 9 | + - https://www.w3.org/TR/webaudio/#AudioWorkletNode-constructors (Step 13) |
| 10 | + |
| 11 | + No new tests, rebaselined existing tests. |
| 12 | + |
| 13 | + * Modules/webaudio/AudioWorklet.cpp: |
| 14 | + (WebCore::AudioWorklet::createProcessor): |
| 15 | + Add createProcessor() function to AudioWorklet which takes care of hopping to the worklet thread |
| 16 | + in order to call createProcessor() on the AudioWorkletGlobalScope. |
| 17 | + |
| 18 | + * Modules/webaudio/AudioWorklet.h: |
| 19 | + |
| 20 | + * Modules/webaudio/AudioWorkletGlobalScope.cpp: |
| 21 | + (WebCore::AudioWorkletGlobalScope::createProcessor): |
| 22 | + Construct an AudioWorkletProcessor, as specified here: |
| 23 | + - https://www.w3.org/TR/webaudio/#AudioWorkletProcessor-instantiation |
| 24 | + |
| 25 | + (WebCore::AudioWorkletGlobalScope::takePendingProcessorConstructionData): |
| 26 | + A function to take the pending ProcessorConstructionData. This construction |
| 27 | + data gets initialized in createProcessor() and gets consumed by |
| 28 | + AudioWorkletProcessor::create(). |
| 29 | + |
| 30 | + * Modules/webaudio/AudioWorkletGlobalScope.h: |
| 31 | + |
| 32 | + * Modules/webaudio/AudioWorkletNode.cpp: |
| 33 | + (WebCore::AudioWorkletNode::create): |
| 34 | + Improve AudioWorkletNode constructor to actually cause the construction of |
| 35 | + the AudioWorkletProcessor on the worklet thread, passing it the options and |
| 36 | + the MessagePort. This is as per the specification here: |
| 37 | + - https://www.w3.org/TR/webaudio/#AudioWorkletNode-constructors |
| 38 | + |
| 39 | + (WebCore::AudioWorkletNode::AudioWorkletNode): |
| 40 | + (WebCore::AudioWorkletNode::~AudioWorkletNode): |
| 41 | + |
| 42 | + (WebCore::AudioWorkletNode::setProcessor): |
| 43 | + Once the AudioWorkletProcessor is created on the worklet thread, this gets |
| 44 | + called so that the AudioWorkletNode has a reference to the processor. This |
| 45 | + will be needed later on once AudioWorkletNode::process() starts doing audio |
| 46 | + processing through the AudioWorkletProcessor. |
| 47 | + |
| 48 | + (WebCore::AudioWorkletNode::process): |
| 49 | + Improve comment. |
| 50 | + |
| 51 | + * Modules/webaudio/AudioWorkletNode.h: |
| 52 | + * Modules/webaudio/AudioWorkletNode.idl: |
| 53 | + Pass the global object to the constructor. It is needed now that the constructor |
| 54 | + serializes script values to pass them to the worklet thread. |
| 55 | + |
| 56 | + * Modules/webaudio/AudioWorkletNodeOptions.idl: |
| 57 | + Add [JSGenerateToJSObject] to AudioWorkletNodeOptions dictionary so that a |
| 58 | + convertDictionaryToJS() function gets generated for this dictionary. This function |
| 59 | + is called by the AudioWorkletNode constructor. |
| 60 | + |
| 61 | + * Modules/webaudio/AudioWorkletProcessor.cpp: |
| 62 | + (WebCore::AudioWorkletProcessor::create): |
| 63 | + (WebCore::AudioWorkletProcessor::AudioWorkletProcessor): |
| 64 | + * Modules/webaudio/AudioWorkletProcessor.h: |
| 65 | + (WebCore::AudioWorkletProcessor::name const): |
| 66 | + (WebCore::AudioWorkletProcessor::port): |
| 67 | + Implement AudioWorkletProcessor constructor so that its retrieves the pending |
| 68 | + construction data from the AudioWorkletGlobalScope and properly initializes |
| 69 | + its name and port. The specification for this is here: |
| 70 | + - https://www.w3.org/TR/webaudio/#dom-audioworkletprocessor-audioworkletprocessor |
| 71 | + |
| 72 | + * Modules/webaudio/AudioWorkletProcessor.idl: |
| 73 | + Indicate that the constructor may throw an exception as per the specification: |
| 74 | + - https://www.w3.org/TR/webaudio/#dom-audioworkletprocessor-audioworkletprocessor (Step 1) |
| 75 | + Also pass the ScriptExecutionContext to the constructor since the constructor |
| 76 | + needs to retrieve the pending construction data from it: |
| 77 | + - https://www.w3.org/TR/webaudio/#dom-audioworkletprocessor-audioworkletprocessor (Step 1) |
| 78 | + |
| 79 | + * Modules/webaudio/AudioWorkletProcessorConstructionData.h: |
| 80 | + |
| 81 | + (WebCore::AudioWorkletProcessorConstructionData::AudioWorkletProcessorConstructionData): |
| 82 | + (WebCore::AudioWorkletProcessorConstructionData::name const): |
| 83 | + (WebCore::AudioWorkletProcessorConstructionData::port const): |
| 84 | + Add class to wrap the AudioWorkletProcess's construction data: |
| 85 | + - https://www.w3.org/TR/webaudio/#pending-processor-construction-data |
| 86 | + |
| 87 | + * Modules/webaudio/AudioWorkletThread.h: |
| 88 | + Move ThreadSafeRefCounted from this class to the parent class (WorkerOrWorkletThread) |
| 89 | + since WorkerMessagePortChannelProvider needs to protect a WorkerOrWorkletThread now. |
| 90 | + |
| 91 | + * WebCore.xcodeproj/project.pbxproj: |
| 92 | + Add new header to project. |
| 93 | + |
| 94 | + * bindings/js/JSDOMGlobalObject.cpp: |
| 95 | + (WebCore::toJSDOMGlobalObject): |
| 96 | + Properly handle WorkletGlobalScope. |
| 97 | + |
| 98 | + * dom/MessagePort.cpp: |
| 99 | + (WebCore::MessagePort::disentangle): |
| 100 | + (WebCore::MessagePort::disentanglePorts): |
| 101 | + (WebCore::MessagePort::entanglePorts): |
| 102 | + (WebCore::MessagePort::entangle): |
| 103 | + * dom/MessagePort.h: |
| 104 | + Tweak MessagePort API to support disentangling/entangling a single |
| 105 | + MessagePort. Previously we had to pass an array of ports. |
| 106 | + |
| 107 | + * dom/ScriptExecutionContext.cpp: |
| 108 | + (WebCore::ScriptExecutionContext::createdMessagePort): |
| 109 | + (WebCore::ScriptExecutionContext::destroyedMessagePort): |
| 110 | + Tweak assertions to handle AudioWorkletGlobalScopes. |
| 111 | + |
| 112 | + * dom/messageports/MessagePortChannelProvider.cpp: |
| 113 | + (WebCore::MessagePortChannelProvider::fromContext): |
| 114 | + * dom/messageports/MessageWithMessagePorts.h: |
| 115 | + * dom/messageports/WorkerMessagePortChannelProvider.cpp: |
| 116 | + (WebCore::WorkerMessagePortChannelProvider::WorkerMessagePortChannelProvider): |
| 117 | + (WebCore::WorkerMessagePortChannelProvider::takeAllMessagesForPort): |
| 118 | + (WebCore::WorkerMessagePortChannelProvider::checkRemotePortForActivity): |
| 119 | + * dom/messageports/WorkerMessagePortChannelProvider.h: |
| 120 | + Update WorkerMessagePortChannelProvider to use WorkerOrWorkletScope instead |
| 121 | + or WorkerGlobalScope. This allows us to reuse this class for AudioWorklets |
| 122 | + so that MessagePort communication between the main thread and the worklet |
| 123 | + thread now works. |
| 124 | + |
| 125 | + * workers/WorkerOrWorkletThread.h: |
| 126 | + Move ThreadSafeRefCounted from subclasses to this class so that |
| 127 | + WorkerMessagePortChannelProvider can protect a WorkerOrWorkletThread. |
| 128 | + |
| 129 | + * workers/WorkerThread.h: |
| 130 | + * worklets/WorkletGlobalScope.cpp: |
| 131 | + (WebCore::WorkletGlobalScope::notifyFinished): |
| 132 | + Only evaluate the script if we have not already evaluated it in this worklet. |
| 133 | + I am assuming this is needed because we are not treating the script as a module |
| 134 | + yet (due to lack of support in workers). Without this changes, the worklet's |
| 135 | + script would get in a bad state when importing several times the same module |
| 136 | + (which is something the WPT tests do). |
| 137 | + |
| 138 | + (WebCore::WorkletGlobalScope::messagePortChannelProvider): |
| 139 | + Instantiate WorkerMessagePortChannelProvider if needed. This is needed for |
| 140 | + MessagePort communication is AudioWorklets. |
| 141 | + |
| 142 | + * worklets/WorkletGlobalScope.h: |
| 143 | + |
1 | 144 | 2020-10-07 Chris Dumez < [email protected]>
|
2 | 145 |
|
3 | 146 | Crash under JSAudioWorkletProcessorConstructor::~JSAudioWorkletProcessorConstructor()
|
|
0 commit comments