Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
1 // String.prototype[@@iterator] and StringIterator.prototype surface tests
3 load(libdir + "array-compare.js");
4 load(libdir + "asserts.js");
5 load(libdir + "iteration.js");
7 function assertDataDescriptor(actual, expected) {
8 assertEq(actual.value, expected.value);
9 assertEq(actual.writable, expected.writable);
10 assertEq(actual.enumerable, expected.enumerable);
11 assertEq(actual.configurable, expected.configurable);
12 }
14 function isConstructor(o) {
15 try {
16 new (new Proxy(o, {construct: () => ({})}));
17 return true;
18 } catch(e) {
19 return false;
20 }
21 }
23 function assertBuiltinFunction(o, name, arity) {
24 var fn = o[name];
25 assertDataDescriptor(Object.getOwnPropertyDescriptor(o, name), {
26 value: fn,
27 writable: true,
28 enumerable: false,
29 configurable: true,
30 });
32 assertEq(typeof fn, "function");
33 assertEq(Object.getPrototypeOf(fn), Function.prototype);
34 // FIXME: Proxy should only have [[Construct]] if target has [[Construct]] (bug 929467)
35 // assertEq(isConstructor(fn), false);
37 arraysEqual(Object.getOwnPropertyNames(fn).sort(), ["length", "name", "arguments", "caller"].sort());
39 // Also test "name", "arguments" and "caller" in addition to "length"?
40 assertDataDescriptor(Object.getOwnPropertyDescriptor(fn, "length"), {
41 value: arity,
42 writable: false,
43 enumerable: false,
44 configurable: false,
45 });
46 }
49 // String.prototype[@@iterator] is a built-in function
50 assertBuiltinFunction(String.prototype, std_iterator, 0);
52 // Test StringIterator.prototype surface
53 var iter = ""[std_iterator]();
54 var iterProto = Object.getPrototypeOf(iter);
56 // StringIterator.prototype inherits from Object.prototype
57 assertEq(Object.getPrototypeOf(iterProto), Object.prototype);
59 // Own properties for StringIterator.prototype: "next" and @@iterator
60 arraysEqual(Object.getOwnPropertyNames(iterProto).sort(), ["next", std_iterator].sort());
62 // StringIterator.prototype[@@iterator] is a built-in function
63 assertBuiltinFunction(iterProto, std_iterator, 0);
65 // StringIterator.prototype.next is a built-in function
66 assertBuiltinFunction(iterProto, "next", 0);
68 // StringIterator.prototype[@@iterator] is generic and returns |this|
69 for (var v of [void 0, null, true, false, "", 0, 1, {}, [], iter, iterProto]) {
70 assertEq(iterProto[std_iterator].call(v), v);
71 }
73 // StringIterator.prototype.next is not generic
74 for (var v of [void 0, null, true, false, "", 0, 1, {}, [], iterProto]) {
75 assertThrowsInstanceOf(() => iterProto.next.call(v), TypeError);
76 }