| 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 | |
| 2942 | void 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()); |
nothing calls this directly
no test coverage detected