initial import
[vuplus_webkit] / Source / JavaScriptCore / tests / mozilla / ecma_2 / instanceof / instanceof-003.js
1 /**
2     File Name:          instanceof-003.js
3     ECMA Section:
4     Description:        http://bugzilla.mozilla.org/show_bug.cgi?id=7635
5
6 js> function Foo() {}
7 js> theproto = {};
8 [object Object]
9 js> Foo.prototype = theproto
10 [object Object]
11 js> theproto instanceof Foo
12 true
13
14 I think this should be 'false'
15
16
17     Author:             christine@netscape.com
18     Date:               12 november 1997
19
20
21 The test case described above is correct, however the second test case in this file is not,
22 'o instanceof o' should thow an exception.  According to ECMA-262:
23
24     8.6.2 Internal Properties and Methods:
25         "... only Function objects implement [[HasInstance]]"
26     11.8.6 The instanceof operator:
27         "6.If Result(4) does not have a [[HasInstance]] method, throw a TypeError exception."
28
29 {} does not implement [[HasInstance]] (since it is not a function), so passing it as the
30 constructor to be tested to instanceof should result in a TypeError being thrown.
31
32 */
33     var SECTION = "instanceof-003";
34     var VERSION = "ECMA_2";
35     var TITLE   = "instanceof operator";
36     var BUGNUMBER ="http://bugzilla.mozilla.org/show_bug.cgi?id=7635";
37
38     startTest();
39
40     function Foo() {};
41     theproto = {};
42     Foo.prototype = theproto;
43
44     AddTestCase(
45         "function Foo() = {}; theproto = {}; Foo.prototype = theproto; " +
46             "theproto instanceof Foo",
47         false,
48         theproto instanceof Foo );
49
50
51     AddTestCase(
52         "o = {}; o instanceof o",
53         "EXCEPTION",
54         (function(){ try { var o = {}; o instanceof o; return "no exception"; } catch (e) { return "EXCEPTION"; } } )() );
55
56
57     test();