peachsim 0.1.1655 → 0.1.1659
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/cli/app-config.ts +4 -0
- package/cli/app-stubs.ts +43 -6
- package/cli/commands/inspect/shared.ts +5 -2
- package/cli/commands/inspect/url.ts +2 -1
- package/cli/commands/screenshot.ts +5 -5
- package/cli/commands/state.ts +9 -6
- package/cli/outbound-endpoints.ts +9 -1
- package/cli/output-redaction.ts +49 -0
- package/dist-lib/agent-daemon-client.cjs +1 -1
- package/dist-lib/agent-events.cjs +1 -1
- package/dist-lib/attached-projects.cjs +1 -1
- package/dist-lib/auth/shared-session.cjs +1 -1
- package/dist-lib/backend-origin.cjs +1 -1
- package/dist-lib/beta.cjs +1 -1
- package/dist-lib/beta.mjs +1 -1
- package/dist-lib/bridge-constants.cjs +1 -1
- package/dist-lib/bridge-contract-input.cjs +1 -1
- package/dist-lib/bridge-contract-input.mjs +1 -1
- package/dist-lib/bridge-contract.cjs +1 -1
- package/dist-lib/bridge-contract.mjs +1 -1
- package/dist-lib/bundle-channel.cjs +11251 -1123
- package/dist-lib/capture-contract.cjs +1 -1
- package/dist-lib/capture-contract.mjs +1 -1
- package/dist-lib/cloud-contract.cjs +1 -1
- package/dist-lib/cloud-contract.mjs +1 -1
- package/dist-lib/cloud-test-args.cjs +1 -1
- package/dist-lib/cloud-test-args.mjs +1 -1
- package/dist-lib/cloud.cjs +1 -1
- package/dist-lib/cloud.mjs +1 -1
- package/dist-lib/config.cjs +29 -5
- package/dist-lib/config.mjs +29 -5
- package/dist-lib/detox/index.cjs +19 -5
- package/dist-lib/dev-bundle-resolution.cjs +1 -1
- package/dist-lib/expo-swift-bundle.cjs +8960 -134
- package/dist-lib/expo-swift-metadata.cjs +1 -1
- package/dist-lib/expo-swift-metadata.mjs +1 -1
- package/dist-lib/home-paths.cjs +1 -1
- package/dist-lib/host/bridge-host.cjs +9769 -731
- package/dist-lib/host/fetch-proxy-handler.cjs +260 -197
- package/dist-lib/host/fetch-proxy-overrides.cjs +1 -1
- package/dist-lib/host/fetch-proxy-overrides.mjs +1 -1
- package/dist-lib/host/replacement-module-handler.cjs +1 -1
- package/dist-lib/host/websocket-proxy.cjs +1 -1
- package/dist-lib/index.cjs +653 -338
- package/dist-lib/jump-to-source-babel.cjs +1 -1
- package/dist-lib/jump-to-source-native.cjs +1 -1
- package/dist-lib/kotlin-host.cjs +443 -312
- package/dist-lib/menu.cjs +1 -1
- package/dist-lib/menu.mjs +1 -1
- package/dist-lib/metro-fingerprint-registry.cjs +1 -1
- package/dist-lib/metro-fingerprint-registry.mjs +1 -1
- package/dist-lib/metro-production-bundle.cjs +1 -1
- package/dist-lib/metro-production-bundle.mjs +1 -1
- package/dist-lib/metro.cjs +548 -163
- package/dist-lib/native-app-identity-project.cjs +179 -33
- package/dist-lib/native-app-identity-project.mjs +179 -33
- package/dist-lib/native-app-identity.cjs +1 -1
- package/dist-lib/native-app-identity.mjs +1 -1
- package/dist-lib/native-firebase-metadata.cjs +1 -1
- package/dist-lib/native-firebase-metadata.mjs +1 -1
- package/dist-lib/plist.cjs +1 -1
- package/dist-lib/plist.mjs +1 -1
- package/dist-lib/profiles.cjs +1 -1
- package/dist-lib/public-brand.cjs +1 -1
- package/dist-lib/public-origins-lib-esm.json +23 -23
- package/dist-lib/public-origins-lib.json +96 -63
- package/dist-lib/react-native-host-modules.cjs +1 -1
- package/dist-lib/react-native-host-modules.mjs +1 -1
- package/dist-lib/scripts/dev-server-scanner.cjs +2 -2
- package/dist-lib/sdk.cjs +1 -1
- package/dist-lib/sdk.mjs +1 -1
- package/dist-lib/skills.cjs +10651 -1418
- package/dist-lib/swift-compile.cjs +8802 -138
- package/dist-lib/swift-compile.mjs +8802 -138
- package/dist-lib/swift-package.cjs +1 -1
- package/dist-lib/swift-package.mjs +1 -1
- package/dist-lib/swift-submit.cjs +1 -1
- package/dist-lib/swift-submit.mjs +1 -1
- package/dist-lib/swift-toolchain.cjs +1 -1
- package/dist-lib/swift.cjs +1 -1
- package/dist-lib/vite-swift.cjs +8960 -134
- package/dist-lib/vite.cjs +149 -163
- package/dist-lib/worklet-executable.cjs +1 -1
- package/dist-lib/worklet-executable.mjs +1 -1
- package/dist-types/packages/peach-compat/src/stubs/native-seams/react-native-gesture-handler.d.ts +1 -0
- package/dist-types/packages/peach-engine/src/engine/app-font-registry.d.ts +14 -0
- package/dist-types/packages/peach-engine/src/engine/image-loader.d.ts +8 -0
- package/dist-types/packages/peach-engine/src/engine/node.d.ts +3 -0
- package/dist-types/packages/peach-engine/src/render-worker/compositor-protocol.d.ts +21 -0
- package/dist-types/packages/peach-engine/src/render-worker/gesture-seam-protocol.d.ts +2 -1
- package/dist-types/packages/peach-engine/src/render-worker/test-bridge-protocol.d.ts +1 -1
- package/dist-types/packages/peach-engine/src/rolldown-bundle-inventory.d.ts +1 -0
- package/dist-types/packages/peach-globals/src/index.d.ts +25 -0
- package/kotlin/README.md +38 -23
- package/kotlin/sdk.tar.gz +0 -0
- package/package.json +2 -12
- package/runtime-companion.json +1 -1
- package/src/bundleGlobalFooter.ts +0 -2
- package/src/config.ts +54 -2
- package/src/configured-bundle-producer.ts +7 -1
- package/src/host/fetch-proxy-handler.ts +14 -50
- package/src/host/rolldown-bundle-forward.ts +71 -0
- package/src/installed-package-versions.ts +54 -2
- package/src/kotlin-host.ts +138 -285
- package/src/kotlin-module.ts +4 -7
- package/src/kotlin-sdk.ts +81 -0
- package/src/kotlin-toolchain.ts +152 -0
- package/src/kotlin-view-models.ts +1 -1
- package/src/kotlinSdkContract.ts +113 -0
- package/src/nitro-adapter.lock.json +3 -3
- package/src/nitro-bundle.ts +18 -4
- package/src/nitro-compile.ts +5 -1
- package/src/nitro-source.ts +112 -28
- package/src/nitroContract.ts +16 -4
- package/src/swift-compile.ts +12 -3
- package/src/swift-host.ts +2 -1
- package/src/swift-objc-compile.ts +117 -4
- package/src/swift-objc-sdk.ts +8792 -135
- package/src/swift-objc-standin.ts +1 -0
- package/src/vite-plugin-one.ts +73 -134
- package/src/worker-system-chunks.ts +14 -4
- package/src/xcode-project.ts +261 -34
- package/kotlin/AndroidViewSources/android/content/Context.kt +0 -22
- package/kotlin/AndroidViewSources/android/content/res/Configuration.kt +0 -25
- package/kotlin/AndroidViewSources/android/content/res/Resources.kt +0 -72
- package/kotlin/AndroidViewSources/android/graphics/Canvas.kt +0 -22
- package/kotlin/AndroidViewSources/android/graphics/Color.kt +0 -13
- package/kotlin/AndroidViewSources/android/graphics/Paint.kt +0 -18
- package/kotlin/AndroidViewSources/android/util/DisplayMetrics.kt +0 -12
- package/kotlin/AndroidViewSources/android/view/View.kt +0 -211
- package/kotlin/AndroidViewSources/android/widget/FrameLayout.kt +0 -61
- package/kotlin/AndroidViewSources/android/widget/LinearLayout.kt +0 -49
- package/kotlin/AndroidViewSources/dev/peach/app/JavaFormat.kt +0 -272
- package/kotlin/AppSources/android/app/Activity.kt +0 -174
- package/kotlin/AppSources/android/app/Application.kt +0 -11
- package/kotlin/AppSources/android/app/UiModeManager.kt +0 -9
- package/kotlin/AppSources/android/content/Intent.kt +0 -16
- package/kotlin/AppSources/android/os/Bundle.kt +0 -11
- package/kotlin/AppSources/android/util/SuperNotCalledException.kt +0 -3
- package/kotlin/AppSources/android/view/Window.kt +0 -182
- package/kotlin/AppSources/android/view/WindowInsets.kt +0 -9
- package/kotlin/AppSources/android/view/WindowInsetsController.kt +0 -17
- package/kotlin/AppSources/android/view/WindowManager.kt +0 -16
- package/kotlin/AppSources/android/window/BackEvent.kt +0 -24
- package/kotlin/AppSources/android/window/OnBackAnimationCallback.kt +0 -7
- package/kotlin/AppSources/android/window/OnBackInvokedDispatcher.kt +0 -84
- package/kotlin/AppSources/androidx/activity/ActivityFlags.kt +0 -9
- package/kotlin/AppSources/androidx/activity/ActivityViewModelLazy.kt +0 -21
- package/kotlin/AppSources/androidx/activity/BackEventCompat.kt +0 -43
- package/kotlin/AppSources/androidx/activity/ComponentActivity.kt +0 -122
- package/kotlin/AppSources/androidx/activity/EdgeToEdge.kt +0 -75
- package/kotlin/AppSources/androidx/activity/ExperimentalActivityApi.kt +0 -6
- package/kotlin/AppSources/androidx/activity/OnBackPressedCallback.kt +0 -69
- package/kotlin/AppSources/androidx/activity/OnBackPressedDispatcher.kt +0 -144
- package/kotlin/AppSources/androidx/activity/OnBackPressedDispatcherOwner.kt +0 -7
- package/kotlin/AppSources/androidx/activity/compose/BackHandler.kt +0 -86
- package/kotlin/AppSources/androidx/activity/compose/ComponentActivity.kt +0 -29
- package/kotlin/AppSources/androidx/activity/compose/internal/BackHandlerCompat.kt +0 -38
- package/kotlin/AppSources/androidx/activity/compose/internal/BackHandlerDispatcherCompat.kt +0 -27
- package/kotlin/AppSources/androidx/compose/foundation/layout/WindowInsets.kt +0 -15
- package/kotlin/AppSources/androidx/compose/ui/platform/AndroidCompositionLocals.kt +0 -27
- package/kotlin/AppSources/androidx/compose/ui/platform/ComposeView.kt +0 -68
- package/kotlin/AppSources/androidx/compose/ui/res/ColorResources.kt +0 -16
- package/kotlin/AppSources/androidx/compose/ui/res/PainterResources.kt +0 -70
- package/kotlin/AppSources/androidx/compose/ui/res/StringResources.kt +0 -38
- package/kotlin/AppSources/androidx/core/view/WindowCompat.kt +0 -32
- package/kotlin/AppSources/androidx/lifecycle/AndroidViewModel.kt +0 -10
- package/kotlin/AppSources/dev/peach/app/PeachApp.kt +0 -388
- package/kotlin/AppSources/dev/peach/app/PeachDrawable.kt +0 -102
- package/kotlin/AppSources/dev/peach/app/PeachWindowHost.kt +0 -14
- package/kotlin/CompilerSources/META-INF/services/org.jetbrains.kotlin.compiler.plugin.CompilerPluginRegistrar +0 -1
- package/kotlin/CompilerSources/PeachJniIncoming.kt +0 -243
- package/kotlin/CompilerSources/PeachJniPlugin.kt +0 -116
- package/kotlin/ComposeSources/PeachComposeHost.kt +0 -724
- package/kotlin/ComposeSources/PeachMagnifier.kt +0 -185
- package/kotlin/ComposeSources/PeachSemantics.kt +0 -127
- package/kotlin/ExpoComposeSources/PeachAndroidView.kt +0 -103
- package/kotlin/ExpoComposeSources/PeachExpoViewMount.kt +0 -24
- package/kotlin/ExpoComposeSources/dev/peach/expo/PeachExpoCompose.kt +0 -28
- package/kotlin/ExpoComposeSources/expo/modules/kotlin/views/ExpoComposeView.kt +0 -70
- package/kotlin/ExpoSources/dev/peach/expo/PeachExpoRuntime.kt +0 -516
- package/kotlin/ExpoSources/dev/peach/expo/PeachExpoTypes.kt +0 -173
- package/kotlin/ExpoSources/expo/modules/kotlin/AppContext.kt +0 -20
- package/kotlin/ExpoSources/expo/modules/kotlin/Promise.kt +0 -19
- package/kotlin/ExpoSources/expo/modules/kotlin/classcomponent/ClassComponentBuilder.kt +0 -198
- package/kotlin/ExpoSources/expo/modules/kotlin/exception/CodedException.kt +0 -126
- package/kotlin/ExpoSources/expo/modules/kotlin/functions/Functions.kt +0 -132
- package/kotlin/ExpoSources/expo/modules/kotlin/jni/JavaScriptTypedArray.kt +0 -81
- package/kotlin/ExpoSources/expo/modules/kotlin/modules/Module.kt +0 -98
- package/kotlin/ExpoSources/expo/modules/kotlin/objects/ObjectDefinitionBuilder.kt +0 -236
- package/kotlin/ExpoSources/expo/modules/kotlin/records/Record.kt +0 -12
- package/kotlin/ExpoSources/expo/modules/kotlin/runtime/Runtime.kt +0 -9
- package/kotlin/ExpoSources/expo/modules/kotlin/sharedobjects/SharedObject.kt +0 -50
- package/kotlin/ExpoSources/expo/modules/kotlin/sharedobjects/SharedObjectRegistry.kt +0 -57
- package/kotlin/ExpoSources/expo/modules/kotlin/sharedobjects/SharedRef.kt +0 -19
- package/kotlin/ExpoSources/expo/modules/kotlin/typedarray/ConcreteTypedArrays.kt +0 -158
- package/kotlin/ExpoSources/expo/modules/kotlin/typedarray/GenericTypedArray.kt +0 -8
- package/kotlin/ExpoSources/expo/modules/kotlin/typedarray/TypedArray.kt +0 -29
- package/kotlin/ExpoSources/expo/modules/kotlin/typedarray/TypedArrayIterator.kt +0 -9
- package/kotlin/ExpoSources/expo/modules/kotlin/types/AnyType.kt +0 -155
- package/kotlin/ExpoSources/expo/modules/kotlin/types/Either.kt +0 -91
- package/kotlin/ExpoSources/expo/modules/kotlin/types/Enumerable.kt +0 -6
- package/kotlin/ExpoSources/expo/modules/kotlin/viewevent/ViewEvent.kt +0 -68
- package/kotlin/ExpoSources/expo/modules/kotlin/views/ExpoView.kt +0 -20
- package/kotlin/ExpoSources/expo/modules/kotlin/views/ViewDefinitionBuilder.kt +0 -72
- package/kotlin/ExpoSources/expo/modules/kotlin/views/ViewProps.kt +0 -36
- package/kotlin/JniPlatformSources/androidx/annotation/CallSuper.kt +0 -5
- package/kotlin/JniPlatformSources/com/facebook/proguard/annotations/DoNotStrip.kt +0 -5
- package/kotlin/JniPlatformSources/dalvik/annotation/optimization/FastNative.kt +0 -5
- package/kotlin/JniPlatformSources/kotlin/Synchronized.kt +0 -6
- package/kotlin/JniPlatformSources/kotlin/jvm/JvmField.kt +0 -5
- package/kotlin/JniPlatformSources/kotlin/jvm/JvmStatic.kt +0 -5
- package/kotlin/JniSources/com/facebook/jni/HybridData.kt +0 -66
- package/kotlin/JniSources/dev/peach/jni/IncomingBindings.kt +0 -157
- package/kotlin/JniSources/dev/peach/jni/NativeBindings.kt +0 -77
- package/kotlin/JniTransportSources/dev/peach/jni/integration/JniTransport.kt +0 -89
- package/kotlin/Sources/android/os/Build.kt +0 -17
- package/kotlin/Sources/android/os/Handler.kt +0 -35
- package/kotlin/Sources/android/os/Looper.kt +0 -17
- package/kotlin/Sources/android/os/MessageQueue.kt +0 -56
- package/kotlin/Sources/android/os/SystemClock.kt +0 -14
- package/kotlin/Sources/android/util/Log.kt +0 -64
- package/kotlin/Sources/androidx/annotation/DrawableRes.kt +0 -14
- package/kotlin/Sources/androidx/annotation/Keep.kt +0 -4
- package/kotlin/Sources/dev/onejs/one/OneNativeSourceDispatch.kt +0 -7
- package/kotlin/Sources/dev/onejs/one/OneNativeSourceViewDispatch.kt +0 -13
- package/kotlin/Sources/dev/onejs/one/source/OneModule.kt +0 -4
- package/kotlin/Sources/java/lang/Runnable.kt +0 -6
- package/kotlin/Sources/java/security/MessageDigest.kt +0 -114
- package/kotlin/Sources/java/util/IllegalFormatCodePointException.kt +0 -10
- package/kotlin/Sources/java/util/IllegalFormatException.kt +0 -5
- package/kotlin/Sources/kotlin/text/StringFormat.kt +0 -9
- package/kotlin/Sources/org/json/JSON.kt +0 -307
- package/kotlin/tools/abi-classes.main.kts +0 -41
- package/kotlin/tools/expo-types.main.kts +0 -127
|
@@ -1,72 +0,0 @@
|
|
|
1
|
-
@file:Suppress("FunctionName", "UNCHECKED_CAST")
|
|
2
|
-
|
|
3
|
-
package expo.modules.kotlin.views
|
|
4
|
-
|
|
5
|
-
import android.content.Context
|
|
6
|
-
import android.view.View
|
|
7
|
-
import expo.modules.kotlin.AppContext
|
|
8
|
-
import expo.modules.kotlin.functions.AsyncFunctionComponent
|
|
9
|
-
import expo.modules.kotlin.objects.ObjectDefinitionBuilder
|
|
10
|
-
import expo.modules.kotlin.types.toAnyType
|
|
11
|
-
import kotlin.reflect.KClass
|
|
12
|
-
import kotlin.reflect.KType
|
|
13
|
-
|
|
14
|
-
class ViewManagerDefinition(
|
|
15
|
-
val name: String,
|
|
16
|
-
internal val viewClass: KClass<*>,
|
|
17
|
-
internal val createView: (Context, AppContext) -> View,
|
|
18
|
-
internal val props: Map<String, AnyViewProp>,
|
|
19
|
-
internal val callbacks: List<String>,
|
|
20
|
-
internal val asyncFunctions: Map<String, AsyncFunctionComponent>,
|
|
21
|
-
internal val onViewDestroys: ((View) -> Unit)?,
|
|
22
|
-
internal val onViewDidUpdateProps: ((View) -> Unit)?,
|
|
23
|
-
)
|
|
24
|
-
|
|
25
|
-
// the view's async functions take the view as their first argument when they
|
|
26
|
-
// name its type, as upstream's do; their arities come from ObjectDefinitionBuilder
|
|
27
|
-
class ViewDefinitionBuilder<T : View>(
|
|
28
|
-
@PublishedApi internal val viewClass: KClass<T>,
|
|
29
|
-
@PublishedApi internal val viewType: KType,
|
|
30
|
-
) : ObjectDefinitionBuilder() {
|
|
31
|
-
@PublishedApi internal var name: String = requireNotNull(viewClass.simpleName)
|
|
32
|
-
@PublishedApi internal val props = mutableMapOf<String, AnyViewProp>()
|
|
33
|
-
@PublishedApi internal var onViewDestroys: ((View) -> Unit)? = null
|
|
34
|
-
@PublishedApi internal var onViewDidUpdateProps: ((View) -> Unit)? = null
|
|
35
|
-
|
|
36
|
-
fun build(createView: (Context, AppContext) -> View): ViewManagerDefinition {
|
|
37
|
-
val functions = asyncFunctions + asyncFunctionBuilders.mapValues { (_, builder) -> builder.build() }
|
|
38
|
-
for (function in functions.values) {
|
|
39
|
-
function.ownerType = viewType
|
|
40
|
-
function.canTakeOwner = true
|
|
41
|
-
}
|
|
42
|
-
return ViewManagerDefinition(name, viewClass, createView, props.toMap(), eventNames, functions, onViewDestroys, onViewDidUpdateProps)
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
fun Name(viewName: String) {
|
|
46
|
-
name = viewName
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
inline fun OnViewDestroys(crossinline body: (view: T) -> Unit) {
|
|
50
|
-
onViewDestroys = { body(it as T) }
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
inline fun OnViewDidUpdateProps(crossinline body: (view: T) -> Unit) {
|
|
54
|
-
onViewDidUpdateProps = { body(it as T) }
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
inline fun <reified PropType> Prop(name: String, noinline body: (view: T, prop: PropType) -> Unit): ConcreteViewProp<T, PropType> =
|
|
58
|
-
ConcreteViewProp(name, toAnyType<PropType>(), body).also { props[name] = it }
|
|
59
|
-
|
|
60
|
-
inline fun <reified ViewType : View, reified PropType> Prop(
|
|
61
|
-
name: String,
|
|
62
|
-
noinline body: (view: ViewType, prop: PropType) -> Unit,
|
|
63
|
-
): ConcreteViewProp<ViewType, PropType> =
|
|
64
|
-
ConcreteViewProp(name, toAnyType<PropType>(), body).also { props[name] = it }
|
|
65
|
-
|
|
66
|
-
inline fun <reified ViewType : View, reified PropType> Prop(
|
|
67
|
-
name: String,
|
|
68
|
-
defaultValue: PropType,
|
|
69
|
-
noinline body: (view: ViewType, prop: PropType) -> Unit,
|
|
70
|
-
): ConcreteViewPropWithDefault<ViewType, PropType> =
|
|
71
|
-
ConcreteViewPropWithDefault(name, toAnyType<PropType>(), body, defaultValue).also { props[name] = it }
|
|
72
|
-
}
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
@file:Suppress("UNCHECKED_CAST")
|
|
2
|
-
|
|
3
|
-
package expo.modules.kotlin.views
|
|
4
|
-
|
|
5
|
-
import android.view.View
|
|
6
|
-
import expo.modules.kotlin.exception.PropSetException
|
|
7
|
-
import expo.modules.kotlin.exception.exceptionDecorator
|
|
8
|
-
import expo.modules.kotlin.types.AnyType
|
|
9
|
-
|
|
10
|
-
abstract class AnyViewProp(val name: String, internal val type: AnyType) {
|
|
11
|
-
abstract fun set(prop: Any?, onView: View)
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
open class ConcreteViewProp<ViewType : View, PropType>(
|
|
15
|
-
name: String,
|
|
16
|
-
propType: AnyType,
|
|
17
|
-
protected val setter: (view: ViewType, prop: PropType) -> Unit,
|
|
18
|
-
) : AnyViewProp(name, propType) {
|
|
19
|
-
override fun set(prop: Any?, onView: View) {
|
|
20
|
-
exceptionDecorator({ PropSetException(name, onView::class, it) }) {
|
|
21
|
-
setter(onView as ViewType, type.convert(prop) as PropType)
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
class ConcreteViewPropWithDefault<ViewType : View, PropType>(
|
|
27
|
-
name: String,
|
|
28
|
-
propType: AnyType,
|
|
29
|
-
setter: (view: ViewType, prop: PropType) -> Unit,
|
|
30
|
-
private val defaultValue: PropType,
|
|
31
|
-
) : ConcreteViewProp<ViewType, PropType>(name, propType, setter) {
|
|
32
|
-
override fun set(prop: Any?, onView: View) {
|
|
33
|
-
if (prop == null) setter(onView as ViewType, defaultValue)
|
|
34
|
-
else super.set(prop, onView)
|
|
35
|
-
}
|
|
36
|
-
}
|
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
package com.facebook.proguard.annotations
|
|
2
|
-
|
|
3
|
-
@Target(AnnotationTarget.CLASS, AnnotationTarget.FUNCTION, AnnotationTarget.CONSTRUCTOR, AnnotationTarget.FIELD, AnnotationTarget.PROPERTY_GETTER, AnnotationTarget.PROPERTY_SETTER)
|
|
4
|
-
@Retention(AnnotationRetention.BINARY)
|
|
5
|
-
annotation class DoNotStrip
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
package kotlin
|
|
2
|
-
|
|
3
|
-
// Kotlin guests execute on one owning JavaScript agent. synchronous native
|
|
4
|
-
// callbacks reenter that agent, matching a reentrant monitor on its thread.
|
|
5
|
-
@Suppress("UNUSED_PARAMETER")
|
|
6
|
-
inline fun <R> synchronized(lock: Any, block: () -> R): R = block()
|
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
package com.facebook.jni
|
|
2
|
-
|
|
3
|
-
import dev.peach.jni.isNativeRuntimeActive
|
|
4
|
-
import dev.peach.jni.registerNativeRetirement
|
|
5
|
-
import kotlin.js.*
|
|
6
|
-
import kotlin.jvm.JvmStatic
|
|
7
|
-
|
|
8
|
-
// fbjni's holder owns the actual BaseHybridClass address, never a runtime slot id.
|
|
9
|
-
open class HybridData {
|
|
10
|
-
private val mDestructor = Destructor(this)
|
|
11
|
-
|
|
12
|
-
fun resetNative() { mDestructor.destruct() }
|
|
13
|
-
fun isValid(): Boolean = mDestructor.isValid()
|
|
14
|
-
|
|
15
|
-
open class Destructor internal constructor(referent: HybridData) {
|
|
16
|
-
private var mNativePointer: Long = 0
|
|
17
|
-
|
|
18
|
-
init { HybridDestructors.register(referent, this) }
|
|
19
|
-
|
|
20
|
-
internal fun isValid(): Boolean = mNativePointer != 0L
|
|
21
|
-
|
|
22
|
-
internal fun destruct() {
|
|
23
|
-
deleteNative(mNativePointer)
|
|
24
|
-
mNativePointer = 0L
|
|
25
|
-
HybridDestructors.remove(this)
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
companion object {
|
|
29
|
-
@JvmStatic
|
|
30
|
-
external fun deleteNative(pointer: Long)
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
// held values contain the destructor only; they cannot retain its HybridData owner.
|
|
36
|
-
private external interface HybridFinalizer : JsAny {
|
|
37
|
-
fun register(target: JsReference<HybridData>, held: JsReference<HybridData.Destructor>, token: JsReference<HybridData.Destructor>)
|
|
38
|
-
fun unregister(token: JsReference<HybridData.Destructor>): Boolean
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
private fun makeHybridFinalizer(callback: (JsReference<HybridData.Destructor>) -> Unit): HybridFinalizer =
|
|
42
|
-
js("new FinalizationRegistry(callback)")
|
|
43
|
-
|
|
44
|
-
private object HybridDestructors {
|
|
45
|
-
private val live = mutableMapOf<HybridData.Destructor, JsReference<HybridData.Destructor>>()
|
|
46
|
-
private val finalizer = makeHybridFinalizer { held ->
|
|
47
|
-
if (isNativeRuntimeActive()) held.get().destruct()
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
init {
|
|
51
|
-
registerNativeRetirement {
|
|
52
|
-
for (destructor in live.keys.toList()) destructor.destruct()
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
fun register(holder: HybridData, destructor: HybridData.Destructor) {
|
|
57
|
-
check(isNativeRuntimeActive()) { "native binding runtime retired" }
|
|
58
|
-
val token = destructor.toJsReference()
|
|
59
|
-
finalizer.register(holder.toJsReference(), token, token)
|
|
60
|
-
live[destructor] = token
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
fun remove(destructor: HybridData.Destructor) {
|
|
64
|
-
live.remove(destructor)?.let { finalizer.unregister(it) }
|
|
65
|
-
}
|
|
66
|
-
}
|
|
@@ -1,157 +0,0 @@
|
|
|
1
|
-
package dev.peach.jni
|
|
2
|
-
|
|
3
|
-
private data class IncomingKey(val owner: String, val name: String, val descriptor: String, val isStatic: Boolean)
|
|
4
|
-
private data class IncomingClass(val parents: Array<String>, val accepts: (Any?) -> Boolean)
|
|
5
|
-
private data class IncomingMethod(
|
|
6
|
-
val key: IncomingKey,
|
|
7
|
-
val arguments: Int,
|
|
8
|
-
val virtual: (Any?, Array<Any?>) -> Any?,
|
|
9
|
-
val nonvirtual: ((Any?, Array<Any?>) -> Any?)?,
|
|
10
|
-
)
|
|
11
|
-
private data class IncomingField(val key: IncomingKey, val read: (Any?) -> Any?, val write: ((Any?, Any?) -> Unit)?)
|
|
12
|
-
private val incomingClasses = mutableMapOf<String, IncomingClass>()
|
|
13
|
-
private val incomingMethods = mutableListOf<IncomingMethod>()
|
|
14
|
-
private val incomingMethodIds = mutableMapOf<IncomingKey, Int>()
|
|
15
|
-
private val incomingFields = mutableListOf<IncomingField>()
|
|
16
|
-
private val incomingFieldIds = mutableMapOf<IncomingKey, Int>()
|
|
17
|
-
private var incomingInitialized = false
|
|
18
|
-
private var incomingRetired = false
|
|
19
|
-
|
|
20
|
-
// the compiler replaces this body with registrations of original declarations.
|
|
21
|
-
internal fun initializeIncomingBindings() {
|
|
22
|
-
error("JNI incoming bindings require the compiler plugin")
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
private fun requireIncomingBindings() {
|
|
26
|
-
check(!incomingRetired) { "native binding runtime retired" }
|
|
27
|
-
if (!incomingInitialized) {
|
|
28
|
-
initializeIncomingBindings()
|
|
29
|
-
incomingInitialized = true
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
internal fun registerIncomingClass(owner: String, parents: Array<String>, accepts: (Any?) -> Boolean) {
|
|
34
|
-
check(incomingClasses.put(owner, IncomingClass(parents, accepts)) == null) { "duplicate incoming class: $owner" }
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
internal fun registerIncomingMethod(
|
|
38
|
-
owner: String, name: String, descriptor: String, isStatic: Boolean, arguments: Int,
|
|
39
|
-
virtual: (Any?, Array<Any?>) -> Any?, nonvirtual: ((Any?, Array<Any?>) -> Any?)?,
|
|
40
|
-
) {
|
|
41
|
-
val key = IncomingKey(owner, name, descriptor, isStatic)
|
|
42
|
-
check(key !in incomingMethodIds) { "duplicate incoming method: $owner.$name$descriptor" }
|
|
43
|
-
incomingMethods += IncomingMethod(key, arguments, virtual, nonvirtual)
|
|
44
|
-
incomingMethodIds[key] = incomingMethods.size
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
internal fun registerIncomingField(owner: String, name: String, descriptor: String, isStatic: Boolean, read: (Any?) -> Any?, write: ((Any?, Any?) -> Unit)?) {
|
|
48
|
-
val key = IncomingKey(owner, name, descriptor, isStatic)
|
|
49
|
-
check(key !in incomingFieldIds) { "duplicate incoming field: $owner.$name:$descriptor" }
|
|
50
|
-
incomingFields += IncomingField(key, read, write)
|
|
51
|
-
incomingFieldIds[key] = incomingFields.size
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
fun requireIncomingClass(owner: String) {
|
|
55
|
-
requireIncomingBindings()
|
|
56
|
-
if (owner !in incomingClasses) throw ClassNotFoundException(owner)
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
fun isIncomingInstance(owner: String, receiver: Any?): Boolean {
|
|
60
|
-
requireIncomingClass(owner)
|
|
61
|
-
return incomingClasses.getValue(owner).accepts(receiver)
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
fun isIncomingAssignableFrom(target: String, source: String): Boolean {
|
|
65
|
-
requireIncomingClass(target)
|
|
66
|
-
requireIncomingClass(source)
|
|
67
|
-
fun inherits(type: String): Boolean = type == target || incomingClasses[type]?.parents.orEmpty().any(::inherits)
|
|
68
|
-
return inherits(source)
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
fun incomingClassOf(receiver: Any): String {
|
|
72
|
-
requireIncomingBindings()
|
|
73
|
-
val matches = incomingClasses.filterValues { it.accepts(receiver) }.keys
|
|
74
|
-
return matches.firstOrNull { candidate -> matches.none { it != candidate && isIncomingAssignableFrom(candidate, it) } }
|
|
75
|
-
?: throw ClassNotFoundException("receiver has no registered class")
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
private fun lookupIncoming(owner: String, name: String, descriptor: String, isStatic: Boolean, ids: Map<IncomingKey, Int>): Int? {
|
|
79
|
-
val key = IncomingKey(owner, name, descriptor, isStatic)
|
|
80
|
-
ids[key]?.let { return it }
|
|
81
|
-
if (name == "<init>") return null
|
|
82
|
-
for (parent in incomingClasses[owner]?.parents.orEmpty()) {
|
|
83
|
-
lookupIncoming(parent, name, descriptor, isStatic, ids)?.let { return it }
|
|
84
|
-
}
|
|
85
|
-
return null
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
// ids describe declarations; a cached base id remains valid on derived instances.
|
|
89
|
-
fun lookupIncomingMethod(owner: String, name: String, descriptor: String, isStatic: Boolean = false): Int {
|
|
90
|
-
requireIncomingClass(owner)
|
|
91
|
-
return lookupIncoming(owner, name, descriptor, isStatic, incomingMethodIds)
|
|
92
|
-
?: throw NoSuchMethodError("$owner.$name$descriptor")
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
fun lookupIncomingField(owner: String, name: String, descriptor: String, isStatic: Boolean = false): Int {
|
|
96
|
-
requireIncomingClass(owner)
|
|
97
|
-
return lookupIncoming(owner, name, descriptor, isStatic, incomingFieldIds)
|
|
98
|
-
?: throw NoSuchFieldError("$owner.$name:$descriptor")
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
private fun requireIncomingReceiver(key: IncomingKey, receiver: Any?) {
|
|
102
|
-
if (!key.isStatic && key.name != "<init>") {
|
|
103
|
-
if (receiver == null) throw NullPointerException("null receiver for ${key.owner}.${key.name}")
|
|
104
|
-
if (!incomingClasses.getValue(key.owner).accepts(receiver))
|
|
105
|
-
throw IllegalArgumentException("receiver is not an instance of ${key.owner}")
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
fun invokeIncoming(id: Int, receiver: Any?, arguments: Array<Any?>, nonvirtual: Boolean = false): Any? {
|
|
110
|
-
requireIncomingBindings()
|
|
111
|
-
val method = incomingMethods.getOrNull(id - 1) ?: throw NoSuchMethodError("invalid incoming method id: $id")
|
|
112
|
-
require(method.key.name != "<init>") { "constructors require constructIncoming" }
|
|
113
|
-
requireIncomingReceiver(method.key, receiver)
|
|
114
|
-
require(arguments.size == method.arguments) { "wrong argument count for ${method.key.owner}.${method.key.name}${method.key.descriptor}" }
|
|
115
|
-
val body = if (nonvirtual) method.nonvirtual
|
|
116
|
-
?: throw AbstractMethodError("${method.key.owner}.${method.key.name}${method.key.descriptor}")
|
|
117
|
-
else method.virtual
|
|
118
|
-
return body(receiver, arguments)
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
fun constructIncoming(id: Int, arguments: Array<Any?>): Any {
|
|
122
|
-
requireIncomingBindings()
|
|
123
|
-
val method = incomingMethods.getOrNull(id - 1) ?: throw NoSuchMethodError("invalid incoming constructor id: $id")
|
|
124
|
-
require(method.key.name == "<init>" && !method.key.isStatic) { "method is not a constructor" }
|
|
125
|
-
require(arguments.size == method.arguments) { "wrong constructor argument count for ${method.key.owner}${method.key.descriptor}" }
|
|
126
|
-
return checkNotNull(method.virtual(null, arguments))
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
fun readIncomingField(id: Int, receiver: Any?): Any? {
|
|
130
|
-
requireIncomingBindings()
|
|
131
|
-
val field = incomingFields.getOrNull(id - 1) ?: throw NoSuchFieldError("invalid incoming field id: $id")
|
|
132
|
-
requireIncomingReceiver(field.key, receiver)
|
|
133
|
-
return field.read(receiver)
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
fun writeIncomingField(id: Int, receiver: Any?, value: Any?) {
|
|
137
|
-
requireIncomingBindings()
|
|
138
|
-
val field = incomingFields.getOrNull(id - 1) ?: throw NoSuchFieldError("invalid incoming field id: $id")
|
|
139
|
-
requireIncomingReceiver(field.key, receiver)
|
|
140
|
-
val write = field.write ?: throw IllegalAccessError("final field: ${field.key.owner}.${field.key.name}")
|
|
141
|
-
write(receiver, value)
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
internal fun retireIncomingBindings() {
|
|
145
|
-
incomingRetired = true
|
|
146
|
-
incomingClasses.clear()
|
|
147
|
-
incomingMethods.clear()
|
|
148
|
-
incomingMethodIds.clear()
|
|
149
|
-
incomingFields.clear()
|
|
150
|
-
incomingFieldIds.clear()
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
class ClassNotFoundException(message: String) : Exception(message)
|
|
154
|
-
class NoSuchMethodError(message: String) : Error(message)
|
|
155
|
-
class NoSuchFieldError(message: String) : Error(message)
|
|
156
|
-
class AbstractMethodError(message: String) : Error(message)
|
|
157
|
-
class IllegalAccessError(message: String) : Error(message)
|
|
@@ -1,77 +0,0 @@
|
|
|
1
|
-
package dev.peach.jni
|
|
2
|
-
|
|
3
|
-
import kotlin.js.*
|
|
4
|
-
|
|
5
|
-
private data class Method(val owner: String, val name: String, val descriptor: String)
|
|
6
|
-
private val methods = mutableMapOf<Method, (Any?, Array<Any?>) -> Any?>()
|
|
7
|
-
private var nativeRuntime: NativeRuntime? = null
|
|
8
|
-
private var retired = false
|
|
9
|
-
private var retiring = false
|
|
10
|
-
private val retirementActions = mutableListOf<() -> Unit>()
|
|
11
|
-
private fun assertActive() = check(!retired) { "native binding runtime retired" }
|
|
12
|
-
|
|
13
|
-
fun isNativeRuntimeActive(): Boolean = !retired && !retiring
|
|
14
|
-
|
|
15
|
-
fun registerNativeRetirement(action: () -> Unit) {
|
|
16
|
-
check(isNativeRuntimeActive()) { "native binding runtime retired" }
|
|
17
|
-
retirementActions += action
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
// registration glue supplies native entrypoints; package method bodies stay unchanged.
|
|
21
|
-
fun registerNative(owner: String, method: String, descriptor: String, body: (Any?, Array<Any?>) -> Any?) {
|
|
22
|
-
check(isNativeRuntimeActive()) { "native binding runtime retired" }
|
|
23
|
-
val key = Method(owner, method, descriptor)
|
|
24
|
-
check(key !in methods) { "native method already bound: $owner.$method$descriptor" }
|
|
25
|
-
methods[key] = body
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
fun invoke(receiver: Any?, owner: String, method: String, descriptor: String, arguments: Array<Any?>): Any? {
|
|
29
|
-
assertActive()
|
|
30
|
-
val body = methods[Method(owner, method, descriptor)]
|
|
31
|
-
?: throw UnsatisfiedLinkError("unbound native method: $owner.$method$descriptor")
|
|
32
|
-
return body(receiver, arguments)
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
class UnsatisfiedLinkError(message: String) : Error(message)
|
|
36
|
-
|
|
37
|
-
external interface NativePeer : JsAny {
|
|
38
|
-
fun reset()
|
|
39
|
-
fun isValid(): Boolean
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
external interface NativeCallback : JsAny {
|
|
43
|
-
fun invoke(arguments: JsReference<Array<Any?>>): JsReference<Any>?
|
|
44
|
-
fun release()
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
external interface NativeRuntime : JsAny {
|
|
48
|
-
fun create(owner: String, receiver: JsReference<Any>): NativePeer
|
|
49
|
-
fun attach(peer: NativePeer, owner: JsReference<Any>)
|
|
50
|
-
fun capture(peer: NativePeer, receiver: JsReference<Any>, dispatch: (JsReference<Any>, JsReference<Array<Any?>>) -> JsReference<Any>?): NativeCallback
|
|
51
|
-
fun retire()
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
fun installNativeRuntime(runtime: NativeRuntime) {
|
|
55
|
-
check(isNativeRuntimeActive()) { "native binding runtime retired" }
|
|
56
|
-
check(nativeRuntime == null) { "native binding runtime is already installed" }
|
|
57
|
-
nativeRuntime = runtime
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
fun retireNativeRuntime() {
|
|
61
|
-
if (retired || retiring) return
|
|
62
|
-
retiring = true
|
|
63
|
-
var failure: Throwable? = null
|
|
64
|
-
try {
|
|
65
|
-
for (action in retirementActions) {
|
|
66
|
-
try { action() } catch (error: Throwable) { if (failure == null) failure = error }
|
|
67
|
-
}
|
|
68
|
-
} finally {
|
|
69
|
-
retirementActions.clear()
|
|
70
|
-
retired = true
|
|
71
|
-
retireIncomingBindings()
|
|
72
|
-
nativeRuntime?.retire()
|
|
73
|
-
methods.clear()
|
|
74
|
-
}
|
|
75
|
-
failure?.let { throw it }
|
|
76
|
-
// retirement is terminal for this Kotlin process.
|
|
77
|
-
}
|
|
@@ -1,89 +0,0 @@
|
|
|
1
|
-
package dev.peach.jni.integration
|
|
2
|
-
|
|
3
|
-
import dev.peach.jni.*
|
|
4
|
-
import kotlin.js.*
|
|
5
|
-
|
|
6
|
-
external interface JniTransportReply : JsAny {
|
|
7
|
-
val value: JsReference<Any>?
|
|
8
|
-
val error: JsReference<Throwable>?
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
private fun transportReply(value: JsReference<Any>?, error: JsReference<Throwable>?): JniTransportReply =
|
|
12
|
-
js("({ value, error })")
|
|
13
|
-
|
|
14
|
-
private inline fun transport(body: () -> Any?): JniTransportReply = try {
|
|
15
|
-
transportReply(body()?.toJsReference(), null)
|
|
16
|
-
} catch (error: Throwable) {
|
|
17
|
-
transportReply(null, error.toJsReference())
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
@JsExport fun jniMethod(owner: String, name: String, descriptor: String, isStatic: Boolean): JniTransportReply =
|
|
21
|
-
transport { lookupIncomingMethod(owner, name, descriptor, isStatic) }
|
|
22
|
-
|
|
23
|
-
@JsExport fun jniField(owner: String, name: String, descriptor: String, isStatic: Boolean): JniTransportReply =
|
|
24
|
-
transport { lookupIncomingField(owner, name, descriptor, isStatic) }
|
|
25
|
-
|
|
26
|
-
@JsExport fun jniInvoke(id: Int, receiver: JsReference<Any>?, arguments: JsReference<Array<Any?>>, nonvirtual: Boolean): JniTransportReply =
|
|
27
|
-
transport { invokeIncoming(id, receiver?.get(), arguments.get(), nonvirtual) }
|
|
28
|
-
|
|
29
|
-
@JsExport fun jniConstruct(id: Int, arguments: JsReference<Array<Any?>>): JniTransportReply =
|
|
30
|
-
transport { constructIncoming(id, arguments.get()) }
|
|
31
|
-
|
|
32
|
-
@JsExport fun jniRead(id: Int, receiver: JsReference<Any>?): JniTransportReply =
|
|
33
|
-
transport { readIncomingField(id, receiver?.get()) }
|
|
34
|
-
|
|
35
|
-
@JsExport fun jniWrite(id: Int, receiver: JsReference<Any>?, value: JsReference<Any>?): JniTransportReply =
|
|
36
|
-
transport { writeIncomingField(id, receiver?.get(), value?.get()); null }
|
|
37
|
-
|
|
38
|
-
@JsExport fun jniRequireClass(owner: String): JniTransportReply = transport { requireIncomingClass(owner); null }
|
|
39
|
-
@JsExport fun jniClassOf(receiver: JsReference<Any>): JniTransportReply = transport { incomingClassOf(receiver.get()) }
|
|
40
|
-
@JsExport fun jniInstanceOf(owner: String, receiver: JsReference<Any>?): JniTransportReply = transport { isIncomingInstance(owner, receiver?.get()) }
|
|
41
|
-
@JsExport fun jniAssignable(target: String, source: String): JniTransportReply = transport { isIncomingAssignableFrom(target, source) }
|
|
42
|
-
@JsExport fun jniSame(a: JsReference<Any>?, b: JsReference<Any>?): Boolean = a?.get() === b?.get()
|
|
43
|
-
|
|
44
|
-
@JsExport fun jniArguments(count: Int): JsReference<Array<Any?>> = arrayOfNulls<Any>(count).toJsReference()
|
|
45
|
-
@JsExport fun jniArgument(arguments: JsReference<Array<Any?>>, index: Int, value: JsReference<Any>?) { arguments.get()[index] = value?.get() }
|
|
46
|
-
@JsExport fun jniArgumentAt(arguments: JsReference<Array<Any?>>, index: Int): JsReference<Any>? = arguments.get()[index]?.toJsReference()
|
|
47
|
-
@JsExport fun jniArgumentCount(arguments: JsReference<Array<Any?>>): Int = arguments.get().size
|
|
48
|
-
@JsExport fun jniInt(value: JsReference<Any>): Int = when (val scalar = value.get()) {
|
|
49
|
-
is Int -> scalar
|
|
50
|
-
is Byte -> scalar.toInt()
|
|
51
|
-
is Short -> scalar.toInt()
|
|
52
|
-
is Char -> scalar.code
|
|
53
|
-
else -> error("JNI value is not an integer scalar")
|
|
54
|
-
}
|
|
55
|
-
@JsExport fun jniLong(value: JsReference<Any>): String = (value.get() as Long).toString()
|
|
56
|
-
@JsExport fun jniString(value: JsReference<Any>): String = value.get() as String
|
|
57
|
-
@JsExport fun jniBoolean(value: JsReference<Any>): Boolean = value.get() as Boolean
|
|
58
|
-
@JsExport fun jniNumber(value: JsReference<Any>): Double = when (val scalar = value.get()) {
|
|
59
|
-
is Float -> scalar.toDouble()
|
|
60
|
-
is Double -> scalar
|
|
61
|
-
else -> error("JNI value is not a floating-point scalar")
|
|
62
|
-
}
|
|
63
|
-
@JsExport fun jniPrimitive(descriptor: String, integer: String, number: Double, text: String): JniTransportReply = transport {
|
|
64
|
-
when (descriptor) {
|
|
65
|
-
"Z" -> when (integer) { "0" -> false; "1" -> true; else -> error("invalid JNI boolean") }
|
|
66
|
-
"B" -> integer.toByte()
|
|
67
|
-
"C" -> integer.toInt().also { require(it in 0..65535) }.toChar()
|
|
68
|
-
"S" -> integer.toShort()
|
|
69
|
-
"I" -> integer.toInt()
|
|
70
|
-
"J" -> integer.toLong()
|
|
71
|
-
"F" -> number.toFloat()
|
|
72
|
-
"D" -> number
|
|
73
|
-
"Ljava/lang/String;" -> text
|
|
74
|
-
else -> error("unsupported JNI scalar descriptor: $descriptor")
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
@JsExport fun jniErrorClass(error: JsReference<Throwable>): String? = error.get()::class.simpleName
|
|
78
|
-
@JsExport fun jniErrorMessage(error: JsReference<Throwable>): String? = error.get().message
|
|
79
|
-
|
|
80
|
-
@JsExport fun jniBind(owner: String, name: String, descriptor: String,
|
|
81
|
-
callback: (JsReference<Any>?, JsReference<Array<Any?>>) -> JniTransportReply): JniTransportReply = transport {
|
|
82
|
-
registerNative(owner, name, descriptor) { receiver, arguments ->
|
|
83
|
-
val result = callback(receiver?.toJsReference(), arguments.toJsReference())
|
|
84
|
-
result.error?.let { throw it.get() }
|
|
85
|
-
result.value?.get()
|
|
86
|
-
}
|
|
87
|
-
null
|
|
88
|
-
}
|
|
89
|
-
@JsExport fun jniRetire(): JniTransportReply = transport { retireNativeRuntime(); null }
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
package android.os
|
|
2
|
-
|
|
3
|
-
// Build values follow the active Peach Android device supplied by its host.
|
|
4
|
-
object Build {
|
|
5
|
-
var MODEL: String = ""
|
|
6
|
-
private set
|
|
7
|
-
|
|
8
|
-
object VERSION {
|
|
9
|
-
var RELEASE: String = ""
|
|
10
|
-
internal set
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
internal fun setDevice(model: String, release: String) {
|
|
14
|
-
MODEL = model
|
|
15
|
-
VERSION.RELEASE = release
|
|
16
|
-
}
|
|
17
|
-
}
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
package android.os
|
|
2
|
-
|
|
3
|
-
import java.lang.Runnable
|
|
4
|
-
|
|
5
|
-
// android.os.Handler's runnable half, posting to its looper's queue
|
|
6
|
-
open class Handler(private val looper: Looper) {
|
|
7
|
-
@Deprecated("implicitly choosing a Looper during Handler construction can lead to bugs")
|
|
8
|
-
constructor() : this(Looper.myLooper() ?: throw RuntimeException("Can't create handler inside thread that has not called Looper.prepare()"))
|
|
9
|
-
|
|
10
|
-
fun getLooper(): Looper = looper
|
|
11
|
-
|
|
12
|
-
fun post(r: Runnable): Boolean = postAtTime(r, SystemClock.uptimeMillis())
|
|
13
|
-
fun postDelayed(r: Runnable, delayMillis: Long): Boolean =
|
|
14
|
-
postAtTime(r, SystemClock.uptimeMillis() + delayMillis.coerceAtLeast(0))
|
|
15
|
-
fun postDelayed(r: Runnable, token: Any?, delayMillis: Long): Boolean =
|
|
16
|
-
postAtTime(r, token, SystemClock.uptimeMillis() + delayMillis.coerceAtLeast(0))
|
|
17
|
-
fun postAtTime(r: Runnable, uptimeMillis: Long): Boolean = postAtTime(r, null, uptimeMillis)
|
|
18
|
-
fun postAtTime(r: Runnable, token: Any?, uptimeMillis: Long): Boolean {
|
|
19
|
-
looper.queue.enqueue(MessageQueue.Entry(uptimeMillis, this, r, token), front = false)
|
|
20
|
-
return true
|
|
21
|
-
}
|
|
22
|
-
fun postAtFrontOfQueue(r: Runnable): Boolean {
|
|
23
|
-
looper.queue.enqueue(MessageQueue.Entry(0, this, r, null), front = true)
|
|
24
|
-
return true
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
fun removeCallbacks(r: Runnable) = looper.queue.remove(this, r, null)
|
|
28
|
-
fun removeCallbacks(r: Runnable, token: Any?) = looper.queue.remove(this, r, token)
|
|
29
|
-
fun removeCallbacksAndMessages(token: Any?) = looper.queue.remove(this, null, token)
|
|
30
|
-
fun hasCallbacks(r: Runnable): Boolean = looper.queue.has(this, r, null)
|
|
31
|
-
|
|
32
|
-
companion object {
|
|
33
|
-
fun createAsync(looper: Looper): Handler = Handler(looper)
|
|
34
|
-
}
|
|
35
|
-
}
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
package android.os
|
|
2
|
-
|
|
3
|
-
// the guest's one thread is Android's main thread: its looper is the main
|
|
4
|
-
// looper and every message runs on the guest event loop
|
|
5
|
-
class Looper private constructor() {
|
|
6
|
-
internal val queue = MessageQueue()
|
|
7
|
-
|
|
8
|
-
fun isCurrentThread(): Boolean = true
|
|
9
|
-
fun getQueue(): MessageQueue = queue
|
|
10
|
-
|
|
11
|
-
companion object {
|
|
12
|
-
private val main = Looper()
|
|
13
|
-
fun getMainLooper(): Looper = main
|
|
14
|
-
fun myLooper(): Looper? = main
|
|
15
|
-
fun myQueue(): MessageQueue = main.queue
|
|
16
|
-
}
|
|
17
|
-
}
|
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
package android.os
|
|
2
|
-
|
|
3
|
-
import java.lang.Runnable
|
|
4
|
-
import kotlinx.coroutines.DelicateCoroutinesApi
|
|
5
|
-
import kotlinx.coroutines.Dispatchers
|
|
6
|
-
import kotlinx.coroutines.GlobalScope
|
|
7
|
-
import kotlinx.coroutines.Job
|
|
8
|
-
import kotlinx.coroutines.delay
|
|
9
|
-
import kotlinx.coroutines.launch
|
|
10
|
-
|
|
11
|
-
// MessageQueue's ordering: by uptime, then by enqueue order, with
|
|
12
|
-
// postAtFrontOfQueue at time zero ahead of everything already queued
|
|
13
|
-
class MessageQueue internal constructor() {
|
|
14
|
-
internal class Entry(val time: Long, val handler: Handler, val callback: Runnable, val token: Any?)
|
|
15
|
-
|
|
16
|
-
private val entries = ArrayList<Entry>()
|
|
17
|
-
private var wake: Job? = null
|
|
18
|
-
private var wakeAt = Long.MAX_VALUE
|
|
19
|
-
|
|
20
|
-
fun isIdle(): Boolean = entries.firstOrNull().let { it == null || it.time > SystemClock.uptimeMillis() }
|
|
21
|
-
|
|
22
|
-
internal fun enqueue(entry: Entry, front: Boolean) {
|
|
23
|
-
val index = if (front) 0 else entries.indexOfFirst { it.time > entry.time }.let { if (it < 0) entries.size else it }
|
|
24
|
-
entries.add(index, entry)
|
|
25
|
-
schedule()
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
internal fun remove(handler: Handler, callback: Runnable?, token: Any?) {
|
|
29
|
-
entries.removeAll { it.handler === handler && (callback == null || it.callback === callback) && (token == null || it.token === token) }
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
internal fun has(handler: Handler, callback: Runnable?, token: Any?): Boolean =
|
|
33
|
-
entries.any { it.handler === handler && (callback == null || it.callback === callback) && (token == null || it.token === token) }
|
|
34
|
-
|
|
35
|
-
@OptIn(DelicateCoroutinesApi::class)
|
|
36
|
-
private fun schedule() {
|
|
37
|
-
val next = entries.firstOrNull()?.time ?: return
|
|
38
|
-
if (wake != null && wakeAt <= next) return
|
|
39
|
-
wake?.cancel()
|
|
40
|
-
wakeAt = next
|
|
41
|
-
wake = GlobalScope.launch(Dispatchers.Main) {
|
|
42
|
-
delay(next - SystemClock.uptimeMillis())
|
|
43
|
-
wake = null
|
|
44
|
-
wakeAt = Long.MAX_VALUE
|
|
45
|
-
// run what is due one message at a time; a callback may post or
|
|
46
|
-
// remove, so read the head again after each one
|
|
47
|
-
while (true) {
|
|
48
|
-
val head = entries.firstOrNull() ?: break
|
|
49
|
-
if (head.time > SystemClock.uptimeMillis()) break
|
|
50
|
-
entries.removeAt(0)
|
|
51
|
-
head.callback.run()
|
|
52
|
-
}
|
|
53
|
-
schedule()
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
}
|