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

Unified Diff: test/mjsunit/regress/regress-3641.js

Issue 1538663002: Reland "Clean up promises and fix an edge case bug (patchset #4 id:60001 of https://codereview.chro… (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Fixes two test262 tests! Created 5 years 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « test/mjsunit/mjsunit.status ('k') | test/test262/test262.status » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: test/mjsunit/regress/regress-3641.js
diff --git a/test/mjsunit/regress/regress-3641.js b/test/mjsunit/regress/regress-3641.js
new file mode 100644
index 0000000000000000000000000000000000000000..9aff8c8f7de599961399559bfd5dcc676aa561ce
--- /dev/null
+++ b/test/mjsunit/regress/regress-3641.js
@@ -0,0 +1,56 @@
+// Copyright 2015 the V8 project authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Flags: --allow-natives-syntax
+
+// If a Promise's then method is overridden, that should be respected
+// even if the promise is already resolved. x's resolution function is
+// only called by Promise.resolve(); there shouldn't be a resolution
+// check before when calling x.then.
+
+
+// Async assert framework copied from mjsunit/es6/promises.js
+
+var asyncAssertsExpected = 0;
+
+function assertAsyncRan() { ++asyncAssertsExpected }
+
+function assertLater(f, name) {
+ assertFalse(f()); // should not be true synchronously
+ ++asyncAssertsExpected;
+ var iterations = 0;
+ function runAssertion() {
+ if (f()) {
+ print(name, "succeeded");
+ --asyncAssertsExpected;
+ } else if (iterations++ < 10) {
+ %EnqueueMicrotask(runAssertion);
+ } else {
+ %AbortJS(name + " FAILED!");
+ }
+ }
+ %EnqueueMicrotask(runAssertion);
+}
+
+function assertAsyncDone(iteration) {
+ var iteration = iteration || 0;
+ %EnqueueMicrotask(function() {
+ if (asyncAssertsExpected === 0)
+ assertAsync(true, "all")
+ else if (iteration > 10) // Shouldn't take more.
+ assertAsync(false, "all... " + asyncAssertsExpected)
+ else
+ assertAsyncDone(iteration + 1)
+ });
+}
+
+// End async assert framework
+
+var y;
+var x = Promise.resolve();
+x.then = () => { y = true; }
+Promise.resolve().then(() => x);
+assertLater(() => y === true, "y === true");
+
+assertAsyncDone();
« no previous file with comments | « test/mjsunit/mjsunit.status ('k') | test/test262/test262.status » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698