| <!doctype html> |
| <meta charset="utf-8"> |
| <title>Iterator prototype objects</title> |
| <script src="/resources/testharness.js"></script> |
| <script src="/resources/testharnessreport.js"></script> |
| <script> |
| test(() => { |
| const esIteratorPrototype = Object.getPrototypeOf(Object.getPrototypeOf([][Symbol.iterator]())); |
| const iteratorProto = Object.getPrototypeOf(new URLSearchParams().entries()); |
| assert_equals(Object.getPrototypeOf(iteratorProto), esIteratorPrototype); |
| }, "Has %IteratorPrototype% as prototype"); |
| |
| test(() => { |
| const iteratorProto = Object.getPrototypeOf(new URLSearchParams().entries()); |
| const desc = Object.getOwnPropertyDescriptor(iteratorProto, "next"); |
| assert_equals(typeof desc.value, "function"); |
| assert_equals(desc.writable, true); |
| assert_equals(desc.enumerable, true); |
| assert_equals(desc.configurable, true); |
| }, "next() exists and is writable, enumerable, and configurable"); |
| |
| test(() => { |
| const usp = new URLSearchParams(); |
| const iteratorProto = Object.getPrototypeOf(usp.entries()); |
| |
| assert_throws(new TypeError(), () => { |
| iteratorProto.next(); |
| }); |
| assert_throws(new TypeError(), () => { |
| iteratorProto.next.call(undefined); |
| }); |
| assert_throws(new TypeError(), () => { |
| iteratorProto.next.call(42); |
| }); |
| assert_throws(new TypeError(), () => { |
| iteratorProto.next.call(new Headers().entries()); |
| }); |
| }, "next() throws TypeError when called on ineligible receiver"); |
| |
| test(() => { |
| const iteratorProto = Object.getPrototypeOf(new URLSearchParams().entries()); |
| assert_equals(Object.prototype.toString.call(iteratorProto), "[object URLSearchParams Iterator]"); |
| }, "Object.prototype.toString returns correct value"); |
| |
| test(() => { |
| const iteratorProto = Object.getPrototypeOf(new URLSearchParams().entries()); |
| assert_equals(Object.getOwnPropertyDescriptor(iteratorProto, Symbol.toStringTag).value, "URLSearchParams Iterator"); |
| // Property attributes have not yet been fully spec'd. |
| }, "@@toStringTag has correct value"); |
| |
| test(() => { |
| const iteratorProto1 = Object.getPrototypeOf(new URLSearchParams().entries()); |
| const iteratorProto2 = Object.getPrototypeOf(new Headers().entries()); |
| assert_not_equals(iteratorProto1, iteratorProto2); |
| }, "Is specific to an interface"); |
| </script> |