MCPcopy Create free account
hub / github.com/Snapchat/Valdi / newError

Method newError

valdi/src/valdi/runtime/Interfaces/IJavaScriptContext.cpp:171–200  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

169
170void IJavaScriptContext::setObjectProperty(const JSValue& object,
171 const std::string_view& propertyName,
172 const JSValue& propertyValue,
173 bool enumerable,
174 JSExceptionTracker& exceptionTracker) {
175 auto jsPropertyName = newPropertyName(propertyName);
176 setObjectProperty(object, jsPropertyName.get(), propertyValue, enumerable, exceptionTracker);
177}
178
179void IJavaScriptContext::setObjectProperty(const JSValue& object,
180 const JSValue& propertyName,
181 const JSValue& propertyValue,
182 JSExceptionTracker& exceptionTracker) {
183 setObjectProperty(object, propertyName, propertyValue, true, exceptionTracker);
184}
185
186JSValueRef IJavaScriptContext::newError(std::string_view message,
187 std::optional<std::string_view> stack,
188 JSExceptionTracker& exceptionTracker) {
189 static auto kErrorConstructor = STRING_LITERAL("Error");
190
191 auto jsMessage = newStringUTF8(message, exceptionTracker);
192 if (!exceptionTracker) {
193 return newUndefined();
194 }
195
196 auto errorConstructor = getPropertyFromGlobalObjectCached(kErrorConstructor, exceptionTracker);
197 if (!exceptionTracker) {
198 return newUndefined();
199 }
200
201 JSFunctionCallContext params(*this, &jsMessage, 1, exceptionTracker);
202
203 auto jsError = callObjectAsConstructor(errorConstructor.get(), params);

Callers 3

TEST_PMethod · 0.80

Calls 2

getMethod · 0.65
valueMethod · 0.65

Tested by 1

TEST_PMethod · 0.64