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

Method runtimeGetAssets

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

Source from the content-addressed store, hash-verified

1783
1784 JSValueRef evalResult;
1785 ModuleLoadMode moduleLoadMode;
1786
1787 {
1788 VALDI_TRACE_META(
1789 "Valdi.evalJsModule",
1790 STRING_FORMAT("importPath: {}, jsModule size: {} bytes", importPath.toStringView(), jsModule.size()));
1791 auto preCompiledContent = getPreCompiledJsModuleData(jsModule);
1792
1793 if (preCompiledContent) {
1794 moduleLoadMode = ModuleLoadMode::JS_BYTECODE;
1795 evalResult =
1796 jsContext.evaluatePreCompiled(preCompiledContent.value(), importPath.toStringView(), exceptionTracker);
1797 } else {
1798 moduleLoadMode = ModuleLoadMode::JS_SOURCE;
1799 auto moduleSrc = jsModule.asStringView();
1800 auto formattedSource = formatJsModule(moduleSrc);
1801 evalResult = jsContext.evaluate(formattedSource, importPath.toStringView(), exceptionTracker);
1802 }
1803 }
1804
1805 if (!exceptionTracker) {
1806 if (outParseFailed != nullptr) {
1807 *outParseFailed = true;
1808 }
1809 return std::make_pair(jsContext.newUndefined(), moduleLoadMode);
1810 }
1811
1812 JSFunctionCallContext callContext(jsContext, parameters, parametersLength, exceptionTracker);
1813 return std::make_pair(jsContext.callObjectAsFunction(evalResult.get(), callContext), moduleLoadMode);
1814}
1815
1816ModuleLoadResult JavaScriptRuntime::loadJsModuleFromNative(IJavaScriptContext& jsContext,
1817 const StringBox& importPath,
1818 const JSValueRef* parameters,
1819 size_t parametersLength,
1820 JSExceptionTracker& exceptionTracker) {
1821 // Assign global context when loading a JS module
1822 JavaScriptContextEntry contextEntry(_globalContext);
1823
1824 JSValueRef evalResult;
1825
1826 {
1827 VALDI_TRACE("Valdi.evalNativeModule");
1828 evalResult = jsContext.evaluateNative(importPath.toStringView(), exceptionTracker);
1829 }
1830
1831 if (!exceptionTracker) {
1832 return std::make_pair(jsContext.newUndefined(), ModuleLoadMode::NATIVE);
1833 }
1834
1835 JSFunctionCallContext callContext(jsContext, parameters, parametersLength, exceptionTracker);
1836 return std::make_pair(jsContext.callObjectAsFunction(evalResult.get(), callContext), ModuleLoadMode::NATIVE);
1837}
1838
1839JSValueRef JavaScriptRuntime::runtimeLoadJsModule(JSFunctionNativeCallContext& callContext) {
1840 auto importPath = callContext.getParameterAsString(0);
1841 CHECK_CALL_CONTEXT(callContext);
1842

Callers

nothing calls this directly

Calls 15

AssetKeyClass · 0.85
makeWrappedObjectFunction · 0.85
getBundleMethod · 0.80
getAssetCatalogMethod · 0.80
newNumberMethod · 0.80
throwErrorMethod · 0.65
getAssetsMethod · 0.65
valueMethod · 0.65
appendMethod · 0.65
getMethod · 0.65
getParameterAsStringMethod · 0.45
newArrayMethod · 0.45

Tested by

no test coverage detected