Debian Codegraph @

js/src/tests/test262/language/module-code/instn-named-bndng-gen.js

raw
1 // |reftest| module
2 // Copyright (C) 2016 the V8 project authors. All rights reserved.
3 // This code is governed by the BSD license found in the LICENSE file.
4 /*---
5 description: >
6 Imported binding reflects state of exported generator function binding
7 esid: sec-moduledeclarationinstantiation
8 info: |
9 [...]
10 12. For each ImportEntry Record in in module.[[ImportEntries]], do
11 a. Let importedModule be ? HostResolveImportedModule(module,
12 in.[[ModuleRequest]]).
13 b. If in.[[ImportName]] is "*", then
14 [...]
15 c. Else,
16 i. Let resolution be ?
17 importedModule.ResolveExport(in.[[ImportName]], « », « »).
18 ii. If resolution is null or resolution is "ambiguous", throw a
19 SyntaxError exception.
20 iii. Call envRec.CreateImportBinding(in.[[LocalName]],
21 resolution.[[Module]], resolution.[[BindingName]]).
22 [...]
23 16. Let lexDeclarations be the LexicallyScopedDeclarations of code.
24 17. For each element d in lexDeclarations do
25 a. For each element dn of the BoundNames of d do
26 i, If IsConstantDeclaration of d is true, then
27 1. Perform ! envRec.CreateImmutableBinding(dn, true).
28 ii. Else,
29 1. Perform ! envRec.CreateMutableBinding(dn, false).
30 iii. If d is a GeneratorDeclaration production or a
31 FunctionDeclaration production, then
32 1. Let fo be the result of performing InstantiateFunctionObject
33 for d with argument env.
34 2. Call envRec.InitializeBinding(dn, fo).
35 [...]
36
37 8.1.1.5.5 CreateImportBinding
38
39 [...]
40 5. Create an immutable indirect binding in envRec for N that references M
41 and N2 as its target binding and record that the binding is initialized.
42 6. Return NormalCompletion(empty).
43 flags: [module]
44 features: [generators]
45 ---*/
46
47 assert.sameValue(
48 g2().next().value,
49 23,
50 'binding is initialized to function value prior to module evaluation'
51 );
52
53 assert.throws(TypeError, function() {
54 g2 = null;
55 }, 'binding rejects assignment');
56
57 assert.sameValue(g2().next().value, 23, 'binding value is immutable');
58
59 import { g as g2 } from './instn-named-bndng-gen.js';
60 export function* g() { return 23; }
61
62 reportCompare(0, 0);