-
Notifications
You must be signed in to change notification settings - Fork 3.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[WebIDL] Add tests for iterator objects and prototypes (#8796)
- Loading branch information
Showing
2 changed files
with
83 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<!doctype html> | ||
<meta charset="utf-8"> | ||
<title>Default iterator objects</title> | ||
<script src="/resources/testharness.js"></script> | ||
<script src="/resources/testharnessreport.js"></script> | ||
<script> | ||
test(() => { | ||
const iterator1 = new URLSearchParams()[Symbol.iterator](); | ||
const iterator2 = new URLSearchParams().keys(); | ||
const iterator3 = new URLSearchParams().values(); | ||
const iterator4 = new URLSearchParams().entries(); | ||
assert_equals(Object.getPrototypeOf(iterator1), Object.getPrototypeOf(iterator2)); | ||
assert_equals(Object.getPrototypeOf(iterator1), Object.getPrototypeOf(iterator3)); | ||
assert_equals(Object.getPrototypeOf(iterator1), Object.getPrototypeOf(iterator4)); | ||
}, "Default iterator objects for an interface have the same prototype"); | ||
|
||
test(() => { | ||
const iterator = new URLSearchParams().entries(); | ||
assert_equals(Object.prototype.toString.call(iterator), "[object URLSearchParams Iterator]"); | ||
}, "Object.prototype.toString returns correct value"); | ||
|
||
test(() => { | ||
const iterator = new URLSearchParams().entries(); | ||
assert_equals(iterator[Symbol.toStringTag], "URLSearchParams Iterator"); | ||
assert_equals(Object.getOwnPropertyDescriptor(iterator, Symbol.toStringTag), undefined); | ||
}, "@@toStringTag has correct value from prototype"); | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
<!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> |