]> git.saurik.com Git - apple/javascriptcore.git/blame - tests/stress/array-fill-put-by-val.js
JavaScriptCore-7601.1.46.3.tar.gz
[apple/javascriptcore.git] / tests / stress / array-fill-put-by-val.js
CommitLineData
ed1e77d3
A
1function shouldThrow(func, message) {
2 var error = null;
3 try {
4 func();
5 } catch (e) {
6 error = e;
7 }
8 if (!error)
9 throw new Error("not thrown.");
10 if (String(error) !== message)
11 throw new Error("bad error: " + String(error));
12}
13
14var array = new Array(10);
15
16for (var i = 0; i < 10; ++i) {
17 (function (index) {
18 var seenOnce = false;
19 var storage = null;
20 Object.defineProperty(Array.prototype, index, {
21 get() {
22 throw new Error('get is called.' + index);
23 return storage;
24 },
25 set(value) {
26 if (seenOnce)
27 throw new Error('set is called.' + index);
28 seenOnce = true;
29 storage = value;
30 return storage;
31 }
32 });
33 }(i));
34}
35
36// No error, but all seenOnce becomes true.
37array.fill(42);
38
39// Ensures that all setter is called once.
40for (var i = 0; i < 10; ++i) {
41 shouldThrow(function () {
42 array[i] = i;
43 }, "Error: set is called." + i);
44}