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
1303// NOLINTNEXTLINE(readability-convert-member-functions-to-static)
1304JSValueRef JavaScriptRuntime::runtimeBytesToString(JSFunctionNativeCallContext& callContext) {
1305 auto convertedBytes =
1306 callContext.getContext().valueToTypedArray(callContext.getParameter(0), callContext.getExceptionTracker());
1307 CHECK_CALL_CONTEXT(callContext);
1308
1309 return callContext.getContext().newStringUTF8(
1310 std::string_view(reinterpret_cast<const char*>(convertedBytes.data), convertedBytes.length),
1311 callContext.getExceptionTracker());
1312}
1313
1314JSValueRef JavaScriptRuntime::runtimeIsModuleLoaded(JSFunctionNativeCallContext& callContext) {
1315 auto moduleName = callContext.getParameterAsString(0);
1316 CHECK_CALL_CONTEXT(callContext);
1317
1318 auto moduleLoaded = _resourceManager.isBundleLoaded(moduleName);
1319 return callContext.getContext().newBool(moduleLoaded);
1320}
1321
1322JSValueRef JavaScriptRuntime::runtimeGetModuleEntry(JSFunctionNativeCallContext& callContext) {
1323 auto moduleName = callContext.getParameterAsString(0);
1324 CHECK_CALL_CONTEXT(callContext);
1325
1326 auto path = callContext.getParameterAsString(1);
1327 CHECK_CALL_CONTEXT(callContext);
1328
1329 auto asString = callContext.getParameterAsBool(2);
1330 CHECK_CALL_CONTEXT(callContext);
1331
1332 auto bundle = _resourceManager.getBundle(moduleName);
1333
1334 if (bundle->hasRemoteArchiveNeedingLoad()) {
1335 return callContext.throwError(
1336 Error(STRING_FORMAT("Bundle '{}' is a remote bundle which was not loaded", moduleName)));
1337 }
1338
1339 auto entry = bundle->getEntry(path);
1340 if (!entry) {
1341 return callContext.throwError(entry.moveError());
1342 }
1343
1344 if (asString) {
1345 return callContext.getContext().newStringUTF8(entry.value().asStringView(), callContext.getExceptionTracker());
1346 } else {
1347 return newTypedArrayFromBytesView(
1348 callContext.getContext(), TypedArrayType::Uint8Array, entry.value(), callContext.getExceptionTracker());
1349 }
1350}
1351
1352JSValueRef JavaScriptRuntime::runtimeGetModuleJsPaths(JSFunctionNativeCallContext& callContext) {
1353 auto moduleName = callContext.getParameterAsString(0);
1354 CHECK_CALL_CONTEXT(callContext);

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