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

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

Issue 1895603002: [esnext] prototype runtime implementation for async functions (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@AsyncFunction
Patch Set: Try new strategy (Option C) Created 4 years, 8 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
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 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
47 // values. 47 // values.
48 // For known primitive values, please use assertEquals. 48 // For known primitive values, please use assertEquals.
49 var assertSame; 49 var assertSame;
50 50
51 // Expected and found values are identical primitive values or functions 51 // Expected and found values are identical primitive values or functions
52 // or similarly structured objects (checking internal properties 52 // or similarly structured objects (checking internal properties
53 // of, e.g., Number and Date objects, the elements of arrays 53 // of, e.g., Number and Date objects, the elements of arrays
54 // and the properties of non-Array objects). 54 // and the properties of non-Array objects).
55 var assertEquals; 55 var assertEquals;
56 56
57 var assertEqualsAsync;
57 58
58 // The difference between expected and found value is within certain tolerance. 59 // The difference between expected and found value is within certain tolerance.
59 var assertEqualsDelta; 60 var assertEqualsDelta;
60 61
61 // The found object is an Array with the same length and elements 62 // The found object is an Array with the same length and elements
62 // as the expected object. The expected object doesn't need to be an Array, 63 // as the expected object. The expected object doesn't need to be an Array,
63 // as long as it's "array-ish". 64 // as long as it's "array-ish".
64 var assertArrayEquals; 65 var assertArrayEquals;
65 66
66 // The found object must have the same enumerable properties as the 67 // The found object must have the same enumerable properties as the
(...skipping 19 matching lines...) Expand all
86 // Checks that the found value is *not* null. 87 // Checks that the found value is *not* null.
87 var assertNotNull; 88 var assertNotNull;
88 89
89 // Assert that the passed function or eval code throws an exception. 90 // Assert that the passed function or eval code throws an exception.
90 // The optional second argument is an exception constructor that the 91 // The optional second argument is an exception constructor that the
91 // thrown exception is checked against with "instanceof". 92 // thrown exception is checked against with "instanceof".
92 // The optional third argument is a message type string that is compared 93 // The optional third argument is a message type string that is compared
93 // to the type property on the thrown exception. 94 // to the type property on the thrown exception.
94 var assertThrows; 95 var assertThrows;
95 96
97 var assertThrowsAsync;
98
96 // Assert that the passed function throws an exception. 99 // Assert that the passed function throws an exception.
97 // The exception is checked against the second argument using assertEquals. 100 // The exception is checked against the second argument using assertEquals.
98 var assertThrowsEquals; 101 var assertThrowsEquals;
99 102
100 // Assert that the passed function or eval code does not throw an exception. 103 // Assert that the passed function or eval code does not throw an exception.
101 var assertDoesNotThrow; 104 var assertDoesNotThrow;
102 105
103 // Asserts that the found value is an instance of the constructor passed 106 // Asserts that the found value is an instance of the constructor passed
104 // as the second argument. 107 // as the second argument.
105 var assertInstanceof; 108 var assertInstanceof;
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after
276 }; 279 };
277 280
278 281
279 assertEquals = function assertEquals(expected, found, name_opt) { 282 assertEquals = function assertEquals(expected, found, name_opt) {
280 if (!deepEquals(found, expected)) { 283 if (!deepEquals(found, expected)) {
281 fail(PrettyPrint(expected), found, name_opt); 284 fail(PrettyPrint(expected), found, name_opt);
282 } 285 }
283 }; 286 };
284 287
285 288
289 assertEqualsAsync = function assertEqualsAsync(expected, run, msg) {
290 var actual;
291 var hadValue = false;
292 var hadError = false;
293 var promise = run();
294
295 if (typeof promise !== "object" || typeof promise.then !== "function") {
296 throw new MjsUnitAssertionError(
297 "Expected " + run.toString() +
298 " to return a Promise, but it returned " + PrettyPrint(promise));
299 }
300
301 promise.then(function(value) { hadValue = true; actual = value; },
302 function(error) { hadError = true; actual = error; });
303
304 assertFalse(hadValue || hadError);
305
306 flushMicrotasks();
307
308 if (hadError) throw actual;
309
310 assertTrue(
311 hadValue, "Expected '" + run.toString() + "' to produce a value");
312
313 assertEquals(expected, actual, msg);
314 };
315
286 assertEqualsDelta = 316 assertEqualsDelta =
287 function assertEqualsDelta(expected, found, delta, name_opt) { 317 function assertEqualsDelta(expected, found, delta, name_opt) {
288 assertTrue(Math.abs(expected - found) <= delta, name_opt); 318 assertTrue(Math.abs(expected - found) <= delta, name_opt);
289 }; 319 };
290 320
291 321
292 assertArrayEquals = function assertArrayEquals(expected, found, name_opt) { 322 assertArrayEquals = function assertArrayEquals(expected, found, name_opt) {
293 var start = ""; 323 var start = "";
294 if (name_opt) { 324 if (name_opt) {
295 start = name_opt + " - "; 325 start = name_opt + " - ";
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
362 } 392 }
363 if (arguments.length >= 3) { 393 if (arguments.length >= 3) {
364 assertEquals(e.type, cause_opt); 394 assertEquals(e.type, cause_opt);
365 } 395 }
366 // Success. 396 // Success.
367 return; 397 return;
368 } 398 }
369 throw new MjsUnitAssertionError("Did not throw exception"); 399 throw new MjsUnitAssertionError("Did not throw exception");
370 }; 400 };
371 401
402 assertThrowsAsync = function assertThrowsAsync(run, errorType, message) {
403 var actual;
404 var hadValue = false;
405 var hadError = false;
406 var promise = run();
407
408 if (typeof promise !== "object" || typeof promise.then !== "function") {
409 throw new MjsUnitAssertionError(
410 "Expected " + run.toString() +
411 " to return a Promise, but it returned " + PrettyPrint(promise));
412 }
413
414 promise.then(function(value) { hadValue = true; actual = value; },
415 function(error) { hadError = true; actual = error; });
416
417 assertFalse(hadValue || hadError);
418
419 flushMicrotasks();
420
421 if (!hadError) {
422 throw new MjsUnitAssertionError(
423 "Expected " + run + "() to throw " + errorType.name +
424 ", but did not throw.");
425 }
426 if (!(actual instanceof errorType))
427 throw new MjsUnitAssertionError(
428 "Expected " + run + "() to throw " + errorType.name +
429 ", but threw '" + actual + "'");
430 if (message !== void 0 && actual.message !== message)
431 throw new MjsUnitAssertionError(
432 "Expected " + run + "() to throw '" + message + "', but threw '" +
433 actual.message + "'");
434 };
435
372 436
373 assertThrowsEquals = function assertThrowsEquals(fun, val) { 437 assertThrowsEquals = function assertThrowsEquals(fun, val) {
374 try { 438 try {
375 fun(); 439 fun();
376 } catch(e) { 440 } catch(e) {
377 assertEquals(val, e); 441 assertEquals(val, e);
378 return; 442 return;
379 } 443 }
380 throw new MjsUnitAssertionError("Did not throw exception"); 444 throw new MjsUnitAssertionError("Did not throw exception");
381 }; 445 };
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
434 if (sync_opt === undefined) sync_opt = ""; 498 if (sync_opt === undefined) sync_opt = "";
435 assertTrue(OptimizationStatus(fun, sync_opt) !== 1, name_opt); 499 assertTrue(OptimizationStatus(fun, sync_opt) !== 1, name_opt);
436 } 500 }
437 501
438 assertOptimized = function assertOptimized(fun, sync_opt, name_opt) { 502 assertOptimized = function assertOptimized(fun, sync_opt, name_opt) {
439 if (sync_opt === undefined) sync_opt = ""; 503 if (sync_opt === undefined) sync_opt = "";
440 assertTrue(OptimizationStatus(fun, sync_opt) !== 2, name_opt); 504 assertTrue(OptimizationStatus(fun, sync_opt) !== 2, name_opt);
441 } 505 }
442 506
443 })(); 507 })();
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698