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

Method runtimeLoadModule

valdi/src/valdi/runtime/JavaScript/JavaScriptRuntime.cpp:1303–1351  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1301
1302 auto callContext =
1303 JSFunctionCallContext(entryParameters.jsContext, &jsResult, 1, entryParameters.exceptionTracker);
1304
1305 entryParameters.jsContext.callObjectAsFunction(jsValue, callContext);
1306 });
1307}
1308
1309JSValueRef JavaScriptRuntime::handleViewNodeSpecificAction(
1310 JSFunctionNativeCallContext& callContext,
1311 Function<void(ViewNode&, Function<void(const Value&)>)>&& handleViewNode) {
1312 auto contextId = getParameterAsContextId(callContext, 0);
1313 CHECK_CALL_CONTEXT(callContext);
1314
1315 auto nodeId = static_cast<RawViewNodeId>(callContext.getParameterAsInt(1));
1316 CHECK_CALL_CONTEXT(callContext);
1317
1318 auto callbackParameterIndex = callContext.getParameterSize() - 1;
1319
1320 auto callbackRef = JSValueRefHolder::makeRetainedCallback(
1321 callContext.getContext(),
1322 callContext.getParameter(callbackParameterIndex),
1323 ReferenceInfoBuilder(callContext.getReferenceInfo()).withParameter(callbackParameterIndex),
1324 callContext.getExceptionTracker());
1325
1326 auto context = _contextManager->getContext(contextId);
1327 if (context == nullptr) {
1328 return callContext.throwError(Valdi::Error(STRING_FORMAT("Could not resolve Context {}", contextId)));
1329 }
1330
1331 auto listener = getListener();
1332 if (!listener) {
1333 return callContext.throwError(
1334 Valdi::Error(STRING_FORMAT("No runtime listener to resolve ViewNodeTree of Context {}", contextId)));
1335 }
1336
1337 listener->resolveViewNodeTree(
1338 context,
1339 true,
1340 true,
1341 [self = strongSmallRef(this), callbackRef, nodeId, contextId, handleViewNode = std::move(handleViewNode)](
1342 const SharedViewNodeTree& viewNodeTree) {
1343 if (viewNodeTree == nullptr) {
1344 [[maybe_unused]] auto capturedContextId = contextId;
1345 VALDI_ERROR(*self->_logger, "Could not resolve ViewNodeTree of Context {}", capturedContextId);
1346 return;
1347 }
1348
1349 viewNodeTree->withLock([&]() {
1350 auto viewNode = viewNodeTree->getViewNode(nodeId);
1351 if (viewNode != nullptr) {
1352 handleViewNode(*viewNode, [self, callbackRef](const auto& result) {
1353 self->callViewNodeActionCallback(callbackRef, result);
1354 });

Callers

nothing calls this directly

Calls 15

getParameterMethod · 0.80
newUndefinedMethod · 0.80
withParameterMethod · 0.80
loadModuleAsyncMethod · 0.80
getJsValueMethod · 0.80
toStringMethod · 0.65
errorMethod · 0.65
getParameterAsStringMethod · 0.45
isValueUndefinedMethod · 0.45

Tested by

no test coverage detected