diff options
Diffstat (limited to 'Source/JavaScriptCore/tests/mozilla/ecma_2/instanceof/instanceof-003.js')
-rw-r--r-- | Source/JavaScriptCore/tests/mozilla/ecma_2/instanceof/instanceof-003.js | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/Source/JavaScriptCore/tests/mozilla/ecma_2/instanceof/instanceof-003.js b/Source/JavaScriptCore/tests/mozilla/ecma_2/instanceof/instanceof-003.js new file mode 100644 index 0000000..c8f84ba --- /dev/null +++ b/Source/JavaScriptCore/tests/mozilla/ecma_2/instanceof/instanceof-003.js @@ -0,0 +1,57 @@ +/** + File Name: instanceof-003.js + ECMA Section: + Description: http://bugzilla.mozilla.org/show_bug.cgi?id=7635 + +js> function Foo() {} +js> theproto = {}; +[object Object] +js> Foo.prototype = theproto +[object Object] +js> theproto instanceof Foo +true + +I think this should be 'false' + + + Author: christine@netscape.com + Date: 12 november 1997 + + +The test case described above is correct, however the second test case in this file is not, +'o instanceof o' should thow an exception. According to ECMA-262: + + 8.6.2 Internal Properties and Methods: + "... only Function objects implement [[HasInstance]]" + 11.8.6 The instanceof operator: + "6.If Result(4) does not have a [[HasInstance]] method, throw a TypeError exception." + +{} does not implement [[HasInstance]] (since it is not a function), so passing it as the +constructor to be tested to instanceof should result in a TypeError being thrown. + +*/ + var SECTION = "instanceof-003"; + var VERSION = "ECMA_2"; + var TITLE = "instanceof operator"; + var BUGNUMBER ="http://bugzilla.mozilla.org/show_bug.cgi?id=7635"; + + startTest(); + + function Foo() {}; + theproto = {}; + Foo.prototype = theproto; + + AddTestCase( + "function Foo() = {}; theproto = {}; Foo.prototype = theproto; " + + "theproto instanceof Foo", + false, + theproto instanceof Foo ); + + + AddTestCase( + "o = {}; o instanceof o", + "EXCEPTION", + (function(){ try { var o = {}; o instanceof o; return "no exception"; } catch (e) { return "EXCEPTION"; } } )() ); + + + test(); |