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

Function nameFromJSFunction

valdi/src/valdi/runtime/JavaScript/JavaScriptUtils.cpp:354–383  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

352 case ValueType::Function: {
353 auto func = value.getFunctionRef();
354
355 auto jsValue = unwrapJSValueIfNeeded(jsContext, func.get(), nullptr, exceptionTracker);
356 if (!exceptionTracker) {
357 return jsContext.newUndefined();
358 }
359
360 if (jsValue) {
361 // Unwrap the original JS function.
362 return JSValueRef::makeRetained(jsContext, jsValue.value());
363 }
364
365 auto callable = makeShared<JSFunctionWithUntypedValueFunction>(std::move(func),
366 referenceInfoBuilder.asFunction().build());
367 return jsContext.newFunction(callable, exceptionTracker);
368 }
369 }
370 SC_ASSERT_FAIL("This should not happen");
371}
372
373JSValueRef valueToJSValue(IJavaScriptContext& jsContext,
374 const Valdi::Value& value,
375 const ReferenceInfoBuilder& referenceInfoBuilder,
376 JSExceptionTracker& exceptionTracker) {
377 return valueToJSValue(jsContext, value, nullptr, referenceInfoBuilder, exceptionTracker);
378}
379
380StringBox nameFromJSFunction(IJavaScriptContext& jsContext, const JSValue& jsValue) {
381 static auto kNameKey = STRING_LITERAL("name");
382 static auto kAnonymousFunction = STRING_LITERAL("<anon>");
383 static auto kAnonymousBoundFunction = STRING_LITERAL("bound <anon>");
384 static auto kNameWhenBoundAnonymous = STRING_LITERAL("bound ");
385
386 JSExceptionTracker exceptionTracker(jsContext);

Calls 7

getPropertyNameCachedMethod · 0.80
clearErrorMethod · 0.80
getMethod · 0.65
valueToStringMethod · 0.65
getObjectPropertyMethod · 0.45
isValueUndefinedMethod · 0.45
isEmptyMethod · 0.45

Tested by

no test coverage detected