diff --git a/incremental/common/src/index.ts b/incremental/common/src/index.ts index 7d500898cce3480ba522f920640293110dee232e..0e47fd13841b9b76f653b8ed1aa363f6bd68e615 100644 --- a/incremental/common/src/index.ts +++ b/incremental/common/src/index.ts @@ -37,6 +37,7 @@ export { propDeepCopy, refEqual, int8Array, + unsafeCast } from "@koalaui/compat" export { clamp, lerp, modulo, parseNumber, isFiniteNumber, getDistancePx } from "./math" export { hashCodeFromString } from "./stringUtils" diff --git a/incremental/compat/src/arkts/index.ts b/incremental/compat/src/arkts/index.ts index 898e2d891637f420a3677005f42b245e9f0622b3..95ec1799f3ee2e82960a2bc4c7e1a6ac41ebf1c7 100644 --- a/incremental/compat/src/arkts/index.ts +++ b/incremental/compat/src/arkts/index.ts @@ -24,3 +24,4 @@ export * from "./reflection" export * from "./strings" export * from "./ts-reflection" export * from "./types" +export * from "./utils" diff --git a/incremental/compat/src/arkts/utils.ts b/incremental/compat/src/arkts/utils.ts new file mode 100644 index 0000000000000000000000000000000000000000..0061d575251e2bd5799c0a8d8be1a632dcc98871 --- /dev/null +++ b/incremental/compat/src/arkts/utils.ts @@ -0,0 +1,18 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +export function unsafeCast(value: Object): T { + return value as T +} diff --git a/incremental/compat/src/index.ts b/incremental/compat/src/index.ts index 6976bcb3397b2ebd30c8701c9b0d87218473adce..5a05c8ee6adbf4bbfe50ac07dc0f2675ace82ca9 100644 --- a/incremental/compat/src/index.ts +++ b/incremental/compat/src/index.ts @@ -52,4 +52,5 @@ export { float32, float64, int8Array, + unsafeCast, } from "#platform" diff --git a/incremental/compat/src/ohos/index.ts b/incremental/compat/src/ohos/index.ts index e59193debbadc89a6078858bc57212302d17aa8b..285981699c2b448aa426f13131d4b7c83c8104ca 100644 --- a/incremental/compat/src/ohos/index.ts +++ b/incremental/compat/src/ohos/index.ts @@ -49,7 +49,8 @@ export { uint64, float32, float64, - int8Array + int8Array, + unsafeCast, } from "../typescript" export { diff --git a/incremental/compat/src/typescript/index.ts b/incremental/compat/src/typescript/index.ts index 220a13b412309d6e0baa071c9b1105014ef8963d..03bb4fbddd19dc1b318e50ee6c3a5eac5f4cc9d9 100644 --- a/incremental/compat/src/typescript/index.ts +++ b/incremental/compat/src/typescript/index.ts @@ -24,3 +24,4 @@ export * from "./reflection" export * from "./strings" export * from "./ts-reflection" export * from "./types" +export * from "./utils" diff --git a/incremental/compat/src/typescript/utils.ts b/incremental/compat/src/typescript/utils.ts new file mode 100644 index 0000000000000000000000000000000000000000..2c08785fb196b3e5d6cbb3657f6db3401a7157db --- /dev/null +++ b/incremental/compat/src/typescript/utils.ts @@ -0,0 +1,18 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +export function unsafeCast(value: unknown): T { + return value as unknown as T +} diff --git a/interop/src/arkts/MaterializedBase.sts b/interop/src/arkts/MaterializedBase.sts new file mode 100644 index 0000000000000000000000000000000000000000..3f26a861ef8f7094a80963a25d1c9da020752c38 --- /dev/null +++ b/interop/src/arkts/MaterializedBase.sts @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import { Finalizable } from "./Finalizable" + +export interface MaterializedBase { + getPeer(): Finalizable | undefined +} + diff --git a/interop/src/arkts/index.sts b/interop/src/arkts/index.sts index 9fb970d80f45cfddf2388ca9f134dc9c33763522..7b8f23670cd07c1ea62e58dc287664703b35d769 100644 --- a/interop/src/arkts/index.sts +++ b/interop/src/arkts/index.sts @@ -23,3 +23,4 @@ export * from "./SerializerBase" export * from "./DeserializerBase" export * from "./Finalizable" export * from "./loadLibraries" +export * from "./MaterializedBase" diff --git a/interop/src/interop/MaterializedBase.ts b/interop/src/interop/MaterializedBase.ts new file mode 100644 index 0000000000000000000000000000000000000000..51135fbaa7beee1e31f48d30b9eebc69c5fa45eb --- /dev/null +++ b/interop/src/interop/MaterializedBase.ts @@ -0,0 +1,20 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import { Finalizable } from "./Finalizable" + +export interface MaterializedBase { + getPeer(): Finalizable | undefined +} diff --git a/interop/src/interop/index.ts b/interop/src/interop/index.ts index f61254d5acbb7d8727394a7134405c49e3b92687..354f21254e52dc43fd8c237d3149c20711fb0e0a 100644 --- a/interop/src/interop/index.ts +++ b/interop/src/interop/index.ts @@ -71,3 +71,4 @@ export { InteropNativeModule, loadInteropNativeModule } from "./InteropNativeMod export { SerializerBase, RuntimeType, Tags, runtimeType, CallbackResource, unsafeCast, isResource, isInstanceOf } from "./SerializerBase" export { DeserializerBase } from "./DeserializerBase" export { loadNativeModuleLibrary, loadNativeLibrary, registerNativeModuleLibraryName } from "./loadLibraries" +export * from "./MaterializedBase"