tor-browser

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

capability-executor-not-callable.js (3206B)


      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.1
      6 description: >
      7  Throws a TypeError if either resolve or reject capability is not callable.
      8 info: |
      9  Promise.all ( iterable )
     10 
     11  ...
     12  6. Let promiseCapability be NewPromiseCapability(C).
     13  7. ReturnIfAbrupt(promiseCapability).
     14  ...
     15 
     16  25.4.1.5 NewPromiseCapability ( C )
     17    ...
     18    4. Let executor be a new built-in function object as defined in GetCapabilitiesExecutor Functions (25.4.1.5.1).
     19    5. Set the [[Capability]] internal slot of executor to promiseCapability.
     20    6. Let promise be Construct(C, «executor»).
     21    7. ReturnIfAbrupt(promise).
     22    8. If IsCallable(promiseCapability.[[Resolve]]) is false, throw a TypeError exception.
     23    9. If IsCallable(promiseCapability.[[Reject]]) is false, throw a TypeError exception.
     24    ...
     25 ---*/
     26 
     27 var checkPoint = "";
     28 function fn1(executor) {
     29  checkPoint += "a";
     30 }
     31 Object.defineProperty(fn1, 'resolve', {
     32  get() { throw new Test262Error; }
     33 });
     34 assert.throws(TypeError, function() {
     35  Promise.all.call(fn1, []);
     36 }, "executor not called at all");
     37 assert.sameValue(checkPoint, "a", "executor not called at all");
     38 
     39 checkPoint = "";
     40 function fn2(executor) {
     41  checkPoint += "a";
     42  executor();
     43  checkPoint += "b";
     44 }
     45 Object.defineProperty(fn2, 'resolve', {
     46  get() { throw new Test262Error; }
     47 });
     48 assert.throws(TypeError, function() {
     49  Promise.all.call(fn2, []);
     50 }, "executor called with no arguments");
     51 assert.sameValue(checkPoint, "ab", "executor called with no arguments");
     52 
     53 checkPoint = "";
     54 function fn3(executor) {
     55  checkPoint += "a";
     56  executor(undefined, undefined);
     57  checkPoint += "b";
     58 }
     59 Object.defineProperty(fn3, 'resolve', {
     60  get() { throw new Test262Error; }
     61 });
     62 assert.throws(TypeError, function() {
     63  Promise.all.call(fn3, []);
     64 }, "executor called with (undefined, undefined)");
     65 assert.sameValue(checkPoint, "ab", "executor called with (undefined, undefined)");
     66 
     67 checkPoint = "";
     68 function fn4(executor) {
     69  checkPoint += "a";
     70  executor(undefined, function() {});
     71  checkPoint += "b";
     72 }
     73 Object.defineProperty(fn4, 'resolve', {
     74  get() { throw new Test262Error; }
     75 });
     76 assert.throws(TypeError, function() {
     77  Promise.all.call(fn4, []);
     78 }, "executor called with (undefined, function)");
     79 assert.sameValue(checkPoint, "ab", "executor called with (undefined, function)");
     80 
     81 checkPoint = "";
     82 function fn5(executor) {
     83  checkPoint += "a";
     84  executor(function() {}, undefined);
     85  checkPoint += "b";
     86 }
     87 Object.defineProperty(fn5, 'resolve', {
     88  get() { throw new Test262Error; }
     89 });
     90 assert.throws(TypeError, function() {
     91  Promise.all.call(fn5, []);
     92 }, "executor called with (function, undefined)");
     93 assert.sameValue(checkPoint, "ab", "executor called with (function, undefined)");
     94 
     95 checkPoint = "";
     96 function fn6(executor) {
     97  checkPoint += "a";
     98  executor(123, "invalid value");
     99  checkPoint += "b";
    100 }
    101 Object.defineProperty(fn6, 'resolve', {
    102  get() { throw new Test262Error; }
    103 });
    104 assert.throws(TypeError, function() {
    105  Promise.all.call(fn6, []);
    106 }, "executor called with (Number, String)");
    107 assert.sameValue(checkPoint, "ab", "executor called with (Number, String)");
    108 
    109 reportCompare(0, 0);