Debian Codegraph @

js/src/tests/non262/generators/properties.js

raw
1 /* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
4
5 function assertOwnDescriptor(object, propertyKey, expected) {
6 var desc = Object.getOwnPropertyDescriptor(object, propertyKey);
7 if (desc === undefined) {
8 assertEq(expected, undefined, "Property shouldn't be present");
9 return;
10 }
11
12 assertEq(desc.enumerable, expected.enumerable, `${String(propertyKey)}.[[Enumerable]]`);
13 assertEq(desc.configurable, expected.configurable, `${String(propertyKey)}.[[Configurable]]`);
14
15 if (Object.prototype.hasOwnProperty.call(desc, "value")) {
16 assertEq(desc.value, expected.value, `${String(propertyKey)}.[[Value]]`);
17 assertEq(desc.writable, expected.writable, `${String(propertyKey)}.[[Writable]]`);
18 } else {
19 assertEq(desc.get, expected.get, `${String(propertyKey)}.[[Get]]`);
20 assertEq(desc.set, expected.set, `${String(propertyKey)}.[[Set]]`);
21 }
22 }
23
24 function* generator(){}
25 var GeneratorFunctionPrototype = Object.getPrototypeOf(generator);
26 var GeneratorFunction = GeneratorFunctionPrototype.constructor;
27 var GeneratorPrototype = GeneratorFunctionPrototype.prototype;
28
29
30 // ES2017, 25.2.2 Properties of the GeneratorFunction Constructor
31
32 assertEqArray(Object.getOwnPropertyNames(GeneratorFunction).sort(), ["length", "name", "prototype"]);
33 assertEqArray(Object.getOwnPropertySymbols(GeneratorFunction), []);
34
35 assertOwnDescriptor(GeneratorFunction, "length", {
36 value: 1, writable: false, enumerable: false, configurable: true
37 });
38
39 assertOwnDescriptor(GeneratorFunction, "name", {
40 value: "GeneratorFunction", writable: false, enumerable: false, configurable: true
41 });
42
43 assertOwnDescriptor(GeneratorFunction, "prototype", {
44 value: GeneratorFunctionPrototype, writable: false, enumerable: false, configurable: false
45 });
46
47
48 // ES2017, 25.2.3 Properties of the GeneratorFunction Prototype Object
49
50 assertEqArray(Object.getOwnPropertyNames(GeneratorFunctionPrototype).sort(), ["constructor", "prototype"]);
51 assertEqArray(Object.getOwnPropertySymbols(GeneratorFunctionPrototype), [Symbol.toStringTag]);
52
53 assertOwnDescriptor(GeneratorFunctionPrototype, "constructor", {
54 value: GeneratorFunction, writable: false, enumerable: false, configurable: true
55 });
56
57 assertOwnDescriptor(GeneratorFunctionPrototype, "prototype", {
58 value: GeneratorPrototype, writable: false, enumerable: false, configurable: true
59 });
60
61 assertOwnDescriptor(GeneratorFunctionPrototype, Symbol.toStringTag, {
62 value: "GeneratorFunction", writable: false, enumerable: false, configurable: true
63 });
64
65
66 // ES2017, 25.2.4 GeneratorFunction Instances
67
68 assertEqArray(Object.getOwnPropertyNames(generator).sort(), ["length", "name", "prototype"]);
69 assertEqArray(Object.getOwnPropertySymbols(generator), []);
70
71 assertOwnDescriptor(generator, "length", {
72 value: 0, writable: false, enumerable: false, configurable: true
73 });
74
75 assertOwnDescriptor(generator, "name", {
76 value: "generator", writable: false, enumerable: false, configurable: true
77 });
78
79 assertOwnDescriptor(generator, "prototype", {
80 value: generator.prototype, writable: true, enumerable: false, configurable: false
81 });
82
83
84 // ES2017, 25.3.1 Properties of Generator Prototype
85
86 assertEqArray(Object.getOwnPropertyNames(GeneratorPrototype).sort(), ["constructor", "next", "return", "throw"]);
87 assertEqArray(Object.getOwnPropertySymbols(GeneratorPrototype), [Symbol.toStringTag]);
88
89 assertOwnDescriptor(GeneratorPrototype, "constructor", {
90 value: GeneratorFunctionPrototype, writable: false, enumerable: false, configurable: true
91 });
92
93 assertOwnDescriptor(GeneratorPrototype, "next", {
94 value: GeneratorPrototype.next, writable: true, enumerable: false, configurable: true
95 });
96
97 assertOwnDescriptor(GeneratorPrototype, "return", {
98 value: GeneratorPrototype.return, writable: true, enumerable: false, configurable: true
99 });
100
101 assertOwnDescriptor(GeneratorPrototype, "throw", {
102 value: GeneratorPrototype.throw, writable: true, enumerable: false, configurable: true
103 });
104
105 assertOwnDescriptor(GeneratorPrototype, Symbol.toStringTag, {
106 value: "Generator", writable: false, enumerable: false, configurable: true
107 });
108
109
110 if (typeof reportCompare == "function")
111 reportCompare(true, true);