summaryrefslogtreecommitdiffstats
path: root/js/src/jit-test/tests/for-of/string-iterator-surfaces.js
diff options
context:
space:
mode:
authorMatt A. Tobin <mattatobin@localhost.localdomain>2018-02-02 04:16:08 -0500
committerMatt A. Tobin <mattatobin@localhost.localdomain>2018-02-02 04:16:08 -0500
commit5f8de423f190bbb79a62f804151bc24824fa32d8 (patch)
tree10027f336435511475e392454359edea8e25895d /js/src/jit-test/tests/for-of/string-iterator-surfaces.js
parent49ee0794b5d912db1f95dce6eb52d781dc210db5 (diff)
downloadUXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.gz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.lz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.xz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.zip
Add m-esr52 at 52.6.0
Diffstat (limited to 'js/src/jit-test/tests/for-of/string-iterator-surfaces.js')
-rw-r--r--js/src/jit-test/tests/for-of/string-iterator-surfaces.js83
1 files changed, 83 insertions, 0 deletions
diff --git a/js/src/jit-test/tests/for-of/string-iterator-surfaces.js b/js/src/jit-test/tests/for-of/string-iterator-surfaces.js
new file mode 100644
index 000000000..293f1b8b3
--- /dev/null
+++ b/js/src/jit-test/tests/for-of/string-iterator-surfaces.js
@@ -0,0 +1,83 @@
+// String.prototype[@@iterator] and StringIterator.prototype surface tests
+
+load(libdir + "array-compare.js");
+load(libdir + "asserts.js");
+load(libdir + "iteration.js");
+
+function assertDataDescriptor(actual, expected) {
+ assertEq(actual.value, expected.value);
+ assertEq(actual.writable, expected.writable);
+ assertEq(actual.enumerable, expected.enumerable);
+ assertEq(actual.configurable, expected.configurable);
+}
+
+function isConstructor(o) {
+ try {
+ new (new Proxy(o, {construct: () => ({})}));
+ return true;
+ } catch(e) {
+ return false;
+ }
+}
+
+function assertBuiltinFunction(o, name, arity) {
+ var fn = o[name];
+ assertDataDescriptor(Object.getOwnPropertyDescriptor(o, name), {
+ value: fn,
+ writable: true,
+ enumerable: false,
+ configurable: true,
+ });
+
+ assertEq(typeof fn, "function");
+ assertEq(Object.getPrototypeOf(fn), Function.prototype);
+ assertEq(isConstructor(fn), false);
+
+ assertEq(arraysEqual(Object.getOwnPropertyNames(fn).sort(), ["length", "name"].sort()), true);
+
+ assertDataDescriptor(Object.getOwnPropertyDescriptor(fn, "length"), {
+ value: arity,
+ writable: false,
+ enumerable: false,
+ configurable: true
+ });
+
+ var functionName = typeof name === "symbol"
+ ? String(name).replace(/^Symbol\((.+)\)$/, "[$1]")
+ : name;
+ assertDataDescriptor(Object.getOwnPropertyDescriptor(fn, "name"), {
+ value: functionName,
+ writable: false,
+ enumerable: false,
+ configurable: true
+ });
+}
+
+
+// String.prototype[@@iterator] is a built-in function
+assertBuiltinFunction(String.prototype, Symbol.iterator, 0);
+
+// Test StringIterator.prototype surface
+var iter = ""[Symbol.iterator]();
+var iterProto = Object.getPrototypeOf(iter);
+
+// StringIterator.prototype inherits from %IteratorPrototype%. Check it's the
+// same object as %ArrayIteratorPrototype%'s proto.
+assertEq(Object.getPrototypeOf(iterProto),
+ Object.getPrototypeOf(Object.getPrototypeOf([][Symbol.iterator]())));
+
+// Own properties for StringIterator.prototype: "next"
+assertEq(arraysEqual(Object.getOwnPropertyNames(iterProto).sort(), ["next"]), true);
+
+// StringIterator.prototype.next is a built-in function
+assertBuiltinFunction(iterProto, "next", 0);
+
+// StringIterator.prototype[@@iterator] is generic and returns |this|
+for (var v of [void 0, null, true, false, "", 0, 1, {}, [], iter, iterProto]) {
+ assertEq(iterProto[Symbol.iterator].call(v), v);
+}
+
+// StringIterator.prototype.next is not generic
+for (var v of [void 0, null, true, false, "", 0, 1, {}, [], iterProto]) {
+ assertThrowsInstanceOf(() => iterProto.next.call(v), TypeError);
+}