OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
11 // with the distribution. | 11 // with the distribution. |
12 // * Neither the name of Google Inc. nor the names of its | 12 // * Neither the name of Google Inc. nor the names of its |
13 // contributors may be used to endorse or promote products derived | 13 // contributors may be used to endorse or promote products derived |
14 // from this software without specific prior written permission. | 14 // from this software without specific prior written permission. |
15 // | 15 // |
16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | 16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | 17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | 18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | 19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | 20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | 21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
27 | 27 |
28 // Tests the object.defineProperty method - ES 15.2.3.6 | 28 // Tests the object.defineProperty method - ES 15.2.3.6 |
29 | 29 |
30 // Flags: --allow-natives-syntax | 30 // Flags: --allow-natives-syntax --es5-readonly |
31 | 31 |
32 // Check that an exception is thrown when null is passed as object. | 32 // Check that an exception is thrown when null is passed as object. |
33 var exception = false; | 33 var exception = false; |
34 try { | 34 try { |
35 Object.defineProperty(null, null, null); | 35 Object.defineProperty(null, null, null); |
36 } catch (e) { | 36 } catch (e) { |
37 exception = true; | 37 exception = true; |
38 assertTrue(/called on non-object/.test(e)); | 38 assertTrue(/called on non-object/.test(e)); |
39 } | 39 } |
40 assertTrue(exception); | 40 assertTrue(exception); |
(...skipping 1037 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1078 | 1078 |
1079 | 1079 |
1080 // Regression test: We should never observe the hole value. | 1080 // Regression test: We should never observe the hole value. |
1081 var objectWithGetter = {}; | 1081 var objectWithGetter = {}; |
1082 objectWithGetter.__defineGetter__('foo', function() {}); | 1082 objectWithGetter.__defineGetter__('foo', function() {}); |
1083 assertEquals(undefined, objectWithGetter.__lookupSetter__('foo')); | 1083 assertEquals(undefined, objectWithGetter.__lookupSetter__('foo')); |
1084 | 1084 |
1085 var objectWithSetter = {}; | 1085 var objectWithSetter = {}; |
1086 objectWithSetter.__defineSetter__('foo', function(x) {}); | 1086 objectWithSetter.__defineSetter__('foo', function(x) {}); |
1087 assertEquals(undefined, objectWithSetter.__lookupGetter__('foo')); | 1087 assertEquals(undefined, objectWithSetter.__lookupGetter__('foo')); |
| 1088 |
| 1089 // An object with a getter on the prototype chain. |
| 1090 function getter() { return 111; } |
| 1091 function anotherGetter() { return 222; } |
| 1092 |
| 1093 function testGetterOnProto(expected, o) { |
| 1094 assertEquals(expected, o.quebec); |
| 1095 } |
| 1096 |
| 1097 obj1 = {}; |
| 1098 Object.defineProperty(obj1, "quebec", { get: getter, configurable: true }); |
| 1099 obj2 = Object.create(obj1); |
| 1100 obj3 = Object.create(obj2); |
| 1101 |
| 1102 testGetterOnProto(111, obj3); |
| 1103 testGetterOnProto(111, obj3); |
| 1104 %OptimizeFunctionOnNextCall(testGetterOnProto); |
| 1105 testGetterOnProto(111, obj3); |
| 1106 testGetterOnProto(111, obj3); |
| 1107 |
| 1108 Object.defineProperty(obj1, "quebec", { get: anotherGetter }); |
| 1109 |
| 1110 testGetterOnProto(222, obj3); |
| 1111 testGetterOnProto(222, obj3); |
| 1112 %OptimizeFunctionOnNextCall(testGetterOnProto); |
| 1113 testGetterOnProto(222, obj3); |
| 1114 testGetterOnProto(222, obj3); |
| 1115 |
| 1116 // An object with a setter on the prototype chain. |
| 1117 var modifyMe; |
| 1118 function setter(x) { modifyMe = x+1; } |
| 1119 function anotherSetter(x) { modifyMe = x+2; } |
| 1120 |
| 1121 function testSetterOnProto(expected, o) { |
| 1122 modifyMe = 333; |
| 1123 o.romeo = 444; |
| 1124 assertEquals(expected, modifyMe); |
| 1125 } |
| 1126 |
| 1127 obj1 = {}; |
| 1128 Object.defineProperty(obj1, "romeo", { set: setter, configurable: true }); |
| 1129 obj2 = Object.create(obj1); |
| 1130 obj3 = Object.create(obj2); |
| 1131 |
| 1132 testSetterOnProto(445, obj3); |
| 1133 testSetterOnProto(445, obj3); |
| 1134 %OptimizeFunctionOnNextCall(testSetterOnProto); |
| 1135 testSetterOnProto(445, obj3); |
| 1136 testSetterOnProto(445, obj3); |
| 1137 |
| 1138 Object.defineProperty(obj1, "romeo", { set: anotherSetter }); |
| 1139 |
| 1140 testSetterOnProto(446, obj3); |
| 1141 testSetterOnProto(446, obj3); |
| 1142 %OptimizeFunctionOnNextCall(testSetterOnProto); |
| 1143 testSetterOnProto(446, obj3); |
| 1144 testSetterOnProto(446, obj3); |
| 1145 |
| 1146 // Removing a setter on the prototype chain. |
| 1147 function testSetterOnProtoStrict(o) { |
| 1148 "use strict"; |
| 1149 o.sierra = 12345; |
| 1150 } |
| 1151 |
| 1152 obj1 = {}; |
| 1153 Object.defineProperty(obj1, "sierra", |
| 1154 { get: getter, set: setter, configurable: true }); |
| 1155 obj2 = Object.create(obj1); |
| 1156 obj3 = Object.create(obj2); |
| 1157 |
| 1158 testSetterOnProtoStrict(obj3); |
| 1159 testSetterOnProtoStrict(obj3); |
| 1160 %OptimizeFunctionOnNextCall(testSetterOnProtoStrict); |
| 1161 testSetterOnProtoStrict(obj3); |
| 1162 testSetterOnProtoStrict(obj3); |
| 1163 |
| 1164 Object.defineProperty(obj1, "sierra", |
| 1165 { get: getter, set: undefined, configurable: true }); |
| 1166 |
| 1167 exception = false; |
| 1168 try { |
| 1169 testSetterOnProtoStrict(obj3); |
| 1170 } catch (e) { |
| 1171 exception = true; |
| 1172 assertTrue(/which has only a getter/.test(e)); |
| 1173 } |
| 1174 assertTrue(exception); |
OLD | NEW |