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

Function getJsModuleWithSchema

valdi/test/integration/Runtime_tests.cpp:156–184  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

154};
155
156static Result<Value> getJsModuleWithSchema(
157 Runtime* runtime,
158 const std::shared_ptr<snap::valdi_core::JSRuntimeNativeObjectsManager>& nativeObjectsManager,
159 ValueSchemaRegistry* registry,
160 std::string_view moduleName,
161 const ValueSchema& schema) {
162 auto resolvedSchema = schema;
163 if (registry != nullptr) {
164 ValueSchemaTypeResolver typeResolver(registry);
165 auto schemaResult = typeResolver.resolveTypeReferences(schema);
166 if (!schemaResult) {
167 return schemaResult.moveError();
168 }
169 resolvedSchema = schemaResult.moveValue();
170 }
171
172 Valdi::SimpleExceptionTracker exceptionTracker;
173 Valdi::Marshaller marshaller(exceptionTracker);
174
175 marshaller.setCurrentSchema(resolvedSchema);
176
177 auto moduleIndex = runtime->getJavaScriptRuntime()->pushModuleToMarshaller(
178 nativeObjectsManager, StringCache::getGlobal().makeString(moduleName), marshaller);
179 if (!exceptionTracker) {
180 return Error(STRING_FORMAT("Couldn't resolve module '{}'", moduleName));
181 }
182
183 return marshaller.get(moduleIndex);
184}
185
186static Result<Value> getJsModulePropertyWithSchema(
187 Runtime* runtime,

Callers 2

TEST_PFunction · 0.85

Calls 8

getGlobalFunction · 0.85
setCurrentSchemaMethod · 0.80
getJavaScriptRuntimeMethod · 0.80
makeStringMethod · 0.80
getMethod · 0.65
ErrorInterface · 0.50
resolveTypeReferencesMethod · 0.45

Tested by

no test coverage detected