]> git.saurik.com Git - apple/javascriptcore.git/blob - tests/stress/exception-in-to-property-key-should-be-handled-early.js
JavaScriptCore-7601.1.46.3.tar.gz
[apple/javascriptcore.git] / tests / stress / exception-in-to-property-key-should-be-handled-early.js
1
2 var propertyKey = {
3 toString() {
4 throw new Error("propertyKey.toString is called.");
5 }
6 };
7
8 function shouldThrow(func, message) {
9 var error = null;
10 try {
11 func();
12 } catch (e) {
13 error = e;
14 }
15 if (!error)
16 throw new Error("not thrown.");
17 if (String(error) !== message)
18 throw new Error("bad error: " + String(error));
19 }
20
21 // GetByVal.
22 (function () {
23 var called = null;
24 var toStringCalled = false;
25 var property = {
26 toString() {
27 toStringCalled = true;
28 return "value";
29 }
30 };
31 var object = {
32 get value() {
33 },
34 set value(val) {
35 }
36 };
37 Object.defineProperty(object, '', {
38 get: function () {
39 called = "getter for '' is called.";
40 }
41 });
42
43 function test(object, property) {
44 object[property];
45 }
46 noInline(test);
47
48 shouldThrow(function () { test(object, propertyKey); }, "Error: propertyKey.toString is called.");
49 if (called)
50 throw new Error(called);
51 toStringCalled = false;
52 shouldThrow(function () { test(null, propertyKey); }, "TypeError: null is not an object (evaluating 'object[property]')");
53 if (toStringCalled)
54 throw new Error("toString is called.");
55 }());
56
57 // GetByVal DFG.
58 (function () {
59 var called = null;
60 var toStringCalled = false;
61 var property = {
62 toString() {
63 toStringCalled = true;
64 return "value";
65 }
66 };
67 var object = {
68 get ""() {
69 called = "getter for '' is called.";
70 },
71 set ""(val) {
72 called = "setter for '' is called.";
73 },
74
75 get value() {
76 },
77 set value(val) {
78 }
79 };
80
81 function test(object, property) {
82 object[property];
83 }
84 noInline(test);
85
86 for (var i = 0; i < 10000; ++i)
87 test(object, property);
88
89 shouldThrow(function () { test(object, propertyKey); }, "Error: propertyKey.toString is called.");
90 if (called)
91 throw new Error(called);
92 toStringCalled = false;
93 shouldThrow(function () { test(null, propertyKey); }, "TypeError: null is not an object (evaluating 'object[property]')");
94 if (toStringCalled)
95 throw new Error("toString is called.");
96 }());
97
98
99 // GetByValString.
100 (function () {
101 var called;
102 var toStringCalled = false;
103 var property = {
104 toString() {
105 toStringCalled = true;
106 return "value";
107 }
108 };
109 function test(array, length, property) {
110 var result = 0;
111 for (var i = 0; i < length; ++i)
112 result += array[property];
113 return result;
114 }
115 noInline(test);
116
117 Object.defineProperty(String.prototype, "", {
118 get: function () {
119 called = "getter for '' is called.";
120 }
121 });
122
123 var array = [1, 2, 3];
124 for (var i = 0; i < 100000; ++i)
125 test(array, array.length, 0);
126
127 var array = [1, false, 3];
128 for (var i = 0; i < 100000; ++i)
129 test(array, array.length, 1);
130
131 test("hello", "hello".length, 2);
132 shouldThrow(function () { test("hello", "hello".length, propertyKey); }, "Error: propertyKey.toString is called.");
133 if (called)
134 throw new Error(called);
135 toStringCalled = false;
136 shouldThrow(function () { test(null, 20, propertyKey); }, "TypeError: null is not an object (near '...for (var i = 0; i < length; ++i)...')");
137 if (toStringCalled)
138 throw new Error("toString is called.");
139 }());