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

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