]> git.saurik.com Git - apple/javascriptcore.git/blame - tests/mozilla/ecma_2/instanceof/instanceof-003.js
JavaScriptCore-1097.3.tar.gz
[apple/javascriptcore.git] / tests / mozilla / ecma_2 / instanceof / instanceof-003.js
CommitLineData
b37bf2e1
A
1/**
2 File Name: instanceof-003.js
3 ECMA Section:
4 Description: http://bugzilla.mozilla.org/show_bug.cgi?id=7635
5
6js> function Foo() {}
7js> theproto = {};
8[object Object]
9js> Foo.prototype = theproto
10[object Object]
11js> theproto instanceof Foo
12true
13
14I think this should be 'false'
15
16
17 Author: christine@netscape.com
18 Date: 12 november 1997
ba379fdc
A
19
20
21The 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
30constructor to be tested to instanceof should result in a TypeError being thrown.
31
b37bf2e1
A
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
b37bf2e1
A
51 AddTestCase(
52 "o = {}; o instanceof o",
ba379fdc
A
53 "EXCEPTION",
54 (function(){ try { var o = {}; o instanceof o; return "no exception"; } catch (e) { return "EXCEPTION"; } } )() );
b37bf2e1
A
55
56
57 test();