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

Method JSValueRefHolder

valdi/src/valdi/runtime/JavaScript/JSValueRefHolder.cpp:17–36  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

15#include "valdi_core/cpp/Utils/Format.hpp"
16
17namespace Valdi {
18
19JSValueRefHolder::JSValueRefHolder(IJavaScriptContext& jsContext,
20 const JSValue& jsValue,
21 const ReferenceInfo& referenceInfo,
22 JSExceptionTracker& exceptionTracker,
23 bool captureStackTrace)
24 : _context(Context::currentRoot()),
25 _taskScheduler(weakRef(jsContext.getTaskScheduler())),
26 _jsValueId(jsContext.stashJSValue(jsValue)),
27 _referenceInfo(referenceInfo) {
28 SC_ASSERT(_context != nullptr, "No context set when creating the JSValueRefHolder");
29 _context->insertDisposable(this);
30
31 auto* runtime = dynamic_cast<JavaScriptRuntime*>(jsContext.getTaskScheduler());
32 if (runtime != nullptr && runtime->isInJsThread() && jsContext.isValueFunction(jsValue)) {
33 _anrAttribution = runtime->getCallbackAttribution();
34 // Some engines report an error when a valid JS function has no native wrapper.
35 JSExceptionTracker attributionExceptionTracker(jsContext);
36 auto function =
37 castOrNull<JSFunctionWithCallable>(jsContext.valueToFunction(jsValue, attributionExceptionTracker));
38 if (attributionExceptionTracker && function != nullptr && !function->getANRAttribution().isEmpty()) {
39 _anrAttribution = function->getANRAttribution();

Callers

nothing calls this directly

Calls 7

weakRefFunction · 0.85
stashJSValueMethod · 0.80
insertDisposableMethod · 0.80
setStackTraceProviderMethod · 0.80
getTaskSchedulerMethod · 0.45
getListenerMethod · 0.45

Tested by

no test coverage detected