-
Notifications
You must be signed in to change notification settings - Fork 609
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: convert HeadersInit to sequence/dictionary correctly #2784
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -218,7 +218,7 @@ webidl.util.IntegerPart = function (n) { | |
|
||
// https://webidl.spec.whatwg.org/#es-sequence | ||
webidl.sequenceConverter = function (converter) { | ||
return (V) => { | ||
return (V, Iterable) => { | ||
// 1. If Type(V) is not Object, throw a TypeError. | ||
if (webidl.util.Type(V) !== 'Object') { | ||
throw webidl.errors.exception({ | ||
|
@@ -229,7 +229,7 @@ webidl.sequenceConverter = function (converter) { | |
|
||
// 2. Let method be ? GetMethod(V, @@iterator). | ||
/** @type {Generator} */ | ||
const method = V?.[Symbol.iterator]?.() | ||
const method = typeof Iterable === 'function' ? Iterable() : V?.[Symbol.iterator]?.() | ||
const seq = [] | ||
|
||
// 3. If method is undefined, throw a TypeError. | ||
|
@@ -273,8 +273,8 @@ webidl.recordConverter = function (keyConverter, valueConverter) { | |
const result = {} | ||
|
||
if (!types.isProxy(O)) { | ||
// Object.keys only returns enumerable properties | ||
const keys = Object.keys(O) | ||
// 1. Let desc be ? O.[[GetOwnProperty]](key). | ||
const keys = [...Object.getOwnPropertyNames(O), ...Object.getOwnPropertySymbols(O)] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Although Object.keys returns enumerable string properties, it didn't include enumerable symbol properties. This is only noticeable when doing something along the lines of |
||
|
||
for (const key of keys) { | ||
// 1. Let typedKey be key converted to an IDL value of type K. | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -719,3 +719,30 @@ test('When the value is updated, update the cache', (t) => { | |
headers.append('d', 'd') | ||
deepStrictEqual([...headers], [...expected, ['d', 'd']]) | ||
}) | ||
|
||
test('Symbol.iterator is only accessed once', (t) => { | ||
const { ok } = tspl(t, { plan: 1 }) | ||
|
||
const dict = new Proxy({}, { | ||
get () { | ||
ok(true) | ||
|
||
return function * () {} | ||
} | ||
}) | ||
|
||
new Headers(dict) // eslint-disable-line no-new | ||
}) | ||
|
||
test('Invalid Symbol.iterators', (t) => { | ||
const { throws } = tspl(t, { plan: 3 }) | ||
|
||
throws(() => new Headers({ [Symbol.iterator]: null }), TypeError) | ||
throws(() => new Headers({ [Symbol.iterator]: undefined }), TypeError) | ||
throws(() => { | ||
const obj = { [Symbol.iterator]: null } | ||
Object.defineProperty(obj, Symbol.iterator, { enumerable: false }) | ||
|
||
new Headers(obj) // eslint-disable-line no-new | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This throws because Symbol.iterator can't be converted to a string rather than being an invalid iterator. Technically still a bug, but this also happens in Chrome so I assume no one in the history of mankind will ever notice. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As in, we can't implement the spec steps stating to ignore non-enumerable properties because then this case wouldn't throw an error. |
||
}, TypeError) | ||
}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So there are two bugs here: