summaryrefslogtreecommitdiffstats
path: root/js/src/tests/ecma_2017/AsyncFunctions/properties.js
blob: ca383901bb47474be33fd31bf6c901630057b43d (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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

function assertOwnDescriptor(object, propertyKey, expected) {
  var desc = Object.getOwnPropertyDescriptor(object, propertyKey);
  if (desc === undefined) {
    assertEq(expected, undefined, "Property shouldn't be present");
    return;
  }

  assertEq(desc.enumerable, expected.enumerable, `${String(propertyKey)}.[[Enumerable]]`);
  assertEq(desc.configurable, expected.configurable, `${String(propertyKey)}.[[Configurable]]`);

  if (Object.prototype.hasOwnProperty.call(desc, "value")) {
    assertEq(desc.value, expected.value, `${String(propertyKey)}.[[Value]]`);
    assertEq(desc.writable, expected.writable, `${String(propertyKey)}.[[Writable]]`);
  } else {
    assertEq(desc.get, expected.get, `${String(propertyKey)}.[[Get]]`);
    assertEq(desc.set, expected.set, `${String(propertyKey)}.[[Set]]`);
  }
}

async function asyncFunc(){}
var AsyncFunctionPrototype = Object.getPrototypeOf(asyncFunc);
var AsyncFunction = AsyncFunctionPrototype.constructor;


// ES2017, 25.5.2 Properties of the AsyncFunction Constructor

assertEqArray(Object.getOwnPropertyNames(AsyncFunction).sort(), ["length", "name", "prototype"]);
assertEqArray(Object.getOwnPropertySymbols(AsyncFunction), []);

assertOwnDescriptor(AsyncFunction, "length", {
    value: 1, writable: false, enumerable: false, configurable: true
});

assertOwnDescriptor(AsyncFunction, "name", {
    value: "AsyncFunction", writable: false, enumerable: false, configurable: true
});

assertOwnDescriptor(AsyncFunction, "prototype", {
    value: AsyncFunctionPrototype, writable: false, enumerable: false, configurable: false
});


// ES2017, 25.5.3 Properties of the AsyncFunction Prototype Object

assertEqArray(Object.getOwnPropertyNames(AsyncFunctionPrototype).sort(), ["constructor"]);
assertEqArray(Object.getOwnPropertySymbols(AsyncFunctionPrototype), [Symbol.toStringTag]);

assertOwnDescriptor(AsyncFunctionPrototype, "constructor", {
    value: AsyncFunction, writable: false, enumerable: false, configurable: true
});

assertOwnDescriptor(AsyncFunctionPrototype, Symbol.toStringTag, {
    value: "AsyncFunction", writable: false, enumerable: false, configurable: true
});


// ES2017, 25.5.4 AsyncFunction Instances

assertEqArray(Object.getOwnPropertyNames(asyncFunc).sort(), ["length", "name"]);
assertEqArray(Object.getOwnPropertySymbols(asyncFunc), []);

assertOwnDescriptor(asyncFunc, "length", {
    value: 0, writable: false, enumerable: false, configurable: true
});

assertOwnDescriptor(asyncFunc, "name", {
    value: "asyncFunc", writable: false, enumerable: false, configurable: true
});


if (typeof reportCompare == "function")
    reportCompare(true, true);