summaryrefslogtreecommitdiffstats
path: root/js/src/tests/ecma_6/Generators/properties.js
blob: 7782e64c0641839415b5e114393037e6a397847f (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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
/* 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]]`);
  }
}

function* generator(){}
var GeneratorFunctionPrototype = Object.getPrototypeOf(generator);
var GeneratorFunction = GeneratorFunctionPrototype.constructor;
var GeneratorPrototype = GeneratorFunctionPrototype.prototype;


// ES2017, 25.2.2 Properties of the GeneratorFunction Constructor

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

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

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

assertOwnDescriptor(GeneratorFunction, "prototype", {
    value: GeneratorFunctionPrototype, writable: false, enumerable: false, configurable: false
});


// ES2017, 25.2.3 Properties of the GeneratorFunction Prototype Object

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

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

assertOwnDescriptor(GeneratorFunctionPrototype, "prototype", {
    value: GeneratorPrototype, writable: false, enumerable: false, configurable: true
});

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


// ES2017, 25.2.4 GeneratorFunction Instances

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

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

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

assertOwnDescriptor(generator, "prototype", {
    value: generator.prototype, writable: true, enumerable: false, configurable: false
});


// ES2017, 25.3.1 Properties of Generator Prototype

assertEqArray(Object.getOwnPropertyNames(GeneratorPrototype).sort(), ["constructor", "next", "return", "throw"]);
assertEqArray(Object.getOwnPropertySymbols(GeneratorPrototype), [Symbol.toStringTag]);

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

assertOwnDescriptor(GeneratorPrototype, "next", {
    value: GeneratorPrototype.next, writable: true, enumerable: false, configurable: true
});

assertOwnDescriptor(GeneratorPrototype, "return", {
    value: GeneratorPrototype.return, writable: true, enumerable: false, configurable: true
});

assertOwnDescriptor(GeneratorPrototype, "throw", {
    value: GeneratorPrototype.throw, writable: true, enumerable: false, configurable: true
});

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


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