Debian Codegraph @

js/src/tests/non262/object/regress-444787.js

raw
1 /* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5
6 //-----------------------------------------------------------------------------
7 var BUGNUMBER = 444787;
8 var summary = 'Object.getPrototypeOf';
9 var actual = '';
10 var expect = '';
11
12
13 //-----------------------------------------------------------------------------
14 test();
15 //-----------------------------------------------------------------------------
16
17 function test()
18 {
19 printBugNumber(BUGNUMBER);
20 printStatus (summary);
21
22 var i;
23 var type;
24 var instance;
25 var types = [
26 Array,
27 Boolean,
28 Date,
29 Error,
30 Function,
31 Math,
32 Number,
33 Object,
34 RegExp,
35 String,
36 ];
37
38 for (i = 0; i < types.length; i++)
39 {
40 type = types[i];
41
42 if (typeof type.__proto__ != 'undefined')
43 {
44 expect = type.__proto__;
45 actual = Object.getPrototypeOf(type);
46 reportCompare(expect, actual, summary + ': ' + type.name);
47 }
48
49 try
50 {
51 eval('instance = new ' + type.name);
52 expect = type.prototype;
53 actual = Object.getPrototypeOf(instance);
54 reportCompare(expect, actual, summary + ': new ' + type.name);
55 }
56 catch(ex) {
57 if (ex instanceof TypeError) {
58 print('Ignore ' + ex);
59 } else {
60 actual = ex + '';
61 reportCompare(expect, actual, summary + ': new ' + type.name);
62 }
63 }
64
65 }
66
67 types = [null, undefined];
68
69 for (i = 0; i < types.length; i++)
70 {
71 type = types[i];
72 expect = 'TypeError: Object.getPrototype is not a function';
73 try
74 {
75 actual = Object.getPrototype(null);
76 }
77 catch(ex)
78 {
79 actual = ex + '';
80 }
81 reportCompare(expect, actual, summary + ': ' + type);
82 }
83
84 var objects = [
85 {instance: [0], type: Array},
86 {instance: (function () {}), type: Function},
87 {instance: eval, type: Function},
88 {instance: parseInt, type: Function},
89 {instance: {a: ''}, type: Object},
90 {instance: /foo/, type: RegExp}
91 ];
92
93 for (i = 0; i < objects.length; i++)
94 {
95 instance = objects[i].instance;
96 type = objects[i].type;
97 expect = type.prototype;
98 actual = Object.getPrototypeOf(instance);
99 reportCompare(expect, actual, summary + ' instance: ' + instance + ', type: ' + type.name);
100 }
101 }