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 43 matching lines...) Loading... |
54 } | 54 } |
55 } | 55 } |
56 } | 56 } |
57 result += str; | 57 result += str; |
58 } | 58 } |
59 return result; | 59 return result; |
60 } | 60 } |
61 | 61 |
62 | 62 |
63 // To check if something is a native error we need to check the | 63 // To check if something is a native error we need to check the |
64 // concrete native error types. It is not enough to check "obj | 64 // concrete native error types. It is not sufficient to use instanceof |
65 // instanceof $Error" because user code can replace | 65 // since it possible to create an object that has Error.prototype on |
66 // NativeError.prototype.__proto__. User code cannot replace | 66 // its prototype chain. This is the case for DOMException for example. |
67 // NativeError.prototype though and therefore this is a safe test. | |
68 function IsNativeErrorObject(obj) { | 67 function IsNativeErrorObject(obj) { |
69 return (obj instanceof $Error) || | 68 switch (%_ClassOf(obj)) { |
70 (obj instanceof $EvalError) || | 69 case 'Error': |
71 (obj instanceof $RangeError) || | 70 case 'EvalError': |
72 (obj instanceof $ReferenceError) || | 71 case 'RangeError': |
73 (obj instanceof $SyntaxError) || | 72 case 'ReferenceError': |
74 (obj instanceof $TypeError) || | 73 case 'SyntaxError': |
75 (obj instanceof $URIError); | 74 case 'TypeError': |
| 75 case 'URIError': |
| 76 return true; |
| 77 } |
| 78 return false; |
76 } | 79 } |
77 | 80 |
78 | 81 |
79 // When formatting internally created error messages, do not | 82 // When formatting internally created error messages, do not |
80 // invoke overwritten error toString methods but explicitly use | 83 // invoke overwritten error toString methods but explicitly use |
81 // the error to string method. This is to avoid leaking error | 84 // the error to string method. This is to avoid leaking error |
82 // objects between script tags in a browser setting. | 85 // objects between script tags in a browser setting. |
83 function ToStringCheckErrorObject(obj) { | 86 function ToStringCheckErrorObject(obj) { |
84 if (IsNativeErrorObject(obj)) { | 87 if (IsNativeErrorObject(obj)) { |
85 return %_CallFunction(obj, ErrorToString); | 88 return %_CallFunction(obj, ErrorToString); |
(...skipping 1148 matching lines...) Loading... |
1234 throw e; | 1237 throw e; |
1235 } | 1238 } |
1236 } | 1239 } |
1237 | 1240 |
1238 | 1241 |
1239 InstallFunctions($Error.prototype, DONT_ENUM, ['toString', ErrorToString]); | 1242 InstallFunctions($Error.prototype, DONT_ENUM, ['toString', ErrorToString]); |
1240 | 1243 |
1241 // Boilerplate for exceptions for stack overflows. Used from | 1244 // Boilerplate for exceptions for stack overflows. Used from |
1242 // Isolate::StackOverflow(). | 1245 // Isolate::StackOverflow(). |
1243 var kStackOverflowBoilerplate = MakeRangeError('stack_overflow', []); | 1246 var kStackOverflowBoilerplate = MakeRangeError('stack_overflow', []); |
OLD | NEW |