expo-modules-core 1.11.13 → 1.12.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +77 -13
- package/ExpoModulesCore.podspec +7 -4
- package/android/ExpoModulesCorePlugin.gradle +40 -28
- package/android/build.gradle +12 -93
- package/android/proguard-rules.pro +0 -8
- package/android/src/main/cpp/Exceptions.cpp +1 -1
- package/android/src/main/cpp/Exceptions.h +1 -1
- package/android/src/main/cpp/ExpoModulesHostObject.cpp +7 -6
- package/android/src/main/cpp/ExpoModulesHostObject.h +3 -3
- package/android/src/main/cpp/JNIInjector.cpp +4 -2
- package/android/src/main/cpp/JSIContext.cpp +354 -0
- package/android/src/main/cpp/{JSIInteropModuleRegistry.h → JSIContext.h} +90 -9
- package/android/src/main/cpp/JavaCallback.cpp +210 -24
- package/android/src/main/cpp/JavaCallback.h +42 -7
- package/android/src/main/cpp/JavaScriptFunction.cpp +20 -6
- package/android/src/main/cpp/JavaScriptFunction.h +4 -1
- package/android/src/main/cpp/JavaScriptModuleObject.cpp +118 -82
- package/android/src/main/cpp/JavaScriptModuleObject.h +21 -18
- package/android/src/main/cpp/JavaScriptObject.cpp +7 -8
- package/android/src/main/cpp/JavaScriptObject.h +4 -2
- package/android/src/main/cpp/JavaScriptRuntime.cpp +18 -41
- package/android/src/main/cpp/JavaScriptRuntime.h +2 -8
- package/android/src/main/cpp/JavaScriptTypedArray.cpp +3 -3
- package/android/src/main/cpp/JavaScriptTypedArray.h +1 -1
- package/android/src/main/cpp/JavaScriptValue.cpp +7 -7
- package/android/src/main/cpp/JavaScriptValue.h +1 -1
- package/android/src/main/cpp/JavaScriptWeakObject.cpp +4 -4
- package/android/src/main/cpp/JavaScriptWeakObject.h +1 -1
- package/android/src/main/cpp/MethodMetadata.cpp +44 -120
- package/android/src/main/cpp/MethodMetadata.h +5 -11
- package/android/src/main/cpp/WeakRuntimeHolder.cpp +3 -3
- package/android/src/main/cpp/WeakRuntimeHolder.h +2 -2
- package/android/src/main/cpp/types/AnyType.cpp +1 -1
- package/android/src/main/cpp/types/AnyType.h +1 -1
- package/android/src/main/cpp/types/FrontendConverter.cpp +32 -43
- package/android/src/main/cpp/types/FrontendConverter.h +1 -23
- package/android/src/main/cpp/types/JNIToJSIConverter.cpp +5 -10
- package/android/src/main/cpp/types/JNIToJSIConverter.h +6 -2
- package/android/src/main/java/expo/modules/adapters/react/ModuleRegistryAdapter.java +3 -0
- package/android/src/main/java/expo/modules/adapters/react/NativeModulesProxy.java +14 -100
- package/android/src/main/java/expo/modules/adapters/react/ReactAdapterPackage.java +3 -5
- package/android/src/main/java/expo/modules/adapters/react/ReactModuleRegistryProvider.java +6 -22
- package/android/src/main/java/expo/modules/adapters/react/apploader/RNHeadlessAppLoader.kt +8 -4
- package/android/src/main/java/expo/modules/adapters/react/services/EventEmitterModule.java +0 -1
- package/android/src/main/java/expo/modules/adapters/react/services/UIManagerModuleWrapper.java +23 -8
- package/android/src/main/java/expo/modules/core/BasePackage.java +0 -10
- package/android/src/main/java/expo/modules/core/ModulePriorities.kt +1 -0
- package/android/src/main/java/expo/modules/core/ModuleRegistry.java +2 -32
- package/android/src/main/java/expo/modules/core/ModuleRegistryProvider.java +0 -18
- package/android/src/main/java/expo/modules/core/Promise.java +2 -0
- package/android/src/main/java/expo/modules/core/interfaces/Package.java +0 -17
- package/android/src/main/java/expo/modules/core/interfaces/ReactActivityHandler.java +0 -9
- package/android/src/main/java/expo/modules/core/interfaces/ReactNativeHostHandler.java +24 -31
- package/android/src/main/java/expo/modules/core/logging/LogHandler.kt +1 -7
- package/android/src/main/java/expo/modules/core/logging/LogHandlers.kt +11 -0
- package/android/src/main/java/expo/modules/core/logging/Logger.kt +18 -29
- package/android/src/main/java/expo/modules/core/logging/LoggerTimer.kt +11 -0
- package/android/src/main/java/expo/modules/core/logging/OSLogHandler.kt +2 -4
- package/android/src/main/java/expo/modules/core/logging/PersistentFileLogHandler.kt +1 -3
- package/android/src/main/java/expo/modules/interfaces/constants/ConstantsInterface.java +0 -2
- package/android/src/main/java/expo/modules/interfaces/permissions/PermissionsStatus.java +1 -1
- package/android/src/main/java/expo/modules/kotlin/AppContext.kt +44 -24
- package/android/src/main/java/expo/modules/kotlin/ArrayExtenstions.kt +15 -0
- package/android/src/main/java/expo/modules/kotlin/CoreLogger.kt +2 -2
- package/android/src/main/java/expo/modules/kotlin/DynamicExtenstions.kt +0 -3
- package/android/src/main/java/expo/modules/kotlin/ExpoBridgeModule.kt +41 -0
- package/android/src/main/java/expo/modules/kotlin/ExpoModulesHelper.kt +1 -2
- package/android/src/main/java/expo/modules/kotlin/KPromiseWrapper.kt +1 -2
- package/android/src/main/java/expo/modules/kotlin/KotlinInteropModuleRegistry.kt +1 -33
- package/android/src/main/java/expo/modules/kotlin/ModuleHolder.kt +7 -6
- package/android/src/main/java/expo/modules/kotlin/ModuleRegistry.kt +12 -12
- package/android/src/main/java/expo/modules/kotlin/Promise.kt +10 -0
- package/android/src/main/java/expo/modules/kotlin/ReactExtensions.kt +14 -0
- package/android/src/main/java/expo/modules/kotlin/Utils.kt +4 -1
- package/android/src/main/java/expo/modules/kotlin/activityaware/AppCompatActivityAwareHelper.kt +1 -1
- package/android/src/main/java/expo/modules/kotlin/activityresult/AppContextActivityResultCaller.kt +1 -1
- package/android/src/main/java/expo/modules/kotlin/activityresult/AppContextActivityResultRegistry.kt +6 -6
- package/android/src/main/java/expo/modules/kotlin/classcomponent/ClassComponentBuilder.kt +44 -15
- package/android/src/main/java/expo/modules/kotlin/defaultmodules/CoreModule.kt +31 -1
- package/android/src/main/java/expo/modules/kotlin/defaultmodules/ErrorManagerModule.kt +2 -4
- package/android/src/main/java/expo/modules/kotlin/events/KModuleEventEmitterWrapper.kt +11 -4
- package/android/src/main/java/expo/modules/kotlin/exception/CodedException.kt +2 -3
- package/android/src/main/java/expo/modules/kotlin/functions/AsyncFunctionBuilder.kt +136 -43
- package/android/src/main/java/expo/modules/kotlin/functions/AsyncFunctionComponent.kt +71 -2
- package/android/src/main/java/expo/modules/kotlin/functions/FunctionBuilder.kt +39 -12
- package/android/src/main/java/expo/modules/kotlin/jni/ExpectedType.kt +2 -2
- package/android/src/main/java/expo/modules/kotlin/jni/JNIDeallocator.kt +1 -1
- package/android/src/main/java/expo/modules/kotlin/jni/{JSIInteropModuleRegistry.kt → JSIContext.kt} +90 -14
- package/android/src/main/java/expo/modules/kotlin/jni/JavaCallback.kt +51 -24
- package/android/src/main/java/expo/modules/kotlin/jni/JavaScriptFunction.kt +3 -3
- package/android/src/main/java/expo/modules/kotlin/jni/JavaScriptModuleObject.kt +4 -1
- package/android/src/main/java/expo/modules/kotlin/jni/JavaScriptObject.kt +1 -0
- package/android/src/main/java/expo/modules/kotlin/jni/JavaScriptValue.kt +1 -0
- package/android/src/main/java/expo/modules/kotlin/jni/PromiseImpl.kt +20 -0
- package/android/src/main/java/expo/modules/kotlin/modules/Module.kt +0 -1
- package/android/src/main/java/expo/modules/kotlin/modules/ModuleDefinitionBuilder.kt +1 -1
- package/android/src/main/java/expo/modules/kotlin/objects/ObjectDefinitionBuilder.kt +164 -65
- package/android/src/main/java/expo/modules/kotlin/objects/PropertyComponentBuilder.kt +3 -4
- package/android/src/main/java/expo/modules/kotlin/sharedobjects/ClassRegistry.kt +21 -0
- package/android/src/main/java/expo/modules/kotlin/sharedobjects/SharedObject.kt +34 -1
- package/android/src/main/java/expo/modules/kotlin/sharedobjects/SharedObjectRegistry.kt +23 -8
- package/android/src/main/java/expo/modules/kotlin/sharedobjects/SharedRef.kt +7 -1
- package/android/src/main/java/expo/modules/kotlin/tracing/ExpoTrace.kt +4 -0
- package/android/src/main/java/expo/modules/kotlin/types/AnyType.kt +134 -2
- package/android/src/main/java/expo/modules/kotlin/types/EnforceType.kt +60 -0
- package/android/src/main/java/expo/modules/kotlin/types/EnumTypeConverter.kt +2 -2
- package/android/src/main/java/expo/modules/kotlin/types/TypeConverter.kt +0 -2
- package/android/src/main/java/expo/modules/kotlin/types/TypeConverterProvider.kt +3 -27
- package/android/src/main/java/expo/modules/kotlin/types/UnitTypeConverter.kt +3 -7
- package/android/src/main/java/expo/modules/kotlin/types/io/PathTypeConverter.kt +3 -0
- package/android/src/main/java/expo/modules/kotlin/viewevent/ViewEvent.kt +2 -5
- package/android/src/main/java/expo/modules/kotlin/views/ViewDefinitionBuilder.kt +137 -48
- package/android/src/main/java/expo/modules/kotlin/views/ViewManagerDefinition.kt +2 -5
- package/build/EventEmitter.d.ts +2 -2
- package/build/EventEmitter.d.ts.map +1 -1
- package/build/EventEmitter.js +8 -8
- package/build/EventEmitter.js.map +1 -1
- package/build/NativeModule.d.ts +4 -0
- package/build/NativeModule.d.ts.map +1 -0
- package/build/NativeModule.js +4 -0
- package/build/NativeModule.js.map +1 -0
- package/build/NativeModulesProxy.native.d.ts.map +1 -1
- package/build/NativeModulesProxy.native.js +4 -0
- package/build/NativeModulesProxy.native.js.map +1 -1
- package/build/NativeModulesProxy.types.d.ts +2 -2
- package/build/NativeModulesProxy.types.d.ts.map +1 -1
- package/build/NativeModulesProxy.types.js.map +1 -1
- package/build/NativeViewManagerAdapter.native.d.ts.map +1 -1
- package/build/NativeViewManagerAdapter.native.js +20 -1
- package/build/NativeViewManagerAdapter.native.js.map +1 -1
- package/build/PermissionsHook.d.ts.map +1 -1
- package/build/PermissionsHook.js +2 -0
- package/build/PermissionsHook.js.map +1 -1
- package/build/Refs.d.ts +8 -0
- package/build/Refs.d.ts.map +1 -0
- package/build/Refs.js +10 -0
- package/build/Refs.js.map +1 -0
- package/build/SharedObject.d.ts +4 -0
- package/build/SharedObject.d.ts.map +1 -0
- package/build/SharedObject.js +4 -0
- package/build/SharedObject.js.map +1 -0
- package/build/createWebModule.d.ts +2 -0
- package/build/createWebModule.d.ts.map +1 -0
- package/build/createWebModule.js +6 -0
- package/build/createWebModule.js.map +1 -0
- package/build/createWebModule.web.d.ts +2 -0
- package/build/createWebModule.web.d.ts.map +1 -0
- package/build/createWebModule.web.js +6 -0
- package/build/createWebModule.web.js.map +1 -0
- package/build/ensureNativeModulesAreInstalled.d.ts +6 -0
- package/build/ensureNativeModulesAreInstalled.d.ts.map +1 -0
- package/build/ensureNativeModulesAreInstalled.js +26 -0
- package/build/ensureNativeModulesAreInstalled.js.map +1 -0
- package/build/hooks/useReleasingSharedObject.d.ts +7 -0
- package/build/hooks/useReleasingSharedObject.d.ts.map +1 -0
- package/build/hooks/useReleasingSharedObject.js +40 -0
- package/build/hooks/useReleasingSharedObject.js.map +1 -0
- package/build/index.d.ts +8 -1
- package/build/index.d.ts.map +1 -1
- package/build/index.js +8 -0
- package/build/index.js.map +1 -1
- package/build/requireNativeModule.d.ts +0 -17
- package/build/requireNativeModule.d.ts.map +1 -1
- package/build/requireNativeModule.js +2 -23
- package/build/requireNativeModule.js.map +1 -1
- package/build/ts-declarations/EventEmitter.d.ts +50 -0
- package/build/ts-declarations/EventEmitter.d.ts.map +1 -0
- package/build/ts-declarations/EventEmitter.js +2 -0
- package/build/ts-declarations/EventEmitter.js.map +1 -0
- package/build/ts-declarations/NativeModule.d.ts +14 -0
- package/build/ts-declarations/NativeModule.d.ts.map +1 -0
- package/build/ts-declarations/NativeModule.js +2 -0
- package/build/ts-declarations/NativeModule.js.map +1 -0
- package/build/ts-declarations/SharedObject.d.ts +14 -0
- package/build/ts-declarations/SharedObject.d.ts.map +1 -0
- package/build/ts-declarations/SharedObject.js +2 -0
- package/build/ts-declarations/SharedObject.js.map +1 -0
- package/build/ts-declarations/global.d.ts +49 -0
- package/build/ts-declarations/global.d.ts.map +1 -0
- package/build/ts-declarations/global.js +2 -0
- package/build/ts-declarations/global.js.map +1 -0
- package/build/web/CoreModule.d.ts +17 -0
- package/build/web/CoreModule.d.ts.map +1 -0
- package/build/web/CoreModule.js +51 -0
- package/build/web/CoreModule.js.map +1 -0
- package/build/web/index.d.ts +1 -0
- package/build/web/index.d.ts.map +1 -0
- package/build/web/index.js +1 -0
- package/build/web/index.js.map +1 -0
- package/build/web/index.web.d.ts +2 -0
- package/build/web/index.web.d.ts.map +1 -0
- package/build/web/index.web.js +2 -0
- package/build/web/index.web.js.map +1 -0
- package/common/cpp/BridgelessJSCallInvoker.h +41 -0
- package/common/cpp/EventEmitter.cpp +299 -0
- package/common/cpp/EventEmitter.h +111 -0
- package/common/cpp/JSIUtils.cpp +116 -11
- package/common/cpp/JSIUtils.h +54 -7
- package/common/cpp/LazyObject.cpp +15 -3
- package/common/cpp/LazyObject.h +13 -0
- package/common/cpp/NativeModule.cpp +16 -0
- package/common/cpp/NativeModule.h +34 -0
- package/common/cpp/ObjectDeallocator.cpp +3 -5
- package/common/cpp/ObjectDeallocator.h +2 -3
- package/common/cpp/SharedObject.cpp +69 -0
- package/common/cpp/SharedObject.h +59 -0
- package/common/cpp/TestingSyncJSCallInvoker.h +44 -0
- package/ios/Api/Builders/ClassComponentBuilder.swift +34 -0
- package/ios/{Objects → Api/Builders}/ObjectDefinitionBuilder.swift +3 -3
- package/ios/Api/Builders/ViewDefinitionBuilder.swift +53 -0
- package/ios/Api/Factories/AsyncFunctionFactories.swift +173 -0
- package/ios/{Classes/ClassComponentFactories.swift → Api/Factories/ClassFactories.swift} +19 -19
- package/ios/{Functions/ConcurrentFunctionDefinition.swift → Api/Factories/ConcurrentFunctionFactories.swift} +0 -113
- package/ios/{Modules/ModuleDefinitionComponents.swift → Api/Factories/EventListenersFactories.swift} +0 -20
- package/ios/Api/Factories/ModuleFactories.swift +6 -0
- package/ios/{Objects/ObjectDefinitionComponents.swift → Api/Factories/ObjectFactories.swift} +5 -5
- package/ios/Api/Factories/PropertyFactories.swift +50 -0
- package/ios/Api/Factories/SyncFunctionFactories.swift +173 -0
- package/ios/{Views/ViewManagerDefinitionComponents.swift → Api/Factories/ViewFactories.swift} +7 -6
- package/ios/AppDelegates/EXAppDelegateWrapper.h +0 -21
- package/ios/AppDelegates/EXAppDelegateWrapper.mm +37 -29
- package/ios/{AppContext.swift → Core/AppContext.swift} +34 -11
- package/ios/Core/Classes/AnyClassDefinitionElement.swift +37 -0
- package/ios/{Classes/ClassComponent.swift → Core/Classes/ClassDefinition.swift} +10 -10
- package/ios/{Conversions.swift → Core/Conversions.swift} +1 -1
- package/ios/{DynamicTypes → Core/DynamicTypes}/DynamicSharedObjectType.swift +3 -3
- package/ios/Core/Events/EventObservingDefinition.swift +79 -0
- package/ios/Core/Events/LegacyEventEmitterCompat.swift +32 -0
- package/ios/Core/ExpoBridgeModule.h +18 -0
- package/ios/Core/ExpoBridgeModule.mm +88 -0
- package/ios/Core/ExpoRuntime.swift +6 -0
- package/ios/{Functions/AnyFunction.swift → Core/Functions/AnyFunctionDefinition.swift} +9 -2
- package/ios/Core/Functions/AsyncFunctionDefinition.swift +150 -0
- package/ios/Core/Functions/ConcurrentFunctionDefinition.swift +112 -0
- package/ios/Core/Functions/SyncFunctionDefinition.swift +108 -0
- package/ios/{JavaScriptUtils.swift → Core/JavaScriptUtils.swift} +4 -4
- package/ios/{Logging → Core/Logging}/LogHandlers.swift +12 -5
- package/ios/{Logging → Core/Logging}/Logger.swift +14 -92
- package/ios/Core/Logging/LoggerTimer.swift +22 -0
- package/ios/{ModuleHolder.swift → Core/ModuleHolder.swift} +2 -10
- package/ios/Core/Modules/CoreModule.swift +43 -0
- package/ios/{Modules → Core/Modules}/ModuleDefinition.swift +20 -12
- package/ios/{Modules → Core/Modules}/ModuleDefinitionBuilder.swift +1 -3
- package/ios/{Objects → Core/Objects}/ObjectDefinition.swift +9 -9
- package/ios/{Objects/PropertyComponent.swift → Core/Objects/PropertyDefinition.swift} +11 -64
- package/ios/Core/Protocols/AnyDefinition.swift +4 -0
- package/ios/Core/Protocols/AnyExpoView.swift +7 -0
- package/ios/Core/Protocols/AnyModule.swift +17 -0
- package/ios/Core/Protocols/AnyViewDefinition.swift +34 -0
- package/ios/Core/SharedObjects/SharedObject.swift +80 -0
- package/ios/{SharedObjects → Core/SharedObjects}/SharedObjectRegistry.swift +45 -19
- package/ios/{Views → Core/Views}/AnyViewProp.swift +1 -1
- package/ios/{Views → Core/Views}/ComponentData.swift +7 -7
- package/ios/{Views → Core/Views}/ExpoView.swift +1 -1
- package/ios/Core/Views/ViewDefinition.swift +97 -0
- package/ios/{Views → Core/Views}/ViewLifecycleMethod.swift +1 -1
- package/ios/{Views → Core/Views}/ViewModuleWrapper.swift +1 -1
- package/ios/Fabric/ExpoFabricView.swift +5 -6
- package/ios/FileSystemUtilities/FileSystemLegacyUtilities.swift +111 -0
- package/ios/JSI/EXJSIInstaller.h +28 -0
- package/ios/JSI/EXJSIInstaller.mm +54 -10
- package/ios/JSI/EXJSIUtils.h +15 -11
- package/ios/JSI/EXJSIUtils.mm +21 -49
- package/ios/JSI/EXJavaScriptObject.mm +2 -2
- package/ios/JSI/EXJavaScriptRuntime.h +15 -0
- package/ios/JSI/EXJavaScriptRuntime.mm +53 -26
- package/ios/JSI/EXSharedObjectUtils.h +15 -0
- package/ios/JSI/EXSharedObjectUtils.mm +18 -0
- package/ios/JSI/JavaScriptRuntime.swift +16 -0
- package/ios/Legacy/ModuleRegistry/EXModuleRegistry.m +1 -0
- package/ios/Legacy/ModuleRegistryProvider/EXModuleRegistryProvider.m +5 -0
- package/ios/Legacy/NativeModulesProxy/EXNativeModulesProxy.mm +5 -4
- package/ios/Legacy/Services/EXReactNativeAdapter.mm +34 -28
- package/ios/ReactDelegates/EXReactDelegateWrapper.h +4 -12
- package/ios/ReactDelegates/EXReactDelegateWrapper.mm +41 -0
- package/ios/ReactDelegates/EXReactRootViewFactory.h +38 -0
- package/ios/ReactDelegates/EXReactRootViewFactory.mm +54 -0
- package/ios/ReactDelegates/ExpoReactDelegate.swift +22 -15
- package/ios/ReactDelegates/ExpoReactDelegateHandler.swift +10 -21
- package/ios/ReactDelegates/RCTAppDelegate+Recreate.h +28 -0
- package/ios/ReactDelegates/RCTAppDelegate+Recreate.mm +47 -0
- package/ios/Tests/{ClassComponentSpec.swift → ClassDefinitionSpec.swift} +6 -6
- package/ios/Tests/ConvertiblesSpec.swift +6 -1
- package/ios/Tests/CoreModuleSpec.swift +0 -4
- package/ios/Tests/DynamicTypeSpec.swift +1 -1
- package/ios/Tests/EventEmitterSpec.swift +274 -0
- package/ios/Tests/ExceptionsSpec.swift +114 -54
- package/ios/Tests/ExpoModulesSpec.swift +4 -3
- package/ios/Tests/LoggerSpec.swift +80 -0
- package/ios/Tests/{PropertyComponentSpec.swift → PropertyDefinitionSpec.swift} +1 -1
- package/ios/Tests/SharedObjectRegistrySpec.swift +34 -28
- package/ios/Tests/SharedObjectSpec.swift +141 -0
- package/ios/Tests/ViewDefinitionSpec.swift +1 -1
- package/package.json +2 -2
- package/src/EventEmitter.ts +15 -18
- package/src/NativeModule.ts +6 -0
- package/src/NativeModulesProxy.native.ts +5 -0
- package/src/NativeModulesProxy.types.ts +2 -2
- package/src/NativeViewManagerAdapter.native.tsx +25 -1
- package/src/PermissionsHook.ts +4 -0
- package/src/Refs.ts +10 -0
- package/src/SharedObject.ts +6 -0
- package/src/createWebModule.ts +5 -0
- package/src/createWebModule.web.ts +6 -0
- package/src/ensureNativeModulesAreInstalled.ts +24 -0
- package/src/hooks/useReleasingSharedObject.ts +51 -0
- package/src/index.ts +13 -0
- package/src/requireNativeModule.ts +2 -51
- package/src/ts-declarations/EventEmitter.ts +65 -0
- package/src/ts-declarations/ExpoModules.d.ts +0 -5
- package/src/ts-declarations/NativeModule.ts +18 -0
- package/src/ts-declarations/SharedObject.ts +16 -0
- package/src/ts-declarations/global.ts +60 -0
- package/src/web/CoreModule.ts +83 -0
- package/src/web/index.ts +0 -0
- package/src/web/index.web.ts +1 -0
- package/android/src/main/cpp/JSIInteropModuleRegistry.cpp +0 -196
- package/android/src/main/java/expo/modules/adapters/react/ArgumentsHelper.java +0 -48
- package/android/src/main/java/expo/modules/adapters/react/PromiseWrapper.java +0 -38
- package/android/src/main/java/expo/modules/adapters/react/services/CookieManagerModule.java +0 -53
- package/android/src/main/java/expo/modules/core/ArgumentsHelper.java +0 -44
- package/android/src/main/java/expo/modules/core/ExportedModule.java +0 -173
- package/android/src/main/java/expo/modules/core/ModuleRegistryDelegate.kt +0 -12
- package/android/src/main/java/expo/modules/core/ViewManager.java +0 -9
- package/android/src/main/java/expo/modules/core/interfaces/ExpoMethod.java +0 -12
- package/android/src/main/java/expo/modules/core/interfaces/ExpoProp.java +0 -10
- package/android/src/main/java/expo/modules/core/logging/LoggerOptions.kt +0 -29
- package/android-annotation/build.gradle +0 -48
- package/android-annotation/src/main/java/expo/modules/annotation/Config.kt +0 -7
- package/android-annotation/src/main/java/expo/modules/annotation/ConverterBinder.kt +0 -7
- package/android-annotation-processor/build.gradle +0 -54
- package/android-annotation-processor/src/main/java/expo/modules/annotationprocessor/ExpoSymbolProcessor.kt +0 -175
- package/android-annotation-processor/src/main/java/expo/modules/annotationprocessor/ExpoSymbolProcessorProvider.kt +0 -10
- package/android-annotation-processor/src/main/resources/META-INF/services/com.google.devtools.ksp.processing.SymbolProcessorProvider +0 -1
- package/ios/Classes/ClassComponentElement.swift +0 -37
- package/ios/Classes/ClassComponentElementsBuilder.swift +0 -34
- package/ios/ExpoBridgeModule.m +0 -7
- package/ios/ExpoBridgeModule.swift +0 -108
- package/ios/ExpoRuntime.swift +0 -28
- package/ios/Functions/AsyncFunctionComponent.swift +0 -327
- package/ios/Functions/SyncFunctionComponent.swift +0 -282
- package/ios/Interfaces/Font/EXFontManagerInterface.h +0 -9
- package/ios/Interfaces/Font/EXFontProcessorInterface.h +0 -15
- package/ios/Interfaces/Font/EXFontScalerInterface.h +0 -9
- package/ios/Interfaces/Font/EXFontScalersManagerInterface.h +0 -9
- package/ios/Legacy/Services/EXReactFontManager.h +0 -6
- package/ios/Legacy/Services/EXReactFontManager.m +0 -130
- package/ios/Modules/AnyModule.swift +0 -53
- package/ios/Modules/CoreModule.swift +0 -17
- package/ios/ReactDelegates/EXRCTBridgeDelegateInterceptor.h +0 -16
- package/ios/ReactDelegates/EXRCTBridgeDelegateInterceptor.m +0 -49
- package/ios/ReactDelegates/EXReactCompatibleHelpers.h +0 -15
- package/ios/ReactDelegates/EXReactCompatibleHelpers.m +0 -25
- package/ios/ReactDelegates/EXReactDelegateWrapper.m +0 -53
- package/ios/SharedObjects/SharedObject.swift +0 -31
- package/ios/Views/ViewDefinition.swift +0 -114
- package/ios/Views/ViewFactory.swift +0 -16
- package/ios/Views/ViewManagerDefinition.swift +0 -77
- package/ios/Views/ViewManagerDefinitionBuilder.swift +0 -11
- /package/ios/{AppContextConfig.swift → Core/AppContextConfig.swift} +0 -0
- /package/ios/{Arguments → Core/Arguments}/AnyArgument.swift +0 -0
- /package/ios/{Arguments → Core/Arguments}/Convertible.swift +0 -0
- /package/ios/{Arguments → Core/Arguments}/Convertibles.swift +0 -0
- /package/ios/{Arguments → Core/Arguments}/Enumerable.swift +0 -0
- /package/ios/{Classes → Core/Classes}/ClassRegistry.swift +0 -0
- /package/ios/{Convertibles → Core/Convertibles}/Convertibles+Color.swift +0 -0
- /package/ios/{Convertibles → Core/Convertibles}/Either.swift +0 -0
- /package/ios/{DynamicTypes → Core/DynamicTypes}/AnyDynamicType.swift +0 -0
- /package/ios/{DynamicTypes → Core/DynamicTypes}/DynamicArrayType.swift +0 -0
- /package/ios/{DynamicTypes → Core/DynamicTypes}/DynamicConvertibleType.swift +0 -0
- /package/ios/{DynamicTypes → Core/DynamicTypes}/DynamicDataType.swift +0 -0
- /package/ios/{DynamicTypes → Core/DynamicTypes}/DynamicDictionaryType.swift +0 -0
- /package/ios/{DynamicTypes → Core/DynamicTypes}/DynamicEnumType.swift +0 -0
- /package/ios/{DynamicTypes → Core/DynamicTypes}/DynamicJavaScriptType.swift +0 -0
- /package/ios/{DynamicTypes → Core/DynamicTypes}/DynamicOptionalType.swift +0 -0
- /package/ios/{DynamicTypes → Core/DynamicTypes}/DynamicRawType.swift +0 -0
- /package/ios/{DynamicTypes → Core/DynamicTypes}/DynamicType.swift +0 -0
- /package/ios/{DynamicTypes → Core/DynamicTypes}/DynamicTypedArrayType.swift +0 -0
- /package/ios/{DynamicTypes → Core/DynamicTypes}/DynamicViewType.swift +0 -0
- /package/ios/{EventListener.swift → Core/EventListener.swift} +0 -0
- /package/ios/{Events → Core/Events}/Callback.swift +0 -0
- /package/ios/{Events → Core/Events}/EventDispatcher.swift +0 -0
- /package/ios/{Exceptions → Core/Exceptions}/ChainableException.swift +0 -0
- /package/ios/{Exceptions → Core/Exceptions}/CodedError.swift +0 -0
- /package/ios/{Exceptions → Core/Exceptions}/CommonExceptions.swift +0 -0
- /package/ios/{Exceptions → Core/Exceptions}/Exception.swift +0 -0
- /package/ios/{Exceptions → Core/Exceptions}/ExceptionOrigin.swift +0 -0
- /package/ios/{Exceptions → Core/Exceptions}/GenericException.swift +0 -0
- /package/ios/{Exceptions → Core/Exceptions}/UnexpectedException.swift +0 -0
- /package/ios/{JavaScriptFunction.swift → Core/JavaScriptFunction.swift} +0 -0
- /package/ios/{Logging → Core/Logging}/LogType.swift +0 -0
- /package/ios/{Logging → Core/Logging}/PersistentFileLog.swift +0 -0
- /package/ios/{ModuleRegistry.swift → Core/ModuleRegistry.swift} +0 -0
- /package/ios/{Modules → Core/Modules}/Module.swift +0 -0
- /package/ios/{ModulesProvider.swift → Core/ModulesProvider.swift} +0 -0
- /package/ios/{Objects → Core/Objects}/JavaScriptObjectBuilder.swift +0 -0
- /package/ios/{Promise.swift → Core/Promise.swift} +0 -0
- /package/ios/{Records → Core/Records}/AnyField.swift +0 -0
- /package/ios/{Records → Core/Records}/Field.swift +0 -0
- /package/ios/{Records → Core/Records}/FieldExtensions.swift +0 -0
- /package/ios/{Records → Core/Records}/FieldOption.swift +0 -0
- /package/ios/{Records → Core/Records}/Record.swift +0 -0
- /package/ios/{SharedObjects → Core/SharedObjects}/SharedRef.swift +0 -0
- /package/ios/{TypedArrays → Core/TypedArrays}/AnyTypedArray.swift +0 -0
- /package/ios/{TypedArrays → Core/TypedArrays}/ConcreteTypedArrays.swift +0 -0
- /package/ios/{TypedArrays → Core/TypedArrays}/GenericTypedArray.swift +0 -0
- /package/ios/{TypedArrays → Core/TypedArrays}/TypedArray.swift +0 -0
- /package/ios/{Views → Core/Views}/ConcreteViewProp.swift +0 -0
|
@@ -0,0 +1,274 @@
|
|
|
1
|
+
import ExpoModulesTestCore
|
|
2
|
+
|
|
3
|
+
@testable import ExpoModulesCore
|
|
4
|
+
|
|
5
|
+
final class EventEmitterSpec: ExpoSpec {
|
|
6
|
+
override class func spec() {
|
|
7
|
+
let appContext = AppContext.create()
|
|
8
|
+
let runtime = try! appContext.runtime
|
|
9
|
+
|
|
10
|
+
describe("JS class") {
|
|
11
|
+
it("exists") {
|
|
12
|
+
let eventEmitterClass = try runtime.eval("expo.EventEmitter")
|
|
13
|
+
expect(eventEmitterClass.kind) == .function
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
it("has functions in prototype") {
|
|
17
|
+
let prototype = try runtime.eval("expo.EventEmitter.prototype").asObject()
|
|
18
|
+
let addListener = prototype.getProperty("addListener")
|
|
19
|
+
let removeListener = prototype.getProperty("removeListener")
|
|
20
|
+
let removeAllListeners = prototype.getProperty("removeAllListeners")
|
|
21
|
+
let emit = prototype.getProperty("emit")
|
|
22
|
+
|
|
23
|
+
expect(addListener.kind) == .function
|
|
24
|
+
expect(removeListener.kind) == .function
|
|
25
|
+
expect(removeAllListeners.kind) == .function
|
|
26
|
+
expect(emit.kind) == .function
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
it("creates an instance") {
|
|
30
|
+
let eventEmitter = try runtime.eval("new expo.EventEmitter()")
|
|
31
|
+
expect(eventEmitter.kind) == .object
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
it("calls a listener") {
|
|
35
|
+
let result = try runtime.eval([
|
|
36
|
+
"emitter = new expo.EventEmitter()",
|
|
37
|
+
"result = null",
|
|
38
|
+
"emitter.addListener('test', payload => { result = payload })",
|
|
39
|
+
"emitter.emit('test', 'it\\'s a payload')",
|
|
40
|
+
"result"
|
|
41
|
+
])
|
|
42
|
+
expect(result.kind) == .string
|
|
43
|
+
expect(try result.asString()) == "it's a payload"
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
it("removes a listener") {
|
|
47
|
+
let result = try runtime.eval([
|
|
48
|
+
"emitter = new expo.EventEmitter()",
|
|
49
|
+
"result = null",
|
|
50
|
+
"listener = () => { result = 1 }",
|
|
51
|
+
"emitter.addListener('test', listener)",
|
|
52
|
+
"emitter.removeListener('test', listener)",
|
|
53
|
+
"emitter.emit('test')",
|
|
54
|
+
"result"
|
|
55
|
+
])
|
|
56
|
+
expect(result.kind) == .null
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
it("removes all listeners") {
|
|
60
|
+
let result = try runtime.eval([
|
|
61
|
+
"emitter = new expo.EventEmitter()",
|
|
62
|
+
"result = null",
|
|
63
|
+
"emitter.addListener('test', () => { result = 1 })",
|
|
64
|
+
"emitter.addListener('test', () => { result = 2 })",
|
|
65
|
+
"emitter.removeAllListeners('test')",
|
|
66
|
+
"emitter.emit('test')",
|
|
67
|
+
"result"
|
|
68
|
+
])
|
|
69
|
+
expect(result.kind) == .null
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
it("emits with multiple arguments") {
|
|
73
|
+
let args = try runtime
|
|
74
|
+
.eval([
|
|
75
|
+
"emitter = new expo.EventEmitter()",
|
|
76
|
+
"result = null",
|
|
77
|
+
"emitter.addListener('test', (a, b, c) => { result = [a, b, c] })",
|
|
78
|
+
"emitter.emit('test', 14, 2, 24)",
|
|
79
|
+
"result"
|
|
80
|
+
])
|
|
81
|
+
.asArray()
|
|
82
|
+
.compactMap({ try $0?.asInt() })
|
|
83
|
+
|
|
84
|
+
expect(args.count) == 3
|
|
85
|
+
expect(args[0]) == 14
|
|
86
|
+
expect(args[1]) == 2
|
|
87
|
+
expect(args[2]) == 24
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
it("returns listener count with listeners added") {
|
|
91
|
+
let listenerCount = try runtime.eval([
|
|
92
|
+
"emitter = new expo.EventEmitter()",
|
|
93
|
+
"emitter.addListener('test', () => {})",
|
|
94
|
+
"emitter.addListener('test', () => {})",
|
|
95
|
+
"emitter.listenerCount('test')"
|
|
96
|
+
])
|
|
97
|
+
expect(listenerCount.kind) == .number
|
|
98
|
+
expect(try listenerCount.asInt()) == 2
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
it("returns listener count without any listeners") {
|
|
102
|
+
let listenerCount = try runtime.eval([
|
|
103
|
+
"emitter = new expo.EventEmitter()",
|
|
104
|
+
"emitter.listenerCount('test')"
|
|
105
|
+
])
|
|
106
|
+
expect(listenerCount.kind) == .number
|
|
107
|
+
expect(try listenerCount.asInt()) == 0
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
it("returns listener count for the proper event") {
|
|
111
|
+
let listenerCount = try runtime.eval([
|
|
112
|
+
"emitter = new expo.EventEmitter()",
|
|
113
|
+
"emitter.addListener('test1', () => {})",
|
|
114
|
+
"emitter.addListener('test1', () => {})",
|
|
115
|
+
"emitter.addListener('test2', () => {})",
|
|
116
|
+
"emitter.listenerCount('test2')"
|
|
117
|
+
])
|
|
118
|
+
expect(listenerCount.kind) == .number
|
|
119
|
+
expect(try listenerCount.asInt()) == 1
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
it("calls startObserving on addListener") {
|
|
123
|
+
var calls: Int = 0
|
|
124
|
+
let eventName = "testEvent"
|
|
125
|
+
let listenerA = runtime.createSyncFunction("listenerA") { _, _ in }
|
|
126
|
+
let listenerB = runtime.createSyncFunction("listenerB") { _, _ in }
|
|
127
|
+
let observer = try setupEventObserver(runtime: runtime, functionName: "startObserving") { arguments in
|
|
128
|
+
expect(try arguments.first?.asString()) == eventName
|
|
129
|
+
calls = calls + 1
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
observer.addListener.call(withArguments: [eventName, listenerA], thisObject: observer.emitter, asConstructor: false)
|
|
133
|
+
observer.addListener.call(withArguments: [eventName, listenerB], thisObject: observer.emitter, asConstructor: false)
|
|
134
|
+
|
|
135
|
+
expect(calls) == 1
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
it("calls stopObserving on removeListener") {
|
|
139
|
+
var calls: Int = 0
|
|
140
|
+
let eventName = "testEvent"
|
|
141
|
+
let listener = runtime.createSyncFunction("listener") { _, _ in }
|
|
142
|
+
let observer = try setupEventObserver(runtime: runtime, functionName: "stopObserving") { arguments in
|
|
143
|
+
expect(try arguments.first?.asString()) == eventName
|
|
144
|
+
calls = calls + 1
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
observer.addListener.call(withArguments: [eventName, listener], thisObject: observer.emitter, asConstructor: false)
|
|
148
|
+
observer.removeListener.call(withArguments: [eventName, listener], thisObject: observer.emitter, asConstructor: false)
|
|
149
|
+
observer.removeListener.call(withArguments: [eventName, listener], thisObject: observer.emitter, asConstructor: false)
|
|
150
|
+
|
|
151
|
+
expect(calls) == 1
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
it("calls stopObserving on removeAllListeners") {
|
|
155
|
+
var calls: Int = 0
|
|
156
|
+
let eventName = "testEvent"
|
|
157
|
+
let listener = runtime.createSyncFunction("listener") { _, _ in }
|
|
158
|
+
let observer = try setupEventObserver(runtime: runtime, functionName: "stopObserving") { arguments in
|
|
159
|
+
expect(try arguments.first?.asString()) == eventName
|
|
160
|
+
calls = calls + 1
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
observer.addListener.call(withArguments: [eventName, listener], thisObject: observer.emitter, asConstructor: false)
|
|
164
|
+
observer.removeAllListeners.call(withArguments: [eventName], thisObject: observer.emitter, asConstructor: false)
|
|
165
|
+
observer.removeAllListeners.call(withArguments: [eventName], thisObject: observer.emitter, asConstructor: false)
|
|
166
|
+
|
|
167
|
+
expect(calls) == 1
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
it("returns a subscription") {
|
|
171
|
+
let subscription = try runtime.eval([
|
|
172
|
+
"emitter = new expo.EventEmitter()",
|
|
173
|
+
"subscription = emitter.addListener('test', () => {})"
|
|
174
|
+
])
|
|
175
|
+
|
|
176
|
+
expect(try subscription.asObject().getPropertyNames()).to(contain("remove"))
|
|
177
|
+
expect(try subscription.asObject().getProperty("remove").kind) == .function
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
it("removes a listener from subscription") {
|
|
181
|
+
let wasCalled = try runtime.eval([
|
|
182
|
+
"wasCalled = false",
|
|
183
|
+
"emitter = new expo.EventEmitter()",
|
|
184
|
+
"subscription = emitter.addListener('test', () => { wasCalled = true })",
|
|
185
|
+
"subscription.remove()",
|
|
186
|
+
"emitter.emit('test')",
|
|
187
|
+
"wasCalled"
|
|
188
|
+
])
|
|
189
|
+
|
|
190
|
+
expect(try wasCalled.asBool()) == false
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
it("removes only related listener") {
|
|
194
|
+
let counter = try runtime.eval([
|
|
195
|
+
"counter = 0",
|
|
196
|
+
"emitter = new expo.EventEmitter()",
|
|
197
|
+
"subscription1 = emitter.addListener('test', () => { counter |= 1 })",
|
|
198
|
+
"subscription2 = emitter.addListener('test', () => { counter |= 2 })",
|
|
199
|
+
"subscription1.remove()",
|
|
200
|
+
"emitter.emit('test')",
|
|
201
|
+
"counter"
|
|
202
|
+
])
|
|
203
|
+
|
|
204
|
+
expect(try counter.asInt()) == 2
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
it("provides backwards compatibility for the legacy wrapper") {
|
|
208
|
+
let emittersAreEqual = try runtime.eval([
|
|
209
|
+
"emitterA = new expo.EventEmitter()",
|
|
210
|
+
"emitterB = new expo.EventEmitter(emitterA)",
|
|
211
|
+
"emitterA === emitterB"
|
|
212
|
+
])
|
|
213
|
+
expect(try emittersAreEqual.asBool()) == true
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
it("calls all listeners even if removed by a listener") {
|
|
217
|
+
// The third listener should be called even though it was already removed by the second listener.
|
|
218
|
+
let result = try runtime.eval([
|
|
219
|
+
"emitter = new expo.EventEmitter()",
|
|
220
|
+
"result = 0",
|
|
221
|
+
"listener = () => emitter.removeAllListeners('test')",
|
|
222
|
+
"emitter.addListener('test', () => result |= 1)",
|
|
223
|
+
"emitter.addListener('test', listener)",
|
|
224
|
+
"emitter.addListener('test', () => result |= 2)",
|
|
225
|
+
"emitter.emit('test')",
|
|
226
|
+
"result"
|
|
227
|
+
])
|
|
228
|
+
expect(try result.asInt()) == 3
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
it("calls only existing listeners even if a listener adds more") {
|
|
232
|
+
// The listener added in the second listener shouldn't be called.
|
|
233
|
+
let result = try runtime.eval([
|
|
234
|
+
"emitter = new expo.EventEmitter()",
|
|
235
|
+
"result = 0",
|
|
236
|
+
"emitter.addListener('test', () => result |= 1)",
|
|
237
|
+
"emitter.addListener('test', () => emitter.addListener('test', () => result |= 2))",
|
|
238
|
+
"emitter.addListener('test', () => result |= 4)",
|
|
239
|
+
"emitter.emit('test')",
|
|
240
|
+
"result"
|
|
241
|
+
])
|
|
242
|
+
expect(try result.asInt()) == 5
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
private typealias EventObserver = (
|
|
249
|
+
emitter: JavaScriptObject,
|
|
250
|
+
addListener: RawJavaScriptFunction,
|
|
251
|
+
removeListener: RawJavaScriptFunction,
|
|
252
|
+
removeAllListeners: RawJavaScriptFunction
|
|
253
|
+
)
|
|
254
|
+
|
|
255
|
+
private func setupEventObserver(
|
|
256
|
+
runtime: ExpoRuntime,
|
|
257
|
+
functionName: String,
|
|
258
|
+
callback: @escaping (_ arguments: [JavaScriptValue]) throws -> Void
|
|
259
|
+
) throws -> EventObserver {
|
|
260
|
+
let emitter = try! runtime.eval("new expo.EventEmitter()").asObject()
|
|
261
|
+
let observingFunction = runtime.createSyncFunction(functionName) { [callback] this, arguments in
|
|
262
|
+
try callback(arguments)
|
|
263
|
+
return Optional<Any>.none as Any
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
emitter.setProperty(functionName, value: observingFunction)
|
|
267
|
+
|
|
268
|
+
return (
|
|
269
|
+
emitter,
|
|
270
|
+
addListener: try emitter.getProperty("addListener").asFunction(),
|
|
271
|
+
removeListener: try emitter.getProperty("removeListener").asFunction(),
|
|
272
|
+
removeAllListeners: try emitter.getProperty("removeAllListeners").asFunction()
|
|
273
|
+
)
|
|
274
|
+
}
|
|
@@ -6,74 +6,126 @@ import ExpoModulesTestCore
|
|
|
6
6
|
|
|
7
7
|
final class ExceptionsSpec: ExpoSpec {
|
|
8
8
|
override class func spec() {
|
|
9
|
-
|
|
10
|
-
let error = TestException()
|
|
11
|
-
expect(error.name) == "TestException"
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
it("has code") {
|
|
15
|
-
let error = TestException()
|
|
16
|
-
expect(error.code) == "ERR_TEST"
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
it("has reason") {
|
|
20
|
-
let error = TestException()
|
|
21
|
-
expect(error.reason) == "This is the test exception"
|
|
22
|
-
}
|
|
9
|
+
let appContext = AppContext.create()
|
|
23
10
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
} catch {
|
|
29
|
-
throw TestException().causedBy(error)
|
|
30
|
-
}
|
|
11
|
+
context("native") {
|
|
12
|
+
it("has name") {
|
|
13
|
+
let error = TestException()
|
|
14
|
+
expect(error.name) == "TestException"
|
|
31
15
|
}
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
16
|
+
|
|
17
|
+
it("has code") {
|
|
18
|
+
let error = TestException()
|
|
19
|
+
expect(error.code) == "ERR_TEST"
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
it("has reason") {
|
|
23
|
+
let error = TestException()
|
|
24
|
+
expect(error.reason) == "This is the test exception"
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
it("can be chained once") {
|
|
28
|
+
func throwable() throws {
|
|
40
29
|
do {
|
|
41
30
|
throw TestExceptionCause()
|
|
42
31
|
} catch {
|
|
43
|
-
throw
|
|
32
|
+
throw TestException().causedBy(error)
|
|
44
33
|
}
|
|
45
|
-
} catch {
|
|
46
|
-
throw TestException().causedBy(error)
|
|
47
34
|
}
|
|
35
|
+
expect { try throwable() }.to(throwError { error in
|
|
36
|
+
testChainedExceptionTypes(error: error, types: [TestException.self, TestExceptionCause.self])
|
|
37
|
+
})
|
|
48
38
|
}
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
39
|
+
|
|
40
|
+
it("can be chained twice") {
|
|
41
|
+
func throwable() throws {
|
|
42
|
+
do {
|
|
43
|
+
do {
|
|
44
|
+
throw TestExceptionCause()
|
|
45
|
+
} catch {
|
|
46
|
+
throw TestExceptionCause().causedBy(error)
|
|
47
|
+
}
|
|
48
|
+
} catch {
|
|
49
|
+
throw TestException().causedBy(error)
|
|
50
|
+
}
|
|
60
51
|
}
|
|
52
|
+
expect { try throwable() }.to(throwError { error in
|
|
53
|
+
testChainedExceptionTypes(error: error, types: [TestException.self, TestExceptionCause.self, TestExceptionCause.self])
|
|
54
|
+
})
|
|
61
55
|
}
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
56
|
+
|
|
57
|
+
it("includes cause description") {
|
|
58
|
+
func throwable() throws {
|
|
59
|
+
do {
|
|
60
|
+
throw TestExceptionCause()
|
|
61
|
+
} catch {
|
|
62
|
+
throw TestException().causedBy(error)
|
|
63
|
+
}
|
|
67
64
|
}
|
|
68
|
-
|
|
65
|
+
expect { try throwable() }.to(throwError { error in
|
|
66
|
+
if let error = error as? TestException, let cause = error.cause as? TestExceptionCause {
|
|
67
|
+
expect(error.description).to(contain(cause.description))
|
|
68
|
+
} else {
|
|
69
|
+
fail("Error and its cause are not of expected types.")
|
|
70
|
+
}
|
|
71
|
+
})
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
it("has root cause") {
|
|
75
|
+
let a = TestException()
|
|
76
|
+
let b = TestException().causedBy(a)
|
|
77
|
+
let c = TestException().causedBy(b)
|
|
78
|
+
|
|
79
|
+
expect(c.rootCause as! TestException) === a
|
|
80
|
+
}
|
|
69
81
|
}
|
|
70
82
|
|
|
71
|
-
|
|
72
|
-
let
|
|
73
|
-
|
|
74
|
-
|
|
83
|
+
context("JavaScript") {
|
|
84
|
+
let runtime = try! appContext.runtime
|
|
85
|
+
|
|
86
|
+
beforeSuite {
|
|
87
|
+
appContext.moduleRegistry.register(holder: mockModuleHolder(appContext) {
|
|
88
|
+
Name("TestModule")
|
|
89
|
+
|
|
90
|
+
Function("codedException") {
|
|
91
|
+
throw TestCodedException()
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
AsyncFunction("codedExceptionThrowAsync") { () in
|
|
95
|
+
throw TestCodedException()
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
AsyncFunction("codedExceptionRejectAsync") { (promise: Promise) in
|
|
99
|
+
promise.reject(TestCodedException())
|
|
100
|
+
}
|
|
75
101
|
|
|
76
|
-
|
|
102
|
+
AsyncFunction("codedExceptionConcurrentAsync") { () async throws in
|
|
103
|
+
throw TestCodedException()
|
|
104
|
+
}
|
|
105
|
+
})
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
it("sync function throw") {
|
|
109
|
+
let error = try runtime.eval("try { expo.modules.TestModule.codedException() } catch (error) { error }").asObject()
|
|
110
|
+
expect(error.getProperty("message").getString()).to(contain("FunctionCallException: Calling the 'codedException' function has failed"))
|
|
111
|
+
expect(error.getProperty("code").getString()).to(equal("E_TEST_CODE"))
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
// TODO: Find a way to evaluate async code
|
|
115
|
+
// it("async function throw") {
|
|
116
|
+
// let error = try runtime.eval("try { await expo.modules.TestModule.codedExceptionThrowAsync() } catch (error) { error }").asObject()
|
|
117
|
+
// expect(error.getProperty("code").getString()).to(equal("E_TEST_CODE"))
|
|
118
|
+
// }
|
|
119
|
+
|
|
120
|
+
// it("async function reject") {
|
|
121
|
+
// let error = try runtime.eval("try { await expo.modules.TestModule.codedExceptionRejectAsync() } catch (error) { error }").asObject()
|
|
122
|
+
// expect(error.getProperty("code").getString()).to(equal("E_TEST_CODE"))
|
|
123
|
+
// }
|
|
124
|
+
|
|
125
|
+
// it("async/concurrent function throw") {
|
|
126
|
+
// let error = try runtime.eval("try { await expo.modules.TestModule.codedExceptionConcurrentAsync() } catch (error) { error }").asObject()
|
|
127
|
+
// expect(error.getProperty("code").getString()).to(equal("E_TEST_CODE"))
|
|
128
|
+
// }
|
|
77
129
|
}
|
|
78
130
|
}
|
|
79
131
|
}
|
|
@@ -90,6 +142,14 @@ class TestExceptionCause: Exception {
|
|
|
90
142
|
}
|
|
91
143
|
}
|
|
92
144
|
|
|
145
|
+
class TestCodedException: Exception {
|
|
146
|
+
init() {
|
|
147
|
+
super.init(name: "TestException",
|
|
148
|
+
description: "This is a test Exception with a code",
|
|
149
|
+
code: "E_TEST_CODE")
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
|
|
93
153
|
/**
|
|
94
154
|
Tests whether the exception chain matches given types and their order.
|
|
95
155
|
*/
|
|
@@ -33,11 +33,12 @@ class ExpoModulesSpec: ExpoSpec {
|
|
|
33
33
|
|
|
34
34
|
describe("host object") {
|
|
35
35
|
it("is defined") {
|
|
36
|
-
expect(try! runtime.eval("'
|
|
36
|
+
expect(try! runtime.eval("'expo' in this").asBool()).to(beTrue())
|
|
37
|
+
expect(try! runtime.eval("'modules' in expo").asBool()).to(beTrue())
|
|
37
38
|
}
|
|
38
39
|
|
|
39
40
|
it("has native module defined") {
|
|
40
|
-
expect(try! runtime.eval("'\(testModuleName)' in
|
|
41
|
+
expect(try! runtime.eval("'\(testModuleName)' in expo.modules").asBool()).to(beTrue())
|
|
41
42
|
}
|
|
42
43
|
|
|
43
44
|
it("can access native module") {
|
|
@@ -49,7 +50,7 @@ class ExpoModulesSpec: ExpoSpec {
|
|
|
49
50
|
|
|
50
51
|
it("has keys for registered modules") {
|
|
51
52
|
let registeredModuleNames = appContext.moduleRegistry.getModuleNames()
|
|
52
|
-
let keys = try runtime.eval("Object.keys(
|
|
53
|
+
let keys = try runtime.eval("Object.keys(expo.modules)").asArray().compactMap {
|
|
53
54
|
return try! $0?.asString()
|
|
54
55
|
}
|
|
55
56
|
expect(keys).to(contain(registeredModuleNames))
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
// Copyright 2022-present 650 Industries. All rights reserved.
|
|
2
|
+
|
|
3
|
+
import ExpoModulesTestCore
|
|
4
|
+
|
|
5
|
+
@testable import ExpoModulesCore
|
|
6
|
+
|
|
7
|
+
final class LoggerSpec: ExpoSpec {
|
|
8
|
+
class TestLogHandler : LogHandler {
|
|
9
|
+
struct TestLogHandlerLogEntry : Equatable {
|
|
10
|
+
let type: LogType
|
|
11
|
+
let message: String
|
|
12
|
+
|
|
13
|
+
static func == (lhs: TestLogHandlerLogEntry, rhs: TestLogHandlerLogEntry) -> Bool {
|
|
14
|
+
// slightly-fuzzy matching for testing only due to prepending emoji to message
|
|
15
|
+
return lhs.type == rhs.type && (lhs.message.contains(rhs.message) || rhs.message.contains(lhs.message))
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
var logEntries: [TestLogHandlerLogEntry] = []
|
|
20
|
+
|
|
21
|
+
func clear() {
|
|
22
|
+
logEntries = []
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
func log(type: ExpoModulesCore.LogType, _ message: String) {
|
|
26
|
+
logEntries.append(TestLogHandlerLogEntry(type: type, message: message))
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
override class func spec() {
|
|
31
|
+
it("should log various levels") {
|
|
32
|
+
let loggerHandler = TestLogHandler()
|
|
33
|
+
let logger = Logger(logHandlers: [loggerHandler])
|
|
34
|
+
|
|
35
|
+
logger.trace("hello")
|
|
36
|
+
expect(loggerHandler.logEntries.first) == TestLogHandler.TestLogHandlerLogEntry(type: .trace, message: "hello")
|
|
37
|
+
loggerHandler.clear()
|
|
38
|
+
|
|
39
|
+
logger.debug("hello")
|
|
40
|
+
expect(loggerHandler.logEntries.first) == TestLogHandler.TestLogHandlerLogEntry(type: .debug, message: "hello")
|
|
41
|
+
loggerHandler.clear()
|
|
42
|
+
|
|
43
|
+
logger.info("hello")
|
|
44
|
+
expect(loggerHandler.logEntries.first) == TestLogHandler.TestLogHandlerLogEntry(type: .info, message: "hello")
|
|
45
|
+
loggerHandler.clear()
|
|
46
|
+
|
|
47
|
+
logger.warn("hello")
|
|
48
|
+
expect(loggerHandler.logEntries.first) == TestLogHandler.TestLogHandlerLogEntry(type: .warn, message: "hello")
|
|
49
|
+
loggerHandler.clear()
|
|
50
|
+
|
|
51
|
+
logger.error("hello")
|
|
52
|
+
expect(loggerHandler.logEntries.first) == TestLogHandler.TestLogHandlerLogEntry(type: .error, message: "hello")
|
|
53
|
+
loggerHandler.clear()
|
|
54
|
+
|
|
55
|
+
logger.fatal("hello")
|
|
56
|
+
expect(loggerHandler.logEntries.first) == TestLogHandler.TestLogHandlerLogEntry(type: .fatal, message: "hello")
|
|
57
|
+
loggerHandler.clear()
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
it("should run a timer") {
|
|
61
|
+
let loggerHandler = TestLogHandler()
|
|
62
|
+
let logger = Logger(logHandlers: [loggerHandler])
|
|
63
|
+
|
|
64
|
+
let timer = logger.startTimer { duration in
|
|
65
|
+
return "\(duration)"
|
|
66
|
+
}
|
|
67
|
+
RunLoop.current.run(until: Date().addingTimeInterval(0.3))
|
|
68
|
+
timer.stop()
|
|
69
|
+
|
|
70
|
+
let entry = loggerHandler.logEntries.first!
|
|
71
|
+
expect(entry.type) == .timer
|
|
72
|
+
|
|
73
|
+
// remove emoji prefix
|
|
74
|
+
let index = entry.message.index(entry.message.startIndex, offsetBy: 2)
|
|
75
|
+
expect(Double(entry.message[index...])) > 300
|
|
76
|
+
|
|
77
|
+
loggerHandler.clear()
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
}
|