| 3032 | auto it = _modules.find(resourceId); |
| 3033 | if (it != _modules.end()) { |
| 3034 | auto moduleContainer = it->second; |
| 3035 | _modules.erase(it); |
| 3036 | |
| 3037 | onModuleUnloaded(resourceId, entry); |
| 3038 | if (!entry.exceptionTracker) { |
| 3039 | onRecoverableError("onModuleUnloaded", entry.exceptionTracker); |
| 3040 | } |
| 3041 | |
| 3042 | moduleContainer->didUnload(); |
| 3043 | } |
| 3044 | } |
| 3045 | } |
| 3046 | |
| 3047 | void JavaScriptRuntime::registerJavaScriptModuleFactory(const Ref<JavaScriptModuleFactory>& moduleFactory) { |
| 3048 | dispatchOnJsThreadUnattributed([=](JavaScriptEntryParameters& entry) { |
| 3049 | _moduleFactories.push_back(moduleFactory); |
| 3050 | auto modulePath = moduleFactory->getModulePath(); |
| 3051 | auto pathResult = entry.jsContext.newStringUTF8(modulePath.toStringView(), entry.exceptionTracker); |
| 3052 | if (!entry.exceptionTracker) { |
| 3053 | onRecoverableError("registerJavaScriptModuleFactory", entry.exceptionTracker); |
| 3054 | return; |
| 3055 | } |
| 3056 | |
| 3057 | auto lambdaFunction = makeShared<JSFunctionWithCallable>( |
| 3058 | ReferenceInfoBuilder().withObject(modulePath), [=](JSFunctionNativeCallContext& callContext) -> JSValueRef { |
| 3059 | JavaScriptContextEntry jsEntry(_globalContext); |
| 3060 | return moduleFactory->loadModule(callContext.getContext(), |
| 3061 | ReferenceInfoBuilder(callContext.getReferenceInfo()), |
| 3062 | callContext.getExceptionTracker()); |
| 3063 | }); |
| 3064 | |
| 3065 | auto functionResult = entry.jsContext.newFunction(lambdaFunction, entry.exceptionTracker); |
| 3066 | if (!entry.exceptionTracker) { |
| 3067 | onRecoverableError("registerJavaScriptModuleFactory", entry.exceptionTracker); |
| 3068 | return; |
| 3069 | } |
| 3070 | |
| 3071 | std::initializer_list<JSValueRef> params = {std::move(pathResult), std::move(functionResult)}; |
| 3072 | |
| 3073 | JSFunctionCallContext callContext(entry.jsContext, params.begin(), params.size(), entry.exceptionTracker); |
| 3074 | |
| 3075 | entry.jsContext.callObjectProperty( |
| 3076 | _moduleLoader.get(), _propertyNameIndex.getJsName(kRegisterModulePropertyName), callContext); |
| 3077 | if (!entry.exceptionTracker) { |
| 3078 | onRecoverableError("registerJavaScriptModuleFactory", entry.exceptionTracker); |
| 3079 | return; |
| 3080 | } |
| 3081 | }); |
no test coverage detected