Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(231)

Side by Side Diff: test/mjsunit/set-prototype-of.js

Issue 178583005: Move all Harmony-only tests to harmony/ (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 6 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright 2014 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
28 // Flags: --harmony-symbols
29
30
31 function getObjects() {
32 function func() {}
33 return [
34 func,
35 new func(),
36 {x: 5},
37 /regexp/,
38 ['array'],
39 // new Error(),
40 new Date(),
41 new Number(1),
42 new Boolean(true),
43 new String('str'),
44 Object(Symbol())
45 ];
46 }
47
48
49 var coercibleValues = [
50 1,
51 true,
52 'string',
53 Symbol()
54 ];
55
56
57 var nonCoercibleValues = [
58 undefined,
59 null
60 ];
61
62
63 var valuesWithoutNull = coercibleValues.concat(undefined);
64
65
66 function TestSetPrototypeOfCoercibleValues() {
67 for (var i = 0; i < coercibleValues.length; i++) {
68 var value = coercibleValues[i];
69 assertThrows(function() {
70 Object.getPrototypeOf(value);
71 }, TypeError);
72
73 assertEquals(Object.setPrototypeOf(value, {}), value);
74
75 assertThrows(function() {
76 Object.getPrototypeOf(value);
77 }, TypeError);
78 }
79 }
80 TestSetPrototypeOfCoercibleValues();
81
82
83 function TestSetPrototypeOfNonCoercibleValues() {
84 for (var i = 0; i < nonCoercibleValues.length; i++) {
85 var value = nonCoercibleValues[i];
86 assertThrows(function() {
87 Object.setPrototypeOf(value, {});
88 }, TypeError);
89 }
90 }
91 TestSetPrototypeOfNonCoercibleValues();
92
93
94 function TestSetPrototypeToNonObject(proto) {
95 var objects = getObjects();
96 for (var i = 0; i < objects.length; i++) {
97 var object = objects[i];
98 for (var j = 0; j < valuesWithoutNull.length; j++) {
99 var proto = valuesWithoutNull[j];
100 assertThrows(function() {
101 Object.setPrototypeOf(object, proto);
102 }, TypeError);
103 }
104 }
105 }
106 TestSetPrototypeToNonObject();
107
108
109 function TestSetPrototypeOf(object, proto) {
110 assertEquals(Object.setPrototypeOf(object, proto), object);
111 assertEquals(Object.getPrototypeOf(object), proto);
112 }
113
114
115 function TestSetPrototypeOfForObjects() {
116 var objects1 = getObjects();
117 var objects2 = getObjects();
118 for (var i = 0; i < objects1.length; i++) {
119 for (var j = 0; j < objects2.length; j++) {
120 TestSetPrototypeOf(objects1[i], objects2[j]);
121 }
122 }
123 }
124 TestSetPrototypeOfForObjects();
125
126
127 function TestSetPrototypeToNull() {
128 var objects = getObjects();
129 for (var i = 0; i < objects.length; i++) {
130 TestSetPrototypeOf(objects[i], null);
131 }
132 }
133 TestSetPrototypeToNull();
134
135
136 function TestSetPrototypeOfNonExtensibleObject() {
137 var objects = getObjects();
138 var proto = {};
139 for (var i = 0; i < objects.length; i++) {
140 var object = objects[i];
141 Object.preventExtensions(object);
142 assertThrows(function() {
143 Object.setPrototypeOf(object, proto);
144 }, TypeError);
145 }
146 }
147 TestSetPrototypeOfNonExtensibleObject();
148
149
150 function TestLookup() {
151 var object = {};
152 assertFalse('x' in object);
153 assertFalse('y' in object);
154
155 var oldProto = {
156 x: 'old x',
157 y: 'old y'
158 };
159 Object.setPrototypeOf(object, oldProto);
160 assertEquals(object.x, 'old x');
161 assertEquals(object.y, 'old y');
162
163 var newProto = {
164 x: 'new x'
165 };
166 Object.setPrototypeOf(object, newProto);
167 assertEquals(object.x, 'new x');
168 assertFalse('y' in object);
169 }
170 TestLookup();
OLDNEW
« test/mjsunit/readonly.js ('K') | « test/mjsunit/regress/regress-observe-empty-double-array.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698