summaryrefslogtreecommitdiffstats
path: root/js/src/tests/test262/built-ins/Promise/race/invoke-resolve-get-once-no-calls.js
diff options
context:
space:
mode:
Diffstat (limited to 'js/src/tests/test262/built-ins/Promise/race/invoke-resolve-get-once-no-calls.js')
-rw-r--r--js/src/tests/test262/built-ins/Promise/race/invoke-resolve-get-once-no-calls.js43
1 files changed, 43 insertions, 0 deletions
diff --git a/js/src/tests/test262/built-ins/Promise/race/invoke-resolve-get-once-no-calls.js b/js/src/tests/test262/built-ins/Promise/race/invoke-resolve-get-once-no-calls.js
new file mode 100644
index 0000000000..43e6718a67
--- /dev/null
+++ b/js/src/tests/test262/built-ins/Promise/race/invoke-resolve-get-once-no-calls.js
@@ -0,0 +1,43 @@
+// Copyright (C) 2019 Leo Balter. All rights reserved.
+// This code is governed by the BSD license found in the LICENSE file.
+
+/*---
+description: >
+ Gets constructor's `resolve` method once from zero to many invocations.
+esid: sec-promise.race
+info: |
+ Runtime Semantics: PerformPromiseRace
+
+ 1. Let promiseResolve be ? Get(constructor, `"resolve"`).
+ 1. If IsCallable(promiseResolve) is false, throw a TypeError exception.
+ ...
+ 1. Repeat,
+ ...
+ 1. Let nextPromise be ? Call(promiseResolve, constructor, « nextValue »).
+---*/
+
+var resolve = Promise.resolve;
+var getCount = 0;
+var callCount = 0;
+
+Object.defineProperty(Promise, 'resolve', {
+ configurable: true,
+ get() {
+ getCount += 1;
+ return function() {
+ callCount += 1;
+ return resolve.apply(Promise, arguments);
+ };
+ }
+});
+
+Promise.race([]);
+
+assert.sameValue(
+ getCount, 1, 'Got `resolve` only once for each iterated value'
+);
+assert.sameValue(
+ callCount, 0, '`resolve` not called for empty iterator'
+);
+
+reportCompare(0, 0);