Coverage Report

Created: 2023-02-22 06:51

/src/hermes/lib/VM/JSLib/CallSite.cpp
Line
Count
Source (jump to first uncovered line)
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
99
void populateCallSitePrototype(Runtime &runtime) {
21
99
  auto callSitePrototype = Handle<JSObject>::vmcast(&runtime.callSitePrototype);
22
23
  // CallSite.prototype.xxx methods.
24
99
  defineMethod(
25
99
      runtime,
26
99
      callSitePrototype,
27
99
      Predefined::getSymbolID(Predefined::getFunctionName),
28
99
      nullptr,
29
99
      callSitePrototypeGetFunctionName,
30
99
      0);
31
99
  defineMethod(
32
99
      runtime,
33
99
      callSitePrototype,
34
99
      Predefined::getSymbolID(Predefined::getFileName),
35
99
      nullptr,
36
99
      callSitePrototypeGetFileName,
37
99
      0);
38
99
  defineMethod(
39
99
      runtime,
40
99
      callSitePrototype,
41
99
      Predefined::getSymbolID(Predefined::getLineNumber),
42
99
      nullptr,
43
99
      callSitePrototypeGetLineNumber,
44
99
      0);
45
99
  defineMethod(
46
99
      runtime,
47
99
      callSitePrototype,
48
99
      Predefined::getSymbolID(Predefined::getColumnNumber),
49
99
      nullptr,
50
99
      callSitePrototypeGetColumnNumber,
51
99
      0);
52
99
  defineMethod(
53
99
      runtime,
54
99
      callSitePrototype,
55
99
      Predefined::getSymbolID(Predefined::getBytecodeAddress),
56
99
      nullptr,
57
99
      callSitePrototypeGetBytecodeAddress,
58
99
      0);
59
99
  defineMethod(
60
99
      runtime,
61
99
      callSitePrototype,
62
99
      Predefined::getSymbolID(Predefined::isNative),
63
99
      nullptr,
64
99
      callSitePrototypeIsNative,
65
99
      0);
66
99
  defineMethod(
67
99
      runtime,
68
99
      callSitePrototype,
69
99
      Predefined::getSymbolID(Predefined::getThis),
70
99
      nullptr,
71
99
      callSitePrototypeGetThis,
72
99
      0);
73
99
  defineMethod(
74
99
      runtime,
75
99
      callSitePrototype,
76
99
      Predefined::getSymbolID(Predefined::getTypeName),
77
99
      nullptr,
78
99
      callSitePrototypeGetTypeName,
79
99
      0);
80
99
  defineMethod(
81
99
      runtime,
82
99
      callSitePrototype,
83
99
      Predefined::getSymbolID(Predefined::getFunction),
84
99
      nullptr,
85
99
      callSitePrototypeGetFunction,
86
99
      0);
87
99
  defineMethod(
88
99
      runtime,
89
99
      callSitePrototype,
90
99
      Predefined::getSymbolID(Predefined::getMethodName),
91
99
      nullptr,
92
99
      callSitePrototypeGetMethodName,
93
99
      0);
94
99
  defineMethod(
95
99
      runtime,
96
99
      callSitePrototype,
97
99
      Predefined::getSymbolID(Predefined::getEvalOrigin),
98
99
      nullptr,
99
99
      callSitePrototypeGetEvalOrigin,
100
99
      0);
101
99
  defineMethod(
102
99
      runtime,
103
99
      callSitePrototype,
104
99
      Predefined::getSymbolID(Predefined::isToplevel),
105
99
      nullptr,
106
99
      callSitePrototypeIsToplevel,
107
99
      0);
108
99
  defineMethod(
109
99
      runtime,
110
99
      callSitePrototype,
111
99
      Predefined::getSymbolID(Predefined::isEval),
112
99
      nullptr,
113
99
      callSitePrototypeIsEval,
114
99
      0);
115
99
  defineMethod(
116
99
      runtime,
117
99
      callSitePrototype,
118
99
      Predefined::getSymbolID(Predefined::isConstructor),
119
99
      nullptr,
120
99
      callSitePrototypeIsConstructor,
121
99
      0);
122
99
  defineMethod(
123
99
      runtime,
124
99
      callSitePrototype,
125
99
      Predefined::getSymbolID(Predefined::isAsync),
126
99
      nullptr,
127
99
      callSitePrototypeIsAsync,
128
99
      0);
129
99
  defineMethod(
130
99
      runtime,
131
99
      callSitePrototype,
132
99
      Predefined::getSymbolID(Predefined::isPromiseAll),
133
99
      nullptr,
134
99
      callSitePrototypeIsPromiseAll,
135
99
      0);
136
99
  defineMethod(
137
99
      runtime,
138
99
      callSitePrototype,
139
99
      Predefined::getSymbolID(Predefined::getPromiseIndex),
140
99
      nullptr,
141
99
      callSitePrototypeGetPromiseIndex,
142
99
      0);
143
144
99
  DefinePropertyFlags dpf = DefinePropertyFlags::getDefaultNewPropertyFlags();
145
99
  dpf.writable = 0;
146
99
  dpf.enumerable = 0;
147
99
  defineProperty(
148
99
      runtime,
149
99
      callSitePrototype,
150
99
      Predefined::getSymbolID(Predefined::SymbolToStringTag),
151
99
      runtime.getPredefinedStringHandle(Predefined::CallSite),
152
99
      dpf);
153
99
}
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:hermes::vm::CallResult<hermes::vm::HermesValue, (hermes::vm::detail::CallResultSpecialize)2> hermes::vm::(anonymous namespace)::ensureJSCallSiteAndCall<&hermes::vm::JSCallSite::getFunctionName>(hermes::vm::Handle<hermes::vm::HermesValue>, hermes::vm::Runtime&)
Unexecuted instantiation: CallSite.cpp:hermes::vm::CallResult<hermes::vm::HermesValue, (hermes::vm::detail::CallResultSpecialize)2> hermes::vm::(anonymous namespace)::ensureJSCallSiteAndCall<&hermes::vm::JSCallSite::getFileName>(hermes::vm::Handle<hermes::vm::HermesValue>, hermes::vm::Runtime&)
Unexecuted instantiation: CallSite.cpp:hermes::vm::CallResult<hermes::vm::HermesValue, (hermes::vm::detail::CallResultSpecialize)2> hermes::vm::(anonymous namespace)::ensureJSCallSiteAndCall<&hermes::vm::JSCallSite::getLineNumber>(hermes::vm::Handle<hermes::vm::HermesValue>, hermes::vm::Runtime&)
Unexecuted instantiation: CallSite.cpp:hermes::vm::CallResult<hermes::vm::HermesValue, (hermes::vm::detail::CallResultSpecialize)2> hermes::vm::(anonymous namespace)::ensureJSCallSiteAndCall<&hermes::vm::JSCallSite::getColumnNumber>(hermes::vm::Handle<hermes::vm::HermesValue>, hermes::vm::Runtime&)
Unexecuted instantiation: CallSite.cpp:hermes::vm::CallResult<hermes::vm::HermesValue, (hermes::vm::detail::CallResultSpecialize)2> hermes::vm::(anonymous namespace)::ensureJSCallSiteAndCall<&hermes::vm::JSCallSite::getBytecodeAddress>(hermes::vm::Handle<hermes::vm::HermesValue>, hermes::vm::Runtime&)
Unexecuted instantiation: CallSite.cpp:hermes::vm::CallResult<hermes::vm::HermesValue, (hermes::vm::detail::CallResultSpecialize)2> hermes::vm::(anonymous namespace)::ensureJSCallSiteAndCall<&hermes::vm::JSCallSite::isNative>(hermes::vm::Handle<hermes::vm::HermesValue>, hermes::vm::Runtime&)
Unexecuted instantiation: CallSite.cpp:hermes::vm::CallResult<hermes::vm::HermesValue, (hermes::vm::detail::CallResultSpecialize)2> hermes::vm::(anonymous namespace)::ensureJSCallSiteAndCall<&hermes::vm::JSCallSite::getThis>(hermes::vm::Handle<hermes::vm::HermesValue>, hermes::vm::Runtime&)
Unexecuted instantiation: CallSite.cpp:hermes::vm::CallResult<hermes::vm::HermesValue, (hermes::vm::detail::CallResultSpecialize)2> hermes::vm::(anonymous namespace)::ensureJSCallSiteAndCall<&hermes::vm::JSCallSite::getTypeName>(hermes::vm::Handle<hermes::vm::HermesValue>, hermes::vm::Runtime&)
Unexecuted instantiation: CallSite.cpp:hermes::vm::CallResult<hermes::vm::HermesValue, (hermes::vm::detail::CallResultSpecialize)2> hermes::vm::(anonymous namespace)::ensureJSCallSiteAndCall<&hermes::vm::JSCallSite::getFunction>(hermes::vm::Handle<hermes::vm::HermesValue>, hermes::vm::Runtime&)
Unexecuted instantiation: CallSite.cpp:hermes::vm::CallResult<hermes::vm::HermesValue, (hermes::vm::detail::CallResultSpecialize)2> hermes::vm::(anonymous namespace)::ensureJSCallSiteAndCall<&hermes::vm::JSCallSite::getMethodName>(hermes::vm::Handle<hermes::vm::HermesValue>, hermes::vm::Runtime&)
Unexecuted instantiation: CallSite.cpp:hermes::vm::CallResult<hermes::vm::HermesValue, (hermes::vm::detail::CallResultSpecialize)2> hermes::vm::(anonymous namespace)::ensureJSCallSiteAndCall<&hermes::vm::JSCallSite::getEvalOrigin>(hermes::vm::Handle<hermes::vm::HermesValue>, hermes::vm::Runtime&)
Unexecuted instantiation: CallSite.cpp:hermes::vm::CallResult<hermes::vm::HermesValue, (hermes::vm::detail::CallResultSpecialize)2> hermes::vm::(anonymous namespace)::ensureJSCallSiteAndCall<&hermes::vm::JSCallSite::isToplevel>(hermes::vm::Handle<hermes::vm::HermesValue>, hermes::vm::Runtime&)
Unexecuted instantiation: CallSite.cpp:hermes::vm::CallResult<hermes::vm::HermesValue, (hermes::vm::detail::CallResultSpecialize)2> hermes::vm::(anonymous namespace)::ensureJSCallSiteAndCall<&hermes::vm::JSCallSite::isEval>(hermes::vm::Handle<hermes::vm::HermesValue>, hermes::vm::Runtime&)
Unexecuted instantiation: CallSite.cpp:hermes::vm::CallResult<hermes::vm::HermesValue, (hermes::vm::detail::CallResultSpecialize)2> hermes::vm::(anonymous namespace)::ensureJSCallSiteAndCall<&hermes::vm::JSCallSite::isConstructor>(hermes::vm::Handle<hermes::vm::HermesValue>, hermes::vm::Runtime&)
Unexecuted instantiation: CallSite.cpp:hermes::vm::CallResult<hermes::vm::HermesValue, (hermes::vm::detail::CallResultSpecialize)2> hermes::vm::(anonymous namespace)::ensureJSCallSiteAndCall<&hermes::vm::JSCallSite::isAsync>(hermes::vm::Handle<hermes::vm::HermesValue>, hermes::vm::Runtime&)
Unexecuted instantiation: CallSite.cpp:hermes::vm::CallResult<hermes::vm::HermesValue, (hermes::vm::detail::CallResultSpecialize)2> hermes::vm::(anonymous namespace)::ensureJSCallSiteAndCall<&hermes::vm::JSCallSite::isPromiseAll>(hermes::vm::Handle<hermes::vm::HermesValue>, hermes::vm::Runtime&)
Unexecuted instantiation: CallSite.cpp:hermes::vm::CallResult<hermes::vm::HermesValue, (hermes::vm::detail::CallResultSpecialize)2> hermes::vm::(anonymous namespace)::ensureJSCallSiteAndCall<&hermes::vm::JSCallSite::getPromiseIndex>(hermes::vm::Handle<hermes::vm::HermesValue>, hermes::vm::Runtime&)
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