Bug 1504464 - Part 5: Fix destructuring behavior in ReadableStream.prototype.getReader. r=jwalden

The section headers in the spec that look like JS destructuring are in fact
normative. The methods have to behave just like JS destructuring; see
<https://streams.spec.whatwg.org/#conventions> for details.

This means the getReader method
<https://streams.spec.whatwg.org/#rs-get-reader> must do a full property Get
for options.mode, even if that means querying %ObjectPrototype%, absurd as it
sounds.

Differential Revision: https://phabricator.services.mozilla.com/D14503

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Jason Orendorff 2019-01-14 20:33:01 +00:00
parent 14e641c6a6
commit 52a5376097

View File

@ -677,11 +677,25 @@ CreateReadableStreamDefaultReader(
HandleObject proto = nullptr);
/**
* Streams spec, 3.2.5.3. getReader()
* Streams spec, 3.2.5.3. getReader({ mode } = {})
*/
static bool ReadableStream_getReader(JSContext* cx, unsigned argc, Value* vp) {
CallArgs args = CallArgsFromVp(argc, vp);
// Implicit in the spec: Argument defaults and destructuring.
RootedValue optionsVal(cx, args.get(0));
if (optionsVal.isUndefined()) {
JSObject* emptyObj = NewBuiltinClassInstance<PlainObject>(cx);
if (!emptyObj) {
return false;
}
optionsVal.setObject(*emptyObj);
}
RootedValue modeVal(cx);
if (!GetProperty(cx, optionsVal, cx->names().mode, &modeVal)) {
return false;
}
// Step 1: If ! IsReadableStream(this) is false, throw a TypeError exception.
Rooted<ReadableStream*> unwrappedStream(
cx, UnwrapAndTypeCheckThis<ReadableStream>(cx, args, "getReader"));
@ -689,18 +703,9 @@ static bool ReadableStream_getReader(JSContext* cx, unsigned argc, Value* vp) {
return false;
}
RootedObject reader(cx);
// Step 2: If mode is undefined, return
// ? AcquireReadableStreamDefaultReader(this).
RootedValue modeVal(cx);
HandleValue optionsVal = args.get(0);
if (!optionsVal.isUndefined()) {
if (!GetProperty(cx, optionsVal, cx->names().mode, &modeVal)) {
return false;
}
}
RootedObject reader(cx);
if (modeVal.isUndefined()) {
reader = CreateReadableStreamDefaultReader(cx, unwrappedStream,
ForAuthorCodeBool::Yes);