| 15 | #include "valdi_core/cpp/Utils/Format.hpp" |
| 16 | |
| 17 | namespace Valdi { |
| 18 | |
| 19 | JSValueRefHolder::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(); |
nothing calls this directly
no test coverage detected