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 auto platformSpecificAssetsMapValue = callContext.getParameterAsValue(1);
1784 CHECK_CALL_CONTEXT(callContext);
1785
1786 auto platformSpecificAssets = platformSpecificAssetsMapValue.getMapRef();
1787 if (platformSpecificAssets == nullptr) {
1788 return callContext.throwError(Error("Invalid platform specific assets object specified"));
1789 }
1790
1791 auto defaultAsset = AssetResolver::resolve(_resourceManager, defaultAssetValue);
1792
1793 Ref<Asset> iOSAsset;
1794 Ref<Asset> androidAsset;
1795
1796 auto iosAssetValue = platformSpecificAssetsMapValue.getMapValue("ios");
1797 if (!iosAssetValue.isNullOrUndefined()) {
1798 iOSAsset = AssetResolver::resolve(_resourceManager, iosAssetValue);
1799 }
1800 auto androidAssetValue = platformSpecificAssetsMapValue.getMapValue("android");
1801 if (!androidAssetValue.isNullOrUndefined()) {
1802 androidAsset = AssetResolver::resolve(_resourceManager, androidAssetValue);
1803 }
1804
1805 if (defaultAsset == nullptr || ((iOSAsset == nullptr) && (androidAsset == nullptr))) {
1806 return callContext.throwError(
1807 Error("Platform specific assets can only be created from URL or Valdi assets. They also require a "
1808 "default asset, and at least one iOS or Android asset specified"));
1809 }
1810
1811 auto asset = makeShared<PlatformSpecificAsset>(defaultAsset, iOSAsset, androidAsset);
1812
1813 return makeWrappedObject(callContext.getContext(), asset, callContext.getExceptionTracker(), false);
1814}
1815
1816JSValueRef JavaScriptRuntime::runtimeGetLoadedAssetMetadata(JSFunctionNativeCallContext& callContext) {
1817 auto loadedAsset = castOrNull<LoadedAsset>(callContext.getParameterAsWrappedObject(0));
1818 CHECK_CALL_CONTEXT(callContext);
1819
1820 if (loadedAsset == nullptr) {
1821 return callContext.throwError(Error("Invalid loaded asset"));
1822 }
1823
1824 auto metadata = loadedAsset->getMetadata();
1825
1826 return valueToJSValue(
1827 callContext.getContext(), metadata, ReferenceInfoBuilder(), callContext.getExceptionTracker());
1828}
1829
1830JSValueRef JavaScriptRuntime::runtimeAddAssetLoadObserver(JSFunctionNativeCallContext& callContext) {
1831 auto assetValue = callContext.getParameterAsValue(0);
1832 CHECK_CALL_CONTEXT(callContext);
1833
1834 auto observerCallback = callContext.getParameterAsFunction(1);
1835 CHECK_CALL_CONTEXT(callContext);
1836
1837 auto outputType = callContext.getParameterAsInt(2);
1838 CHECK_CALL_CONTEXT(callContext);
1839
1840 auto preferredWidth = callContext.getParameterAsInt(3);
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