Debian Codegraph @

rhino/testsrc/tests/ecma_3_1/Object/regress-444787.js

raw symbols SCIP
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 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 var gTestfile = 'regress-444787.js';
7 //-----------------------------------------------------------------------------
8 var BUGNUMBER = 444787;
9 var summary = 'Object.getPrototypeOf';
10 var actual = '';
11 var expect = '';
12
13
14 //-----------------------------------------------------------------------------
15 test();
16 //-----------------------------------------------------------------------------
17
18 function test()
19 {
20 enterFunc ('test');
21 printBugNumber(BUGNUMBER);
22 printStatus (summary);
23
24 var i;
25 var type;
26 var instance;
27 var types = [
28 Array,
29 Boolean,
30 Date,
31 Error,
32 Function,
33 Math,
34 Number,
35 Object,
36 RegExp,
37 String,
38 ];
39
40 for (i = 0; i < types.length; i++)
41 {
42 type = types[i];
43
44 if (typeof type.__proto__ != 'undefined')
45 {
46 expect = type.__proto__;
47 actual = Object.getPrototypeOf(type);
48 reportCompare(expect, actual, summary + ': ' + type.name);
49 }
50
51 try
52 {
53 eval('instance = new ' + type.name);
54 expect = type.prototype;
55 actual = Object.getPrototypeOf(instance);
56 reportCompare(expect, actual, summary + ': new ' + type.name);
57 }
58 catch(ex if ex instanceof TypeError)
59 {
60 print('Ignore ' + ex);
61 }
62 catch(ex)
63 {
64 actual = ex + '';
65 reportCompare(expect, actual, summary + ': new ' + type.name);
66 }
67
68 }
69
70 types = [null, undefined];
71
72 for (i = 0; i < types.length; i++)
73 {
74 type = types[i];
75 expect = 'TypeError: Object.getPrototype is not a function';
76 try
77 {
78 actual = Object.getPrototype(null);
79 }
80 catch(ex)
81 {
82 actual = ex + '';
83 }
84 reportCompare(expect, actual, summary + ': ' + type);
85 }
86
87 var objects = [
88 {instance: [0], type: Array},
89 {instance: true, type: Boolean},
90 {instance: false, type: Boolean},
91 {instance: (function () {}), type: Function},
92 {instance: eval, type: Function},
93 {instance: parseInt, type: Function},
94 {instance: 1.0, type: Number},
95 {instance: Infinity, type: Number},
96 {instance: NaN, type: Number},
97 {instance: Math.PI, type: Number},
98 {instance: {a: ''}, type: Object},
99 {instance: /foo/, type: RegExp},
100 {instance: "bar", type: String}
101 ];
102
103 for (i = 0; i < objects.length; i++)
104 {
105 instance = objects[i].instance;
106 type = objects[i].type;
107 expect = type.prototype;
108 actual = Object.getPrototypeOf(instance);
109 reportCompare(expect, actual, summary + ' instance: ' + instance + ', type: ' + type.name);
110 }
111
112 exitFunc ('test');
113 }