MCPcopy Create free account
hub / github.com/mozilla/rhino / ES6Generator

Class ES6Generator

rhino/src/main/java/org/mozilla/javascript/ES6Generator.java:15–425  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

13import java.io.Serial;
14
15public final class ES6Generator extends ScriptableObject {
16 @Serial private static final long serialVersionUID = -1617667918827493330L;
17
18 static final SymbolKey GENERATOR_TAG = new SymbolKey("GeneratorPrototype", REGULAR);
19
20 private static final ClassDescriptor DESCRIPTOR;
21
22 static {
23 DESCRIPTOR =
24 new ClassDescriptor.Builder(GENERATOR_TAG)
25 .withMethod(CTOR, "next", 1, ES6Generator::js_next)
26 .withMethod(CTOR, "return", 1, ES6Generator::js_return)
27 .withMethod(CTOR, "throw", 1, ES6Generator::js_throw)
28 .withMethod(CTOR, SymbolKey.ITERATOR, 0, ES6Generator::js_iterator)
29 .withProp(
30 CTOR,
31 SymbolKey.TO_STRING_TAG,
32 value("Generator", DONTENUM | READONLY))
33 .build();
34 }
35
36 private JSFunction function;
37 private Object savedState;
38 private String lineSource;
39 private int lineNumber;
40 private State state = State.SUSPENDED_START;
41 private Object delegee;
42
43 static ScriptableObject init(Context cx, TopLevel scope, boolean sealed) {
44
45 NativeObject prototype = new NativeObject();
46 DESCRIPTOR.populateGlobal(cx, scope, prototype, sealed);
47
48 var iterCtor = (JSFunction) scope.get("Iterator", scope);
49 prototype.setPrototype((Scriptable) iterCtor.getPrototypeProperty());
50
51 // Need to access Generator prototype when constructing
52 // Generator instances, but don't have a generator constructor
53 // to use to find the prototype. Use the "associateValue"
54 // approach instead.
55 if (scope != null) {
56 scope.associateValue(GENERATOR_TAG, prototype);
57 }
58
59 return prototype;
60 }
61
62 /** Only for constructing the prototype object. */
63 private ES6Generator() {}
64
65 public ES6Generator(VarScope scope, JSFunction function, Object savedState) {
66 this.function = function;
67 this.savedState = savedState;
68 // Set parent and prototype properties.
69 TopLevel top = ScriptableObject.getTopLevelScope(scope);
70 this.setParentScope(top);
71 // Per ES6 spec, generator instance's [[Prototype]] should be
72 // the generator function's .prototype property.

Callers

nothing calls this directly

Calls 4

withPropMethod · 0.80
withMethodMethod · 0.80
buildMethod · 0.45
valueMethod · 0.45

Tested by

no test coverage detected