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 |
(...skipping 1253 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1264 } | 1264 } |
1265 throw e; | 1265 throw e; |
1266 } | 1266 } |
1267 } | 1267 } |
1268 | 1268 |
1269 | 1269 |
1270 InstallFunctions($Error.prototype, DONT_ENUM, ['toString', ErrorToString]); | 1270 InstallFunctions($Error.prototype, DONT_ENUM, ['toString', ErrorToString]); |
1271 | 1271 |
1272 // Boilerplate for exceptions for stack overflows. Used from | 1272 // Boilerplate for exceptions for stack overflows. Used from |
1273 // Isolate::StackOverflow(). | 1273 // Isolate::StackOverflow(). |
1274 var kStackOverflowBoilerplate = MakeRangeError('stack_overflow', []); | 1274 function SetUpStackOverflowBoilerplate() { |
| 1275 var boilerplate = MakeRangeError('stack_overflow', []); |
| 1276 |
| 1277 // 'this' may not be the holder of the accessor. However, all Error objects |
| 1278 // have a 'stack' property. By searching the prototype chain for an Error |
| 1279 // object, we can find the holder of this accessor. |
| 1280 function GetHolder(receiver) { |
| 1281 var holder = receiver; |
| 1282 while (!IS_ERROR(holder)) { |
| 1283 holder = %GetPrototype(holder); |
| 1284 if (holder == null) return MakeSyntaxError('illegal_access', []); |
| 1285 } |
| 1286 return holder; |
| 1287 } |
| 1288 |
| 1289 // We cannot use a context allocated value to hold the value after the |
| 1290 // stack trace string has been formatted or the setter has been called, |
| 1291 // because that value would be shared between all copies of the boilerplate. |
| 1292 // We also cannot replace the accessors with a normal property because |
| 1293 // accessors behave differently than normal properties wrt prototype chain. |
| 1294 // Instead, we replace the getter with a new getter. |
| 1295 function Getter() { |
| 1296 var holder = GetHolder(this); |
| 1297 var raw_stack = %GetOverflowedRawStackTrace(holder) |
| 1298 var result = FormatRawStackTrace(holder, raw_stack); |
| 1299 %DefineOrRedefineAccessorProperty( |
| 1300 holder, 'stack', function() { return result; }, null, DONT_ENUM); |
| 1301 return result; |
| 1302 } |
| 1303 |
| 1304 function Setter(v) { |
| 1305 var holder = GetHolder(this); |
| 1306 %DefineOrRedefineAccessorProperty( |
| 1307 holder, 'stack', function() { return v; }, null, DONT_ENUM); |
| 1308 } |
| 1309 |
| 1310 %DefineOrRedefineAccessorProperty( |
| 1311 boilerplate, 'stack', Getter, Setter, DONT_ENUM); |
| 1312 |
| 1313 return boilerplate; |
| 1314 } |
| 1315 |
| 1316 var kStackOverflowBoilerplate = SetUpStackOverflowBoilerplate(); |
OLD | NEW |