mirror of
https://github.com/lexmount/moli.git
synced 2026-10-06 08:00:59 +00:00
test(webidl): cover platform initializer record discrimination
This commit is contained in:
@@ -1385,3 +1385,40 @@ fn initializer_pairs_use_inner_iterators_and_convert_extra_elements() {
|
||||
"#).unwrap();
|
||||
assert_eq!(result, "ok");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn webidl_initializer_unions_convert_platform_objects_without_iterators_as_records() {
|
||||
let mut vm = new_storage_test_vm("https://initializer-record.test/");
|
||||
let result = vm.eval(r#"
|
||||
(() => {
|
||||
for (const Constructor of [Headers, URLSearchParams]) {
|
||||
const url = new URL('https://initializer-record.test/path?query=value');
|
||||
Object.defineProperty(url, Symbol.toPrimitive, {value() {
|
||||
throw new Error('URL object must use record conversion');
|
||||
}});
|
||||
if (Array.from(new Constructor(url)).length !== 0) throw new Error('empty URL record');
|
||||
url['x-record'] = 'record';
|
||||
if (JSON.stringify(Array.from(new Constructor(url))) !== '[["x-record","record"]]') {
|
||||
throw new Error(Constructor.name + ' must use own URL properties');
|
||||
}
|
||||
for (const factory of [() => new Headers(), () => new URLSearchParams(), () => new FormData()]) {
|
||||
for (const value of [undefined, null]) {
|
||||
const input = factory();
|
||||
let iteratorReads = 0;
|
||||
Object.defineProperty(input, Symbol.iterator, {enumerable: true, get() {
|
||||
iteratorReads++;
|
||||
return value;
|
||||
}});
|
||||
let caught;
|
||||
try { new Constructor(input); } catch (error) { caught = error; }
|
||||
if (!(caught instanceof TypeError) || iteratorReads !== 1) {
|
||||
throw new Error(Constructor.name + ' must reject the enumerable Symbol key before reading its value');
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return 'ok';
|
||||
})()
|
||||
"#).unwrap();
|
||||
assert_eq!(result, "ok");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user