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
1784JSValueRef JavaScriptRuntime::runtimeGetCSSModule(JSFunctionNativeCallContext& callContext) {
1785 auto cssModulePath = callContext.getParameterAsString(0);
1786 CHECK_CALL_CONTEXT(callContext);
1787
1788 auto resourceIdResult = JavaScriptPathResolver::resolveResourceId(cssModulePath);
1789 if (!resourceIdResult) {
1790 return callContext.throwError(resourceIdResult.moveError());
1791 }
1792
1793 auto resourceId = resourceIdResult.moveValue();
1794
1795 auto bundle = _resourceManager.getBundle(resourceId.bundleName);
1796
1797 auto cssDocumentResult = bundle->getCSSDocument(resourceId.resourcePath, _attributeIds);
1798 if (!cssDocumentResult) {
1799 return callContext.throwError(cssDocumentResult.moveError());
1800 }
1801
1802 auto cssDocument = cssDocumentResult.moveValue();
1803
1804 static auto kFunctionName = STRING_LITERAL("getRule");
1805
1806 auto lambdaFunction = makeShared<JSFunctionWithCallable>(
1807 ReferenceInfoBuilder(callContext.getReferenceInfo()).withProperty(kFunctionName),
1808 [cssDocument](JSFunctionNativeCallContext& callContext) -> JSValueRef {
1809 auto ruleName = callContext.getParameterAsString(0);
1810 CHECK_CALL_CONTEXT(callContext);
1811
1812 auto attributes = cssDocument->getAttributesForClass(ruleName);
1813 if (!attributes) {
1814 return callContext.throwError(attributes.moveError());
1815 }
1816
1817 return makeWrappedObject(
1818 callContext.getContext(), attributes.value(), callContext.getExceptionTracker(), false);
1819 });
1820
1821 auto jsGetRuleFunction = callContext.getContext().newFunction(lambdaFunction, callContext.getExceptionTracker());
1822 CHECK_CALL_CONTEXT(callContext);
1823
1824 auto jsCssDocument =
1825 makeWrappedObject(callContext.getContext(), cssDocument, callContext.getExceptionTracker(), false);
1826 CHECK_CALL_CONTEXT(callContext);
1827
1828 callContext.getContext().setObjectProperty(jsCssDocument.get(),
1829 kFunctionName.toStringView(),
1830 jsGetRuleFunction.get(),
1831 true,
1832 callContext.getExceptionTracker());
1833 CHECK_CALL_CONTEXT(callContext);
1834
1835 return jsCssDocument;
1836}
1837
1838JSValueRef JavaScriptRuntime::runtimeCreateCSSRule(JSFunctionNativeCallContext& callContext) {
1839 auto attributesResult = callContext.getParameterAsValue(0);
1840 CHECK_CALL_CONTEXT(callContext);
1841
1842 auto attributes = attributesResult.getMapRef();

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