Skip to content
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

[WebIDL] Add tests for iterator objects and prototypes #8796

Merged
merged 1 commit into from
Feb 23, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions WebIDL/ecmascript-binding/default-iterator-object.html
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>
56 changes: 56 additions & 0 deletions WebIDL/ecmascript-binding/iterator-prototype-object.html
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>