summaryrefslogtreecommitdiffstats
path: root/js/src/tests/test262/built-ins/Promise/prototype/finally/resolved-observable-then-calls-argument.js
blob: 0f9fc558c5b1f42ac65ea3b567399b9501219880 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
// |reftest| async
// Copyright (C) 2019 Alexey Shvayka. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-thenfinallyfunctions
description: >
  valueThunk is anonymous built-in function with length of 1 that returns value.
info: |
  Then Finally Functions

  ...
  8. Let valueThunk be equivalent to a function that returns value.
  9. Return ? Invoke(promise, "then", « valueThunk »).

  The "length" property of a Then Finally function is 1.
features: [Promise.prototype.finally, Reflect.construct, arrow-function]
includes: [isConstructor.js]
flags: [async]
---*/

var value = {};

Promise.resolve(value)
  .finally(function() {})
  .then(() => $DONE(), $DONE);

var calls = 0;
var expected = [
  { length: 0, name: '' },
  { length: 1, name: '' }
];

var then = Promise.prototype.then;
Promise.prototype.then = function(resolve) {
  assert.sameValue(isConstructor(resolve), false, 'isConstructor(resolve) must return false');
  assert.throws(TypeError, () => {
    new resolve();
  });

  assert.sameValue(
    resolve.length,
    expected[calls].length,
    'The value of resolve.length is expected to equal the value of expected[calls].length'
  );
  assert.sameValue(
    resolve.name,
    expected[calls].name,
    'The value of resolve.name is expected to equal the value of expected[calls].name'
  );
  if (calls === 0) {
    assert.sameValue(resolve(), value, 'resolve() must return the value of value');
  }
  calls += 1;
  return then.call(this, resolve);
};