blob: 0a43b4cc265be3d716b9e782c5583acd4a91c336 [file] [log] [blame]
Leon Clarkee46be812010-01-19 14:06:41 +00001// Copyright 2010 the V8 project authors. All rights reserved.
2// Redistribution and use in source and binary forms, with or without
3// modification, are permitted provided that the following conditions are
4// met:
5//
6// * Redistributions of source code must retain the above copyright
7// notice, this list of conditions and the following disclaimer.
8// * Redistributions in binary form must reproduce the above
9// copyright notice, this list of conditions and the following
10// disclaimer in the documentation and/or other materials provided
11// with the distribution.
12// * Neither the name of Google Inc. nor the names of its
13// contributors may be used to endorse or promote products derived
14// from this software without specific prior written permission.
15//
16// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000028function assertPrototypeOf(func, expected) {
29 assertEquals(expected, Object.getPrototypeOf(func));
Leon Clarkee46be812010-01-19 14:06:41 +000030}
31
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000032
33assertThrows(function() {
34 Object.getPrototypeOf(undefined);
35}, TypeError);
36
37
38assertThrows(function() {
39 Object.getPrototypeOf(null);
40}, TypeError);
41
42
Leon Clarkee46be812010-01-19 14:06:41 +000043function F(){};
Leon Clarkee46be812010-01-19 14:06:41 +000044var y = new F();
45
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000046assertPrototypeOf(y, F.prototype);
47assertPrototypeOf(F, Function.prototype);
Leon Clarkee46be812010-01-19 14:06:41 +000048
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000049assertPrototypeOf({x: 5}, Object.prototype);
50assertPrototypeOf({x: 5, __proto__: null}, null);
51
52assertPrototypeOf([1, 2], Array.prototype);
53
54
55assertPrototypeOf(1, Number.prototype);
56assertPrototypeOf(true, Boolean.prototype);
57assertPrototypeOf(false, Boolean.prototype);
58assertPrototypeOf('str', String.prototype);
59assertPrototypeOf(Symbol(), Symbol.prototype);
60
61
62var errorFunctions = [
63 EvalError,
64 RangeError,
65 ReferenceError,
66 SyntaxError,
67 TypeError,
68 URIError,
69];
70
71for (var f of errorFunctions) {
72 assertPrototypeOf(f, Error);
73 assertPrototypeOf(new f(), f.prototype);
74}
75
76
77// Builtin constructors.
78var functions = [
79 Array,
80 ArrayBuffer,
81 Boolean,
82 // DataView,
83 Date,
84 Error,
85 // Float32Array, prototype is %TypedArray%
86 // Float64Array,
87 Function,
88 // Int16Array,
89 // Int32Array,
90 // Int8Array,
91 Map,
92 Number,
93 Object,
94 // Promise,
95 RegExp,
96 Set,
97 String,
98 // Symbol, not constructible
99 // Uint16Array,
100 // Uint32Array,
101 // Uint8Array,
102 // Uint8ClampedArray,
103 WeakMap,
104 WeakSet,
105];
106
107for (var f of functions) {
108 assertPrototypeOf(f, Function.prototype);
109 assertPrototypeOf(new f(), f.prototype);
110}
111
112var p = new Promise(function() {});
113assertPrototypeOf(p, Promise.prototype);
114
115var dv = new DataView(new ArrayBuffer());
116assertPrototypeOf(dv, DataView.prototype);