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

Method onModulesUnloaded

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

Source from the content-addressed store, hash-verified

2910 VALDI_TRACE_META("Valdi.importModule", absoluteModulePath);
2911 JavaScriptContextEntry contextEntry(_globalContext);
2912
2913 auto bundle = _resourceManager.getBundle(resourceId.bundleName);
2914
2915 auto path = jsEntry.jsContext.newStringUTF8(absoluteModulePath, jsEntry.exceptionTracker);
2916 if (!jsEntry.exceptionTracker) {
2917 return nullptr;
2918 }
2919
2920 std::initializer_list<JSValueRef> params = {
2921 std::move(path),
2922 jsEntry.jsContext.newBool(true), // disableProxy
2923 };
2924
2925 JSFunctionCallContext callContext(jsEntry.jsContext, params.begin(), params.size(), jsEntry.exceptionTracker);
2926
2927 auto result = jsEntry.jsContext.callObjectProperty(
2928 _moduleLoader.get(), _propertyNameIndex.getJsName(kLoadPropertyName), callContext);
2929 if (!jsEntry.exceptionTracker) {
2930 return nullptr;
2931 }
2932
2933 auto jsModuleContainer = Valdi::makeShared<JavaScriptModuleContainer>(
2934 std::move(bundle), jsEntry.jsContext, result.get(), jsEntry.exceptionTracker);
2935 _modules[resourceId] = jsModuleContainer;
2936
2937 onModuleLoaded(jsEntry.jsContext, resourceId, result.get(), /* isFromJsEval */ false, jsEntry.exceptionTracker);
2938
2939 return jsModuleContainer;
2940}
2941
2942void JavaScriptRuntime::onModuleLoaded(IJavaScriptContext& jsContext,
2943 const ResourceId& resourceId,
2944 const JSValue& value,
2945 bool isFromJsEval,
2946 JSExceptionTracker& exceptionTracker) {
2947 if (!exceptionTracker) {
2948 return;
2949 }
2950
2951 if (resourceId == valdiModuleResourceId()) {
2952 _onDaemonClientEventFunction = exceptionTracker.toRetainedResult(
2953 jsContext.getObjectProperty(value, "onDaemonClientEvent", exceptionTracker));
2954 if (!_onDaemonClientEventFunction) {
2955 onRecoverableError("onModuleLoaded", _onDaemonClientEventFunction.error());

Callers

nothing calls this directly

Calls 12

jsValueToValueFunction · 0.85
getArrayRefMethod · 0.80
didUnloadMethod · 0.80
errorMethod · 0.65
insertMethod · 0.65
containsMethod · 0.65
endMethod · 0.65
ErrorInterface · 0.50
toStringBoxMethod · 0.45
findMethod · 0.45
eraseMethod · 0.45

Tested by

no test coverage detected