Skip to content

armgit / moli

Public Imported from GitHub
0

Best headless browser for AI agents. Lite, Fast, High-Compatibility. Built in Rust

test(webidl): cover platform initializer record discrimination

ldm0c6b3b1af41ce
diff --git a/moli-renderer-v8/src/script_vm/tests/webidl_fetch/url_and_initializer_semantics.rs b/moli-renderer-v8/src/script_vm/tests/webidl_fetch/url_and_initializer_semantics.rs
index 659eded53..69988da69 100644
--- a/moli-renderer-v8/src/script_vm/tests/webidl_fetch/url_and_initializer_semantics.rs
+++ b/moli-renderer-v8/src/script_vm/tests/webidl_fetch/url_and_initializer_semantics.rs
@@ -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");
+}