Revision: 11589
Author:   [email protected]
Date:     Fri May 18 02:45:10 2012
Log:      Correctly check for native error objects.

BUG=2138
TEST=

Review URL: https://chromiumcodereview.appspot.com/10392158
http://code.google.com/p/v8/source/detail?r=11589

Modified:
 /branches/bleeding_edge/src/messages.js

=======================================
--- /branches/bleeding_edge/src/messages.js     Tue May 15 05:24:44 2012
+++ /branches/bleeding_edge/src/messages.js     Fri May 18 02:45:10 2012
@@ -61,18 +61,21 @@


 // To check if something is a native error we need to check the
-// concrete native error types. It is not enough to check "obj
-// instanceof $Error" because user code can replace
-// NativeError.prototype.__proto__. User code cannot replace
-// NativeError.prototype though and therefore this is a safe test.
+// concrete native error types. It is not sufficient to use instanceof
+// since it possible to create an object that has Error.prototype on
+// its prototype chain. This is the case for DOMException for example.
 function IsNativeErrorObject(obj) {
-  return (obj instanceof $Error) ||
-      (obj instanceof $EvalError) ||
-      (obj instanceof $RangeError) ||
-      (obj instanceof $ReferenceError) ||
-      (obj instanceof $SyntaxError) ||
-      (obj instanceof $TypeError) ||
-      (obj instanceof $URIError);
+  switch (%_ClassOf(obj)) {
+    case 'Error':
+    case 'EvalError':
+    case 'RangeError':
+    case 'ReferenceError':
+    case 'SyntaxError':
+    case 'TypeError':
+    case 'URIError':
+      return true;
+  }
+  return false;
 }


--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev

Reply via email to