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

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

Issue 141913002: ES6: Implement Object.setPrototypeOf (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 6 years, 11 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
« src/v8natives.js ('K') | « src/v8natives.js ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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() {
Dmitry Lomov (no reviews) 2014/01/17 20:17:36 Maybe more tests to check that slots from new prot
arv (Not doing code reviews) 2014/01/17 21:03:15 Done.
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 var coercibleValues = [
49 1,
50 true,
51 'string',
52 Symbol()
53 ];
54
55
56 var nonCoercibleValues = [
57 undefined,
58 null
59 ];
60
61
62 var valuesWithoutNull = coercibleValues.concat(undefined);
63
64
65 function TestSetPrototypeOfCoercibleValues() {
66 for (var i = 0; i < coercibleValues.length; i++) {
67 var value = coercibleValues[i];
68 assertThrows(function() {
69 Object.getPrototypeOf(value);
70 }, TypeError);
71
72 assertEquals(Object.setPrototypeOf(value, {}), value);
73
74 assertThrows(function() {
75 Object.getPrototypeOf(value);
76 }, TypeError);
77 }
78 }
79 TestSetPrototypeOfCoercibleValues();
80
81
82 function TestSetPrototypeOfNonCoercibleValues() {
83 for (var i = 0; i < nonCoercibleValues.length; i++) {
84 var value = nonCoercibleValues[i];
85 assertThrows(function() {
86 Object.setPrototypeOf(value, {});
87 }, TypeError);
88 }
89 }
90 TestSetPrototypeOfNonCoercibleValues();
91
92
93 function TestSetPrototypeToNonObject(proto) {
94 var objects = getObjects();
95 for (var i = 0; i < objects.length; i++) {
96 var object = objects[i];
97 for (var j = 0; j < valuesWithoutNull.length; j++) {
98 var proto = valuesWithoutNull[j];
99 assertThrows(function() {
100 Object.setPrototypeOf(object, proto);
101 }, TypeError);
102 }
103 }
104 }
105 TestSetPrototypeToNonObject();
106
107
108 function TestSetPrototypeOf(object, proto) {
109 assertEquals(Object.setPrototypeOf(object, proto), object);
110 assertEquals(Object.getPrototypeOf(object), proto);
111 }
112
113
114 function TestSetPrototypeOfForObjects() {
115 var objects1 = getObjects();
116 var objects2 = getObjects();
117 for (var i = 0; i < objects1.length; i++) {
118 for (var j = 0; j < objects2.length; j++) {
119 TestSetPrototypeOf(objects1[i], objects2[j]);
120 }
121 }
122 }
123 TestSetPrototypeOfForObjects();
124
125
126 function TestSetPrototypeToNull() {
127 var objects = getObjects();
128 for (var i = 0; i < objects.length; i++) {
129 TestSetPrototypeOf(objects[i], null);
130 }
131 }
132 TestSetPrototypeToNull();
133
134
135 function TestSetPrototypeOfNonExtensibleObject() {
136 var objects = getObjects();
137 var proto = {};
138 for (var i = 0; i < objects.length; i++) {
139 var object = objects[i];
140 Object.preventExtensions(object);
141 assertThrows(function() {
142 Object.setPrototypeOf(object, proto);
143 }, TypeError);
144 }
145 }
146 TestSetPrototypeOfNonExtensibleObject();
OLDNEW
« src/v8natives.js ('K') | « src/v8natives.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698