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/CallSite.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
/// Initialize the internal CallSite prototype.
11
//===----------------------------------------------------------------------===//
12
13
#include "JSLibInternal.h"
14
#include "hermes/VM/JSCallSite.h"
15
#include "hermes/VM/StringPrimitive.h"
16
17
namespace hermes {
18
namespace vm {
19
20
113
void populateCallSitePrototype(Runtime &runtime) {
21
113
  auto callSitePrototype = Handle<JSObject>::vmcast(&runtime.callSitePrototype);
22
23
  // CallSite.prototype.xxx methods.
24
113
  defineMethod(
25
113
      runtime,
26
113
      callSitePrototype,
27
113
      Predefined::getSymbolID(Predefined::getFunctionName),
28
113
      nullptr,
29
113
      callSitePrototypeGetFunctionName,
30
113
      0);
31
113
  defineMethod(
32
113
      runtime,
33
113
      callSitePrototype,
34
113
      Predefined::getSymbolID(Predefined::getFileName),
35
113
      nullptr,
36
113
      callSitePrototypeGetFileName,
37
113
      0);
38
113
  defineMethod(
39
113
      runtime,
40
113
      callSitePrototype,
41
113
      Predefined::getSymbolID(Predefined::getLineNumber),
42
113
      nullptr,
43
113
      callSitePrototypeGetLineNumber,
44
113
      0);
45
113
  defineMethod(
46
113
      runtime,
47
113
      callSitePrototype,
48
113
      Predefined::getSymbolID(Predefined::getColumnNumber),
49
113
      nullptr,
50
113
      callSitePrototypeGetColumnNumber,
51
113
      0);
52
113
  defineMethod(
53
113
      runtime,
54
113
      callSitePrototype,
55
113
      Predefined::getSymbolID(Predefined::getBytecodeAddress),
56
113
      nullptr,
57
113
      callSitePrototypeGetBytecodeAddress,
58
113
      0);
59
113
  defineMethod(
60
113
      runtime,
61
113
      callSitePrototype,
62
113
      Predefined::getSymbolID(Predefined::isNative),
63
113
      nullptr,
64
113
      callSitePrototypeIsNative,
65
113
      0);
66
113
  defineMethod(
67
113
      runtime,
68
113
      callSitePrototype,
69
113
      Predefined::getSymbolID(Predefined::getThis),
70
113
      nullptr,
71
113
      callSitePrototypeGetThis,
72
113
      0);
73
113
  defineMethod(
74
113
      runtime,
75
113
      callSitePrototype,
76
113
      Predefined::getSymbolID(Predefined::getTypeName),
77
113
      nullptr,
78
113
      callSitePrototypeGetTypeName,
79
113
      0);
80
113
  defineMethod(
81
113
      runtime,
82
113
      callSitePrototype,
83
113
      Predefined::getSymbolID(Predefined::getFunction),
84
113
      nullptr,
85
113
      callSitePrototypeGetFunction,
86
113
      0);
87
113
  defineMethod(
88
113
      runtime,
89
113
      callSitePrototype,
90
113
      Predefined::getSymbolID(Predefined::getMethodName),
91
113
      nullptr,
92
113
      callSitePrototypeGetMethodName,
93
113
      0);
94
113
  defineMethod(
95
113
      runtime,
96
113
      callSitePrototype,
97
113
      Predefined::getSymbolID(Predefined::getEvalOrigin),
98
113
      nullptr,
99
113
      callSitePrototypeGetEvalOrigin,
100
113
      0);
101
113
  defineMethod(
102
113
      runtime,
103
113
      callSitePrototype,
104
113
      Predefined::getSymbolID(Predefined::isToplevel),
105
113
      nullptr,
106
113
      callSitePrototypeIsToplevel,
107
113
      0);
108
113
  defineMethod(
109
113
      runtime,
110
113
      callSitePrototype,
111
113
      Predefined::getSymbolID(Predefined::isEval),
112
113
      nullptr,
113
113
      callSitePrototypeIsEval,
114
113
      0);
115
113
  defineMethod(
116
113
      runtime,
117
113
      callSitePrototype,
118
113
      Predefined::getSymbolID(Predefined::isConstructor),
119
113
      nullptr,
120
113
      callSitePrototypeIsConstructor,
121
113
      0);
122
113
  defineMethod(
123
113
      runtime,
124
113
      callSitePrototype,
125
113
      Predefined::getSymbolID(Predefined::isAsync),
126
113
      nullptr,
127
113
      callSitePrototypeIsAsync,
128
113
      0);
129
113
  defineMethod(
130
113
      runtime,
131
113
      callSitePrototype,
132
113
      Predefined::getSymbolID(Predefined::isPromiseAll),
133
113
      nullptr,
134
113
      callSitePrototypeIsPromiseAll,
135
113
      0);
136
113
  defineMethod(
137
113
      runtime,
138
113
      callSitePrototype,
139
113
      Predefined::getSymbolID(Predefined::getPromiseIndex),
140
113
      nullptr,
141
113
      callSitePrototypeGetPromiseIndex,
142
113
      0);
143
144
113
  DefinePropertyFlags dpf = DefinePropertyFlags::getDefaultNewPropertyFlags();
145
113
  dpf.writable = 0;
146
113
  dpf.enumerable = 0;
147
113
  defineProperty(
148
113
      runtime,
149
113
      callSitePrototype,
150
113
      Predefined::getSymbolID(Predefined::SymbolToStringTag),
151
113
      runtime.getPredefinedStringHandle(Predefined::CallSite),
152
113
      dpf);
153
113
}
154
155
namespace {
156
template <auto Fn>
157
static CallResult<HermesValue> ensureJSCallSiteAndCall(
158
    Handle<> self,
159
0
    Runtime &runtime) {
160
0
  if (auto jsCallSiteSelf = Handle<JSCallSite>::dyn_vmcast(self)) {
161
0
    return (*Fn)(runtime, jsCallSiteSelf);
162
0
  }
163
164
0
  return runtime.raiseTypeError(
165
0
      "CallSite method called on an incompatible receiver");
166
0
}
Unexecuted instantiation: CallSite.cpp:_ZN6hermes2vm12_GLOBAL__N_123ensureJSCallSiteAndCallITnDaXadL_ZNS0_10JSCallSite15getFunctionNameERNS0_7RuntimeENS0_6HandleIS3_EEEEEENS0_10CallResultINS0_11HermesValueELNS0_6detail20CallResultSpecializeE2EEENS6_IS9_EES5_
Unexecuted instantiation: CallSite.cpp:_ZN6hermes2vm12_GLOBAL__N_123ensureJSCallSiteAndCallITnDaXadL_ZNS0_10JSCallSite11getFileNameERNS0_7RuntimeENS0_6HandleIS3_EEEEEENS0_10CallResultINS0_11HermesValueELNS0_6detail20CallResultSpecializeE2EEENS6_IS9_EES5_
Unexecuted instantiation: CallSite.cpp:_ZN6hermes2vm12_GLOBAL__N_123ensureJSCallSiteAndCallITnDaXadL_ZNS0_10JSCallSite13getLineNumberERNS0_7RuntimeENS0_6HandleIS3_EEEEEENS0_10CallResultINS0_11HermesValueELNS0_6detail20CallResultSpecializeE2EEENS6_IS9_EES5_
Unexecuted instantiation: CallSite.cpp:_ZN6hermes2vm12_GLOBAL__N_123ensureJSCallSiteAndCallITnDaXadL_ZNS0_10JSCallSite15getColumnNumberERNS0_7RuntimeENS0_6HandleIS3_EEEEEENS0_10CallResultINS0_11HermesValueELNS0_6detail20CallResultSpecializeE2EEENS6_IS9_EES5_
Unexecuted instantiation: CallSite.cpp:_ZN6hermes2vm12_GLOBAL__N_123ensureJSCallSiteAndCallITnDaXadL_ZNS0_10JSCallSite18getBytecodeAddressERNS0_7RuntimeENS0_6HandleIS3_EEEEEENS0_10CallResultINS0_11HermesValueELNS0_6detail20CallResultSpecializeE2EEENS6_IS9_EES5_
Unexecuted instantiation: CallSite.cpp:_ZN6hermes2vm12_GLOBAL__N_123ensureJSCallSiteAndCallITnDaXadL_ZNS0_10JSCallSite8isNativeERNS0_7RuntimeENS0_6HandleIS3_EEEEEENS0_10CallResultINS0_11HermesValueELNS0_6detail20CallResultSpecializeE2EEENS6_IS9_EES5_
Unexecuted instantiation: CallSite.cpp:_ZN6hermes2vm12_GLOBAL__N_123ensureJSCallSiteAndCallITnDaXadL_ZNS0_10JSCallSite7getThisERNS0_7RuntimeENS0_6HandleIS3_EEEEEENS0_10CallResultINS0_11HermesValueELNS0_6detail20CallResultSpecializeE2EEENS6_IS9_EES5_
Unexecuted instantiation: CallSite.cpp:_ZN6hermes2vm12_GLOBAL__N_123ensureJSCallSiteAndCallITnDaXadL_ZNS0_10JSCallSite11getTypeNameERNS0_7RuntimeENS0_6HandleIS3_EEEEEENS0_10CallResultINS0_11HermesValueELNS0_6detail20CallResultSpecializeE2EEENS6_IS9_EES5_
Unexecuted instantiation: CallSite.cpp:_ZN6hermes2vm12_GLOBAL__N_123ensureJSCallSiteAndCallITnDaXadL_ZNS0_10JSCallSite11getFunctionERNS0_7RuntimeENS0_6HandleIS3_EEEEEENS0_10CallResultINS0_11HermesValueELNS0_6detail20CallResultSpecializeE2EEENS6_IS9_EES5_
Unexecuted instantiation: CallSite.cpp:_ZN6hermes2vm12_GLOBAL__N_123ensureJSCallSiteAndCallITnDaXadL_ZNS0_10JSCallSite13getMethodNameERNS0_7RuntimeENS0_6HandleIS3_EEEEEENS0_10CallResultINS0_11HermesValueELNS0_6detail20CallResultSpecializeE2EEENS6_IS9_EES5_
Unexecuted instantiation: CallSite.cpp:_ZN6hermes2vm12_GLOBAL__N_123ensureJSCallSiteAndCallITnDaXadL_ZNS0_10JSCallSite13getEvalOriginERNS0_7RuntimeENS0_6HandleIS3_EEEEEENS0_10CallResultINS0_11HermesValueELNS0_6detail20CallResultSpecializeE2EEENS6_IS9_EES5_
Unexecuted instantiation: CallSite.cpp:_ZN6hermes2vm12_GLOBAL__N_123ensureJSCallSiteAndCallITnDaXadL_ZNS0_10JSCallSite10isToplevelERNS0_7RuntimeENS0_6HandleIS3_EEEEEENS0_10CallResultINS0_11HermesValueELNS0_6detail20CallResultSpecializeE2EEENS6_IS9_EES5_
Unexecuted instantiation: CallSite.cpp:_ZN6hermes2vm12_GLOBAL__N_123ensureJSCallSiteAndCallITnDaXadL_ZNS0_10JSCallSite6isEvalERNS0_7RuntimeENS0_6HandleIS3_EEEEEENS0_10CallResultINS0_11HermesValueELNS0_6detail20CallResultSpecializeE2EEENS6_IS9_EES5_
Unexecuted instantiation: CallSite.cpp:_ZN6hermes2vm12_GLOBAL__N_123ensureJSCallSiteAndCallITnDaXadL_ZNS0_10JSCallSite13isConstructorERNS0_7RuntimeENS0_6HandleIS3_EEEEEENS0_10CallResultINS0_11HermesValueELNS0_6detail20CallResultSpecializeE2EEENS6_IS9_EES5_
Unexecuted instantiation: CallSite.cpp:_ZN6hermes2vm12_GLOBAL__N_123ensureJSCallSiteAndCallITnDaXadL_ZNS0_10JSCallSite7isAsyncERNS0_7RuntimeENS0_6HandleIS3_EEEEEENS0_10CallResultINS0_11HermesValueELNS0_6detail20CallResultSpecializeE2EEENS6_IS9_EES5_
Unexecuted instantiation: CallSite.cpp:_ZN6hermes2vm12_GLOBAL__N_123ensureJSCallSiteAndCallITnDaXadL_ZNS0_10JSCallSite12isPromiseAllERNS0_7RuntimeENS0_6HandleIS3_EEEEEENS0_10CallResultINS0_11HermesValueELNS0_6detail20CallResultSpecializeE2EEENS6_IS9_EES5_
Unexecuted instantiation: CallSite.cpp:_ZN6hermes2vm12_GLOBAL__N_123ensureJSCallSiteAndCallITnDaXadL_ZNS0_10JSCallSite15getPromiseIndexERNS0_7RuntimeENS0_6HandleIS3_EEEEEENS0_10CallResultINS0_11HermesValueELNS0_6detail20CallResultSpecializeE2EEENS6_IS9_EES5_
167
} // namespace
168
169
CallResult<HermesValue>
170
0
callSitePrototypeGetFunctionName(void *, Runtime &runtime, NativeArgs args) {
171
0
  return ensureJSCallSiteAndCall<&JSCallSite::getFunctionName>(
172
0
      args.getThisHandle(), runtime);
173
0
}
174
175
CallResult<HermesValue>
176
0
callSitePrototypeGetFileName(void *, Runtime &runtime, NativeArgs args) {
177
0
  return ensureJSCallSiteAndCall<&JSCallSite::getFileName>(
178
0
      args.getThisHandle(), runtime);
179
0
}
180
181
CallResult<HermesValue>
182
0
callSitePrototypeGetLineNumber(void *, Runtime &runtime, NativeArgs args) {
183
0
  return ensureJSCallSiteAndCall<&JSCallSite::getLineNumber>(
184
0
      args.getThisHandle(), runtime);
185
0
}
186
187
CallResult<HermesValue>
188
0
callSitePrototypeGetColumnNumber(void *, Runtime &runtime, NativeArgs args) {
189
0
  return ensureJSCallSiteAndCall<&JSCallSite::getColumnNumber>(
190
0
      args.getThisHandle(), runtime);
191
0
}
192
193
CallResult<HermesValue>
194
0
callSitePrototypeGetBytecodeAddress(void *, Runtime &runtime, NativeArgs args) {
195
0
  return ensureJSCallSiteAndCall<&JSCallSite::getBytecodeAddress>(
196
0
      args.getThisHandle(), runtime);
197
0
}
198
199
CallResult<HermesValue>
200
0
callSitePrototypeIsNative(void *, Runtime &runtime, NativeArgs args) {
201
0
  return ensureJSCallSiteAndCall<&JSCallSite::isNative>(
202
0
      args.getThisHandle(), runtime);
203
0
}
204
205
CallResult<HermesValue>
206
0
callSitePrototypeGetThis(void *, Runtime &runtime, NativeArgs args) {
207
0
  return ensureJSCallSiteAndCall<&JSCallSite::getThis>(
208
0
      args.getThisHandle(), runtime);
209
0
}
210
211
CallResult<HermesValue>
212
0
callSitePrototypeGetTypeName(void *, Runtime &runtime, NativeArgs args) {
213
0
  return ensureJSCallSiteAndCall<&JSCallSite::getTypeName>(
214
0
      args.getThisHandle(), runtime);
215
0
}
216
217
CallResult<HermesValue>
218
0
callSitePrototypeGetFunction(void *, Runtime &runtime, NativeArgs args) {
219
0
  return ensureJSCallSiteAndCall<&JSCallSite::getFunction>(
220
0
      args.getThisHandle(), runtime);
221
0
}
222
223
CallResult<HermesValue>
224
0
callSitePrototypeGetMethodName(void *, Runtime &runtime, NativeArgs args) {
225
0
  return ensureJSCallSiteAndCall<&JSCallSite::getMethodName>(
226
0
      args.getThisHandle(), runtime);
227
0
}
228
229
CallResult<HermesValue>
230
0
callSitePrototypeGetEvalOrigin(void *, Runtime &runtime, NativeArgs args) {
231
0
  return ensureJSCallSiteAndCall<&JSCallSite::getEvalOrigin>(
232
0
      args.getThisHandle(), runtime);
233
0
}
234
235
CallResult<HermesValue>
236
0
callSitePrototypeIsToplevel(void *, Runtime &runtime, NativeArgs args) {
237
0
  return ensureJSCallSiteAndCall<&JSCallSite::isToplevel>(
238
0
      args.getThisHandle(), runtime);
239
0
}
240
241
CallResult<HermesValue>
242
0
callSitePrototypeIsEval(void *, Runtime &runtime, NativeArgs args) {
243
0
  return ensureJSCallSiteAndCall<&JSCallSite::isEval>(
244
0
      args.getThisHandle(), runtime);
245
0
}
246
247
CallResult<HermesValue>
248
0
callSitePrototypeIsConstructor(void *, Runtime &runtime, NativeArgs args) {
249
0
  return ensureJSCallSiteAndCall<&JSCallSite::isConstructor>(
250
0
      args.getThisHandle(), runtime);
251
0
}
252
253
CallResult<HermesValue>
254
0
callSitePrototypeIsAsync(void *, Runtime &runtime, NativeArgs args) {
255
0
  return ensureJSCallSiteAndCall<&JSCallSite::isAsync>(
256
0
      args.getThisHandle(), runtime);
257
0
}
258
259
CallResult<HermesValue>
260
0
callSitePrototypeIsPromiseAll(void *, Runtime &runtime, NativeArgs args) {
261
0
  return ensureJSCallSiteAndCall<&JSCallSite::isPromiseAll>(
262
0
      args.getThisHandle(), runtime);
263
0
}
264
265
CallResult<HermesValue>
266
0
callSitePrototypeGetPromiseIndex(void *, Runtime &runtime, NativeArgs args) {
267
0
  return ensureJSCallSiteAndCall<&JSCallSite::getPromiseIndex>(
268
0
      args.getThisHandle(), runtime);
269
0
}
270
271
} // namespace vm
272
} // namespace hermes