mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-24 02:35:41 +00:00
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:
parent
14e641c6a6
commit
52a5376097
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user