diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmBasicDataTypes_pr1/.gitignore b/code/DocsSample/ArkTs/JSVMAPI/JsvmBasicDataTypes_pr1/.gitignore new file mode 100755 index 0000000000000000000000000000000000000000..d2ff20141ceed86d87c0ea5d99481973005bab2b --- /dev/null +++ b/code/DocsSample/ArkTs/JSVMAPI/JsvmBasicDataTypes_pr1/.gitignore @@ -0,0 +1,12 @@ +/node_modules +/oh_modules +/local.properties +/.idea +**/build +/.hvigor +.cxx +/.clangd +/.clang-format +/.clang-tidy +**/.test +/.appanalyzer \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmBasicDataTypes_pr1/AppScope/app.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmBasicDataTypes_pr1/AppScope/app.json5 new file mode 100755 index 0000000000000000000000000000000000000000..58ba37fd0dd76a29781d5bfae252434f4d39c5ca --- /dev/null +++ b/code/DocsSample/ArkTs/JSVMAPI/JsvmBasicDataTypes_pr1/AppScope/app.json5 @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2025 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. + */ + +{ + "app": { + "bundleName": "com.sample.jsvmbasicdatatypes", + "vendor": "example", + "versionCode": 1000000, + "versionName": "1.0.0", + "icon": "$media:app_icon", + "label": "$string:app_name" + } +} diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmBasicDataTypes_pr1/AppScope/resources/base/element/string.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmBasicDataTypes_pr1/AppScope/resources/base/element/string.json new file mode 100755 index 0000000000000000000000000000000000000000..07b44328064a591d0308043aa22ee1bedc9ae3a5 --- /dev/null +++ b/code/DocsSample/ArkTs/JSVMAPI/JsvmBasicDataTypes_pr1/AppScope/resources/base/element/string.json @@ -0,0 +1,8 @@ +{ + "string": [ + { + "name": "app_name", + "value": "JsvmBasicDataTypes" + } + ] +} diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmBasicDataTypes_pr1/AppScope/resources/base/media/app_icon.png b/code/DocsSample/ArkTs/JSVMAPI/JsvmBasicDataTypes_pr1/AppScope/resources/base/media/app_icon.png new file mode 100755 index 0000000000000000000000000000000000000000..a39445dc87828b76fed6d2ec470dd455c45319e3 Binary files /dev/null and b/code/DocsSample/ArkTs/JSVMAPI/JsvmBasicDataTypes_pr1/AppScope/resources/base/media/app_icon.png differ diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmBasicDataTypes_pr1/README.md b/code/DocsSample/ArkTs/JSVMAPI/JsvmBasicDataTypes_pr1/README.md new file mode 100644 index 0000000000000000000000000000000000000000..53a7d19757428e09525bc4faa3b1bf930f45405d --- /dev/null +++ b/code/DocsSample/ArkTs/JSVMAPI/JsvmBasicDataTypes_pr1/README.md @@ -0,0 +1,133 @@ +# ArkTS使用JSVM-API接口创建基本数据类型 + +### 介绍 + +在JavaScript中,整数类型是一种基本数据类型,用于表示没有小数部分的数值。double类型用于表示有小数的数值。JavaScript的数值存储方式会导致在某些情况下无法准确表示非常大或非常小的数值,在这种情况下,需要使用BigInt对应的JSVM-API接口来处理更大范围的整数。 + +该工程中展示的代码详细描述可查如下链接: + +- [使用JSVM-API接口创建基本数据类型](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/napi/use-jsvm-basic-data-types.md) + +### 效果预览 + +| 首页 | 执行及结果即时反馈 | +| :----------------------------------------------------------: | :----------------------------------------------------------: | +| | | + +### 使用说明 + +1. 在主界面,可以点击OH_JSVM_CreateDouble,开始执行。 +2. 执行结果会即时反馈在屏幕中央,并在控制台打印log。 + +### 工程目录 + +``` +createdouble/src/ + ├── main + │ ├── cpp + │ │ ├── types + │ │ │ ├── libentry + │ │ │ │ ├── Index.d.ts // 提供JS侧的接口方法 + │ │ │ │ ├── oh-package.json5 // 将index.d.ts与cpp文件关联 + │ │ ├── CMakeLists.txt // 配置CMake打包参数 + │ │ ├── hello.cpp // 实现Native侧的runTest接口 + │ ├── ets + │ │ ├── entryability + │ │ ├── entrybackupability + │ │ ├── pages + │ │ ├── Index.ets // ArkTS侧调用C/C++方法实现 + │ ├── module.json5 + │ └── resources + ├── ohosTest + │ ├── ets + │ │ ├── test + │ │ ├── Ability.test.ets // 自动化测试代码 +createint32/src/ + ├── main + │ ├── cpp + │ │ ├── types + │ │ │ ├── libentry + │ │ │ │ ├── Index.d.ts // 提供JS侧的接口方法 + │ │ │ │ ├── oh-package.json5 // 将index.d.ts与cpp文件关联 + │ │ ├── CMakeLists.txt // 配置CMake打包参数 + │ │ ├── hello.cpp // 实现Native侧的runTest接口 + │ ├── ets + │ │ ├── entryability + │ │ ├── entrybackupability + │ │ ├── pages + │ │ ├── Index.ets // ArkTS侧调用C/C++方法实现 + │ ├── module.json5 + │ └── resources + ├── ohosTest + │ ├── ets + │ │ ├── test + │ │ ├── Ability.test.ets // 自动化测试代码 +createint64/src/ + ├── main + │ ├── cpp + │ │ ├── types + │ │ │ ├── libentry + │ │ │ │ ├── Index.d.ts // 提供JS侧的接口方法 + │ │ │ │ ├── oh-package.json5 // 将index.d.ts与cpp文件关 + │ │ ├── CMakeLists.txt // 配置CMake打包参数 + │ │ ├── hello.cpp // 实现Native侧的runTest接 + │ ├── ets + │ │ ├── entryability + │ │ ├── entrybackupability + │ │ ├── pages + │ │ ├── Index.ets // ArkTS侧调用C/C++方法实现 + │ ├── module.json5 + │ └── resources + ├── ohosTest + │ ├── ets + │ │ ├── test + │ │ ├── Ability.test.ets // 自动化测试代码 +createuint32/src/ + ├── main + │ ├── cpp + │ │ ├── types + │ │ │ ├── libentry + │ │ │ │ ├── Index.d.ts // 提供JS侧的接口方法 + │ │ │ │ ├── oh-package.json5 // 将index.d.ts与cpp文件关 + │ │ ├── CMakeLists.txt // 配置CMake打包参数 + │ │ ├── hello.cpp // 实现Native侧的runTest接 + │ ├── ets + │ │ ├── entryability + │ │ ├── entrybackupability + │ │ ├── pages + │ │ ├── Index.ets // ArkTS侧调用C/C++方法实现 + │ ├── module.json5 + │ └── resources + ├── ohosTest + │ ├── ets + │ │ ├── test + │ │ ├── Ability.test.ets // 自动化测试代码 +``` + +### 相关权限 + +不涉及。 + +### 依赖 + +不涉及。 + +### 约束与限制 + +1.本示例仅支持标准系统上运行, 支持设备:mate60。 + +2.本示例为Stage模型,支持API14版本SDK,版本号:5.0.0.117,镜像版本号:HarmonyOS NEXT_5.0.0.117。 + +3.本示例需要使用DevEco Studio 5.0.1 Release (Build Version: 5.0.5.306, built on December 6, 2024)及以上版本才可编译运行。 + +### 下载 + +如需单独下载本工程,执行如下命令: + +```` +git init +git config core.sparsecheckout true +echo code/DocsSample/ArkTs/JSVMAPI/JsvmBasicDataTypes > .git/info/sparse-checkout +git remote add origin https://gitee.com/openharmony/applications_app_samples.git +git pull origin master +```` diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmBasicDataTypes_pr1/build-profile.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmBasicDataTypes_pr1/build-profile.json5 new file mode 100755 index 0000000000000000000000000000000000000000..d66ec0be93ce199018bb9fd923a2bdb8179e103e --- /dev/null +++ b/code/DocsSample/ArkTs/JSVMAPI/JsvmBasicDataTypes_pr1/build-profile.json5 @@ -0,0 +1,92 @@ +/* + * Copyright (c) 2025 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. + */ + +{ + "app": { + "signingConfigs": [], + "products": [ + { + "name": "default", + "signingConfig": "default", + "compatibleSdkVersion": "5.0.2(14)", + "runtimeOS": "HarmonyOS", + "buildOption": { + "strictMode": { + "caseSensitiveCheck": true, + "useNormalizedOHMUrl": true + } + } + } + ], + "buildModeSet": [ + { + "name": "debug", + }, + { + "name": "release" + } + ] + }, + "modules": [ + { + "name": "createint32", + "srcPath": "./createint32", + "targets": [ + { + "name": "default", + "applyToProducts": [ + "default" + ] + } + ] + }, + { + "name": "createuint32", + "srcPath": "./createuint32", + "targets": [ + { + "name": "default", + "applyToProducts": [ + "default" + ] + } + ] + }, + { + "name": "createint64", + "srcPath": "./createint64", + "targets": [ + { + "name": "default", + "applyToProducts": [ + "default" + ] + } + ] + }, + { + "name": "createdouble", + "srcPath": "./createdouble", + "targets": [ + { + "name": "default", + "applyToProducts": [ + "default" + ] + } + ] + } + ] +} diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmBasicDataTypes_pr1/code-linter.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmBasicDataTypes_pr1/code-linter.json5 new file mode 100755 index 0000000000000000000000000000000000000000..ed05653cca31b61d64cf6471529eaf50d4f70709 --- /dev/null +++ b/code/DocsSample/ArkTs/JSVMAPI/JsvmBasicDataTypes_pr1/code-linter.json5 @@ -0,0 +1,47 @@ +/* + * Copyright (c) 2025 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. + */ + +{ + "files": [ + "**/*.ets" + ], + "ignore": [ + "**/src/ohosTest/**/*", + "**/src/test/**/*", + "**/src/mock/**/*", + "**/node_modules/**/*", + "**/oh_modules/**/*", + "**/build/**/*", + "**/.preview/**/*" + ], + "ruleSet": [ + "plugin:@performance/recommended", + "plugin:@typescript-eslint/recommended" + ], + "rules": { + "@security/no-unsafe-aes": "error", + "@security/no-unsafe-hash": "error", + "@security/no-unsafe-mac": "warn", + "@security/no-unsafe-dh": "error", + "@security/no-unsafe-dsa": "error", + "@security/no-unsafe-ecdsa": "error", + "@security/no-unsafe-rsa-encrypt": "error", + "@security/no-unsafe-rsa-sign": "error", + "@security/no-unsafe-rsa-key": "error", + "@security/no-unsafe-dsa-key": "error", + "@security/no-unsafe-dh-key": "error", + "@security/no-unsafe-3des": "error" + } +} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmBasicDataTypes_pr1/createdouble/.gitignore b/code/DocsSample/ArkTs/JSVMAPI/JsvmBasicDataTypes_pr1/createdouble/.gitignore new file mode 100755 index 0000000000000000000000000000000000000000..e2713a2779c5a3e0eb879efe6115455592caeea5 --- /dev/null +++ b/code/DocsSample/ArkTs/JSVMAPI/JsvmBasicDataTypes_pr1/createdouble/.gitignore @@ -0,0 +1,6 @@ +/node_modules +/oh_modules +/.preview +/build +/.cxx +/.test \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmBasicDataTypes_pr1/createdouble/build-profile.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmBasicDataTypes_pr1/createdouble/build-profile.json5 new file mode 100755 index 0000000000000000000000000000000000000000..2c0104dcb596135013aa98865f37de336700177a --- /dev/null +++ b/code/DocsSample/ArkTs/JSVMAPI/JsvmBasicDataTypes_pr1/createdouble/build-profile.json5 @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2025 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. + */ + +{ + "apiType": "stageMode", + "buildOption": { + "externalNativeOptions": { + "path": "./src/main/cpp/CMakeLists.txt", + "arguments": "", + "cppFlags": "", + } + }, + "buildOptionSet": [ + { + "name": "release", + "arkOptions": { + "obfuscation": { + "ruleOptions": { + "enable": false, + "files": [ + "./obfuscation-rules.txt" + ] + } + } + }, + "nativeLib": { + "debugSymbol": { + "strip": true, + "exclude": [] + } + } + }, + ], + "targets": [ + { + "name": "default" + }, + { + "name": "ohosTest", + } + ] +} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmBasicDataTypes_pr1/createdouble/hvigorfile.ts b/code/DocsSample/ArkTs/JSVMAPI/JsvmBasicDataTypes_pr1/createdouble/hvigorfile.ts new file mode 100755 index 0000000000000000000000000000000000000000..e4f43d54667f8327c367c8096bd08bb8c75aff54 --- /dev/null +++ b/code/DocsSample/ArkTs/JSVMAPI/JsvmBasicDataTypes_pr1/createdouble/hvigorfile.ts @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2025 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 { hapTasks } from '@ohos/hvigor-ohos-plugin'; + +export default { + system: hapTasks, /* Built-in plugin of Hvigor. It cannot be modified. */ + plugins:[] /* Custom plugin to extend the functionality of Hvigor. */ +} diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmBasicDataTypes_pr1/createdouble/obfuscation-rules.txt b/code/DocsSample/ArkTs/JSVMAPI/JsvmBasicDataTypes_pr1/createdouble/obfuscation-rules.txt new file mode 100755 index 0000000000000000000000000000000000000000..272efb6ca3f240859091bbbfc7c5802d52793b0b --- /dev/null +++ b/code/DocsSample/ArkTs/JSVMAPI/JsvmBasicDataTypes_pr1/createdouble/obfuscation-rules.txt @@ -0,0 +1,23 @@ +# Define project specific obfuscation rules here. +# You can include the obfuscation configuration files in the current module's build-profile.json5. +# +# For more details, see +# https://developer.huawei.com/consumer/cn/doc/harmonyos-guides-V5/source-obfuscation-V5 + +# Obfuscation options: +# -disable-obfuscation: disable all obfuscations +# -enable-property-obfuscation: obfuscate the property names +# -enable-toplevel-obfuscation: obfuscate the names in the global scope +# -compact: remove unnecessary blank spaces and all line feeds +# -remove-log: remove all console.* statements +# -print-namecache: print the name cache that contains the mapping from the old names to new names +# -apply-namecache: reuse the given cache file + +# Keep options: +# -keep-property-name: specifies property names that you want to keep +# -keep-global-name: specifies names that you want to keep in the global scope + +-enable-property-obfuscation +-enable-toplevel-obfuscation +-enable-filename-obfuscation +-enable-export-obfuscation \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmBasicDataTypes_pr1/createdouble/oh-package.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmBasicDataTypes_pr1/createdouble/oh-package.json5 new file mode 100755 index 0000000000000000000000000000000000000000..2ffad1e6aba3494f0bbfcb121b8396d545896871 --- /dev/null +++ b/code/DocsSample/ArkTs/JSVMAPI/JsvmBasicDataTypes_pr1/createdouble/oh-package.json5 @@ -0,0 +1,26 @@ +/* + * Copyright (c) 2025 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. + */ + +{ + "name": "createdouble", + "version": "1.0.0", + "description": "Please describe the basic information.", + "main": "", + "author": "", + "license": "", + "dependencies": { + "libcreatedouble.so": "file:./src/main/cpp/types/libcreatedouble" + } +} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmBasicDataTypes_pr1/createdouble/src/main/cpp/CMakeLists.txt b/code/DocsSample/ArkTs/JSVMAPI/JsvmBasicDataTypes_pr1/createdouble/src/main/cpp/CMakeLists.txt new file mode 100755 index 0000000000000000000000000000000000000000..8defe1820f7c3e3625b480d83057fd806e6f4ea7 --- /dev/null +++ b/code/DocsSample/ArkTs/JSVMAPI/JsvmBasicDataTypes_pr1/createdouble/src/main/cpp/CMakeLists.txt @@ -0,0 +1,14 @@ +cmake_minimum_required(VERSION 3.4.1) +project(UsageInstructionsTwo) + +set(NATIVERENDER_ROOT_PATH ${CMAKE_CURRENT_SOURCE_DIR}) +# 日志打印配置 +add_definitions( "-DLOG_DOMAIN=0xd0d0" ) +add_definitions( "-DLOG_TAG=\"testTag\"" ) +include_directories(${NATIVERENDER_ROOT_PATH} + ${NATIVERENDER_ROOT_PATH}/include) + +# 添加名为entry的库 +add_library(createdouble SHARED hello.cpp) +# 构建此可执行文件需要链接的库 +target_link_libraries(createdouble PUBLIC libace_napi.z.so libjsvm.so libhilog_ndk.z.so) \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmBasicDataTypes_pr1/createdouble/src/main/cpp/hello.cpp b/code/DocsSample/ArkTs/JSVMAPI/JsvmBasicDataTypes_pr1/createdouble/src/main/cpp/hello.cpp new file mode 100755 index 0000000000000000000000000000000000000000..e0f1cd5f808881335cec5f1caeeb27384807a432 --- /dev/null +++ b/code/DocsSample/ArkTs/JSVMAPI/JsvmBasicDataTypes_pr1/createdouble/src/main/cpp/hello.cpp @@ -0,0 +1,153 @@ +/* + * Copyright (c) 2025 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. + */ + +#include "napi/native_api.h" +#include "hilog/log.h" +#include "ark_runtime/jsvm.h" + +#define LOG_DOMAIN 0x3200 +#define LOG_TAG "APP" + +static int g_aa = 0; + +#define CHECK_RET(theCall) \ + do { \ + JSVM_Status cond = theCall; \ + if ((cond) != JSVM_OK) { \ + const JSVM_ExtendedErrorInfo *info; \ + OH_JSVM_GetLastErrorInfo(env, &info); \ + OH_LOG_ERROR(LOG_APP, "jsvm fail file: %{public}s line: %{public}d ret = %{public}d message = %{public}s", \ + __FILE__, __LINE__, cond, info != nullptr ? info->errorMessage : ""); \ + return -1; \ + } \ + } while (0) + +#define CHECK(theCall) \ + do { \ + JSVM_Status cond = theCall; \ + if ((cond) != JSVM_OK) { \ + OH_LOG_ERROR(LOG_APP, "jsvm fail file: %{public}s line: %{public}d ret = %{public}d", __FILE__, __LINE__, \ + cond); \ + return -1; \ + } \ + } while (0) + +// 用于调用theCall并检查其返回值是否为JSVM_OK。 +// 如果不是,则调用OH_JSVM_GetLastErrorInfo处理错误并返回retVal。 +#define JSVM_CALL_BASE(env, theCall, retVal) \ + do { \ + JSVM_Status cond = theCall; \ + if (cond != JSVM_OK) { \ + const JSVM_ExtendedErrorInfo *info; \ + OH_JSVM_GetLastErrorInfo(env, &info); \ + OH_LOG_ERROR(LOG_APP, "jsvm fail file: %{public}s line: %{public}d ret = %{public}d message = %{public}s", \ + __FILE__, __LINE__, cond, info != nullptr ? info->errorMessage : ""); \ + return retVal; \ + } \ + } while (0) + +// JSVM_CALL_BASE的简化版本,返回nullptr +#define JSVM_CALL(theCall) JSVM_CALL_BASE(env, theCall, nullptr) + +// OH_JSVM_CreateDouble的样例方法 +static JSVM_Value CreateDouble(JSVM_Env env, JSVM_CallbackInfo info) +{ + double value = 1.234; + // 创建JavaScript中的double数字 + JSVM_Value result = nullptr; + JSVM_Status status = OH_JSVM_CreateDouble(env, value, &result); + if (status != JSVM_OK) { + OH_LOG_ERROR(LOG_APP, "JSVM CreateDouble fail"); + } else { + double number = 0; + OH_JSVM_GetValueDouble(env, result, &number); + OH_LOG_INFO(LOG_APP, "JSVM CreateDouble success: %{public}f", number); + } + return result; +} + +static JSVM_CallbackStruct param[] = { + {.data = nullptr, .callback = CreateDouble}, +}; +static JSVM_CallbackStruct *method = param; +// CreateDouble方法别名,供JS调用 +static JSVM_PropertyDescriptor descriptor[] = { + {"createDouble", nullptr, method++, nullptr, nullptr, nullptr, JSVM_DEFAULT}, +}; + +// 样例测试js +const char* srcCallNative = R"JS(createDouble())JS"; + +static int32_t TestJSVM() { + JSVM_InitOptions initOptions = {0}; + JSVM_VM vm; + JSVM_Env env = nullptr; + JSVM_VMScope vmScope; + JSVM_EnvScope envScope; + JSVM_HandleScope handleScope; + JSVM_Value result; + // 初始化JavaScript引擎实例 + if (g_aa == 0) { + g_aa++; + CHECK(OH_JSVM_Init(&initOptions)); + } + // 创建JSVM环境 + CHECK(OH_JSVM_CreateVM(nullptr, &vm)); + CHECK(OH_JSVM_CreateEnv(vm, sizeof(descriptor) / sizeof(descriptor[0]), descriptor, &env)); + CHECK(OH_JSVM_OpenVMScope(vm, &vmScope)); + CHECK_RET(OH_JSVM_OpenEnvScope(env, &envScope)); + CHECK_RET(OH_JSVM_OpenHandleScope(env, &handleScope)); + + // 通过script调用测试函数 + JSVM_Script script; + JSVM_Value jsSrc; + CHECK_RET(OH_JSVM_CreateStringUtf8(env, srcCallNative, JSVM_AUTO_LENGTH, &jsSrc)); + CHECK_RET(OH_JSVM_CompileScript(env, jsSrc, nullptr, 0, true, nullptr, &script)); + CHECK_RET(OH_JSVM_RunScript(env, script, &result)); + + // 销毁JSVM环境 + CHECK_RET(OH_JSVM_CloseHandleScope(env, handleScope)); + CHECK_RET(OH_JSVM_CloseEnvScope(env, envScope)); + CHECK(OH_JSVM_CloseVMScope(vm, vmScope)); + CHECK(OH_JSVM_DestroyEnv(env)); + CHECK(OH_JSVM_DestroyVM(vm)); + return 0; +} + +static napi_value RunTest(napi_env env, napi_callback_info info) { + TestJSVM(); + return nullptr; +} + +// 模块注册信息,供arkts侧调用 +EXTERN_C_START +static napi_value Init(napi_env env, napi_value exports) { + napi_property_descriptor desc[] = {{"runTest", nullptr, RunTest, nullptr, nullptr, nullptr, napi_default, nullptr}}; + napi_define_properties(env, exports, sizeof(desc) / sizeof(desc[0]), desc); + return exports; +} +EXTERN_C_END + +static napi_module demoModule = { + .nm_version = 1, + .nm_flags = 0, + .nm_filename = nullptr, + .nm_register_func = Init, + .nm_modname = "createdouble", + .nm_priv = ((void *)0), + .reserved = {0}, +}; + +extern "C" __attribute__((constructor)) void RegisterEntryModule(void) { napi_module_register(&demoModule); } \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmBasicDataTypes_pr1/createdouble/src/main/cpp/types/libcreatedouble/Index.d.ts b/code/DocsSample/ArkTs/JSVMAPI/JsvmBasicDataTypes_pr1/createdouble/src/main/cpp/types/libcreatedouble/Index.d.ts new file mode 100755 index 0000000000000000000000000000000000000000..8fc2c9e21ff1c104f0d0649acc1b5ea70ba4bab3 --- /dev/null +++ b/code/DocsSample/ArkTs/JSVMAPI/JsvmBasicDataTypes_pr1/createdouble/src/main/cpp/types/libcreatedouble/Index.d.ts @@ -0,0 +1,16 @@ +/* + * Copyright (c) 2025 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 const runTest: () => void; \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmBasicDataTypes_pr1/createdouble/src/main/cpp/types/libcreatedouble/oh-package.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmBasicDataTypes_pr1/createdouble/src/main/cpp/types/libcreatedouble/oh-package.json5 new file mode 100755 index 0000000000000000000000000000000000000000..3fb55a4452ec27a4a15ed27fa8ceb137c0183811 --- /dev/null +++ b/code/DocsSample/ArkTs/JSVMAPI/JsvmBasicDataTypes_pr1/createdouble/src/main/cpp/types/libcreatedouble/oh-package.json5 @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2025 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. + */ + +{ + "name": "libcreatedouble.so", + "types": "./Index.d.ts", + "version": "1.0.0", + "description": "Please describe the basic information." +} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmBasicDataTypes_pr1/createdouble/src/main/ets/createdoubleability/CreatedoubleAbility.ets b/code/DocsSample/ArkTs/JSVMAPI/JsvmBasicDataTypes_pr1/createdouble/src/main/ets/createdoubleability/CreatedoubleAbility.ets new file mode 100755 index 0000000000000000000000000000000000000000..d67f550837a6b8c560ca5cce48e2af13a2e3aaf2 --- /dev/null +++ b/code/DocsSample/ArkTs/JSVMAPI/JsvmBasicDataTypes_pr1/createdouble/src/main/ets/createdoubleability/CreatedoubleAbility.ets @@ -0,0 +1,58 @@ +/* + * Copyright (c) 2025 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 { AbilityConstant, UIAbility, Want } from '@kit.AbilityKit'; +import { hilog } from '@kit.PerformanceAnalysisKit'; +import { window } from '@kit.ArkUI'; + +const DOMAIN = 0x0000; + +export default class CreatedoubleAbility extends UIAbility { + onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void { + hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onCreate'); + } + + onDestroy(): void { + hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onDestroy'); + } + + onWindowStageCreate(windowStage: window.WindowStage): void { + // Main window is created, set main page for this ability + hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onWindowStageCreate'); + + windowStage.loadContent('pages/Index', (err) => { + if (err.code) { + hilog.error(DOMAIN, 'testTag', 'Failed to load the content. Cause: %{public}s', JSON.stringify(err)); + return; + } + hilog.info(DOMAIN, 'testTag', 'Succeeded in loading the content.'); + }); + } + + onWindowStageDestroy(): void { + // Main window is destroyed, release UI related resources + hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onWindowStageDestroy'); + } + + onForeground(): void { + // Ability has brought to foreground + hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onForeground'); + } + + onBackground(): void { + // Ability has back to background + hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onBackground'); + } +} diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmBasicDataTypes_pr1/createdouble/src/main/ets/pages/Index.ets b/code/DocsSample/ArkTs/JSVMAPI/JsvmBasicDataTypes_pr1/createdouble/src/main/ets/pages/Index.ets new file mode 100755 index 0000000000000000000000000000000000000000..c427922fde3d0495824e7196e364ec703ea9bf4f --- /dev/null +++ b/code/DocsSample/ArkTs/JSVMAPI/JsvmBasicDataTypes_pr1/createdouble/src/main/ets/pages/Index.ets @@ -0,0 +1,57 @@ +/* + * Copyright (c) 2025 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. + */ +/* + * Copyright (c) 2025 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 napitest from 'libcreatedouble.so'; + +@Entry +@Component +struct Index { + @State message: string = 'OH_JSVM_CreateDouble'; + + build() { + Row() { + Column() { + Text(this.message) + .fontSize(30) + .fontWeight(FontWeight.Bold) + .onClick(() => { + try { + napitest.runTest(); + this.message = 'success'; + } catch (error) { + console.error('An error occurred: ', error); + this.message = 'fail'; + } + }) + } + .width('100%') + } + .height('100%') + } +} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmBasicDataTypes_pr1/createdouble/src/main/module.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmBasicDataTypes_pr1/createdouble/src/main/module.json5 new file mode 100755 index 0000000000000000000000000000000000000000..ff2cfde8bf2ff8d686bd69e0cf01b1bf7245937a --- /dev/null +++ b/code/DocsSample/ArkTs/JSVMAPI/JsvmBasicDataTypes_pr1/createdouble/src/main/module.json5 @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2025 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. + */ + +{ + "module": { + "name": "createdouble", + "type": "feature", + "description": "$string:module_desc", + "mainElement": "CreatedoubleAbility", + "deviceTypes": [ + "phone", + "tablet", + "2in1" + ], + "deliveryWithInstall": true, + "installationFree": false, + "pages": "$profile:main_pages", + "abilities": [ + { + "name": "CreatedoubleAbility", + "srcEntry": "./ets/createdoubleability/CreatedoubleAbility.ets", + "description": "$string:CreatedoubleAbility_desc", + "icon": "$media:layered_image", + "label": "$string:CreatedoubleAbility_label", + "startWindowIcon": "$media:startIcon", + "startWindowBackground": "$color:start_window_background", + "exported": true + } + ] + } +} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmBasicDataTypes_pr1/createdouble/src/main/resources/base/element/color.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmBasicDataTypes_pr1/createdouble/src/main/resources/base/element/color.json new file mode 100755 index 0000000000000000000000000000000000000000..d66f9a7d4ac61fb8d215239ab3620b7bcd77bf33 --- /dev/null +++ b/code/DocsSample/ArkTs/JSVMAPI/JsvmBasicDataTypes_pr1/createdouble/src/main/resources/base/element/color.json @@ -0,0 +1,8 @@ +{ + "color": [ + { + "name": "start_window_background", + "value": "#FFFFFF" + } + ] +} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmBasicDataTypes_pr1/createdouble/src/main/resources/base/element/float.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmBasicDataTypes_pr1/createdouble/src/main/resources/base/element/float.json new file mode 100755 index 0000000000000000000000000000000000000000..a8a5d404dcd8b0466194afc3aa25d90a8a327470 --- /dev/null +++ b/code/DocsSample/ArkTs/JSVMAPI/JsvmBasicDataTypes_pr1/createdouble/src/main/resources/base/element/float.json @@ -0,0 +1,8 @@ +{ + "float": [ + { + "name": "page_text_font_size", + "value": "50fp" + } + ] +} diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmBasicDataTypes_pr1/createdouble/src/main/resources/base/element/string.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmBasicDataTypes_pr1/createdouble/src/main/resources/base/element/string.json new file mode 100755 index 0000000000000000000000000000000000000000..e1275bfb9201a3f0ac8c48d4b8277cbe60ccdd75 --- /dev/null +++ b/code/DocsSample/ArkTs/JSVMAPI/JsvmBasicDataTypes_pr1/createdouble/src/main/resources/base/element/string.json @@ -0,0 +1,16 @@ +{ + "string": [ + { + "name": "module_desc", + "value": "module description" + }, + { + "name": "CreatedoubleAbility_desc", + "value": "description" + }, + { + "name": "CreatedoubleAbility_label", + "value": "JsvmBasicDataTypes" + } + ] +} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmBasicDataTypes_pr1/createdouble/src/main/resources/base/media/background.png b/code/DocsSample/ArkTs/JSVMAPI/JsvmBasicDataTypes_pr1/createdouble/src/main/resources/base/media/background.png new file mode 100755 index 0000000000000000000000000000000000000000..923f2b3f27e915d6871871deea0420eb45ce102f Binary files /dev/null and b/code/DocsSample/ArkTs/JSVMAPI/JsvmBasicDataTypes_pr1/createdouble/src/main/resources/base/media/background.png differ diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmBasicDataTypes_pr1/createdouble/src/main/resources/base/media/foreground.png b/code/DocsSample/ArkTs/JSVMAPI/JsvmBasicDataTypes_pr1/createdouble/src/main/resources/base/media/foreground.png new file mode 100755 index 0000000000000000000000000000000000000000..97014d3e10e5ff511409c378cd4255713aecd85f Binary files /dev/null and b/code/DocsSample/ArkTs/JSVMAPI/JsvmBasicDataTypes_pr1/createdouble/src/main/resources/base/media/foreground.png differ diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmBasicDataTypes_pr1/createdouble/src/main/resources/base/media/layered_image.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmBasicDataTypes_pr1/createdouble/src/main/resources/base/media/layered_image.json new file mode 100755 index 0000000000000000000000000000000000000000..fb49920440fb4d246c82f9ada275e26123a2136a --- /dev/null +++ b/code/DocsSample/ArkTs/JSVMAPI/JsvmBasicDataTypes_pr1/createdouble/src/main/resources/base/media/layered_image.json @@ -0,0 +1,7 @@ +{ + "layered-image": + { + "background" : "$media:background", + "foreground" : "$media:foreground" + } +} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmBasicDataTypes_pr1/createdouble/src/main/resources/base/media/startIcon.png b/code/DocsSample/ArkTs/JSVMAPI/JsvmBasicDataTypes_pr1/createdouble/src/main/resources/base/media/startIcon.png new file mode 100755 index 0000000000000000000000000000000000000000..205ad8b5a8a42e8762fbe4899b8e5e31ce822b8b Binary files /dev/null and b/code/DocsSample/ArkTs/JSVMAPI/JsvmBasicDataTypes_pr1/createdouble/src/main/resources/base/media/startIcon.png differ diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmBasicDataTypes_pr1/createdouble/src/main/resources/base/profile/main_pages.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmBasicDataTypes_pr1/createdouble/src/main/resources/base/profile/main_pages.json new file mode 100755 index 0000000000000000000000000000000000000000..1898d94f58d6128ab712be2c68acc7c98e9ab9ce --- /dev/null +++ b/code/DocsSample/ArkTs/JSVMAPI/JsvmBasicDataTypes_pr1/createdouble/src/main/resources/base/profile/main_pages.json @@ -0,0 +1,5 @@ +{ + "src": [ + "pages/Index" + ] +} diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmBasicDataTypes_pr1/createdouble/src/ohosTest/ets/test/Ability.test.ets b/code/DocsSample/ArkTs/JSVMAPI/JsvmBasicDataTypes_pr1/createdouble/src/ohosTest/ets/test/Ability.test.ets new file mode 100755 index 0000000000000000000000000000000000000000..5f0c1a03fb1db4af8d83a079a8c1baab10fde1af --- /dev/null +++ b/code/DocsSample/ArkTs/JSVMAPI/JsvmBasicDataTypes_pr1/createdouble/src/ohosTest/ets/test/Ability.test.ets @@ -0,0 +1,52 @@ +/* + * Copyright (c) 2025 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 { describe, it, expect } from '@ohos/hypium'; +import { abilityDelegatorRegistry, Driver, ON } from '@kit.TestKit'; +import { UIAbility, Want } from '@kit.AbilityKit'; + +const delegator: abilityDelegatorRegistry.AbilityDelegator = abilityDelegatorRegistry.getAbilityDelegator(); +const bundleName = abilityDelegatorRegistry.getArguments().bundleName; + +export default function abilityTest() { + describe('ActsAbilityTest', () => { + /** + * 打开应用,点击OH_JSVM_CreateDouble执行 + */ + it('testCreateDouble', 0, async (done: Function) => { + console.log('uitest: TestCreateDouble begin'); + + const want: Want = { + bundleName: bundleName, + abilityName: 'CreatedoubleAbility' + } + const driver = Driver.create(); + await delegator.startAbility(want); + await driver.delayMs(1000); + + const ability: UIAbility = await delegator.getCurrentTopAbility(); + console.log('get top ability'); + expect(ability.context.abilityInfo.name).assertEqual('CreatedoubleAbility'); + + await driver.delayMs(1000); + const text = await driver.findComponent(ON.text('OH_JSVM_CreateDouble')); + await text.click(); + await driver.delayMs(1000); + await driver.assertComponentExist(ON.text('success')); + console.log('uitest: TestCreateDouble end'); + done(); + }) + }) +} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmBasicDataTypes_pr1/createdouble/src/ohosTest/ets/test/List.test.ets b/code/DocsSample/ArkTs/JSVMAPI/JsvmBasicDataTypes_pr1/createdouble/src/ohosTest/ets/test/List.test.ets new file mode 100755 index 0000000000000000000000000000000000000000..1eac52fcebe8958e19a7b8fed2e8f39c520a3e42 --- /dev/null +++ b/code/DocsSample/ArkTs/JSVMAPI/JsvmBasicDataTypes_pr1/createdouble/src/ohosTest/ets/test/List.test.ets @@ -0,0 +1,20 @@ +/* + * Copyright (c) 2025 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 abilityTest from './Ability.test'; + +export default function testsuite() { + abilityTest(); +} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmBasicDataTypes_pr1/createdouble/src/ohosTest/module.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmBasicDataTypes_pr1/createdouble/src/ohosTest/module.json5 new file mode 100755 index 0000000000000000000000000000000000000000..9377e40ba1955d2b2c40b6b5fbd46cc9c079584e --- /dev/null +++ b/code/DocsSample/ArkTs/JSVMAPI/JsvmBasicDataTypes_pr1/createdouble/src/ohosTest/module.json5 @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2025 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. + */ + +{ + "module": { + "name": "createdouble_test", + "type": "feature", + "deviceTypes": [ + "phone", + "tablet", + "2in1" + ], + "deliveryWithInstall": true, + "installationFree": false + } +} diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmBasicDataTypes_pr1/createint32/.gitignore b/code/DocsSample/ArkTs/JSVMAPI/JsvmBasicDataTypes_pr1/createint32/.gitignore new file mode 100755 index 0000000000000000000000000000000000000000..e2713a2779c5a3e0eb879efe6115455592caeea5 --- /dev/null +++ b/code/DocsSample/ArkTs/JSVMAPI/JsvmBasicDataTypes_pr1/createint32/.gitignore @@ -0,0 +1,6 @@ +/node_modules +/oh_modules +/.preview +/build +/.cxx +/.test \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmBasicDataTypes_pr1/createint32/build-profile.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmBasicDataTypes_pr1/createint32/build-profile.json5 new file mode 100755 index 0000000000000000000000000000000000000000..2c0104dcb596135013aa98865f37de336700177a --- /dev/null +++ b/code/DocsSample/ArkTs/JSVMAPI/JsvmBasicDataTypes_pr1/createint32/build-profile.json5 @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2025 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. + */ + +{ + "apiType": "stageMode", + "buildOption": { + "externalNativeOptions": { + "path": "./src/main/cpp/CMakeLists.txt", + "arguments": "", + "cppFlags": "", + } + }, + "buildOptionSet": [ + { + "name": "release", + "arkOptions": { + "obfuscation": { + "ruleOptions": { + "enable": false, + "files": [ + "./obfuscation-rules.txt" + ] + } + } + }, + "nativeLib": { + "debugSymbol": { + "strip": true, + "exclude": [] + } + } + }, + ], + "targets": [ + { + "name": "default" + }, + { + "name": "ohosTest", + } + ] +} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmBasicDataTypes_pr1/createint32/hvigorfile.ts b/code/DocsSample/ArkTs/JSVMAPI/JsvmBasicDataTypes_pr1/createint32/hvigorfile.ts new file mode 100755 index 0000000000000000000000000000000000000000..e4f43d54667f8327c367c8096bd08bb8c75aff54 --- /dev/null +++ b/code/DocsSample/ArkTs/JSVMAPI/JsvmBasicDataTypes_pr1/createint32/hvigorfile.ts @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2025 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 { hapTasks } from '@ohos/hvigor-ohos-plugin'; + +export default { + system: hapTasks, /* Built-in plugin of Hvigor. It cannot be modified. */ + plugins:[] /* Custom plugin to extend the functionality of Hvigor. */ +} diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmBasicDataTypes_pr1/createint32/obfuscation-rules.txt b/code/DocsSample/ArkTs/JSVMAPI/JsvmBasicDataTypes_pr1/createint32/obfuscation-rules.txt new file mode 100755 index 0000000000000000000000000000000000000000..272efb6ca3f240859091bbbfc7c5802d52793b0b --- /dev/null +++ b/code/DocsSample/ArkTs/JSVMAPI/JsvmBasicDataTypes_pr1/createint32/obfuscation-rules.txt @@ -0,0 +1,23 @@ +# Define project specific obfuscation rules here. +# You can include the obfuscation configuration files in the current module's build-profile.json5. +# +# For more details, see +# https://developer.huawei.com/consumer/cn/doc/harmonyos-guides-V5/source-obfuscation-V5 + +# Obfuscation options: +# -disable-obfuscation: disable all obfuscations +# -enable-property-obfuscation: obfuscate the property names +# -enable-toplevel-obfuscation: obfuscate the names in the global scope +# -compact: remove unnecessary blank spaces and all line feeds +# -remove-log: remove all console.* statements +# -print-namecache: print the name cache that contains the mapping from the old names to new names +# -apply-namecache: reuse the given cache file + +# Keep options: +# -keep-property-name: specifies property names that you want to keep +# -keep-global-name: specifies names that you want to keep in the global scope + +-enable-property-obfuscation +-enable-toplevel-obfuscation +-enable-filename-obfuscation +-enable-export-obfuscation \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmBasicDataTypes_pr1/createint32/oh-package.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmBasicDataTypes_pr1/createint32/oh-package.json5 new file mode 100755 index 0000000000000000000000000000000000000000..3ddb6a7f84c19862ab4aba77d3244740a298cb02 --- /dev/null +++ b/code/DocsSample/ArkTs/JSVMAPI/JsvmBasicDataTypes_pr1/createint32/oh-package.json5 @@ -0,0 +1,26 @@ +/* + * Copyright (c) 2025 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. + */ + +{ + "name": "createint32", + "version": "1.0.0", + "description": "Please describe the basic information.", + "main": "", + "author": "", + "license": "", + "dependencies": { + "libcreateint32.so": "file:./src/main/cpp/types/libcreateint32" + } +} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmBasicDataTypes_pr1/createint32/src/main/cpp/CMakeLists.txt b/code/DocsSample/ArkTs/JSVMAPI/JsvmBasicDataTypes_pr1/createint32/src/main/cpp/CMakeLists.txt new file mode 100755 index 0000000000000000000000000000000000000000..b4b5138d8ceb4c2dbd8c3d8fac3e8217ef0ebaea --- /dev/null +++ b/code/DocsSample/ArkTs/JSVMAPI/JsvmBasicDataTypes_pr1/createint32/src/main/cpp/CMakeLists.txt @@ -0,0 +1,14 @@ +cmake_minimum_required(VERSION 3.4.1) +project(UsageInstructionsTwo) + +set(NATIVERENDER_ROOT_PATH ${CMAKE_CURRENT_SOURCE_DIR}) +# 日志打印配置 +add_definitions( "-DLOG_DOMAIN=0xd0d0" ) +add_definitions( "-DLOG_TAG=\"testTag\"" ) +include_directories(${NATIVERENDER_ROOT_PATH} + ${NATIVERENDER_ROOT_PATH}/include) + +# 添加名为entry的库 +add_library(createint32 SHARED hello.cpp) +# 构建此可执行文件需要链接的库 +target_link_libraries(createint32 PUBLIC libace_napi.z.so libjsvm.so libhilog_ndk.z.so) \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmBasicDataTypes_pr1/createint32/src/main/cpp/hello.cpp b/code/DocsSample/ArkTs/JSVMAPI/JsvmBasicDataTypes_pr1/createint32/src/main/cpp/hello.cpp new file mode 100755 index 0000000000000000000000000000000000000000..4c980910394cec30ec5fce8667fc85b34a111004 --- /dev/null +++ b/code/DocsSample/ArkTs/JSVMAPI/JsvmBasicDataTypes_pr1/createint32/src/main/cpp/hello.cpp @@ -0,0 +1,154 @@ +/* + * Copyright (c) 2025 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. + */ + +#include "napi/native_api.h" +#include "hilog/log.h" +#include "ark_runtime/jsvm.h" + +#define LOG_DOMAIN 0x3200 +#define LOG_TAG "APP" + +static int g_aa = 0; + +#define CHECK_RET(theCall) \ + do { \ + JSVM_Status cond = theCall; \ + if ((cond) != JSVM_OK) { \ + const JSVM_ExtendedErrorInfo *info; \ + OH_JSVM_GetLastErrorInfo(env, &info); \ + OH_LOG_ERROR(LOG_APP, "jsvm fail file: %{public}s line: %{public}d ret = %{public}d message = %{public}s", \ + __FILE__, __LINE__, cond, info != nullptr ? info->errorMessage : ""); \ + return -1; \ + } \ + } while (0) + +#define CHECK(theCall) \ + do { \ + JSVM_Status cond = theCall; \ + if ((cond) != JSVM_OK) { \ + OH_LOG_ERROR(LOG_APP, "jsvm fail file: %{public}s line: %{public}d ret = %{public}d", __FILE__, __LINE__, \ + cond); \ + return -1; \ + } \ + } while (0) + +// 用于调用theCall并检查其返回值是否为JSVM_OK。 +// 如果不是,则调用OH_JSVM_GetLastErrorInfo处理错误并返回retVal。 +#define JSVM_CALL_BASE(env, theCall, retVal) \ + do { \ + JSVM_Status cond = theCall; \ + if (cond != JSVM_OK) { \ + const JSVM_ExtendedErrorInfo *info; \ + OH_JSVM_GetLastErrorInfo(env, &info); \ + OH_LOG_ERROR(LOG_APP, "jsvm fail file: %{public}s line: %{public}d ret = %{public}d message = %{public}s", \ + __FILE__, __LINE__, cond, info != nullptr ? info->errorMessage : ""); \ + return retVal; \ + } \ + } while (0) + +// JSVM_CALL_BASE的简化版本,返回nullptr +#define JSVM_CALL(theCall) JSVM_CALL_BASE(env, theCall, nullptr) + +// OH_JSVM_CreateInt32的样例方法 +static JSVM_Value CreateInt32(JSVM_Env env, JSVM_CallbackInfo info) +{ + int32_t value = -20; + // 创建JavaScript中的int32数字 + JSVM_Value result = nullptr; + JSVM_Status status = OH_JSVM_CreateInt32(env, value, &result); + if (status != JSVM_OK) { + OH_LOG_ERROR(LOG_APP, "JSVM CreateInt32 fail"); + } else { + int32_t number = 0; + OH_JSVM_GetValueInt32(env, result, &number); + OH_LOG_INFO(LOG_APP, "JSVM CreateInt32 success: %{public}d", number); + } + return result; +} + +// CreateInt32注册回调 +static JSVM_CallbackStruct param[] = { + {.data = nullptr, .callback = CreateInt32}, +}; +static JSVM_CallbackStruct *method = param; +// CreateInt32方法别名,供JS调用 +static JSVM_PropertyDescriptor descriptor[] = { + {"createInt32", nullptr, method++, nullptr, nullptr, nullptr, JSVM_DEFAULT}, +}; + +// 样例测试js +const char* srcCallNative = R"JS(createInt32())JS"; + +static int32_t TestJSVM() { + JSVM_InitOptions initOptions = {0}; + JSVM_VM vm; + JSVM_Env env = nullptr; + JSVM_VMScope vmScope; + JSVM_EnvScope envScope; + JSVM_HandleScope handleScope; + JSVM_Value result; + // 初始化JavaScript引擎实例 + if (g_aa == 0) { + g_aa++; + CHECK(OH_JSVM_Init(&initOptions)); + } + // 创建JSVM环境 + CHECK(OH_JSVM_CreateVM(nullptr, &vm)); + CHECK(OH_JSVM_CreateEnv(vm, sizeof(descriptor) / sizeof(descriptor[0]), descriptor, &env)); + CHECK(OH_JSVM_OpenVMScope(vm, &vmScope)); + CHECK_RET(OH_JSVM_OpenEnvScope(env, &envScope)); + CHECK_RET(OH_JSVM_OpenHandleScope(env, &handleScope)); + + // 通过script调用测试函数 + JSVM_Script script; + JSVM_Value jsSrc; + CHECK_RET(OH_JSVM_CreateStringUtf8(env, srcCallNative, JSVM_AUTO_LENGTH, &jsSrc)); + CHECK_RET(OH_JSVM_CompileScript(env, jsSrc, nullptr, 0, true, nullptr, &script)); + CHECK_RET(OH_JSVM_RunScript(env, script, &result)); + + // 销毁JSVM环境 + CHECK_RET(OH_JSVM_CloseHandleScope(env, handleScope)); + CHECK_RET(OH_JSVM_CloseEnvScope(env, envScope)); + CHECK(OH_JSVM_CloseVMScope(vm, vmScope)); + CHECK(OH_JSVM_DestroyEnv(env)); + CHECK(OH_JSVM_DestroyVM(vm)); + return 0; +} + +static napi_value RunTest(napi_env env, napi_callback_info info) { + TestJSVM(); + return nullptr; +} + +// 模块注册信息,供arkts侧调用 +EXTERN_C_START +static napi_value Init(napi_env env, napi_value exports) { + napi_property_descriptor desc[] = {{"runTest", nullptr, RunTest, nullptr, nullptr, nullptr, napi_default, nullptr}}; + napi_define_properties(env, exports, sizeof(desc) / sizeof(desc[0]), desc); + return exports; +} +EXTERN_C_END + +static napi_module demoModule = { + .nm_version = 1, + .nm_flags = 0, + .nm_filename = nullptr, + .nm_register_func = Init, + .nm_modname = "createint32", + .nm_priv = ((void *)0), + .reserved = {0}, +}; + +extern "C" __attribute__((constructor)) void RegisterEntryModule(void) { napi_module_register(&demoModule); } \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmBasicDataTypes_pr1/createint32/src/main/cpp/types/libcreateint32/Index.d.ts b/code/DocsSample/ArkTs/JSVMAPI/JsvmBasicDataTypes_pr1/createint32/src/main/cpp/types/libcreateint32/Index.d.ts new file mode 100755 index 0000000000000000000000000000000000000000..8fc2c9e21ff1c104f0d0649acc1b5ea70ba4bab3 --- /dev/null +++ b/code/DocsSample/ArkTs/JSVMAPI/JsvmBasicDataTypes_pr1/createint32/src/main/cpp/types/libcreateint32/Index.d.ts @@ -0,0 +1,16 @@ +/* + * Copyright (c) 2025 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 const runTest: () => void; \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmBasicDataTypes_pr1/createint32/src/main/cpp/types/libcreateint32/oh-package.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmBasicDataTypes_pr1/createint32/src/main/cpp/types/libcreateint32/oh-package.json5 new file mode 100755 index 0000000000000000000000000000000000000000..7e936c3553ddcf771fc36f4b4fc559e43e2653e4 --- /dev/null +++ b/code/DocsSample/ArkTs/JSVMAPI/JsvmBasicDataTypes_pr1/createint32/src/main/cpp/types/libcreateint32/oh-package.json5 @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2025 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. + */ + +{ + "name": "libcreateint32.so", + "types": "./Index.d.ts", + "version": "1.0.0", + "description": "Please describe the basic information." +} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmBasicDataTypes_pr1/createint32/src/main/ets/createint32ability/Createint32Ability.ets b/code/DocsSample/ArkTs/JSVMAPI/JsvmBasicDataTypes_pr1/createint32/src/main/ets/createint32ability/Createint32Ability.ets new file mode 100755 index 0000000000000000000000000000000000000000..19e4b37789b986925fa04b69dc9a50e166135f02 --- /dev/null +++ b/code/DocsSample/ArkTs/JSVMAPI/JsvmBasicDataTypes_pr1/createint32/src/main/ets/createint32ability/Createint32Ability.ets @@ -0,0 +1,58 @@ +/* + * Copyright (c) 2025 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 { AbilityConstant, UIAbility, Want } from '@kit.AbilityKit'; +import { hilog } from '@kit.PerformanceAnalysisKit'; +import { window } from '@kit.ArkUI'; + +const DOMAIN = 0x0000; + +export default class Createint32Ability extends UIAbility { + onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void { + hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onCreate'); + } + + onDestroy(): void { + hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onDestroy'); + } + + onWindowStageCreate(windowStage: window.WindowStage): void { + // Main window is created, set main page for this ability + hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onWindowStageCreate'); + + windowStage.loadContent('pages/Index', (err) => { + if (err.code) { + hilog.error(DOMAIN, 'testTag', 'Failed to load the content. Cause: %{public}s', JSON.stringify(err)); + return; + } + hilog.info(DOMAIN, 'testTag', 'Succeeded in loading the content.'); + }); + } + + onWindowStageDestroy(): void { + // Main window is destroyed, release UI related resources + hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onWindowStageDestroy'); + } + + onForeground(): void { + // Ability has brought to foreground + hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onForeground'); + } + + onBackground(): void { + // Ability has back to background + hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onBackground'); + } +} diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmBasicDataTypes_pr1/createint32/src/main/ets/pages/Index.ets b/code/DocsSample/ArkTs/JSVMAPI/JsvmBasicDataTypes_pr1/createint32/src/main/ets/pages/Index.ets new file mode 100755 index 0000000000000000000000000000000000000000..6e2bbe21add0c0b735363faee83468f7b47fbc07 --- /dev/null +++ b/code/DocsSample/ArkTs/JSVMAPI/JsvmBasicDataTypes_pr1/createint32/src/main/ets/pages/Index.ets @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2025 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 napitest from 'libcreateint32.so'; + +@Entry +@Component +struct Index { + @State message: string = 'OH_JSVM_CreateInt32'; + + build() { + Row() { + Column() { + Text(this.message) + .fontSize(30) + .fontWeight(FontWeight.Bold) + .onClick(() => { + try { + napitest.runTest(); + this.message = 'success'; + } catch (error) { + console.error('An error occurred: ', error); + this.message = 'fail'; + } + }) + } + .width('100%') + } + .height('100%') + } +} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmBasicDataTypes_pr1/createint32/src/main/module.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmBasicDataTypes_pr1/createint32/src/main/module.json5 new file mode 100755 index 0000000000000000000000000000000000000000..b3c8b90365bc3e7826d8dc4cfe0f00b53205d04f --- /dev/null +++ b/code/DocsSample/ArkTs/JSVMAPI/JsvmBasicDataTypes_pr1/createint32/src/main/module.json5 @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2025 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. + */ + +{ + "module": { + "name": "createint32", + "type": "feature", + "description": "$string:module_desc", + "mainElement": "Createint32Ability", + "deviceTypes": [ + "phone", + "tablet", + "2in1" + ], + "deliveryWithInstall": true, + "installationFree": false, + "pages": "$profile:main_pages", + "abilities": [ + { + "name": "Createint32Ability", + "srcEntry": "./ets/createint32ability/Createint32Ability.ets", + "description": "$string:Createint32Ability_desc", + "icon": "$media:layered_image", + "label": "$string:Createint32Ability_label", + "startWindowIcon": "$media:startIcon", + "startWindowBackground": "$color:start_window_background", + "exported": true + } + ] + } +} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmBasicDataTypes_pr1/createint32/src/main/resources/base/element/color.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmBasicDataTypes_pr1/createint32/src/main/resources/base/element/color.json new file mode 100755 index 0000000000000000000000000000000000000000..d66f9a7d4ac61fb8d215239ab3620b7bcd77bf33 --- /dev/null +++ b/code/DocsSample/ArkTs/JSVMAPI/JsvmBasicDataTypes_pr1/createint32/src/main/resources/base/element/color.json @@ -0,0 +1,8 @@ +{ + "color": [ + { + "name": "start_window_background", + "value": "#FFFFFF" + } + ] +} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmBasicDataTypes_pr1/createint32/src/main/resources/base/element/float.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmBasicDataTypes_pr1/createint32/src/main/resources/base/element/float.json new file mode 100755 index 0000000000000000000000000000000000000000..a8a5d404dcd8b0466194afc3aa25d90a8a327470 --- /dev/null +++ b/code/DocsSample/ArkTs/JSVMAPI/JsvmBasicDataTypes_pr1/createint32/src/main/resources/base/element/float.json @@ -0,0 +1,8 @@ +{ + "float": [ + { + "name": "page_text_font_size", + "value": "50fp" + } + ] +} diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmBasicDataTypes_pr1/createint32/src/main/resources/base/element/string.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmBasicDataTypes_pr1/createint32/src/main/resources/base/element/string.json new file mode 100755 index 0000000000000000000000000000000000000000..19b814ed2a2c9fce357062e488f034f1085ffe0c --- /dev/null +++ b/code/DocsSample/ArkTs/JSVMAPI/JsvmBasicDataTypes_pr1/createint32/src/main/resources/base/element/string.json @@ -0,0 +1,16 @@ +{ + "string": [ + { + "name": "module_desc", + "value": "module description" + }, + { + "name": "Createint32Ability_desc", + "value": "description" + }, + { + "name": "Createint32Ability_label", + "value": "JsvmBasicDataTypes" + } + ] +} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmBasicDataTypes_pr1/createint32/src/main/resources/base/media/background.png b/code/DocsSample/ArkTs/JSVMAPI/JsvmBasicDataTypes_pr1/createint32/src/main/resources/base/media/background.png new file mode 100755 index 0000000000000000000000000000000000000000..923f2b3f27e915d6871871deea0420eb45ce102f Binary files /dev/null and b/code/DocsSample/ArkTs/JSVMAPI/JsvmBasicDataTypes_pr1/createint32/src/main/resources/base/media/background.png differ diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmBasicDataTypes_pr1/createint32/src/main/resources/base/media/foreground.png b/code/DocsSample/ArkTs/JSVMAPI/JsvmBasicDataTypes_pr1/createint32/src/main/resources/base/media/foreground.png new file mode 100755 index 0000000000000000000000000000000000000000..97014d3e10e5ff511409c378cd4255713aecd85f Binary files /dev/null and b/code/DocsSample/ArkTs/JSVMAPI/JsvmBasicDataTypes_pr1/createint32/src/main/resources/base/media/foreground.png differ diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmBasicDataTypes_pr1/createint32/src/main/resources/base/media/layered_image.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmBasicDataTypes_pr1/createint32/src/main/resources/base/media/layered_image.json new file mode 100755 index 0000000000000000000000000000000000000000..fb49920440fb4d246c82f9ada275e26123a2136a --- /dev/null +++ b/code/DocsSample/ArkTs/JSVMAPI/JsvmBasicDataTypes_pr1/createint32/src/main/resources/base/media/layered_image.json @@ -0,0 +1,7 @@ +{ + "layered-image": + { + "background" : "$media:background", + "foreground" : "$media:foreground" + } +} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmBasicDataTypes_pr1/createint32/src/main/resources/base/media/startIcon.png b/code/DocsSample/ArkTs/JSVMAPI/JsvmBasicDataTypes_pr1/createint32/src/main/resources/base/media/startIcon.png new file mode 100755 index 0000000000000000000000000000000000000000..205ad8b5a8a42e8762fbe4899b8e5e31ce822b8b Binary files /dev/null and b/code/DocsSample/ArkTs/JSVMAPI/JsvmBasicDataTypes_pr1/createint32/src/main/resources/base/media/startIcon.png differ diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmBasicDataTypes_pr1/createint32/src/main/resources/base/profile/main_pages.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmBasicDataTypes_pr1/createint32/src/main/resources/base/profile/main_pages.json new file mode 100755 index 0000000000000000000000000000000000000000..1898d94f58d6128ab712be2c68acc7c98e9ab9ce --- /dev/null +++ b/code/DocsSample/ArkTs/JSVMAPI/JsvmBasicDataTypes_pr1/createint32/src/main/resources/base/profile/main_pages.json @@ -0,0 +1,5 @@ +{ + "src": [ + "pages/Index" + ] +} diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmBasicDataTypes_pr1/createint32/src/ohosTest/ets/test/Ability.test.ets b/code/DocsSample/ArkTs/JSVMAPI/JsvmBasicDataTypes_pr1/createint32/src/ohosTest/ets/test/Ability.test.ets new file mode 100755 index 0000000000000000000000000000000000000000..bb70d2cc1bd9c605b0434816711c8e3cc18eab94 --- /dev/null +++ b/code/DocsSample/ArkTs/JSVMAPI/JsvmBasicDataTypes_pr1/createint32/src/ohosTest/ets/test/Ability.test.ets @@ -0,0 +1,52 @@ +/* + * Copyright (c) 2025 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 { describe, it, expect } from '@ohos/hypium'; +import { abilityDelegatorRegistry, Driver, ON } from '@kit.TestKit'; +import { UIAbility, Want } from '@kit.AbilityKit'; + +const delegator: abilityDelegatorRegistry.AbilityDelegator = abilityDelegatorRegistry.getAbilityDelegator(); +const bundleName = abilityDelegatorRegistry.getArguments().bundleName; + +export default function abilityTest() { + describe('ActsAbilityTest', () => { + /** + * 打开应用,点击OH_JSVM_CreateInt32执行 + */ + it('testCreateInt32', 0, async (done: Function) => { + console.log('uitest: TestCreateInt32 begin'); + + const want: Want = { + bundleName: bundleName, + abilityName: 'Createint32Ability' + } + const driver = Driver.create(); + await delegator.startAbility(want); + await driver.delayMs(1000); + + const ability: UIAbility = await delegator.getCurrentTopAbility(); + console.log('get top ability'); + expect(ability.context.abilityInfo.name).assertEqual('Createint32Ability'); + + await driver.delayMs(1000); + const text = await driver.findComponent(ON.text('OH_JSVM_CreateInt32')); + await text.click(); + await driver.delayMs(1000); + await driver.assertComponentExist(ON.text('success')); + console.log('uitest: TestCreateInt32 end'); + done(); + }) + }) +} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmBasicDataTypes_pr1/createint32/src/ohosTest/ets/test/List.test.ets b/code/DocsSample/ArkTs/JSVMAPI/JsvmBasicDataTypes_pr1/createint32/src/ohosTest/ets/test/List.test.ets new file mode 100755 index 0000000000000000000000000000000000000000..1eac52fcebe8958e19a7b8fed2e8f39c520a3e42 --- /dev/null +++ b/code/DocsSample/ArkTs/JSVMAPI/JsvmBasicDataTypes_pr1/createint32/src/ohosTest/ets/test/List.test.ets @@ -0,0 +1,20 @@ +/* + * Copyright (c) 2025 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 abilityTest from './Ability.test'; + +export default function testsuite() { + abilityTest(); +} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmBasicDataTypes_pr1/createint32/src/ohosTest/module.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmBasicDataTypes_pr1/createint32/src/ohosTest/module.json5 new file mode 100755 index 0000000000000000000000000000000000000000..96f5248b006f5376e8defe4da967f0983ba2308a --- /dev/null +++ b/code/DocsSample/ArkTs/JSVMAPI/JsvmBasicDataTypes_pr1/createint32/src/ohosTest/module.json5 @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2025 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. + */ + +{ + "module": { + "name": "createint32_test", + "type": "feature", + "deviceTypes": [ + "phone", + "tablet", + "2in1" + ], + "deliveryWithInstall": true, + "installationFree": false + } +} diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmBasicDataTypes_pr1/createint64/.gitignore b/code/DocsSample/ArkTs/JSVMAPI/JsvmBasicDataTypes_pr1/createint64/.gitignore new file mode 100755 index 0000000000000000000000000000000000000000..e2713a2779c5a3e0eb879efe6115455592caeea5 --- /dev/null +++ b/code/DocsSample/ArkTs/JSVMAPI/JsvmBasicDataTypes_pr1/createint64/.gitignore @@ -0,0 +1,6 @@ +/node_modules +/oh_modules +/.preview +/build +/.cxx +/.test \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmBasicDataTypes_pr1/createint64/build-profile.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmBasicDataTypes_pr1/createint64/build-profile.json5 new file mode 100755 index 0000000000000000000000000000000000000000..2c0104dcb596135013aa98865f37de336700177a --- /dev/null +++ b/code/DocsSample/ArkTs/JSVMAPI/JsvmBasicDataTypes_pr1/createint64/build-profile.json5 @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2025 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. + */ + +{ + "apiType": "stageMode", + "buildOption": { + "externalNativeOptions": { + "path": "./src/main/cpp/CMakeLists.txt", + "arguments": "", + "cppFlags": "", + } + }, + "buildOptionSet": [ + { + "name": "release", + "arkOptions": { + "obfuscation": { + "ruleOptions": { + "enable": false, + "files": [ + "./obfuscation-rules.txt" + ] + } + } + }, + "nativeLib": { + "debugSymbol": { + "strip": true, + "exclude": [] + } + } + }, + ], + "targets": [ + { + "name": "default" + }, + { + "name": "ohosTest", + } + ] +} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmBasicDataTypes_pr1/createint64/hvigorfile.ts b/code/DocsSample/ArkTs/JSVMAPI/JsvmBasicDataTypes_pr1/createint64/hvigorfile.ts new file mode 100755 index 0000000000000000000000000000000000000000..e4f43d54667f8327c367c8096bd08bb8c75aff54 --- /dev/null +++ b/code/DocsSample/ArkTs/JSVMAPI/JsvmBasicDataTypes_pr1/createint64/hvigorfile.ts @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2025 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 { hapTasks } from '@ohos/hvigor-ohos-plugin'; + +export default { + system: hapTasks, /* Built-in plugin of Hvigor. It cannot be modified. */ + plugins:[] /* Custom plugin to extend the functionality of Hvigor. */ +} diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmBasicDataTypes_pr1/createint64/obfuscation-rules.txt b/code/DocsSample/ArkTs/JSVMAPI/JsvmBasicDataTypes_pr1/createint64/obfuscation-rules.txt new file mode 100755 index 0000000000000000000000000000000000000000..272efb6ca3f240859091bbbfc7c5802d52793b0b --- /dev/null +++ b/code/DocsSample/ArkTs/JSVMAPI/JsvmBasicDataTypes_pr1/createint64/obfuscation-rules.txt @@ -0,0 +1,23 @@ +# Define project specific obfuscation rules here. +# You can include the obfuscation configuration files in the current module's build-profile.json5. +# +# For more details, see +# https://developer.huawei.com/consumer/cn/doc/harmonyos-guides-V5/source-obfuscation-V5 + +# Obfuscation options: +# -disable-obfuscation: disable all obfuscations +# -enable-property-obfuscation: obfuscate the property names +# -enable-toplevel-obfuscation: obfuscate the names in the global scope +# -compact: remove unnecessary blank spaces and all line feeds +# -remove-log: remove all console.* statements +# -print-namecache: print the name cache that contains the mapping from the old names to new names +# -apply-namecache: reuse the given cache file + +# Keep options: +# -keep-property-name: specifies property names that you want to keep +# -keep-global-name: specifies names that you want to keep in the global scope + +-enable-property-obfuscation +-enable-toplevel-obfuscation +-enable-filename-obfuscation +-enable-export-obfuscation \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmBasicDataTypes_pr1/createint64/oh-package.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmBasicDataTypes_pr1/createint64/oh-package.json5 new file mode 100755 index 0000000000000000000000000000000000000000..a10a43543c72e7da9089ab37df5ecfa08c2819df --- /dev/null +++ b/code/DocsSample/ArkTs/JSVMAPI/JsvmBasicDataTypes_pr1/createint64/oh-package.json5 @@ -0,0 +1,26 @@ +/* + * Copyright (c) 2025 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. + */ + +{ + "name": "createint64", + "version": "1.0.0", + "description": "Please describe the basic information.", + "main": "", + "author": "", + "license": "", + "dependencies": { + "libcreateint64.so": "file:./src/main/cpp/types/libcreateint64" + } +} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmBasicDataTypes_pr1/createint64/src/main/cpp/CMakeLists.txt b/code/DocsSample/ArkTs/JSVMAPI/JsvmBasicDataTypes_pr1/createint64/src/main/cpp/CMakeLists.txt new file mode 100755 index 0000000000000000000000000000000000000000..6a981df243288ab52d9eb8fb2b7ca96ebb909655 --- /dev/null +++ b/code/DocsSample/ArkTs/JSVMAPI/JsvmBasicDataTypes_pr1/createint64/src/main/cpp/CMakeLists.txt @@ -0,0 +1,14 @@ +cmake_minimum_required(VERSION 3.4.1) +project(UsageInstructionsTwo) + +set(NATIVERENDER_ROOT_PATH ${CMAKE_CURRENT_SOURCE_DIR}) +# 日志打印配置 +add_definitions( "-DLOG_DOMAIN=0xd0d0" ) +add_definitions( "-DLOG_TAG=\"testTag\"" ) +include_directories(${NATIVERENDER_ROOT_PATH} + ${NATIVERENDER_ROOT_PATH}/include) + +# 添加名为entry的库 +add_library(createint64 SHARED hello.cpp) +# 构建此可执行文件需要链接的库 +target_link_libraries(createint64 PUBLIC libace_napi.z.so libjsvm.so libhilog_ndk.z.so) \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmBasicDataTypes_pr1/createint64/src/main/cpp/hello.cpp b/code/DocsSample/ArkTs/JSVMAPI/JsvmBasicDataTypes_pr1/createint64/src/main/cpp/hello.cpp new file mode 100755 index 0000000000000000000000000000000000000000..60a5f434af692b4ed1c36bbe52dff4ab77fd19f8 --- /dev/null +++ b/code/DocsSample/ArkTs/JSVMAPI/JsvmBasicDataTypes_pr1/createint64/src/main/cpp/hello.cpp @@ -0,0 +1,156 @@ +/* + * Copyright (c) 2025 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. + */ + +#include "napi/native_api.h" +#include "hilog/log.h" +#include "ark_runtime/jsvm.h" + +#define LOG_DOMAIN 0x3200 +#define LOG_TAG "APP" + +static int g_aa = 0; + +#define CHECK_RET(theCall) \ + do { \ + JSVM_Status cond = theCall; \ + if ((cond) != JSVM_OK) { \ + const JSVM_ExtendedErrorInfo *info; \ + OH_JSVM_GetLastErrorInfo(env, &info); \ + OH_LOG_ERROR(LOG_APP, "jsvm fail file: %{public}s line: %{public}d ret = %{public}d message = %{public}s", \ + __FILE__, __LINE__, cond, info != nullptr ? info->errorMessage : ""); \ + return -1; \ + } \ + } while (0) + +#define CHECK(theCall) \ + do { \ + JSVM_Status cond = theCall; \ + if ((cond) != JSVM_OK) { \ + OH_LOG_ERROR(LOG_APP, "jsvm fail file: %{public}s line: %{public}d ret = %{public}d", __FILE__, __LINE__, \ + cond); \ + return -1; \ + } \ + } while (0) + +// 用于调用theCall并检查其返回值是否为JSVM_OK。 +// 如果不是,则调用OH_JSVM_GetLastErrorInfo处理错误并返回retVal。 +#define JSVM_CALL_BASE(env, theCall, retVal) \ + do { \ + JSVM_Status cond = theCall; \ + if (cond != JSVM_OK) { \ + const JSVM_ExtendedErrorInfo *info; \ + OH_JSVM_GetLastErrorInfo(env, &info); \ + OH_LOG_ERROR(LOG_APP, "jsvm fail file: %{public}s line: %{public}d ret = %{public}d message = %{public}s", \ + __FILE__, __LINE__, cond, info != nullptr ? info->errorMessage : ""); \ + return retVal; \ + } \ + } while (0) + +// JSVM_CALL_BASE的简化版本,返回nullptr +#define JSVM_CALL(theCall) JSVM_CALL_BASE(env, theCall, nullptr) + +// OH_JSVM_CreateInt64的样例方法 +static JSVM_Value CreateInt64(JSVM_Env env, JSVM_CallbackInfo info) +{ + // int64是有符号的64位整数类型,可以表示范围从-2^63到2^63 - 1的整数,即 -9223372036854775808到9223372036854775807 + // 要表示的整数值 + int64_t value = 2147483648; + // 创建JavaScript中的int64数字 + JSVM_Value result = nullptr; + JSVM_Status status = OH_JSVM_CreateInt64(env, value, &result); + if (status != JSVM_OK) { + OH_LOG_ERROR(LOG_APP, "JSVM CreateInt64 fail"); + } else { + int64_t number = 0; + OH_JSVM_GetValueInt64(env, result, &number); + OH_LOG_INFO(LOG_APP, "JSVM CreateInt64 success: %{public}ld", number); + } + return result; +} + +// CreateInt64注册回调 +static JSVM_CallbackStruct param[] = { + {.data = nullptr, .callback = CreateInt64}, +}; +static JSVM_CallbackStruct *method = param; +// CreateInt64方法别名,供JS调用 +static JSVM_PropertyDescriptor descriptor[] = { + {"createInt64", nullptr, method++, nullptr, nullptr, nullptr, JSVM_DEFAULT}, +}; + +// 样例测试js +const char* srcCallNative = R"JS(createInt64())JS"; + +static int32_t TestJSVM() { + JSVM_InitOptions initOptions = {0}; + JSVM_VM vm; + JSVM_Env env = nullptr; + JSVM_VMScope vmScope; + JSVM_EnvScope envScope; + JSVM_HandleScope handleScope; + JSVM_Value result; + // 初始化JavaScript引擎实例 + if (g_aa == 0) { + g_aa++; + CHECK(OH_JSVM_Init(&initOptions)); + } + // 创建JSVM环境 + CHECK(OH_JSVM_CreateVM(nullptr, &vm)); + CHECK(OH_JSVM_CreateEnv(vm, sizeof(descriptor) / sizeof(descriptor[0]), descriptor, &env)); + CHECK(OH_JSVM_OpenVMScope(vm, &vmScope)); + CHECK_RET(OH_JSVM_OpenEnvScope(env, &envScope)); + CHECK_RET(OH_JSVM_OpenHandleScope(env, &handleScope)); + + // 通过script调用测试函数 + JSVM_Script script; + JSVM_Value jsSrc; + CHECK_RET(OH_JSVM_CreateStringUtf8(env, srcCallNative, JSVM_AUTO_LENGTH, &jsSrc)); + CHECK_RET(OH_JSVM_CompileScript(env, jsSrc, nullptr, 0, true, nullptr, &script)); + CHECK_RET(OH_JSVM_RunScript(env, script, &result)); + + // 销毁JSVM环境 + CHECK_RET(OH_JSVM_CloseHandleScope(env, handleScope)); + CHECK_RET(OH_JSVM_CloseEnvScope(env, envScope)); + CHECK(OH_JSVM_CloseVMScope(vm, vmScope)); + CHECK(OH_JSVM_DestroyEnv(env)); + CHECK(OH_JSVM_DestroyVM(vm)); + return 0; +} + +static napi_value RunTest(napi_env env, napi_callback_info info) { + TestJSVM(); + return nullptr; +} + +// 模块注册信息,供arkts侧调用 +EXTERN_C_START +static napi_value Init(napi_env env, napi_value exports) { + napi_property_descriptor desc[] = {{"runTest", nullptr, RunTest, nullptr, nullptr, nullptr, napi_default, nullptr}}; + napi_define_properties(env, exports, sizeof(desc) / sizeof(desc[0]), desc); + return exports; +} +EXTERN_C_END + +static napi_module demoModule = { + .nm_version = 1, + .nm_flags = 0, + .nm_filename = nullptr, + .nm_register_func = Init, + .nm_modname = "createint64", + .nm_priv = ((void *)0), + .reserved = {0}, +}; + +extern "C" __attribute__((constructor)) void RegisterEntryModule(void) { napi_module_register(&demoModule); } \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmBasicDataTypes_pr1/createint64/src/main/cpp/types/libcreateint64/Index.d.ts b/code/DocsSample/ArkTs/JSVMAPI/JsvmBasicDataTypes_pr1/createint64/src/main/cpp/types/libcreateint64/Index.d.ts new file mode 100755 index 0000000000000000000000000000000000000000..8fc2c9e21ff1c104f0d0649acc1b5ea70ba4bab3 --- /dev/null +++ b/code/DocsSample/ArkTs/JSVMAPI/JsvmBasicDataTypes_pr1/createint64/src/main/cpp/types/libcreateint64/Index.d.ts @@ -0,0 +1,16 @@ +/* + * Copyright (c) 2025 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 const runTest: () => void; \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmBasicDataTypes_pr1/createint64/src/main/cpp/types/libcreateint64/oh-package.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmBasicDataTypes_pr1/createint64/src/main/cpp/types/libcreateint64/oh-package.json5 new file mode 100755 index 0000000000000000000000000000000000000000..08e7a45a0bc8e2db6ed1a6d1a511e31d347ab248 --- /dev/null +++ b/code/DocsSample/ArkTs/JSVMAPI/JsvmBasicDataTypes_pr1/createint64/src/main/cpp/types/libcreateint64/oh-package.json5 @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2025 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. + */ + +{ + "name": "libcreateint64.so", + "types": "./Index.d.ts", + "version": "1.0.0", + "description": "Please describe the basic information." +} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmBasicDataTypes_pr1/createint64/src/main/ets/createint64ability/Createint64Ability.ets b/code/DocsSample/ArkTs/JSVMAPI/JsvmBasicDataTypes_pr1/createint64/src/main/ets/createint64ability/Createint64Ability.ets new file mode 100755 index 0000000000000000000000000000000000000000..48e34d5cef246299e12c3f0bbfafbd4b090b0e34 --- /dev/null +++ b/code/DocsSample/ArkTs/JSVMAPI/JsvmBasicDataTypes_pr1/createint64/src/main/ets/createint64ability/Createint64Ability.ets @@ -0,0 +1,58 @@ +/* + * Copyright (c) 2025 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 { AbilityConstant, UIAbility, Want } from '@kit.AbilityKit'; +import { hilog } from '@kit.PerformanceAnalysisKit'; +import { window } from '@kit.ArkUI'; + +const DOMAIN = 0x0000; + +export default class Createint64Ability extends UIAbility { + onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void { + hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onCreate'); + } + + onDestroy(): void { + hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onDestroy'); + } + + onWindowStageCreate(windowStage: window.WindowStage): void { + // Main window is created, set main page for this ability + hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onWindowStageCreate'); + + windowStage.loadContent('pages/Index', (err) => { + if (err.code) { + hilog.error(DOMAIN, 'testTag', 'Failed to load the content. Cause: %{public}s', JSON.stringify(err)); + return; + } + hilog.info(DOMAIN, 'testTag', 'Succeeded in loading the content.'); + }); + } + + onWindowStageDestroy(): void { + // Main window is destroyed, release UI related resources + hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onWindowStageDestroy'); + } + + onForeground(): void { + // Ability has brought to foreground + hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onForeground'); + } + + onBackground(): void { + // Ability has back to background + hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onBackground'); + } +} diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmBasicDataTypes_pr1/createint64/src/main/ets/pages/Index.ets b/code/DocsSample/ArkTs/JSVMAPI/JsvmBasicDataTypes_pr1/createint64/src/main/ets/pages/Index.ets new file mode 100755 index 0000000000000000000000000000000000000000..8c10e8476f89d9564cb167540cef79823f4d38f9 --- /dev/null +++ b/code/DocsSample/ArkTs/JSVMAPI/JsvmBasicDataTypes_pr1/createint64/src/main/ets/pages/Index.ets @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2025 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 napitest from 'libcreateint64.so'; + +@Entry +@Component +struct Index { + @State message: string = 'OH_JSVM_CreateInt64'; + + build() { + Row() { + Column() { + Text(this.message) + .fontSize(30) + .fontWeight(FontWeight.Bold) + .onClick(() => { + try { + napitest.runTest(); + this.message = 'success'; + } catch (error) { + console.error('An error occurred: ', error); + this.message = 'fail'; + } + }) + } + .width('100%') + } + .height('100%') + } +} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmBasicDataTypes_pr1/createint64/src/main/module.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmBasicDataTypes_pr1/createint64/src/main/module.json5 new file mode 100755 index 0000000000000000000000000000000000000000..e9a2dbf07d39e699f3ae22524a66b16b624bc111 --- /dev/null +++ b/code/DocsSample/ArkTs/JSVMAPI/JsvmBasicDataTypes_pr1/createint64/src/main/module.json5 @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2025 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. + */ + +{ + "module": { + "name": "createint64", + "type": "feature", + "description": "$string:module_desc", + "mainElement": "Createint64Ability", + "deviceTypes": [ + "phone", + "tablet", + "2in1" + ], + "deliveryWithInstall": true, + "installationFree": false, + "pages": "$profile:main_pages", + "abilities": [ + { + "name": "Createint64Ability", + "srcEntry": "./ets/createint64ability/Createint64Ability.ets", + "description": "$string:Createint64Ability_desc", + "icon": "$media:layered_image", + "label": "$string:Createint64Ability_label", + "startWindowIcon": "$media:startIcon", + "startWindowBackground": "$color:start_window_background", + "exported": true + } + ] + } +} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmBasicDataTypes_pr1/createint64/src/main/resources/base/element/color.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmBasicDataTypes_pr1/createint64/src/main/resources/base/element/color.json new file mode 100755 index 0000000000000000000000000000000000000000..d66f9a7d4ac61fb8d215239ab3620b7bcd77bf33 --- /dev/null +++ b/code/DocsSample/ArkTs/JSVMAPI/JsvmBasicDataTypes_pr1/createint64/src/main/resources/base/element/color.json @@ -0,0 +1,8 @@ +{ + "color": [ + { + "name": "start_window_background", + "value": "#FFFFFF" + } + ] +} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmBasicDataTypes_pr1/createint64/src/main/resources/base/element/float.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmBasicDataTypes_pr1/createint64/src/main/resources/base/element/float.json new file mode 100755 index 0000000000000000000000000000000000000000..a8a5d404dcd8b0466194afc3aa25d90a8a327470 --- /dev/null +++ b/code/DocsSample/ArkTs/JSVMAPI/JsvmBasicDataTypes_pr1/createint64/src/main/resources/base/element/float.json @@ -0,0 +1,8 @@ +{ + "float": [ + { + "name": "page_text_font_size", + "value": "50fp" + } + ] +} diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmBasicDataTypes_pr1/createint64/src/main/resources/base/element/string.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmBasicDataTypes_pr1/createint64/src/main/resources/base/element/string.json new file mode 100755 index 0000000000000000000000000000000000000000..1e3a4cefa2ec46ad5037ca39adf96562562a7491 --- /dev/null +++ b/code/DocsSample/ArkTs/JSVMAPI/JsvmBasicDataTypes_pr1/createint64/src/main/resources/base/element/string.json @@ -0,0 +1,16 @@ +{ + "string": [ + { + "name": "module_desc", + "value": "module description" + }, + { + "name": "Createint64Ability_desc", + "value": "description" + }, + { + "name": "Createint64Ability_label", + "value": "JsvmBasicDataTypes" + } + ] +} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmBasicDataTypes_pr1/createint64/src/main/resources/base/media/background.png b/code/DocsSample/ArkTs/JSVMAPI/JsvmBasicDataTypes_pr1/createint64/src/main/resources/base/media/background.png new file mode 100755 index 0000000000000000000000000000000000000000..923f2b3f27e915d6871871deea0420eb45ce102f Binary files /dev/null and b/code/DocsSample/ArkTs/JSVMAPI/JsvmBasicDataTypes_pr1/createint64/src/main/resources/base/media/background.png differ diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmBasicDataTypes_pr1/createint64/src/main/resources/base/media/foreground.png b/code/DocsSample/ArkTs/JSVMAPI/JsvmBasicDataTypes_pr1/createint64/src/main/resources/base/media/foreground.png new file mode 100755 index 0000000000000000000000000000000000000000..97014d3e10e5ff511409c378cd4255713aecd85f Binary files /dev/null and b/code/DocsSample/ArkTs/JSVMAPI/JsvmBasicDataTypes_pr1/createint64/src/main/resources/base/media/foreground.png differ diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmBasicDataTypes_pr1/createint64/src/main/resources/base/media/layered_image.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmBasicDataTypes_pr1/createint64/src/main/resources/base/media/layered_image.json new file mode 100755 index 0000000000000000000000000000000000000000..fb49920440fb4d246c82f9ada275e26123a2136a --- /dev/null +++ b/code/DocsSample/ArkTs/JSVMAPI/JsvmBasicDataTypes_pr1/createint64/src/main/resources/base/media/layered_image.json @@ -0,0 +1,7 @@ +{ + "layered-image": + { + "background" : "$media:background", + "foreground" : "$media:foreground" + } +} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmBasicDataTypes_pr1/createint64/src/main/resources/base/media/startIcon.png b/code/DocsSample/ArkTs/JSVMAPI/JsvmBasicDataTypes_pr1/createint64/src/main/resources/base/media/startIcon.png new file mode 100755 index 0000000000000000000000000000000000000000..205ad8b5a8a42e8762fbe4899b8e5e31ce822b8b Binary files /dev/null and b/code/DocsSample/ArkTs/JSVMAPI/JsvmBasicDataTypes_pr1/createint64/src/main/resources/base/media/startIcon.png differ diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmBasicDataTypes_pr1/createint64/src/main/resources/base/profile/main_pages.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmBasicDataTypes_pr1/createint64/src/main/resources/base/profile/main_pages.json new file mode 100755 index 0000000000000000000000000000000000000000..1898d94f58d6128ab712be2c68acc7c98e9ab9ce --- /dev/null +++ b/code/DocsSample/ArkTs/JSVMAPI/JsvmBasicDataTypes_pr1/createint64/src/main/resources/base/profile/main_pages.json @@ -0,0 +1,5 @@ +{ + "src": [ + "pages/Index" + ] +} diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmBasicDataTypes_pr1/createint64/src/ohosTest/ets/test/Ability.test.ets b/code/DocsSample/ArkTs/JSVMAPI/JsvmBasicDataTypes_pr1/createint64/src/ohosTest/ets/test/Ability.test.ets new file mode 100755 index 0000000000000000000000000000000000000000..0b7b62f422d50b7af553c9dd640fe7fb59c2d0ef --- /dev/null +++ b/code/DocsSample/ArkTs/JSVMAPI/JsvmBasicDataTypes_pr1/createint64/src/ohosTest/ets/test/Ability.test.ets @@ -0,0 +1,52 @@ +/* + * Copyright (c) 2025 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 { describe, it, expect } from '@ohos/hypium'; +import { abilityDelegatorRegistry, Driver, ON } from '@kit.TestKit'; +import { UIAbility, Want } from '@kit.AbilityKit'; + +const delegator: abilityDelegatorRegistry.AbilityDelegator = abilityDelegatorRegistry.getAbilityDelegator(); +const bundleName = abilityDelegatorRegistry.getArguments().bundleName; + +export default function abilityTest() { + describe('ActsAbilityTest', () => { + /** + * 打开应用,点击OH_JSVM_CreateInt64执行 + */ + it('testCreateInt64', 0, async (done: Function) => { + console.log('uitest: TestCreateInt64 begin'); + + const want: Want = { + bundleName: bundleName, + abilityName: 'Createint64Ability' + } + const driver = Driver.create(); + await delegator.startAbility(want); + await driver.delayMs(1000); + + const ability: UIAbility = await delegator.getCurrentTopAbility(); + console.log('get top ability'); + expect(ability.context.abilityInfo.name).assertEqual('Createint64Ability'); + + await driver.delayMs(1000); + const text = await driver.findComponent(ON.text('OH_JSVM_CreateInt64')); + await text.click(); + await driver.delayMs(1000); + await driver.assertComponentExist(ON.text('success')); + console.log('uitest: TestCreateInt64 end'); + done(); + }) + }) +} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmBasicDataTypes_pr1/createint64/src/ohosTest/ets/test/List.test.ets b/code/DocsSample/ArkTs/JSVMAPI/JsvmBasicDataTypes_pr1/createint64/src/ohosTest/ets/test/List.test.ets new file mode 100755 index 0000000000000000000000000000000000000000..1eac52fcebe8958e19a7b8fed2e8f39c520a3e42 --- /dev/null +++ b/code/DocsSample/ArkTs/JSVMAPI/JsvmBasicDataTypes_pr1/createint64/src/ohosTest/ets/test/List.test.ets @@ -0,0 +1,20 @@ +/* + * Copyright (c) 2025 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 abilityTest from './Ability.test'; + +export default function testsuite() { + abilityTest(); +} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmBasicDataTypes_pr1/createint64/src/ohosTest/module.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmBasicDataTypes_pr1/createint64/src/ohosTest/module.json5 new file mode 100755 index 0000000000000000000000000000000000000000..21425baac17df8ea2518bd75bea632bb1cc2e5f2 --- /dev/null +++ b/code/DocsSample/ArkTs/JSVMAPI/JsvmBasicDataTypes_pr1/createint64/src/ohosTest/module.json5 @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2025 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. + */ + +{ + "module": { + "name": "createint64_test", + "type": "feature", + "deviceTypes": [ + "phone", + "tablet", + "2in1" + ], + "deliveryWithInstall": true, + "installationFree": false + } +} diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmBasicDataTypes_pr1/createuint32/.gitignore b/code/DocsSample/ArkTs/JSVMAPI/JsvmBasicDataTypes_pr1/createuint32/.gitignore new file mode 100755 index 0000000000000000000000000000000000000000..e2713a2779c5a3e0eb879efe6115455592caeea5 --- /dev/null +++ b/code/DocsSample/ArkTs/JSVMAPI/JsvmBasicDataTypes_pr1/createuint32/.gitignore @@ -0,0 +1,6 @@ +/node_modules +/oh_modules +/.preview +/build +/.cxx +/.test \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmBasicDataTypes_pr1/createuint32/build-profile.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmBasicDataTypes_pr1/createuint32/build-profile.json5 new file mode 100755 index 0000000000000000000000000000000000000000..2c0104dcb596135013aa98865f37de336700177a --- /dev/null +++ b/code/DocsSample/ArkTs/JSVMAPI/JsvmBasicDataTypes_pr1/createuint32/build-profile.json5 @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2025 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. + */ + +{ + "apiType": "stageMode", + "buildOption": { + "externalNativeOptions": { + "path": "./src/main/cpp/CMakeLists.txt", + "arguments": "", + "cppFlags": "", + } + }, + "buildOptionSet": [ + { + "name": "release", + "arkOptions": { + "obfuscation": { + "ruleOptions": { + "enable": false, + "files": [ + "./obfuscation-rules.txt" + ] + } + } + }, + "nativeLib": { + "debugSymbol": { + "strip": true, + "exclude": [] + } + } + }, + ], + "targets": [ + { + "name": "default" + }, + { + "name": "ohosTest", + } + ] +} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmBasicDataTypes_pr1/createuint32/hvigorfile.ts b/code/DocsSample/ArkTs/JSVMAPI/JsvmBasicDataTypes_pr1/createuint32/hvigorfile.ts new file mode 100755 index 0000000000000000000000000000000000000000..e4f43d54667f8327c367c8096bd08bb8c75aff54 --- /dev/null +++ b/code/DocsSample/ArkTs/JSVMAPI/JsvmBasicDataTypes_pr1/createuint32/hvigorfile.ts @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2025 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 { hapTasks } from '@ohos/hvigor-ohos-plugin'; + +export default { + system: hapTasks, /* Built-in plugin of Hvigor. It cannot be modified. */ + plugins:[] /* Custom plugin to extend the functionality of Hvigor. */ +} diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmBasicDataTypes_pr1/createuint32/obfuscation-rules.txt b/code/DocsSample/ArkTs/JSVMAPI/JsvmBasicDataTypes_pr1/createuint32/obfuscation-rules.txt new file mode 100755 index 0000000000000000000000000000000000000000..272efb6ca3f240859091bbbfc7c5802d52793b0b --- /dev/null +++ b/code/DocsSample/ArkTs/JSVMAPI/JsvmBasicDataTypes_pr1/createuint32/obfuscation-rules.txt @@ -0,0 +1,23 @@ +# Define project specific obfuscation rules here. +# You can include the obfuscation configuration files in the current module's build-profile.json5. +# +# For more details, see +# https://developer.huawei.com/consumer/cn/doc/harmonyos-guides-V5/source-obfuscation-V5 + +# Obfuscation options: +# -disable-obfuscation: disable all obfuscations +# -enable-property-obfuscation: obfuscate the property names +# -enable-toplevel-obfuscation: obfuscate the names in the global scope +# -compact: remove unnecessary blank spaces and all line feeds +# -remove-log: remove all console.* statements +# -print-namecache: print the name cache that contains the mapping from the old names to new names +# -apply-namecache: reuse the given cache file + +# Keep options: +# -keep-property-name: specifies property names that you want to keep +# -keep-global-name: specifies names that you want to keep in the global scope + +-enable-property-obfuscation +-enable-toplevel-obfuscation +-enable-filename-obfuscation +-enable-export-obfuscation \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmBasicDataTypes_pr1/createuint32/oh-package.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmBasicDataTypes_pr1/createuint32/oh-package.json5 new file mode 100755 index 0000000000000000000000000000000000000000..2205c7d23f7f39c1d4cef62bdf757a8fbbff1445 --- /dev/null +++ b/code/DocsSample/ArkTs/JSVMAPI/JsvmBasicDataTypes_pr1/createuint32/oh-package.json5 @@ -0,0 +1,26 @@ +/* + * Copyright (c) 2025 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. + */ + +{ + "name": "createuint32", + "version": "1.0.0", + "description": "Please describe the basic information.", + "main": "", + "author": "", + "license": "", + "dependencies": { + "libcreateuint32.so": "file:./src/main/cpp/types/libcreateuint32" + } +} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmBasicDataTypes_pr1/createuint32/src/main/cpp/CMakeLists.txt b/code/DocsSample/ArkTs/JSVMAPI/JsvmBasicDataTypes_pr1/createuint32/src/main/cpp/CMakeLists.txt new file mode 100755 index 0000000000000000000000000000000000000000..9463604e10f153870d056655affe444ce1b90ce2 --- /dev/null +++ b/code/DocsSample/ArkTs/JSVMAPI/JsvmBasicDataTypes_pr1/createuint32/src/main/cpp/CMakeLists.txt @@ -0,0 +1,14 @@ +cmake_minimum_required(VERSION 3.4.1) +project(UsageInstructionsTwo) + +set(NATIVERENDER_ROOT_PATH ${CMAKE_CURRENT_SOURCE_DIR}) +# 日志打印配置 +add_definitions( "-DLOG_DOMAIN=0xd0d0" ) +add_definitions( "-DLOG_TAG=\"testTag\"" ) +include_directories(${NATIVERENDER_ROOT_PATH} + ${NATIVERENDER_ROOT_PATH}/include) + +# 添加名为entry的库 +add_library(createuint32 SHARED hello.cpp) +# 构建此可执行文件需要链接的库 +target_link_libraries(createuint32 PUBLIC libace_napi.z.so libjsvm.so libhilog_ndk.z.so) \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmBasicDataTypes_pr1/createuint32/src/main/cpp/hello.cpp b/code/DocsSample/ArkTs/JSVMAPI/JsvmBasicDataTypes_pr1/createuint32/src/main/cpp/hello.cpp new file mode 100755 index 0000000000000000000000000000000000000000..a1c0b5c3b23d27855394acb2998ea39c41764a70 --- /dev/null +++ b/code/DocsSample/ArkTs/JSVMAPI/JsvmBasicDataTypes_pr1/createuint32/src/main/cpp/hello.cpp @@ -0,0 +1,158 @@ +/* + * Copyright (c) 2025 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. + */ + +#include "napi/native_api.h" +#include "hilog/log.h" +#include "ark_runtime/jsvm.h" + +#define LOG_DOMAIN 0x3200 +#define LOG_TAG "APP" + +static int g_aa = 0; + +#define CHECK_RET(theCall) \ + do { \ + JSVM_Status cond = theCall; \ + if ((cond) != JSVM_OK) { \ + const JSVM_ExtendedErrorInfo *info; \ + OH_JSVM_GetLastErrorInfo(env, &info); \ + OH_LOG_ERROR(LOG_APP, "jsvm fail file: %{public}s line: %{public}d ret = %{public}d message = %{public}s", \ + __FILE__, __LINE__, cond, info != nullptr ? info->errorMessage : ""); \ + return -1; \ + } \ + } while (0) + +#define CHECK(theCall) \ + do { \ + JSVM_Status cond = theCall; \ + if ((cond) != JSVM_OK) { \ + OH_LOG_ERROR(LOG_APP, "jsvm fail file: %{public}s line: %{public}d ret = %{public}d", __FILE__, __LINE__, \ + cond); \ + return -1; \ + } \ + } while (0) + +// 用于调用theCall并检查其返回值是否为JSVM_OK。 +// 如果不是,则调用OH_JSVM_GetLastErrorInfo处理错误并返回retVal。 +#define JSVM_CALL_BASE(env, theCall, retVal) \ + do { \ + JSVM_Status cond = theCall; \ + if (cond != JSVM_OK) { \ + const JSVM_ExtendedErrorInfo *info; \ + OH_JSVM_GetLastErrorInfo(env, &info); \ + OH_LOG_ERROR(LOG_APP, "jsvm fail file: %{public}s line: %{public}d ret = %{public}d message = %{public}s", \ + __FILE__, __LINE__, cond, info != nullptr ? info->errorMessage : ""); \ + return retVal; \ + } \ + } while (0) + +// JSVM_CALL_BASE的简化版本,返回nullptr +#define JSVM_CALL(theCall) JSVM_CALL_BASE(env, theCall, nullptr) + +// OH_JSVM_CreateUint32的样例方法 +static JSVM_Value CreateUInt32(JSVM_Env env, JSVM_CallbackInfo info) +{ + // 如果使用 + // uint32_t类型来定义-26,会发生溢出,溢出时会对结果进行模运算,将负数的二进制补码转换为相应的正数。-26输出4294967270 + // uint32_t是无符号的32位整数类型,只能表示非负整数。它的范围是从0到2 ^32 - 1,即0到4294967295 + // 要表示的整数值 + uint32_t value = 26; + // 创建JavaScript中的uint32数字 + JSVM_Value result = nullptr; + JSVM_Status status = OH_JSVM_CreateUint32(env, value, &result); + if (status != JSVM_OK) { + OH_LOG_ERROR(LOG_APP, "JSVM CreateUInt32 fail"); + } else { + uint32_t number = 0; + OH_JSVM_GetValueUint32(env, result, &number); + OH_LOG_INFO(LOG_APP, "JSVM CreateUInt32 success: %{public}u", number); + } + return result; +} + +// CreateUInt32注册回调 +static JSVM_CallbackStruct param[] = { + {.data = nullptr, .callback = CreateUInt32}, +}; +static JSVM_CallbackStruct *method = param; +// CreateUInt32方法别名,供JS调用 +static JSVM_PropertyDescriptor descriptor[] = { + {"createUInt32", nullptr, method++, nullptr, nullptr, nullptr, JSVM_DEFAULT}, +}; + +// 样例测试js +const char* srcCallNative = R"JS(createUInt32())JS"; + +static int32_t TestJSVM() { + JSVM_InitOptions initOptions = {0}; + JSVM_VM vm; + JSVM_Env env = nullptr; + JSVM_VMScope vmScope; + JSVM_EnvScope envScope; + JSVM_HandleScope handleScope; + JSVM_Value result; + // 初始化JavaScript引擎实例 + if (g_aa == 0) { + g_aa++; + CHECK(OH_JSVM_Init(&initOptions)); + } + // 创建JSVM环境 + CHECK(OH_JSVM_CreateVM(nullptr, &vm)); + CHECK(OH_JSVM_CreateEnv(vm, sizeof(descriptor) / sizeof(descriptor[0]), descriptor, &env)); + CHECK(OH_JSVM_OpenVMScope(vm, &vmScope)); + CHECK_RET(OH_JSVM_OpenEnvScope(env, &envScope)); + CHECK_RET(OH_JSVM_OpenHandleScope(env, &handleScope)); + + // 通过script调用测试函数 + JSVM_Script script; + JSVM_Value jsSrc; + CHECK_RET(OH_JSVM_CreateStringUtf8(env, srcCallNative, JSVM_AUTO_LENGTH, &jsSrc)); + CHECK_RET(OH_JSVM_CompileScript(env, jsSrc, nullptr, 0, true, nullptr, &script)); + CHECK_RET(OH_JSVM_RunScript(env, script, &result)); + + // 销毁JSVM环境 + CHECK_RET(OH_JSVM_CloseHandleScope(env, handleScope)); + CHECK_RET(OH_JSVM_CloseEnvScope(env, envScope)); + CHECK(OH_JSVM_CloseVMScope(vm, vmScope)); + CHECK(OH_JSVM_DestroyEnv(env)); + CHECK(OH_JSVM_DestroyVM(vm)); + return 0; +} + +static napi_value RunTest(napi_env env, napi_callback_info info) { + TestJSVM(); + return nullptr; +} + +// 模块注册信息,供arkts侧调用 +EXTERN_C_START +static napi_value Init(napi_env env, napi_value exports) { + napi_property_descriptor desc[] = {{"runTest", nullptr, RunTest, nullptr, nullptr, nullptr, napi_default, nullptr}}; + napi_define_properties(env, exports, sizeof(desc) / sizeof(desc[0]), desc); + return exports; +} +EXTERN_C_END + +static napi_module demoModule = { + .nm_version = 1, + .nm_flags = 0, + .nm_filename = nullptr, + .nm_register_func = Init, + .nm_modname = "createuint32", + .nm_priv = ((void *)0), + .reserved = {0}, +}; + +extern "C" __attribute__((constructor)) void RegisterEntryModule(void) { napi_module_register(&demoModule); } \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmBasicDataTypes_pr1/createuint32/src/main/cpp/types/libcreateuint32/Index.d.ts b/code/DocsSample/ArkTs/JSVMAPI/JsvmBasicDataTypes_pr1/createuint32/src/main/cpp/types/libcreateuint32/Index.d.ts new file mode 100755 index 0000000000000000000000000000000000000000..8fc2c9e21ff1c104f0d0649acc1b5ea70ba4bab3 --- /dev/null +++ b/code/DocsSample/ArkTs/JSVMAPI/JsvmBasicDataTypes_pr1/createuint32/src/main/cpp/types/libcreateuint32/Index.d.ts @@ -0,0 +1,16 @@ +/* + * Copyright (c) 2025 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 const runTest: () => void; \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmBasicDataTypes_pr1/createuint32/src/main/cpp/types/libcreateuint32/oh-package.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmBasicDataTypes_pr1/createuint32/src/main/cpp/types/libcreateuint32/oh-package.json5 new file mode 100755 index 0000000000000000000000000000000000000000..7bfb2c66cf5c1000638ac3dc6463b440c96108ea --- /dev/null +++ b/code/DocsSample/ArkTs/JSVMAPI/JsvmBasicDataTypes_pr1/createuint32/src/main/cpp/types/libcreateuint32/oh-package.json5 @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2025 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. + */ + +{ + "name": "libcreateuint32.so", + "types": "./Index.d.ts", + "version": "1.0.0", + "description": "Please describe the basic information." +} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmBasicDataTypes_pr1/createuint32/src/main/ets/createuint32ability/Createuint32Ability.ets b/code/DocsSample/ArkTs/JSVMAPI/JsvmBasicDataTypes_pr1/createuint32/src/main/ets/createuint32ability/Createuint32Ability.ets new file mode 100755 index 0000000000000000000000000000000000000000..efcda6ddd2282ed9cdb8457e3a014a788219382e --- /dev/null +++ b/code/DocsSample/ArkTs/JSVMAPI/JsvmBasicDataTypes_pr1/createuint32/src/main/ets/createuint32ability/Createuint32Ability.ets @@ -0,0 +1,58 @@ +/* + * Copyright (c) 2025 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 { AbilityConstant, UIAbility, Want } from '@kit.AbilityKit'; +import { hilog } from '@kit.PerformanceAnalysisKit'; +import { window } from '@kit.ArkUI'; + +const DOMAIN = 0x0000; + +export default class Createuint32Ability extends UIAbility { + onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void { + hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onCreate'); + } + + onDestroy(): void { + hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onDestroy'); + } + + onWindowStageCreate(windowStage: window.WindowStage): void { + // Main window is created, set main page for this ability + hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onWindowStageCreate'); + + windowStage.loadContent('pages/Index', (err) => { + if (err.code) { + hilog.error(DOMAIN, 'testTag', 'Failed to load the content. Cause: %{public}s', JSON.stringify(err)); + return; + } + hilog.info(DOMAIN, 'testTag', 'Succeeded in loading the content.'); + }); + } + + onWindowStageDestroy(): void { + // Main window is destroyed, release UI related resources + hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onWindowStageDestroy'); + } + + onForeground(): void { + // Ability has brought to foreground + hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onForeground'); + } + + onBackground(): void { + // Ability has back to background + hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onBackground'); + } +} diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmBasicDataTypes_pr1/createuint32/src/main/ets/pages/Index.ets b/code/DocsSample/ArkTs/JSVMAPI/JsvmBasicDataTypes_pr1/createuint32/src/main/ets/pages/Index.ets new file mode 100755 index 0000000000000000000000000000000000000000..707e9427f68f1d7a5e147c98606af40a9ffe6502 --- /dev/null +++ b/code/DocsSample/ArkTs/JSVMAPI/JsvmBasicDataTypes_pr1/createuint32/src/main/ets/pages/Index.ets @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2025 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 napitest from 'libcreateuint32.so'; + +@Entry +@Component +struct Index { + @State message: string = 'OH_JSVM_CreateUint32'; + + build() { + Row() { + Column() { + Text(this.message) + .fontSize(30) + .fontWeight(FontWeight.Bold) + .onClick(() => { + try { + napitest.runTest(); + this.message = 'success'; + } catch (error) { + console.error('An error occurred: ', error); + this.message = 'fail'; + } + }) + } + .width('100%') + } + .height('100%') + } +} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmBasicDataTypes_pr1/createuint32/src/main/module.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmBasicDataTypes_pr1/createuint32/src/main/module.json5 new file mode 100755 index 0000000000000000000000000000000000000000..a640ae52d5c68a0ab6cf91fecb861b2644e64752 --- /dev/null +++ b/code/DocsSample/ArkTs/JSVMAPI/JsvmBasicDataTypes_pr1/createuint32/src/main/module.json5 @@ -0,0 +1,28 @@ +{ + "module": { + "name": "createuint32", + "type": "feature", + "description": "$string:module_desc", + "mainElement": "Createuint32Ability", + "deviceTypes": [ + "phone", + "tablet", + "2in1" + ], + "deliveryWithInstall": true, + "installationFree": false, + "pages": "$profile:main_pages", + "abilities": [ + { + "name": "Createuint32Ability", + "srcEntry": "./ets/createuint32ability/Createuint32Ability.ets", + "description": "$string:Createuint32Ability_desc", + "icon": "$media:layered_image", + "label": "$string:Createuint32Ability_label", + "startWindowIcon": "$media:startIcon", + "startWindowBackground": "$color:start_window_background", + "exported": true + } + ] + } +} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmBasicDataTypes_pr1/createuint32/src/main/resources/base/element/color.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmBasicDataTypes_pr1/createuint32/src/main/resources/base/element/color.json new file mode 100755 index 0000000000000000000000000000000000000000..d66f9a7d4ac61fb8d215239ab3620b7bcd77bf33 --- /dev/null +++ b/code/DocsSample/ArkTs/JSVMAPI/JsvmBasicDataTypes_pr1/createuint32/src/main/resources/base/element/color.json @@ -0,0 +1,8 @@ +{ + "color": [ + { + "name": "start_window_background", + "value": "#FFFFFF" + } + ] +} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmBasicDataTypes_pr1/createuint32/src/main/resources/base/element/float.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmBasicDataTypes_pr1/createuint32/src/main/resources/base/element/float.json new file mode 100755 index 0000000000000000000000000000000000000000..a8a5d404dcd8b0466194afc3aa25d90a8a327470 --- /dev/null +++ b/code/DocsSample/ArkTs/JSVMAPI/JsvmBasicDataTypes_pr1/createuint32/src/main/resources/base/element/float.json @@ -0,0 +1,8 @@ +{ + "float": [ + { + "name": "page_text_font_size", + "value": "50fp" + } + ] +} diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmBasicDataTypes_pr1/createuint32/src/main/resources/base/element/string.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmBasicDataTypes_pr1/createuint32/src/main/resources/base/element/string.json new file mode 100755 index 0000000000000000000000000000000000000000..45dd30e382140fb937578b3fc1cad3547d41af3b --- /dev/null +++ b/code/DocsSample/ArkTs/JSVMAPI/JsvmBasicDataTypes_pr1/createuint32/src/main/resources/base/element/string.json @@ -0,0 +1,16 @@ +{ + "string": [ + { + "name": "module_desc", + "value": "module description" + }, + { + "name": "Createuint32Ability_desc", + "value": "description" + }, + { + "name": "Createuint32Ability_label", + "value": "JsvmBasicDataTypes" + } + ] +} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmBasicDataTypes_pr1/createuint32/src/main/resources/base/media/background.png b/code/DocsSample/ArkTs/JSVMAPI/JsvmBasicDataTypes_pr1/createuint32/src/main/resources/base/media/background.png new file mode 100755 index 0000000000000000000000000000000000000000..923f2b3f27e915d6871871deea0420eb45ce102f Binary files /dev/null and b/code/DocsSample/ArkTs/JSVMAPI/JsvmBasicDataTypes_pr1/createuint32/src/main/resources/base/media/background.png differ diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmBasicDataTypes_pr1/createuint32/src/main/resources/base/media/foreground.png b/code/DocsSample/ArkTs/JSVMAPI/JsvmBasicDataTypes_pr1/createuint32/src/main/resources/base/media/foreground.png new file mode 100755 index 0000000000000000000000000000000000000000..97014d3e10e5ff511409c378cd4255713aecd85f Binary files /dev/null and b/code/DocsSample/ArkTs/JSVMAPI/JsvmBasicDataTypes_pr1/createuint32/src/main/resources/base/media/foreground.png differ diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmBasicDataTypes_pr1/createuint32/src/main/resources/base/media/layered_image.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmBasicDataTypes_pr1/createuint32/src/main/resources/base/media/layered_image.json new file mode 100755 index 0000000000000000000000000000000000000000..fb49920440fb4d246c82f9ada275e26123a2136a --- /dev/null +++ b/code/DocsSample/ArkTs/JSVMAPI/JsvmBasicDataTypes_pr1/createuint32/src/main/resources/base/media/layered_image.json @@ -0,0 +1,7 @@ +{ + "layered-image": + { + "background" : "$media:background", + "foreground" : "$media:foreground" + } +} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmBasicDataTypes_pr1/createuint32/src/main/resources/base/media/startIcon.png b/code/DocsSample/ArkTs/JSVMAPI/JsvmBasicDataTypes_pr1/createuint32/src/main/resources/base/media/startIcon.png new file mode 100755 index 0000000000000000000000000000000000000000..205ad8b5a8a42e8762fbe4899b8e5e31ce822b8b Binary files /dev/null and b/code/DocsSample/ArkTs/JSVMAPI/JsvmBasicDataTypes_pr1/createuint32/src/main/resources/base/media/startIcon.png differ diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmBasicDataTypes_pr1/createuint32/src/main/resources/base/profile/main_pages.json b/code/DocsSample/ArkTs/JSVMAPI/JsvmBasicDataTypes_pr1/createuint32/src/main/resources/base/profile/main_pages.json new file mode 100755 index 0000000000000000000000000000000000000000..1898d94f58d6128ab712be2c68acc7c98e9ab9ce --- /dev/null +++ b/code/DocsSample/ArkTs/JSVMAPI/JsvmBasicDataTypes_pr1/createuint32/src/main/resources/base/profile/main_pages.json @@ -0,0 +1,5 @@ +{ + "src": [ + "pages/Index" + ] +} diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmBasicDataTypes_pr1/createuint32/src/ohosTest/ets/test/Ability.test.ets b/code/DocsSample/ArkTs/JSVMAPI/JsvmBasicDataTypes_pr1/createuint32/src/ohosTest/ets/test/Ability.test.ets new file mode 100755 index 0000000000000000000000000000000000000000..7a30eac72b2b3ad81752223dbffe8cc37bce7903 --- /dev/null +++ b/code/DocsSample/ArkTs/JSVMAPI/JsvmBasicDataTypes_pr1/createuint32/src/ohosTest/ets/test/Ability.test.ets @@ -0,0 +1,52 @@ +/* + * Copyright (c) 2025 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 { describe, it, expect } from '@ohos/hypium'; +import { abilityDelegatorRegistry, Driver, ON } from '@kit.TestKit'; +import { UIAbility, Want } from '@kit.AbilityKit'; + +const delegator: abilityDelegatorRegistry.AbilityDelegator = abilityDelegatorRegistry.getAbilityDelegator(); +const bundleName = abilityDelegatorRegistry.getArguments().bundleName; + +export default function abilityTest() { + describe('ActsAbilityTest', () => { + /** + * 打开应用,点击OH_JSVM_CreateUint32执行 + */ + it('testCreateUint32', 0, async (done: Function) => { + console.log('uitest: TestCreateUint32 begin'); + + const want: Want = { + bundleName: bundleName, + abilityName: 'Createuint32Ability' + } + const driver = Driver.create(); + await delegator.startAbility(want); + await driver.delayMs(1000); + + const ability: UIAbility = await delegator.getCurrentTopAbility(); + console.log('get top ability'); + expect(ability.context.abilityInfo.name).assertEqual('Createuint32Ability'); + + await driver.delayMs(1000); + const text = await driver.findComponent(ON.text('OH_JSVM_CreateUint32')); + await text.click(); + await driver.delayMs(1000); + await driver.assertComponentExist(ON.text('success')); + console.log('uitest: TestCreateUint32 end'); + done(); + }) + }) +} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmBasicDataTypes_pr1/createuint32/src/ohosTest/ets/test/List.test.ets b/code/DocsSample/ArkTs/JSVMAPI/JsvmBasicDataTypes_pr1/createuint32/src/ohosTest/ets/test/List.test.ets new file mode 100755 index 0000000000000000000000000000000000000000..1eac52fcebe8958e19a7b8fed2e8f39c520a3e42 --- /dev/null +++ b/code/DocsSample/ArkTs/JSVMAPI/JsvmBasicDataTypes_pr1/createuint32/src/ohosTest/ets/test/List.test.ets @@ -0,0 +1,20 @@ +/* + * Copyright (c) 2025 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 abilityTest from './Ability.test'; + +export default function testsuite() { + abilityTest(); +} \ No newline at end of file diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmBasicDataTypes_pr1/createuint32/src/ohosTest/module.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmBasicDataTypes_pr1/createuint32/src/ohosTest/module.json5 new file mode 100755 index 0000000000000000000000000000000000000000..08044e55c524ebde209d8485f6ccdd176c1eab6a --- /dev/null +++ b/code/DocsSample/ArkTs/JSVMAPI/JsvmBasicDataTypes_pr1/createuint32/src/ohosTest/module.json5 @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2025 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. + */ + +{ + "module": { + "name": "createuint32_test", + "type": "feature", + "deviceTypes": [ + "phone", + "tablet", + "2in1" + ], + "deliveryWithInstall": true, + "installationFree": false + } +} diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmBasicDataTypes_pr1/hvigor/hvigor-config.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmBasicDataTypes_pr1/hvigor/hvigor-config.json5 new file mode 100755 index 0000000000000000000000000000000000000000..8d4c6165b5641a4b568559d24ebba0d7105ee19c --- /dev/null +++ b/code/DocsSample/ArkTs/JSVMAPI/JsvmBasicDataTypes_pr1/hvigor/hvigor-config.json5 @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2025 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. + */ + +{ + "modelVersion": "5.0.2", + "dependencies": { + }, + "execution": { + // "analyze": "normal", /* Define the build analyze mode. Value: [ "normal" | "advanced" | false ]. Default: "normal" */ + // "daemon": true, /* Enable daemon compilation. Value: [ true | false ]. Default: true */ + // "incremental": true, /* Enable incremental compilation. Value: [ true | false ]. Default: true */ + // "parallel": true, /* Enable parallel compilation. Value: [ true | false ]. Default: true */ + // "typeCheck": false, /* Enable typeCheck. Value: [ true | false ]. Default: false */ + }, + "logging": { + // "level": "info" /* Define the log level. Value: [ "debug" | "info" | "warn" | "error" ]. Default: "info" */ + }, + "debugging": { + // "stacktrace": false /* Disable stacktrace compilation. Value: [ true | false ]. Default: false */ + }, + "nodeOptions": { + // "maxOldSpaceSize": 8192 /* Enable nodeOptions maxOldSpaceSize compilation. Unit M. Used for the daemon process. Default: 8192*/ + // "exposeGC": true /* Enable to trigger garbage collection explicitly. Default: true*/ + } +} diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmBasicDataTypes_pr1/hvigorfile.ts b/code/DocsSample/ArkTs/JSVMAPI/JsvmBasicDataTypes_pr1/hvigorfile.ts new file mode 100755 index 0000000000000000000000000000000000000000..2a5e543f190732c159beb574dfc9fa37bc94e156 --- /dev/null +++ b/code/DocsSample/ArkTs/JSVMAPI/JsvmBasicDataTypes_pr1/hvigorfile.ts @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2025 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 { appTasks } from '@ohos/hvigor-ohos-plugin'; + +export default { + system: appTasks, /* Built-in plugin of Hvigor. It cannot be modified. */ + plugins:[] /* Custom plugin to extend the functionality of Hvigor. */ +} diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmBasicDataTypes_pr1/oh-package.json5 b/code/DocsSample/ArkTs/JSVMAPI/JsvmBasicDataTypes_pr1/oh-package.json5 new file mode 100755 index 0000000000000000000000000000000000000000..635416b1c57681f2f8e7fad6afd753a3f0753daf --- /dev/null +++ b/code/DocsSample/ArkTs/JSVMAPI/JsvmBasicDataTypes_pr1/oh-package.json5 @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2025 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. + */ + +{ + "modelVersion": "5.0.2", + "description": "Please describe the basic information.", + "dependencies": { + }, + "devDependencies": { + "@ohos/hypium": "1.0.21", + "@ohos/hamock": "1.0.0" + } +} diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmBasicDataTypes_pr1/ohosTest.md b/code/DocsSample/ArkTs/JSVMAPI/JsvmBasicDataTypes_pr1/ohosTest.md new file mode 100644 index 0000000000000000000000000000000000000000..40a52c70853c1ab7fb241e9c92f55523bb17c832 --- /dev/null +++ b/code/DocsSample/ArkTs/JSVMAPI/JsvmBasicDataTypes_pr1/ohosTest.md @@ -0,0 +1,11 @@ +# JsvmBasicDataTypes 测试用例归档 + +## 用例表 + +| 测试功能 | 预置条件 | 输入 | 预期输出 | 是否自动 | 测试结果 | +| --------------------------------------------- | ------------ | ------------------------ | ---------------------- | -------- | -------- | +| 拉起应用 | 设备正常运行 | | 成功拉起应用 | 是 | Pass | +| 根据Double类型对象创建JavaScript number对象 | 位于首页 | 点击OH_JSVM_CreateDouble | 1秒后页面显示“success” | 是 | Pass | +| 根据Int32_t类型对象创建JavaScript number对象 | 位于首页 | 点击OH_JSVM_CreateInt32 | 1秒后页面显示“success” | 是 | Pass | +| 根据Int64_t类型对象创建JavaScript number对象 | 位于首页 | 点击OH_JSVM_CreateInt64 | 1秒后页面显示“success” | 是 | Pass | +| 根据Uint32_t类型对象创建JavaScript number对象 | 位于首页 | 点击OH_JSVM_CreateUint32 | 1秒后页面显示“success” | 是 | Pass | diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmBasicDataTypes_pr1/screenshots/JsvmBasicDataTypes_1.png b/code/DocsSample/ArkTs/JSVMAPI/JsvmBasicDataTypes_pr1/screenshots/JsvmBasicDataTypes_1.png new file mode 100755 index 0000000000000000000000000000000000000000..5915bb3e624287553ed80ddbbc74006188a1db97 Binary files /dev/null and b/code/DocsSample/ArkTs/JSVMAPI/JsvmBasicDataTypes_pr1/screenshots/JsvmBasicDataTypes_1.png differ diff --git a/code/DocsSample/ArkTs/JSVMAPI/JsvmBasicDataTypes_pr1/screenshots/JsvmBasicDataTypes_2.png b/code/DocsSample/ArkTs/JSVMAPI/JsvmBasicDataTypes_pr1/screenshots/JsvmBasicDataTypes_2.png new file mode 100755 index 0000000000000000000000000000000000000000..a00a7dcdbff1a648873037fb488bd54d8f167f3e Binary files /dev/null and b/code/DocsSample/ArkTs/JSVMAPI/JsvmBasicDataTypes_pr1/screenshots/JsvmBasicDataTypes_2.png differ