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

Side by Side Diff: test/mjsunit/mjsunit.js

Issue 1448933002: Introduce a BuiltinsConstructStub that sets up new.target and does a [[call]] per ES6 9.3.2 (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 5 years, 1 month 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
« no previous file with comments | « test/mjsunit/es6/regexp-constructor.js ('k') | test/mjsunit/regexp.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2008 the V8 project authors. All rights reserved. 1 // Copyright 2008 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
106 // Assert that the function code is (not) optimized. If "no sync" is passed 106 // Assert that the function code is (not) optimized. If "no sync" is passed
107 // as second argument, we do not wait for the concurrent optimization thread to 107 // as second argument, we do not wait for the concurrent optimization thread to
108 // finish when polling for optimization status. 108 // finish when polling for optimization status.
109 // Only works with --allow-natives-syntax. 109 // Only works with --allow-natives-syntax.
110 var assertOptimized; 110 var assertOptimized;
111 var assertUnoptimized; 111 var assertUnoptimized;
112 112
113 113
114 (function () { // Scope for utility functions. 114 (function () { // Scope for utility functions.
115 115
116 var ObjectPrototypeToString = Object.prototype.toString;
117 var NumberPrototypeValueOf = Number.prototype.valueOf;
118 var BooleanPrototypeValueOf = Boolean.prototype.valueOf;
119 var StringPrototypeValueOf = String.prototype.valueOf;
120 var DatePrototypeValueOf = Date.prototype.valueOf;
121 var RegExpPrototypeToString = RegExp.prototype.toString;
122 var ArrayPrototypeMap = Array.prototype.map;
123 var ArrayPrototypeJoin = Array.prototype.join;
124
116 function classOf(object) { 125 function classOf(object) {
117 // Argument must not be null or undefined. 126 // Argument must not be null or undefined.
118 var string = Object.prototype.toString.call(object); 127 var string = ObjectPrototypeToString.call(object);
119 // String has format [object <ClassName>]. 128 // String has format [object <ClassName>].
120 return string.substring(8, string.length - 1); 129 return string.substring(8, string.length - 1);
121 } 130 }
122 131
123 132
133 function ValueOf(value) {
134 switch (classOf(value)) {
135 case "Number":
136 return NumberPrototypeValueOf.call(value);
137 case "String":
138 return StringPrototypeValueOf.call(value);
139 case "Boolean":
140 return BooleanPrototypeValueOf.call(value);
141 case "Date":
142 return DatePrototypeValueOf.call(value);
143 default:
144 return value;
145 }
146 }
147
148
124 function PrettyPrint(value) { 149 function PrettyPrint(value) {
125 switch (typeof value) { 150 switch (typeof value) {
126 case "string": 151 case "string":
127 return JSON.stringify(value); 152 return JSON.stringify(value);
128 case "number": 153 case "number":
129 if (value === 0 && (1 / value) < 0) return "-0"; 154 if (value === 0 && (1 / value) < 0) return "-0";
130 // FALLTHROUGH. 155 // FALLTHROUGH.
131 case "boolean": 156 case "boolean":
132 case "undefined": 157 case "undefined":
133 case "function": 158 case "function":
134 case "symbol": 159 case "symbol":
135 return String(value); 160 return String(value);
136 case "object": 161 case "object":
137 if (value === null) return "null"; 162 if (value === null) return "null";
138 var objectClass = classOf(value); 163 var objectClass = classOf(value);
139 switch (objectClass) { 164 switch (objectClass) {
140 case "Number": 165 case "Number":
141 case "String": 166 case "String":
142 case "Boolean": 167 case "Boolean":
143 case "Date": 168 case "Date":
144 return objectClass + "(" + PrettyPrint(value.valueOf()) + ")"; 169 return objectClass + "(" + PrettyPrint(ValueOf(value)) + ")";
145 case "RegExp": 170 case "RegExp":
146 return value.toString(); 171 return RegExpPrototypeToString.call(value);
147 case "Array": 172 case "Array":
148 return "[" + value.map(PrettyPrintArrayElement).join(",") + "]"; 173 var mapped = ArrayPrototypeMap.call(value, PrettyPrintArrayElement);
149 case "Object": 174 var joined = ArrayPrototypeJoin.call(mapped, ",");
150 break; 175 return "[" + joined + "]";
151 default: 176 case "Object":
152 return objectClass + "()"; 177 break;
178 default:
179 return objectClass + "()";
153 } 180 }
154 // [[Class]] is "Object". 181 // [[Class]] is "Object".
155 var name = value.constructor.name; 182 var name = value.constructor.name;
156 if (name) return name + "()"; 183 if (name) return name + "()";
157 return "Object()"; 184 return "Object()";
158 default: 185 default:
159 return "-- unknown value --"; 186 return "-- unknown value --";
160 } 187 }
161 } 188 }
162 189
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
204 return true; 231 return true;
205 } 232 }
206 if (typeof a !== typeof b) return false; 233 if (typeof a !== typeof b) return false;
207 if (typeof a === "number") return isNaN(a) && isNaN(b); 234 if (typeof a === "number") return isNaN(a) && isNaN(b);
208 if (typeof a !== "object" && typeof a !== "function") return false; 235 if (typeof a !== "object" && typeof a !== "function") return false;
209 // Neither a nor b is primitive. 236 // Neither a nor b is primitive.
210 var objectClass = classOf(a); 237 var objectClass = classOf(a);
211 if (objectClass !== classOf(b)) return false; 238 if (objectClass !== classOf(b)) return false;
212 if (objectClass === "RegExp") { 239 if (objectClass === "RegExp") {
213 // For RegExp, just compare pattern and flags using its toString. 240 // For RegExp, just compare pattern and flags using its toString.
214 return (a.toString() === b.toString()); 241 return RegExpPrototypeToString.call(a) ===
242 RegExpPrototypeToString.call(b);
215 } 243 }
216 // Functions are only identical to themselves. 244 // Functions are only identical to themselves.
217 if (objectClass === "Function") return false; 245 if (objectClass === "Function") return false;
218 if (objectClass === "Array") { 246 if (objectClass === "Array") {
219 var elementCount = 0; 247 var elementCount = 0;
220 if (a.length !== b.length) { 248 if (a.length !== b.length) {
221 return false; 249 return false;
222 } 250 }
223 for (var i = 0; i < a.length; i++) { 251 for (var i = 0; i < a.length; i++) {
224 if (!deepEquals(a[i], b[i])) return false; 252 if (!deepEquals(a[i], b[i])) return false;
225 } 253 }
226 return true; 254 return true;
227 } 255 }
228 if (objectClass === "String" || objectClass === "Number" || 256 if (objectClass === "String" || objectClass === "Number" ||
229 objectClass === "Boolean" || objectClass === "Date") { 257 objectClass === "Boolean" || objectClass === "Date") {
230 if (a.valueOf() !== b.valueOf()) return false; 258 if (ValueOf(a) !== ValueOf(b)) return false;
231 } 259 }
232 return deepObjectEquals(a, b); 260 return deepObjectEquals(a, b);
233 } 261 }
234 262
235 assertSame = function assertSame(expected, found, name_opt) { 263 assertSame = function assertSame(expected, found, name_opt) {
236 // TODO(mstarzinger): We should think about using Harmony's egal operator 264 // TODO(mstarzinger): We should think about using Harmony's egal operator
237 // or the function equivalent Object.is() here. 265 // or the function equivalent Object.is() here.
238 if (found === expected) { 266 if (found === expected) {
239 if (expected !== 0 || (1 / expected) === (1 / found)) return; 267 if (expected !== 0 || (1 / expected) === (1 / found)) return;
240 } else if ((expected !== expected) && (found !== found)) { 268 } else if ((expected !== expected) && (found !== found)) {
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after
389 if (sync_opt === undefined) sync_opt = ""; 417 if (sync_opt === undefined) sync_opt = "";
390 assertTrue(OptimizationStatus(fun, sync_opt) !== 1, name_opt); 418 assertTrue(OptimizationStatus(fun, sync_opt) !== 1, name_opt);
391 } 419 }
392 420
393 assertOptimized = function assertOptimized(fun, sync_opt, name_opt) { 421 assertOptimized = function assertOptimized(fun, sync_opt, name_opt) {
394 if (sync_opt === undefined) sync_opt = ""; 422 if (sync_opt === undefined) sync_opt = "";
395 assertTrue(OptimizationStatus(fun, sync_opt) !== 2, name_opt); 423 assertTrue(OptimizationStatus(fun, sync_opt) !== 2, name_opt);
396 } 424 }
397 425
398 })(); 426 })();
OLDNEW
« no previous file with comments | « test/mjsunit/es6/regexp-constructor.js ('k') | test/mjsunit/regexp.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698