WebAudio / web-audio-api

The Web Audio API v1.0, developed by the W3C Audio WG
https://webaudio.github.io/web-audio-api/
Other
1.05k stars 167 forks source link

AudioWorkletNode options serialization is underdefined #1971

Closed bzbarsky closed 5 years ago

bzbarsky commented 5 years ago

https://webaudio.github.io/web-audio-api/#instantiation-of-AudioWorkletNode-and-AudioWorkletProcessor step 7 says:

Let optionsSerialization be the result of StructuredSerialize(options).

But at this point options is an IDL dictionary (in particular an AudioWorkletNodeOptions), while StructuredSerialize takes as input an IDL value, not an ES value. It's not 100% clear where this ES value should come from. Possible options are:

1) The original ES object the AudioWorkletNodeOptions was created from. This is not generally available from a dictionary, though. 2) A new ES object derived by calling https://heycam.github.io/webidl/#dictionary-to-es in the current global. 3) A new ES object derived by calling https://heycam.github.io/webidl/#dictionary-to-es in a clean new global.

These are all observably different from each other when proxies and getters on Object.prototype are involved.

The spec should really define what happens here, and there should be tests for the behavior.

@karlt

hoch commented 5 years ago

What's the difference between the option 2 and 3? How do you specify the target global in the algorithm?

bzbarsky commented 5 years ago

What's the difference between the option 2 and 3?

Hmm. I guess what we are doing with the resulting object is structured cloning it, not converting it back to a dictionary, so maybe there is no difference in practice, because structured cloning is never affected by the prototype, right? (This claim needs to be carefully double-checked!)

If that's correct, then we can just use https://heycam.github.io/webidl/#dictionary-to-es as-is; it picks up the global from the ambient "current Realm" state, which should be fine here.

hoch commented 5 years ago

not converting it back to a dictionary

Yes. It's just an intermediate step for the post-messaging.

bzbarsky commented 5 years ago

Note that someone still needs to:

1) Carefully double-check that structured cloning ignores prototypes. 2) Add a test where there are relevant properties on Object.prototype, an Object.create(null) is passed as the dictionary, and the test checks that those properties don't pop out on the far end.

padenot commented 5 years ago
  1. https://html.spec.whatwg.org/multipage/structured-data.html#safe-passing-of-structured-data does not copy the prototype (this is corroborated by other higher level documents on the web).
  2. https://github.com/web-platform-tests/wpt/issues/17883
hoch commented 5 years ago

Thanks for the verification @padenot! Per last 2 comments above, I think we can merge #1996.