From: yangguo@chromium.org Date: Fri, 18 May 2012 09:45:10 +0000 (+0000) Subject: Correctly check for native error objects. X-Git-Tag: upstream/4.7.83~16696 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=cb06ffab5e31f012d64d46840400e12f9376adab;p=platform%2Fupstream%2Fv8.git Correctly check for native error objects. BUG=2138 TEST= Review URL: https://chromiumcodereview.appspot.com/10392158 git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@11589 ce2b1a6d-e550-0410-aec6-3dcde31c8c00 --- diff --git a/src/messages.js b/src/messages.js index d813df9..ab71936 100644 --- a/src/messages.js +++ b/src/messages.js @@ -61,18 +61,21 @@ function FormatString(format, message) { // 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; }