OLD | NEW |
1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 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 |
(...skipping 1123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1134 })(); | 1134 })(); |
1135 | 1135 |
1136 | 1136 |
1137 (function TestNonStrictFunctionCallerPillSimple() { | 1137 (function TestNonStrictFunctionCallerPillSimple() { |
1138 function return_my_caller() { | 1138 function return_my_caller() { |
1139 return return_my_caller.caller; | 1139 return return_my_caller.caller; |
1140 } | 1140 } |
1141 | 1141 |
1142 function strict() { | 1142 function strict() { |
1143 "use strict"; | 1143 "use strict"; |
1144 return_my_caller(); | 1144 return return_my_caller(); |
1145 } | 1145 } |
1146 assertThrows(strict, TypeError); | 1146 assertSame(null, strict()); |
1147 | 1147 |
1148 function non_strict() { | 1148 function non_strict() { |
1149 return return_my_caller(); | 1149 return return_my_caller(); |
1150 } | 1150 } |
1151 assertSame(non_strict(), non_strict); | 1151 assertSame(non_strict(), non_strict); |
1152 })(); | 1152 })(); |
1153 | 1153 |
1154 | 1154 |
1155 (function TestNonStrictFunctionCallerPill() { | 1155 (function TestNonStrictFunctionCallerPill() { |
1156 function strict(n) { | 1156 function strict(n) { |
1157 "use strict"; | 1157 "use strict"; |
1158 non_strict(n); | 1158 return non_strict(n); |
1159 } | 1159 } |
1160 | 1160 |
1161 function recurse(n, then) { | 1161 function recurse(n, then) { |
1162 if (n > 0) { | 1162 if (n > 0) { |
1163 recurse(n - 1); | 1163 return recurse(n - 1, then); |
1164 } else { | 1164 } else { |
1165 return then(); | 1165 return then(); |
1166 } | 1166 } |
1167 } | 1167 } |
1168 | 1168 |
1169 function non_strict(n) { | 1169 function non_strict(n) { |
1170 recurse(n, function() { non_strict.caller; }); | 1170 return recurse(n, function() { return non_strict.caller; }); |
1171 } | 1171 } |
1172 | 1172 |
1173 function test(n) { | 1173 function test(n) { |
1174 try { | 1174 return recurse(n, function() { return strict(n); }); |
1175 recurse(n, function() { strict(n); }); | |
1176 } catch(e) { | |
1177 return e instanceof TypeError; | |
1178 } | |
1179 return false; | |
1180 } | 1175 } |
1181 | 1176 |
1182 for (var i = 0; i < 10; i ++) { | 1177 for (var i = 0; i < 10; i ++) { |
1183 assertEquals(test(i), true); | 1178 assertSame(null, test(i)); |
1184 } | 1179 } |
1185 })(); | 1180 })(); |
1186 | 1181 |
| 1182 |
| 1183 (function TestNonStrictFunctionCallerDescriptorPill() { |
| 1184 function strict(n) { |
| 1185 "use strict"; |
| 1186 return non_strict(n); |
| 1187 } |
| 1188 |
| 1189 function recurse(n, then) { |
| 1190 if (n > 0) { |
| 1191 return recurse(n - 1, then); |
| 1192 } else { |
| 1193 return then(); |
| 1194 } |
| 1195 } |
| 1196 |
| 1197 function non_strict(n) { |
| 1198 return recurse(n, function() { |
| 1199 return Object.getOwnPropertyDescriptor(non_strict, "caller").value; |
| 1200 }); |
| 1201 } |
| 1202 |
| 1203 function test(n) { |
| 1204 return recurse(n, function() { return strict(n); }); |
| 1205 } |
| 1206 |
| 1207 for (var i = 0; i < 10; i ++) { |
| 1208 assertSame(null, test(i)); |
| 1209 } |
| 1210 })(); |
| 1211 |
1187 | 1212 |
1188 (function TestStrictModeEval() { | 1213 (function TestStrictModeEval() { |
1189 "use strict"; | 1214 "use strict"; |
1190 eval("var eval_local = 10;"); | 1215 eval("var eval_local = 10;"); |
1191 assertThrows(function() { return eval_local; }, ReferenceError); | 1216 assertThrows(function() { return eval_local; }, ReferenceError); |
1192 })(); | 1217 })(); |
OLD | NEW |