Coverage Report

Created: 2025-12-12 07:27

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/hermes/lib/VM/JSLib/GeneratorFunction.cpp
Line
Count
Source
1
/*
2
 * Copyright (c) Meta Platforms, Inc. and affiliates.
3
 *
4
 * This source code is licensed under the MIT license found in the
5
 * LICENSE file in the root directory of this source tree.
6
 */
7
8
//===----------------------------------------------------------------------===//
9
/// \file
10
/// ES6.0 25.2.1 The GeneratorFunction constructor.
11
//===----------------------------------------------------------------------===//
12
#include "JSLibInternal.h"
13
14
namespace hermes {
15
namespace vm {
16
17
113
Handle<JSObject> createGeneratorFunctionConstructor(Runtime &runtime) {
18
113
  auto proto = Handle<JSObject>::vmcast(&runtime.generatorFunctionPrototype);
19
20
113
  auto cons = runtime.makeHandle(
21
113
      NativeConstructor::create(
22
113
          runtime,
23
113
          Handle<JSObject>::vmcast(&runtime.functionConstructor),
24
113
          nullptr,
25
113
          generatorFunctionConstructor,
26
113
          1,
27
113
          NativeConstructor::creatorFunction<JSGeneratorFunction>,
28
113
          CellKind::JSGeneratorFunctionKind));
29
30
113
  auto st = Callable::defineNameLengthAndPrototype(
31
113
      cons,
32
113
      runtime,
33
113
      Predefined::getSymbolID(Predefined::GeneratorFunction),
34
113
      1,
35
113
      proto,
36
113
      Callable::WritablePrototype::No,
37
113
      false);
38
113
  (void)st;
39
113
  assert(
40
113
      st != ExecutionStatus::EXCEPTION && "defineLengthAndPrototype() failed");
41
42
113
  auto dpf = DefinePropertyFlags::getDefaultNewPropertyFlags();
43
113
  dpf.writable = 0;
44
113
  dpf.enumerable = 0;
45
46
  // The initial value of GeneratorFunction.prototype.constructor is the
47
  // intrinsic object %GeneratorFunction%.
48
113
  defineProperty(
49
113
      runtime,
50
113
      proto,
51
113
      Predefined::getSymbolID(Predefined::constructor),
52
113
      cons,
53
113
      dpf);
54
55
  // The value of GeneratorFunction.prototype.prototype is the
56
  // %GeneratorPrototype% intrinsic object.
57
113
  defineProperty(
58
113
      runtime,
59
113
      proto,
60
113
      Predefined::getSymbolID(Predefined::prototype),
61
113
      Handle<>(&runtime.generatorPrototype),
62
113
      dpf);
63
64
113
  defineProperty(
65
113
      runtime,
66
113
      proto,
67
113
      Predefined::getSymbolID(Predefined::SymbolToStringTag),
68
113
      runtime.getPredefinedStringHandle(Predefined::GeneratorFunction),
69
113
      dpf);
70
71
113
  return cons;
72
113
}
73
74
CallResult<HermesValue>
75
0
generatorFunctionConstructor(void *, Runtime &runtime, NativeArgs args) {
76
0
  return createDynamicFunction(runtime, args, DynamicFunctionKind::Generator);
77
0
}
78
79
} // namespace vm
80
} // namespace hermes