tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

resolve-from-promise-capability.js (1133B)


      1 // Copyright (C) 2015 André Bargull. All rights reserved.
      2 // This code is governed by the BSD license found in the LICENSE file.
      3 
      4 /*---
      5 es6id: 25.4.4.5
      6 description: >
      7  Resolve function is called after Promise constructor returns.
      8 info: |
      9  Promise.resolve ( x )
     10 
     11  ...
     12  4. Let promiseCapability be NewPromiseCapability(C).
     13  5. ReturnIfAbrupt(promiseCapability).
     14  6. Let resolveResult be Call(promiseCapability.[[Resolve]], undefined, «x»).
     15  7. ReturnIfAbrupt(resolveResult).
     16  ...
     17 ---*/
     18 
     19 var expectedThisValue = (function() {
     20  return this;
     21 }());
     22 var callCount = 0;
     23 var object = {};
     24 var thisValue, args;
     25 
     26 Promise.resolve.call(function(executor) {
     27  function resolve(v) {
     28    callCount += 1;
     29    thisValue = this;
     30    args = arguments;
     31  }
     32  executor(resolve, Test262Error.thrower);
     33  assert.sameValue(callCount, 0, "callCount before returning from constructor");
     34 }, object);
     35 
     36 assert.sameValue(callCount, 1, "callCount after call to resolve()");
     37 assert.sameValue(typeof args, "object");
     38 assert.sameValue(args.length, 1);
     39 assert.sameValue(args[0], object);
     40 assert.sameValue(thisValue, expectedThisValue);
     41 
     42 reportCompare(0, 0);