From a475d8ae7a7d4e620f1ea05b968d026758d7be11 Mon Sep 17 00:00:00 2001 From: tang jie Date: Mon, 30 Jun 2025 19:54:48 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BB=A3=E7=A0=81=E6=8C=87=E5=8D=97=20Issue:?= =?UTF-8?q?=20https://gitee.com/openharmony/docs/issues/ICFL20?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: tang jie --- .../arkts-utils/arraybuffer-object.md | 2 +- .../arkts-utils/async-concurrency-overview.md | 8 +- .../multi-thread-concurrency-overview.md | 2 +- .../arkts-utils/native-interthread-shared.md | 12 +-- .../arkts-utils/normal-object.md | 4 +- .../arkts-utils/sendable-constraints.md | 12 +-- .../arkts-utils/shared-arraybuffer-object.md | 2 +- .../arkts-utils/transferabled-object.md | 4 +- .../arkts-utils/arkts-dynamic-import.md | 36 +++++++ .../arkts-utils/arkts-module-side-effects.md | 39 +++++-- .../arkts-utils/js-apis-load-native-module.md | 6 ++ .../jsvm-debugger-cpuprofiler-heapsnapshot.md | 4 +- .../napi/use-jsvm-about-version.md | 2 +- ...stics-debugger-cpuprofiler-heapsnapshot.md | 4 +- .../application-dev/napi/use-jsvm-process.md | 4 +- .../napi/use-napi-about-array.md | 86 +++++++-------- .../napi/use-napi-about-arraybuffer.md | 24 ++--- .../napi/use-napi-about-bigint.md | 36 +++---- .../napi/use-napi-about-buffer.md | 36 +++---- .../napi/use-napi-about-class.md | 14 +-- .../napi/use-napi-about-cleanuphook.md | 14 +-- .../napi/use-napi-about-extension.md | 102 +++++++++--------- .../napi/use-napi-basic-data-types.md | 48 ++++----- .../ason-parsing-generation-Abnormal-1.md | 10 +- .../ason-parsing-generation-Abnormal-2.md | 8 +- .../ason-parsing-generation-Abnormal-3.md | 2 +- .../ason-parsing-generation-Abnormal-4.md | 8 +- .../ason-parsing-generation-Abnormal-5.md | 6 +- .../ason-parsing-generation-normal.md | 8 +- .../arkts-utils/async-concurrency-overview.md | 16 +-- .../multi-thread-concurrency-overview.md | 2 +- 31 files changed, 315 insertions(+), 246 deletions(-) diff --git a/en/application-dev/arkts-utils/arraybuffer-object.md b/en/application-dev/arkts-utils/arraybuffer-object.md index 85e7260de24..07368fb1f5f 100644 --- a/en/application-dev/arkts-utils/arraybuffer-object.md +++ b/en/application-dev/arkts-utils/arraybuffer-object.md @@ -82,7 +82,7 @@ struct Index { } } ``` - + ## Pass-by-Transfer diff --git a/en/application-dev/arkts-utils/async-concurrency-overview.md b/en/application-dev/arkts-utils/async-concurrency-overview.md index ac6ccdd6923..8aedb646ca7 100644 --- a/en/application-dev/arkts-utils/async-concurrency-overview.md +++ b/en/application-dev/arkts-utils/async-concurrency-overview.md @@ -31,7 +31,7 @@ const promise: Promise = new Promise((resolve: Function, reject: Functio }, 1000); }) ``` - + In the above code, the **setTimeout** function simulates an asynchronous operation and generates a random number after 1 second. If the random number is greater than 0.5, the **resolve** callback is invoked with the random number; otherwise, the **reject** callback is invoked with an error object. @@ -55,7 +55,7 @@ promise.then((result: number) => { console.error(error.message); // Executed on failure. }); ``` - + In this example, the callback function of the **then** method receives the successful result of the Promise object as a parameter and outputs it to the console. If the Promise object enters the rejected state, the callback function of the **catch** method receives the error object as a parameter and outputs it to the console. @@ -103,7 +103,7 @@ struct Index { } } ``` - + In this code, the await keyword is used to wait for the resolution of the Promise object and store its resolved value in the **result** variable. @@ -122,6 +122,6 @@ async function myAsyncFunction(): Promise { myAsyncFunction(); ``` - + \ No newline at end of file diff --git a/en/application-dev/arkts-utils/multi-thread-concurrency-overview.md b/en/application-dev/arkts-utils/multi-thread-concurrency-overview.md index 7a149a0b8b4..69c7325e0f4 100644 --- a/en/application-dev/arkts-utils/multi-thread-concurrency-overview.md +++ b/en/application-dev/arkts-utils/multi-thread-concurrency-overview.md @@ -195,7 +195,7 @@ struct Index { } } ``` - + You can also wait until all the producer's tasks are complete, and then pass the results to the UI thread through serialization. After the UI thread receives the results, the consumer can handle them all together. diff --git a/en/application-dev/arkts-utils/native-interthread-shared.md b/en/application-dev/arkts-utils/native-interthread-shared.md index 57d608e4c0d..ff737ad1a65 100644 --- a/en/application-dev/arkts-utils/native-interthread-shared.md +++ b/en/application-dev/arkts-utils/native-interthread-shared.md @@ -22,7 +22,7 @@ export class SendableObjTest { } } ``` - + Native implementation to load ArkTS modules @@ -73,7 +73,7 @@ static void *CreateArkRuntimeFunc(void *arg) return nullptr; } ``` - + The process consists of four steps: creating an execution environment, loading modules, searching for and calling functions (or directly creating Sendable objects through Node-API), and finally destroying the execution environment. For details about how to load modules, see [Loading a Module Using Node-API](../napi/use-napi-load-module-with-info.md). For details about how to search for and call functions and more Node-API capabilities, see [Node-API](../reference/native-lib/napi.md#node-api). @@ -94,7 +94,7 @@ export class SendableObjTest { } } ``` - + Native implementation for serialization and deserialization of Sendable objects @@ -207,14 +207,14 @@ extern "C" __attribute__((constructor)) void RegisterEntryModule(void) { napi_module_register(&demoModule); } ``` - + ``` // Index.d.ts export const testSendSendable: () => void; ``` - + UI main thread invocation @@ -248,7 +248,7 @@ struct Index { } } ``` - + The logic implementation of the entire process is as follows: diff --git a/en/application-dev/arkts-utils/normal-object.md b/en/application-dev/arkts-utils/normal-object.md index b621cac5665..2dfb5850b24 100644 --- a/en/application-dev/arkts-utils/normal-object.md +++ b/en/application-dev/arkts-utils/normal-object.md @@ -22,7 +22,7 @@ export class TestA { name: string = 'ClassA'; } ``` - + ```ts // Index.ets @@ -68,6 +68,6 @@ struct Index { } } ``` - + \ No newline at end of file diff --git a/en/application-dev/arkts-utils/sendable-constraints.md b/en/application-dev/arkts-utils/sendable-constraints.md index f8e87235183..9a94d293940 100644 --- a/en/application-dev/arkts-utils/sendable-constraints.md +++ b/en/application-dev/arkts-utils/sendable-constraints.md @@ -120,7 +120,7 @@ class A { a: number = 0; } ``` - + **Incorrect Example** @@ -148,7 +148,7 @@ class A { a: number = 0; } ``` - + **Incorrect Example** @@ -212,7 +212,7 @@ try { console.error(`taskpool execute: Code: ${e.code}, message: ${e.message}`); } ``` - + **Incorrect Example** @@ -267,7 +267,7 @@ class C { } } ``` - + **Incorrect Example** @@ -372,7 +372,7 @@ import { collections } from '@kit.ArkTS'; let arr1: collections.Array = new collections.Array(1, 2, 3); // The type is Sendable. ``` - + **Incorrect Example** @@ -404,7 +404,7 @@ class SendableA { let a1: A = new SendableA() as A; ``` - + **Incorrect Example** diff --git a/en/application-dev/arkts-utils/shared-arraybuffer-object.md b/en/application-dev/arkts-utils/shared-arraybuffer-object.md index 1f9c0059042..e8e35cc8047 100644 --- a/en/application-dev/arkts-utils/shared-arraybuffer-object.md +++ b/en/application-dev/arkts-utils/shared-arraybuffer-object.md @@ -31,6 +31,6 @@ setTimeout(() => { Atomics.notify(int32, 0, 1); }, 1000); ``` - + \ No newline at end of file diff --git a/en/application-dev/arkts-utils/transferabled-object.md b/en/application-dev/arkts-utils/transferabled-object.md index 86785a438dd..12f149b2bae 100644 --- a/en/application-dev/arkts-utils/transferabled-object.md +++ b/en/application-dev/arkts-utils/transferabled-object.md @@ -80,7 +80,7 @@ struct Index { } } ``` - + ```ts // pixelMapTest.ets @@ -100,6 +100,6 @@ export async function loadPixelMap(rawFileDescriptor: number): Promise return pixelMap; } ``` - + \ No newline at end of file diff --git a/zh-cn/application-dev/arkts-utils/arkts-dynamic-import.md b/zh-cn/application-dev/arkts-utils/arkts-dynamic-import.md index 37e16e6afc5..eb9a5544968 100644 --- a/zh-cn/application-dev/arkts-utils/arkts-dynamic-import.md +++ b/zh-cn/application-dev/arkts-utils/arkts-dynamic-import.md @@ -35,11 +35,13 @@ export function addHarLibrary(a:number, b:number):number { return c; } ``` + ```typescript // harlibrary's Index.ets export { Calc, addHarLibrary } from './src/main/ets/utils/Calc' ``` + ```json5 // HAP's oh-package.json5 @@ -67,6 +69,7 @@ import('harlibrary').then((ns:ESObject) => { ns[functionName](16, 17); // 调用全局方法addHarLibrary() }); ``` + ## 动态import实现方案介绍 动态import根据入参是常量还是变量,分成动态import常量表达式和动态import变量表达式两大特性规格。 @@ -110,6 +113,7 @@ import('harlibrary').then((ns:ESObject) => { return c; } ``` + ```typescript // HAP's src/main/ets/pages/Index.ets @@ -123,6 +127,7 @@ import('harlibrary').then((ns:ESObject) => { console.info(ns.add(3, 5)); } ``` + ```json5 // HAP's oh-package.json5 @@ -148,6 +153,7 @@ import('harlibrary').then((ns:ESObject) => { console.info(ns.add(3, 5)); }); ``` + ```json5 // HAP's oh-package.json5 @@ -166,6 +172,7 @@ import('harlibrary').then((ns:ESObject) => { return c; } ``` + ```typescript // HAP's src/main/ets/pages/Index.ets @@ -173,6 +180,7 @@ import('harlibrary').then((ns:ESObject) => { console.info(ns.add(3, 5)); }); ``` + ```json5 // HAP's oh-package.json5 @@ -198,6 +206,7 @@ import('harlibrary').then((ns:ESObject) => { console.info(ns.add(3, 5)); }); ``` + ```json5 // HAP's oh-package.json5 @@ -214,6 +223,7 @@ import('harlibrary').then((ns:ESObject) => { console.info('DynamicImport @ohos/crypto-js: ' + ns.CryptoJS.MD5(123456)); }); ``` + ```json5 // HAP's oh-package.json5 @@ -230,6 +240,7 @@ import('harlibrary').then((ns:ESObject) => { console.info('DynamicImport json5'); }); ``` + ```json5 // HAP's oh-package.json5 @@ -248,6 +259,7 @@ import('harlibrary').then((ns:ESObject) => { return c; } ``` + ```typescript // HAP's src/main/ets/pages/Index.ets @@ -255,6 +267,7 @@ import('harlibrary').then((ns:ESObject) => { console.info(ns.add(3, 5)); }); ``` + - **HAP常量动态import自己的Native库** @@ -262,6 +275,7 @@ import('harlibrary').then((ns:ESObject) => { // libnativeapi.so's index.d.ts export const add: (a:number, b:number) => number; ``` + ```typescript // HAP's src/main/ets/pages/Index.ets @@ -269,6 +283,7 @@ import('harlibrary').then((ns:ESObject) => { console.info('DynamicImport libnativeapi.so: ' + ns.default.add(2, 3)); }); ``` + ```json5 // HAP's oh-package.json5 @@ -276,6 +291,7 @@ import('harlibrary').then((ns:ESObject) => { "libnativeapi.so": "file:./src/main/cpp/types/libnativeapi" } ``` + - **HAP常量动态import加载API** @@ -287,6 +303,7 @@ import('harlibrary').then((ns:ESObject) => { import('@ohos.matrix4').then((ns:ESObject) => { ns.default.identity(); }); import('@ohos.hilog').then((ns:ESObject) => { ns.default.info(0x0000, 'testTag', '%{public}s', 'DynamicImport @ohos.hilog.'); }); ``` + ### 动态import变量表达式 @@ -310,6 +327,7 @@ import(filePath).then((obj: ESObject) => { console.info('DynamicImport I am a file'); } ``` + 对应的runtimeOnly配置: @@ -346,6 +364,7 @@ import(filePath).then((obj: ESObject) => { console.info(ns.add(3, 5)); }); ``` + ```json5 // HAP's oh-package.json5 "dependencies": { @@ -382,6 +401,7 @@ import(filePath).then((obj: ESObject) => { console.info(ns.add(3, 5)); }); ``` + ```json5 // HAP's oh-package.json5 "dependencies": { @@ -410,6 +430,7 @@ import(filePath).then((obj: ESObject) => { console.info('DynamicImport @ohos/crypto-js: ' + ns.CryptoJS.MD5(123456)); }); ``` + ```json5 // HAP's oh-package.json5 "dependencies": { @@ -438,6 +459,7 @@ import(filePath).then((obj: ESObject) => { console.info('DynamicImport json5'); }); ``` + ```json5 // HAP's oh-package.json5 "dependencies": { @@ -474,6 +496,7 @@ import(filePath).then((obj: ESObject) => { console.info(ns.add(3, 5)); }); ``` + ```json5 // HAP's build-profile.json5 "buildOption": { @@ -500,6 +523,7 @@ import(filePath).then((obj: ESObject) => { console.info('DynamicImport libnativeapi.so: ' + ns.default.add(2, 3)); }); ``` + ```json5 // HAP's oh-package.json5 "dependencies": { @@ -518,6 +542,7 @@ import(filePath).then((obj: ESObject) => { } } ``` + - **HAP变量动态import加载API** @@ -534,6 +559,8 @@ import(filePath).then((obj: ESObject) => { packageName = '@ohos.hilog'; import(packageName).then((ns:ESObject) => { ns.default.info(0x0000, 'testTag', '%{public}s', 'DynamicImport @ohos.hilog.'); }); ``` + + 变量动态import加载API时无需配置runtimeOnly。 ### HAR模块间动态import依赖解耦 @@ -584,6 +611,8 @@ import(harName).then((ns:ESObject) => { console.info('DynamicImport addHar1 4 + 5 = ' + ns.addHar1(4, 5)); }); ``` + + ```json5 // har1's oh-package.json5 "dependencies": { @@ -606,6 +635,8 @@ import(harName).then((ns:ESObject) => { // har1's Index.ets export { addHar1 } from './src/main/ets/utils/Calc' ``` + + ```typescript // har1's src/main/ets/utils/Calc.ets export function addHar1(a:number, b:number):number { @@ -619,10 +650,14 @@ export function addHar1(a:number, b:number):number { return c; } ``` + + ```typescript // har2's Index.ets export { addHar2 } from './src/main/ets/utils/Calc' ``` + + ```typescript // har2's src/main/ets/utils/Calc.ets export function addHar2(a:number, b:number):number { @@ -631,6 +666,7 @@ export function addHar2(a:number, b:number):number { return c; } ``` + har1对har2的依赖dependencies和runtimeOnly配置转移到HAP中,har1不需要配置对har2的dependencies和runtimeOnly配置: diff --git a/zh-cn/application-dev/arkts-utils/arkts-module-side-effects.md b/zh-cn/application-dev/arkts-utils/arkts-module-side-effects.md index 62258287a7d..16d2fe85b9d 100644 --- a/zh-cn/application-dev/arkts-utils/arkts-module-side-effects.md +++ b/zh-cn/application-dev/arkts-utils/arkts-module-side-effects.md @@ -40,11 +40,15 @@ Module loaded! ```typescript // module.ets export const data = 1; +``` + +```typescript // main.ets import { data } from './module' console.log(data); ``` + 输出内容: @@ -127,13 +131,20 @@ export let data1 = "data from module" export function changeGlobalVar() { globalThis.someGlobalVar = 100; } +``` + + +```typescript // sideEffectModule.ets export let data2 = "data from side effect module" export function changeGlobalVar() { globalThis.someGlobalVar = 200; } +``` + +```typescript // moduleUseGlobalVar.ets import { data1, changeGlobalVar } from './module' export function useGlobalVar() { @@ -141,6 +152,10 @@ export function useGlobalVar() { changeGlobalVar(); // 在需要的时候执行代码,而不是模块加载时执行。 console.log(globalThis.someGlobalVar); } +``` + + +```typescript // main.ets(执行入口) import { data1 } from "./module" @@ -153,6 +168,7 @@ function maybeNotCalledAtAll() { console.log(data2); } ``` + 输出内容: @@ -171,6 +187,10 @@ data from module // module.ets export let data = "data from module" AppStorage.setOrCreate("SomeAppStorageVar", 200); // 修改应用全局的UI状态 +``` + + +```typescript // Index.ets import { data } from "./module" // 将AppStorage中的SomeAppStorageVar改为200 @@ -195,6 +215,7 @@ function maybeNotCalledAtAll() { console.log(data); } ``` + 显示内容: @@ -260,7 +281,9 @@ export let data = "data from modifyPrototype" Array.prototype.includes = function (value) { return this.indexOf(value) !== -1; }; - +``` + +```typescript // main.ets import { data } from "./modifyPrototype" // 此时修改了Array的原型链 let arr = [1, 2, 3, 4]; @@ -269,7 +292,7 @@ function maybeNotCalledAtAll() { console.log(data); } ``` - + **产生的副作用** 修改内置的全局对象或原型链,影响其他代码运行。 @@ -289,13 +312,15 @@ ArkTS模块化支持循环依赖,即模块A依赖模块B,同时模块B又依 import { b } from "./b" console.log('Module A: ', b); export const a = 'A'; - +``` + +```typescript // b.ets import { a } from "./a" console.log('Module B: ', a); export const b = 'B'; ``` - + 输出内容: ```text @@ -322,13 +347,15 @@ Stacktrace: // module.ets export let data = "data from module" globalThis.someGlobalVar = 100; - +``` + +```typescript // moduleUseGlobalVar.ets import lazy { data } from "./module" console.log(globalThis.someGlobalVar); // 此时由于lazy特性,module模块还未执行,someGlobalVar的值为undefined console.log(data); // 使用到module模块的变量,此时module模块执行,someGlobalVar的值变为100 ``` - + 输出内容: ```text diff --git a/zh-cn/application-dev/arkts-utils/js-apis-load-native-module.md b/zh-cn/application-dev/arkts-utils/js-apis-load-native-module.md index 7e4805bff2a..4da7e507ebb 100644 --- a/zh-cn/application-dev/arkts-utils/js-apis-load-native-module.md +++ b/zh-cn/application-dev/arkts-utils/js-apis-load-native-module.md @@ -34,6 +34,7 @@ loadNativeModule(moduleName: string): Object; let hilog: ESObject = loadNativeModule("@ohos.hilog"); hilog.info(0, "testTag", "loadNativeModule ohos.hilog success"); ``` + - **HAP加载Native库** @@ -43,6 +44,8 @@ libentry.so的index.d.ts文件如下: //index.d.ts export const add: (a: number, b: number) => number; ``` + + 1.在加载本地so库时,需在oh-package.json5文件中配置dependencies项。 @@ -53,6 +56,7 @@ export const add: (a: number, b: number) => number; } } ``` + 2.在build-profile.json5中进行配置。 @@ -69,6 +73,7 @@ export const add: (a: number, b: number) => number; } } ``` + 3.使用loadNativeModule加载libentry.so,并调用函数add。 @@ -76,3 +81,4 @@ export const add: (a: number, b: number) => number; let module: ESObject = loadNativeModule("libentry.so"); let sum: number = module.add(1, 2); ``` + diff --git a/zh-cn/application-dev/napi/jsvm-debugger-cpuprofiler-heapsnapshot.md b/zh-cn/application-dev/napi/jsvm-debugger-cpuprofiler-heapsnapshot.md index 774d0a1bf32..2ee5812a939 100644 --- a/zh-cn/application-dev/napi/jsvm-debugger-cpuprofiler-heapsnapshot.md +++ b/zh-cn/application-dev/napi/jsvm-debugger-cpuprofiler-heapsnapshot.md @@ -128,7 +128,7 @@ void TestJSVM() { } ``` - + ### 使用 OH_JSVM_OpenInspectorWithName @@ -316,7 +316,7 @@ static JSVM_PropertyDescriptor descriptor[] = { ```cpp const char *srcCallNative = R"JS(runScriptWithStatistics();)JS"; ``` - + 预计的输出结果: ``` 在对应鸿蒙设备内生成两个文件用于后续调优: diff --git a/zh-cn/application-dev/napi/use-jsvm-about-version.md b/zh-cn/application-dev/napi/use-jsvm-about-version.md index 4430fe1f260..c61c134cf88 100644 --- a/zh-cn/application-dev/napi/use-jsvm-about-version.md +++ b/zh-cn/application-dev/napi/use-jsvm-about-version.md @@ -70,4 +70,4 @@ static JSVM_PropertyDescriptor descriptor[] = { {"getVMInfo", nullptr, method++, nullptr, nullptr, nullptr, JSVM_DEFAULT}, }; ``` - + diff --git a/zh-cn/application-dev/napi/use-jsvm-heapstatistics-debugger-cpuprofiler-heapsnapshot.md b/zh-cn/application-dev/napi/use-jsvm-heapstatistics-debugger-cpuprofiler-heapsnapshot.md index 8727ced17f5..eb64f7da06f 100644 --- a/zh-cn/application-dev/napi/use-jsvm-heapstatistics-debugger-cpuprofiler-heapsnapshot.md +++ b/zh-cn/application-dev/napi/use-jsvm-heapstatistics-debugger-cpuprofiler-heapsnapshot.md @@ -70,7 +70,7 @@ static JSVM_PropertyDescriptor descriptor[] = { ```c++ const char *srcCallNative = R"JS(getVM())JS"; ``` - + 预计的输出结果: ``` @@ -143,7 +143,7 @@ static JSVM_PropertyDescriptor descriptor[] = { ```c++ const char *srcCallNative = R"JS(getHeapStatistics())JS"; ``` - + 预计的输出结果: ``` JSVM API heap totalHeapSize: 1597440 diff --git a/zh-cn/application-dev/napi/use-jsvm-process.md b/zh-cn/application-dev/napi/use-jsvm-process.md index a12c2d8ff6e..5984579835d 100644 --- a/zh-cn/application-dev/napi/use-jsvm-process.md +++ b/zh-cn/application-dev/napi/use-jsvm-process.md @@ -22,7 +22,7 @@ // entry/src/main/cpp/types/libentry/index.d.ts export const runTest: () => void; ``` - + - 在oh-package.json5文件中将index.d.ts与cpp文件关联起来。 @@ -237,7 +237,7 @@ struct Index { } } ``` - + 预期输出结果 ```ts diff --git a/zh-cn/application-dev/napi/use-napi-about-array.md b/zh-cn/application-dev/napi/use-napi-about-array.md index eee38f03efc..4e979b4be0e 100644 --- a/zh-cn/application-dev/napi/use-napi-about-array.md +++ b/zh-cn/application-dev/napi/use-napi-about-array.md @@ -64,7 +64,7 @@ static napi_value CreateArray(napi_env env, napi_callback_info info) return jsArray; } ``` - + 接口声明 @@ -72,7 +72,7 @@ static napi_value CreateArray(napi_env env, napi_callback_info info) // index.d.ts export const createArray: () => number[]; ``` - + ArkTS侧示例代码 @@ -82,7 +82,7 @@ import testNapi from 'libentry.so'; hilog.info(0x0000, 'testTag', 'Test Node-API napi_create_array:%{public}s', JSON.stringify(testNapi.createArray())); ``` - + ### napi_create_array_with_length @@ -109,7 +109,7 @@ static napi_value CreateArrayWithLength(napi_env env, napi_callback_info info) return jsArray; } ``` - + 接口声明 @@ -117,7 +117,7 @@ static napi_value CreateArrayWithLength(napi_env env, napi_callback_info info) // index.d.ts export const createArrayWithLength: (length: number) => void[]; ``` - + ArkTS侧示例代码 @@ -128,7 +128,7 @@ import testNapi from 'libentry.so'; let array = testNapi.createArrayWithLength(6); hilog.info(0x0000, 'testTag', 'Test Node-API napi_create_array_with_length:%{public}d', array.length); ``` - + ### napi_get_array_length @@ -160,7 +160,7 @@ static napi_value GetArrayLength(napi_env env, napi_callback_info info) return result; } ``` - + 接口声明 @@ -168,7 +168,7 @@ static napi_value GetArrayLength(napi_env env, napi_callback_info info) // index.d.ts export const getArrayLength: (arr: Array) => number | undefined; ``` - + ArkTS侧示例代码 @@ -179,7 +179,7 @@ import testNapi from 'libentry.so'; const arr = [0, 1, 2, 3, 4, 5]; hilog.info(0x0000, 'testTag', 'Test Node-API get_array_length:%{public}d', testNapi.getArrayLength(arr)); ``` - + ### napi_is_array @@ -211,7 +211,7 @@ static napi_value IsArray(napi_env env, napi_callback_info info) return returnValue; } ``` - + 接口声明 @@ -219,7 +219,7 @@ static napi_value IsArray(napi_env env, napi_callback_info info) // index.d.ts export const isArray: (data: Array | T) => boolean | undefined; ``` - + ArkTS侧示例代码 @@ -235,7 +235,7 @@ try { hilog.error(0x0000, 'testTag', 'Test Node-API napi_is_array error: %{public}s', error.message); } ``` - + ### napi_set_element @@ -271,14 +271,14 @@ static napi_value NapiSetElement(napi_env env, napi_callback_info info) return nullptr; } ``` - + 接口声明 ```ts export const napiSetElement: (arr: Array, index: number, value: T) => void; ``` - + ArkTS侧示例代码 @@ -302,7 +302,7 @@ testNapi.napiSetElement(arr, 4, obj); let objAsString = JSON.stringify(arr[4]); hilog.info(0x0000, 'testTag', 'Test Node-API napi_set_element arr[4]: %{public}s', objAsString); ``` - + ### napi_get_element @@ -329,7 +329,7 @@ static napi_value NapiGetElement(napi_env env, napi_callback_info info) return result; } ``` - + 接口声明 @@ -337,7 +337,7 @@ static napi_value NapiGetElement(napi_env env, napi_callback_info info) // index.d.ts export const napiGetElement: (arr: Array, index: number) => number | string | Object | boolean | undefined; ``` - + ArkTS侧示例代码 @@ -361,7 +361,7 @@ hilog.info(0x0000, 'testTag', 'Test Node-API napi_get_element arr[3]: %{public}s hilog.info(0x0000, 'testTag', 'Test Node-API napi_get_element arr[4]: %{public}s', JSON.stringify(testNapi.napiGetElement(arr, 4))); hilog.info(0x0000, 'testTag', 'Test Node-API napi_get_element arr[null]: %{public}s', testNapi.napiGetElement(arr, 5)); ``` - + ### napi_has_element @@ -390,7 +390,7 @@ static napi_value NapiHasElement(napi_env env, napi_callback_info info) return result; } ``` - + 接口声明 @@ -398,7 +398,7 @@ static napi_value NapiHasElement(napi_env env, napi_callback_info info) // index.d.ts export const napiHasElement: (arr: Array, index: number) => boolean; ``` - + ArkTS侧示例代码 @@ -410,7 +410,7 @@ let arr = [10, 'hello', null, 'world']; hilog.info(0x0000, 'testTag', 'Test Node-API napi_has_element arr[0]: %{public}s', testNapi.napiHasElement(arr, 0)); hilog.info(0x0000, 'testTag', 'Test Node-API napi_has_element arr[7]: %{public}s', testNapi.napiHasElement(arr, 7)); ``` - + ### napi_delete_element @@ -439,7 +439,7 @@ static napi_value NapiDeleteElement(napi_env env, napi_callback_info info) return result; } ``` - + 接口声明 @@ -447,7 +447,7 @@ static napi_value NapiDeleteElement(napi_env env, napi_callback_info info) // index.d.ts export const napiDeleteElement: (arr: Array, index: number) => boolean; ``` - + ArkTS侧示例代码 @@ -462,7 +462,7 @@ hilog.info(0x0000, 'testTag', 'Test Node-API napi_delete_element arr[0]: %{publi hilog.info(0x0000, 'testTag', 'Test Node-API napi_has_element deleted arr[0]: %{public}s', testNapi.napiHasElement(arr, 0)); hilog.info(0x0000, 'testTag', 'Test Node-API napi_get_element arr[0]: %{public}d', testNapi.napiGetElement(arr, 0)); ``` - + ### napi_create_typedarray @@ -527,7 +527,7 @@ static napi_value CreateTypedArray(napi_env env, napi_callback_info info) return typedArray; } ``` - + 接口声明 @@ -548,7 +548,7 @@ export const enum TypedArrayTypes { } export const createTypedArray: (type: TypedArrayTypes) => T; ``` - + ArkTS侧示例代码 @@ -566,7 +566,7 @@ if (uint8Array instanceof Uint8Array) { hilog.info(0x0000, 'testTag', ' Node-API napi_create_typedarray: Uint8Array'); } ``` - + 需要对use-napi-process.md中的模块初始化部分进行修改,具体见如下: @@ -598,7 +598,7 @@ static napi_value Init(napi_env env, napi_value exports) EXTERN_C_END ``` - + ### napi_is_typedarray @@ -630,7 +630,7 @@ static napi_value IsTypedarray(napi_env env, napi_callback_info info) return returnValue; } ``` - + 接口声明 @@ -638,7 +638,7 @@ static napi_value IsTypedarray(napi_env env, napi_callback_info info) // index.d.ts export const isTypedarray: (data: Object) => boolean | undefined; ``` - + ArkTS侧示例代码 @@ -654,7 +654,7 @@ try { hilog.error(0x0000, 'testTag', 'Test Node-API napi_is_typedarray error: %{public}s', error.message); } ``` - + ### napi_get_typedarray_info @@ -713,7 +713,7 @@ static napi_value GetTypedarrayInfo(napi_env env, napi_callback_info info) return result; } ``` - + 接口声明 @@ -721,7 +721,7 @@ static napi_value GetTypedarrayInfo(napi_env env, napi_callback_info info) // index.d.ts export const getTypedarrayInfo: (typeArray: T, infoType: number) => ArrayBuffer | number | boolean; ``` - + ArkTS侧示例代码 @@ -747,7 +747,7 @@ hilog.info(0x0000, 'Node-API', 'get_typedarray_info_isIn8Array: %{public}s', tes hilog.info(0x0000, 'Node-API', 'get_typedarray_info_length: %{public}d', testNapi.getTypedarrayInfo(int8Array, InfoType.LENGTH)); hilog.info(0x0000, 'Node-API', 'get_typedarray_info_byte_offset: %{public}d', testNapi.getTypedarrayInfo(int8Array, InfoType.BYTE_OFFSET)); ``` - + ### napi_create_dataview @@ -791,7 +791,7 @@ static napi_value CreateDataView(napi_env env, napi_callback_info info) return result; } ``` - + 接口声明 @@ -799,7 +799,7 @@ static napi_value CreateDataView(napi_env env, napi_callback_info info) // index.d.ts export const createDataView: (arraybuffer:ArrayBuffer) => DataView | undefined; ``` - + ArkTS侧示例代码 @@ -812,7 +812,7 @@ const dataView = testNapi.createDataView(arrayBuffer) as DataView; hilog.info(0x0000, 'testTag', 'Test Node-API dataView:%{public}d', dataView.byteLength); hilog.info(0x0000, 'testTag', 'Test Node-API dataView第一个数据:%{public}d', dataView.getInt8(0)); ``` - + ### napi_is_dataview @@ -845,7 +845,7 @@ static napi_value IsDataView(napi_env env, napi_callback_info info) return returnValue; } ``` - + 接口声明 @@ -853,7 +853,7 @@ static napi_value IsDataView(napi_env env, napi_callback_info info) // index.d.ts export const isDataView: (date: DataView | string) => boolean | undefined; ``` - + ArkTS侧示例代码 @@ -870,7 +870,7 @@ try { hilog.error(0x0000, 'testTag', 'Test Node-API napi_is_dataview error: %{public}s', error.message); } ``` - + ### napi_get_dataview_info @@ -922,7 +922,7 @@ static napi_value GetDataViewInfo(napi_env env, napi_callback_info info) return result; } ``` - + 接口声明 @@ -930,7 +930,7 @@ static napi_value GetDataViewInfo(napi_env env, napi_callback_info info) // index.d.ts export const getDataViewInfo: (dataView: DataView, infoType: number) => ArrayBuffer | number; ``` - + ArkTS侧示例代码 @@ -958,7 +958,7 @@ hilog.info(0x0000, 'Node-API', 'get_dataview_info_arraybuffer %{public}s', arr.t // 传入DataView类型参数查询DataView开始投影的数据缓冲区中的字节偏移量 hilog.info(0x0000, 'Node-API', 'get_dataview_info_byteoffset %{public}d', testNapi.getDataViewInfo(dataView, InfoType.BYTE_OFFSET)); ``` - + 以上代码如果要在native cpp中打印日志,需在CMakeLists.txt文件中添加以下配置信息(并添加头文件:#include "hilog/log.h"): diff --git a/zh-cn/application-dev/napi/use-napi-about-arraybuffer.md b/zh-cn/application-dev/napi/use-napi-about-arraybuffer.md index e6a5ebc3437..6ed9ffa5d0e 100644 --- a/zh-cn/application-dev/napi/use-napi-about-arraybuffer.md +++ b/zh-cn/application-dev/napi/use-napi-about-arraybuffer.md @@ -52,7 +52,7 @@ static napi_value IsArrayBuffer(napi_env env, napi_callback_info info) return returnValue; } ``` - + 接口声明 @@ -60,7 +60,7 @@ static napi_value IsArrayBuffer(napi_env env, napi_callback_info info) // index.d.ts export const isArrayBuffer: (arrayBuffer: T) => boolean | void; ``` - + ArkTS侧示例代码 @@ -76,7 +76,7 @@ try { hilog.error(0x0000, 'testTag', 'Test Node-API napi_is_arraybuffer error: %{public}s', error.message); } ``` - + 输出日志: @@ -127,7 +127,7 @@ static napi_value GetArrayBufferInfo(napi_env env, napi_callback_info info) return result; } ``` - + 接口声明 @@ -139,7 +139,7 @@ export class ArrayBufferInfo { } export const getArrayBufferInfo: (data: ArrayBuffer) => ArrayBufferInfo | void; ``` - + ArkTS侧示例代码 @@ -150,7 +150,7 @@ import testNapi from 'libentry.so'; const buffer = new ArrayBuffer(10); hilog.info(0x0000, 'testTag', 'Test Node-API get_arrayBuffer_info:%{public}s ', JSON.stringify(testNapi.getArrayBufferInfo(buffer))); ``` - + 输出日志: @@ -196,7 +196,7 @@ static napi_value IsDetachedArrayBuffer(napi_env env, napi_callback_info info) return returnValue; } ``` - + 接口声明 @@ -205,7 +205,7 @@ static napi_value IsDetachedArrayBuffer(napi_env env, napi_callback_info info) export const detachedArrayBuffer: (buffer:ArrayBuffer) => ArrayBuffer; export const isDetachedArrayBuffer: (arrayBuffer: ArrayBuffer) => boolean; ``` - + ArkTS侧示例代码 @@ -220,7 +220,7 @@ try { hilog.error(0x0000, 'testTag', 'Test Node-API napi_is_detached_arraybuffer error: %{public}s', error.message); } ``` - + 输出日志: @@ -262,7 +262,7 @@ static napi_value CreateArrayBuffer(napi_env env, napi_callback_info info) return result; } ``` - + 接口声明 @@ -270,7 +270,7 @@ static napi_value CreateArrayBuffer(napi_env env, napi_callback_info info) // index.d.ts export const createArrayBuffer: (size: number) => ArrayBuffer; ``` - + ArkTS侧示例代码 @@ -280,7 +280,7 @@ import testNapi from 'libentry.so'; hilog.info(0x0000, 'testTag', 'Test Node-API napi_create_arraybuffer:%{public}s', testNapi.createArrayBuffer(10).toString()); ``` - + 以上代码如果要在native cpp中打印日志,需在CMakeLists.txt文件中添加以下配置信息(并添加头文件:#include "hilog/log.h"): diff --git a/zh-cn/application-dev/napi/use-napi-about-bigint.md b/zh-cn/application-dev/napi/use-napi-about-bigint.md index 64f84c11a89..d2983b6c20d 100644 --- a/zh-cn/application-dev/napi/use-napi-about-bigint.md +++ b/zh-cn/application-dev/napi/use-napi-about-bigint.md @@ -47,7 +47,7 @@ static napi_value CreateBigintInt64t(napi_env env, napi_callback_info info) return returnValue; } ``` - + 接口声明 @@ -55,7 +55,7 @@ static napi_value CreateBigintInt64t(napi_env env, napi_callback_info info) // index.d.ts export const createBigintInt64t: () => bigint; ``` - + ArkTS侧示例代码 @@ -65,7 +65,7 @@ import testNapi from 'libentry.so'; hilog.info(0x0000, 'testTag', 'Test Node-API napi_create_bigint_int64: %{public}d', testNapi.createBigintInt64t()); ``` - + ### napi_create_bigint_uint64 @@ -86,7 +86,7 @@ static napi_value CreateBigintUint64t(napi_env env, napi_callback_info info) return returnValue; } ``` - + 接口声明 @@ -94,7 +94,7 @@ static napi_value CreateBigintUint64t(napi_env env, napi_callback_info info) // index.d.ts export const createBigintUint64t: () => bigint; ``` - + ArkTS侧示例代码 @@ -104,7 +104,7 @@ import testNapi from 'libentry.so'; hilog.info(0x0000, 'testTag', 'Test Node-API napi_create_bigint_uint64: %{public}d', testNapi.createBigintUint64t()); ``` - + ### napi_create_bigint_words @@ -130,7 +130,7 @@ static napi_value CreateBigintWords(napi_env env, napi_callback_info info) return returnValue; } ``` - + 接口声明 @@ -138,7 +138,7 @@ static napi_value CreateBigintWords(napi_env env, napi_callback_info info) // index.d.ts export const createBigintWords: () => bigint | void; ``` - + ArkTS侧示例代码 @@ -151,7 +151,7 @@ try { hilog.error(0x0000, 'testTag', 'Test Node-API NapiGetValueBigint: %{public}s', error.message); } ``` - + ### napi_get_value_bigint_int64 @@ -182,7 +182,7 @@ static napi_value GetValueBigintInt64t(napi_env env, napi_callback_info info) return returnValue; } ``` - + 接口声明 @@ -190,7 +190,7 @@ static napi_value GetValueBigintInt64t(napi_env env, napi_callback_info info) // index.d.ts export const getValueBigintInt64t: (bigInt64: bigint) => boolean | void; ``` - + ArkTS侧示例代码 @@ -205,7 +205,7 @@ try { hilog.error(0x0000, 'testTag', 'Test Node-API NapiGetValueBigint: %{public}s', error.message); } ``` - + ### napi_get_value_bigint_uint64 @@ -236,7 +236,7 @@ static napi_value GetValueBigintUint64t(napi_env env, napi_callback_info info) return returnValue; } ``` - + 接口声明 @@ -244,7 +244,7 @@ static napi_value GetValueBigintUint64t(napi_env env, napi_callback_info info) // index.d.ts export const getValueBigintUint64t: (bigUint64: bigint) => boolean | void; ``` - + ArkTS侧示例代码 @@ -259,7 +259,7 @@ try { hilog.error(0x0000, 'testTag', 'Test Node-API NapiGetValueBigint: %{public}s', error.message); } ``` - + ### napi_get_value_bigint_words @@ -296,7 +296,7 @@ static napi_value GetValueBigintWords(napi_env env, napi_callback_info info) return returnValue; } ``` - + 接口声明 @@ -304,7 +304,7 @@ static napi_value GetValueBigintWords(napi_env env, napi_callback_info info) // index.d.ts export const getValueBigintWords: (bigIntWords: bigint) => bigint | void; ``` - + ArkTS侧示例代码 @@ -320,7 +320,7 @@ try { hilog.error(0x0000, 'testTag', 'Test Node-API NapiGetValueBigint: %{public}s', error.message); } ``` - + 以上代码如果要在native cpp中打印日志,需在CMakeLists.txt文件中添加以下配置信息(并添加头文件:#include "hilog/log.h"): diff --git a/zh-cn/application-dev/napi/use-napi-about-buffer.md b/zh-cn/application-dev/napi/use-napi-about-buffer.md index 565c0952e77..eff5b1077d6 100644 --- a/zh-cn/application-dev/napi/use-napi-about-buffer.md +++ b/zh-cn/application-dev/napi/use-napi-about-buffer.md @@ -50,7 +50,7 @@ static napi_value CreateBuffer(napi_env env, napi_callback_info info) return buffer; } ``` - + 接口声明 @@ -58,7 +58,7 @@ static napi_value CreateBuffer(napi_env env, napi_callback_info info) // index.d.ts export const createBuffer: () => string; ``` - + ArkTS侧示例代码 @@ -71,7 +71,7 @@ try { hilog.error(0x0000, 'testTag', 'Test Node-API napi_create_buffer error'); } ``` - + ### napi_create_buffer_copy @@ -96,7 +96,7 @@ static napi_value CreateBufferCopy(napi_env env, napi_callback_info info) return buffer; } ``` - + 接口声明 @@ -104,7 +104,7 @@ static napi_value CreateBufferCopy(napi_env env, napi_callback_info info) // index.d.ts export const createBufferCopy: () => string; ``` - + ArkTS侧示例代码 @@ -117,7 +117,7 @@ try { hilog.error(0x0000, 'testTag', 'Test Node-API napi_create_buffer_copy error'); } ``` - + ### napi_create_external_buffer @@ -154,7 +154,7 @@ static napi_value CreateExternalBuffer(napi_env env, napi_callback_info info) return buffer; } ``` - + 接口声明 @@ -162,7 +162,7 @@ static napi_value CreateExternalBuffer(napi_env env, napi_callback_info info) // index.d.ts export const createExternalBuffer: () => string; ``` - + ArkTS侧示例代码 @@ -176,7 +176,7 @@ try { hilog.error(0x0000, 'testTag', 'Test Node-API napi_create_external_buffer error'); } ``` - + ### napi_get_buffer_info @@ -209,7 +209,7 @@ static napi_value GetBufferInfo(napi_env env, napi_callback_info info) return returnValue; } ``` - + 接口声明 @@ -217,7 +217,7 @@ static napi_value GetBufferInfo(napi_env env, napi_callback_info info) // index.d.ts export const getBufferInfo: () => string; ``` - + ArkTS侧示例代码 @@ -230,7 +230,7 @@ try { hilog.error(0x0000, 'testTag', 'Test Node-API napi_get_buffer_info error'); } ``` - + ### napi_is_buffer @@ -258,7 +258,7 @@ static napi_value IsBuffer(napi_env env, napi_callback_info info) return returnValue; } ``` - + 接口声明 @@ -266,7 +266,7 @@ static napi_value IsBuffer(napi_env env, napi_callback_info info) // index.d.ts export const isBuffer: () => boolean; ``` - + ArkTS侧示例代码 @@ -279,7 +279,7 @@ try { hilog.info(0x0000, 'testTag', 'Test Node-API napi_is_buffer error'); } ``` - + ### napi_create_external_arraybuffer @@ -331,7 +331,7 @@ napi_value CreateExternalArraybuffer(napi_env env, napi_callback_info info) return outputArray; } ``` - + 接口声明 @@ -339,7 +339,7 @@ napi_value CreateExternalArraybuffer(napi_env env, napi_callback_info info) // index.d.ts export const createExternalArraybuffer: () => ArrayBuffer | void; ``` - + ArkTS侧示例代码 @@ -350,7 +350,7 @@ import testNapi from 'libentry.so'; hilog.info(0x0000, 'testTag', 'Node-API createExternalArraybuffer: %{public}s', JSON.stringify(testNapi.createExternalArraybuffer())); ``` - + 以上代码如果要在native cpp中打印日志,需在CMakeLists.txt文件中添加以下配置信息(并添加头文件:#include "hilog/log.h"): diff --git a/zh-cn/application-dev/napi/use-napi-about-class.md b/zh-cn/application-dev/napi/use-napi-about-class.md index 0237bf7890b..a091bdbd23b 100644 --- a/zh-cn/application-dev/napi/use-napi-about-class.md +++ b/zh-cn/application-dev/napi/use-napi-about-class.md @@ -50,7 +50,7 @@ static napi_value NewInstance(napi_env env, napi_callback_info info) return result; } ``` - + 接口声明 @@ -58,7 +58,7 @@ static napi_value NewInstance(napi_env env, napi_callback_info info) // index.d.ts export const newInstance: (obj: Object, param: string) => Object; ``` - + ArkTS侧示例代码 @@ -76,7 +76,7 @@ let obj = testNapi.newInstance(Fruit, 'test'); // 打印实例化对象obj的信息 hilog.info(0x0000, 'Node-API', 'napi_new_instance %{public}s', JSON.stringify(obj)); ``` - + ### napi_get_new_target @@ -185,7 +185,7 @@ static napi_value UnWrap(napi_env env, napi_callback_info info) return nullptr; } ``` - + 接口声明 @@ -195,7 +195,7 @@ export const wrap: (obj: Object) => Object; export const unWrap: (obj: Object) => void; export const removeWrap: (obj: Object) => void; ``` - + ArkTS侧示例代码 @@ -212,7 +212,7 @@ try { hilog.error(0x0000, 'testTag', 'Test Node-API error: %{public}s', error.message); } ``` - + 以上代码如果要在native cpp中打印日志,需在CMakeLists.txt文件中添加以下配置信息(并添加头文件:#include "hilog/log.h"): @@ -222,4 +222,4 @@ add_definitions( "-DLOG_DOMAIN=0xd0d0" ) add_definitions( "-DLOG_TAG=\"testTag\"" ) target_link_libraries(entry PUBLIC libhilog_ndk.z.so) ``` - + diff --git a/zh-cn/application-dev/napi/use-napi-about-cleanuphook.md b/zh-cn/application-dev/napi/use-napi-about-cleanuphook.md index 912535670fa..b732714aac7 100644 --- a/zh-cn/application-dev/napi/use-napi-about-cleanuphook.md +++ b/zh-cn/application-dev/napi/use-napi-about-cleanuphook.md @@ -97,7 +97,7 @@ static napi_value NapiEnvCleanUpHook(napi_env env, napi_callback_info info) return buffer; } ``` - + 接口声明 @@ -105,7 +105,7 @@ static napi_value NapiEnvCleanUpHook(napi_env env, napi_callback_info info) // index.d.ts export const napiEnvCleanUpHook: () => Object | void; ``` - + ArkTS侧示例代码 @@ -123,7 +123,7 @@ wk.onmessage = (message) => { wk.terminate(); }; ``` - + ```ts // worker.ts @@ -139,7 +139,7 @@ parent.onmessage = (message) => { parent.postMessage('Test Node-API worker:' + testNapi.napiEnvCleanUpHook()); } ``` - + worker相关开发配置和流程参考以下链接: [使用Worker进行线程间通信](../arkts-utils/worker-introduction.md) @@ -228,7 +228,7 @@ static napi_value NapiAsyncCleanUpHook(napi_env env, napi_callback_info info) return result; } ``` - + 由于需要包含“uv.h”库,所以需要在CMakeLists文件中添加配置: ```text @@ -242,7 +242,7 @@ target_link_libraries(entry PUBLIC libuv.so) // index.d.ts export const napiAsyncCleanUpHook: () => boolean | void; ``` - + ArkTS侧示例代码 @@ -255,7 +255,7 @@ try { hilog.error(0x0000, 'testTag', 'Test Node-API napi_add_async_cleanup_hook error.message: %{public}s', error.message); } ``` - + 以上代码如果要在native cpp中打印日志,需在CMakeLists.txt文件中添加以下配置信息(并添加头文件:#include "hilog/log.h"): diff --git a/zh-cn/application-dev/napi/use-napi-about-extension.md b/zh-cn/application-dev/napi/use-napi-about-extension.md index b6ba67bf707..a6e485f8cc0 100644 --- a/zh-cn/application-dev/napi/use-napi-about-extension.md +++ b/zh-cn/application-dev/napi/use-napi-about-extension.md @@ -87,7 +87,7 @@ extern "C" __attribute__((constructor)) void RegisterEntryModule(void) napi_module_register(&demoModule); } ``` - + 接口声明 @@ -95,7 +95,7 @@ extern "C" __attribute__((constructor)) void RegisterEntryModule(void) // index.d.ts export const add: (a: number, b: number) => number; ``` - + ArkTS侧示例代码 @@ -105,7 +105,7 @@ import testNapi from 'libentry.so'; hilog.info(0x0000, 'testTag', 'Test Node-API 2 + 3 = %{public}d', testNapi.add(2, 3)); ``` - + ## ArkTS Object相关 @@ -146,7 +146,7 @@ static napi_value CreateObjectWithProperties(napi_env env, napi_callback_info in } } ``` - + 接口声明 @@ -154,7 +154,7 @@ static napi_value CreateObjectWithProperties(napi_env env, napi_callback_info in // index.d.ts export const createObjectWithProperties: (data: string) => Object; ``` - + ArkTS侧示例代码 @@ -165,7 +165,7 @@ import testNapi from 'libentry.so'; let value = testNapi.createObjectWithProperties('createObject'); hilog.info(0x0000, 'testTag', 'Node-API napi_create_object_with_properties:%{public}s', JSON.stringify(value)); ``` - + #### napi_create_object_with_named_properties @@ -199,7 +199,7 @@ static napi_value CreateObjectWithNameProperties(napi_env env, napi_callback_inf return obj; } ``` - + 接口声明 @@ -207,7 +207,7 @@ static napi_value CreateObjectWithNameProperties(napi_env env, napi_callback_inf // index.d.ts export const createObjectWithNameProperties: (data: string) => string | { name: string }; ``` - + ArkTS侧示例代码 @@ -218,7 +218,7 @@ import testNapi from 'libentry.so'; let value = testNapi.createObjectWithNameProperties('ls'); hilog.info(0x0000, 'testTag', 'Node-API napi_create_object_with_named_properties:%{public}s', JSON.stringify(value)); ``` - + ## 运行指定abc文件 @@ -256,7 +256,7 @@ static napi_value RunScriptPath(napi_env env, napi_callback_info info) return returnValue; } ``` - + 接口声明 @@ -264,7 +264,7 @@ static napi_value RunScriptPath(napi_env env, napi_callback_info info) // index.d.ts export const runScriptPath: () => boolean; ``` - + ArkTS侧示例代码 @@ -279,7 +279,7 @@ try { hilog.error(0x0000, 'testTag', 'Test Node-API napi_run_script_path errorMessage: %{public}s', error.message); } ``` - + test.js代码,将js代码编成.abc文件,步骤如下: @@ -545,7 +545,7 @@ extern "C" __attribute__((constructor)) void RegisterEntryModule(void) napi_module_register(&demoModule); } ``` - + 接口声明 @@ -557,7 +557,7 @@ export const store: (a: number) => void; export const erase: (a: number) => void; export const clear: () => void; ``` - + ArkTS侧示例代码 @@ -626,7 +626,7 @@ async function test01(): Promise { test01(); ``` - + **注意事项** @@ -720,7 +720,7 @@ static napi_value AboutSerialize(napi_env env, napi_callback_info info) return number; } ``` - + 接口声明 @@ -728,7 +728,7 @@ static napi_value AboutSerialize(napi_env env, napi_callback_info info) // index.d.ts export const aboutSerialize: (obj: Object) => number; ``` - + ArkTS侧示例代码 @@ -741,7 +741,7 @@ class Obj { let obj: Obj = { numKey: 500 }; hilog.info(0x0000, 'testTag', ' Node-API aboutSerialize: %{public}d', testNapi.aboutSerialize(obj)); ``` - + ## 根据任务指定的优先级和入队方式进行处理异步线程向ArkTS线程投递的任务 @@ -797,7 +797,7 @@ static napi_value IsSendable(napi_env env, napi_callback_info info) { return result; } ``` - + 接口声明 @@ -805,7 +805,7 @@ static napi_value IsSendable(napi_env env, napi_callback_info info) { // index.d.ts export const isSendable: (a: T) => boolean; ``` - + ArkTS侧示例代码 @@ -816,7 +816,7 @@ import testNapi from 'libentry.so'; let value = testNapi.isSendable('createObject'); hilog.info(0x0000, 'testTag', 'Node-API napi_is_sendable: %{public}s', JSON.stringify(value)); ``` - + #### napi_define_sendable_class @@ -893,7 +893,7 @@ extern "C" __attribute__((constructor)) void RegisterEntryModule(void) napi_module_register(&demoModule); } ``` - + 接口声明 @@ -907,7 +907,7 @@ export class SendableClass { func(): string; } ``` - + ArkTS侧示例代码 @@ -918,7 +918,7 @@ import testNapi from 'libentry.so'; let value = new testNapi.SendableClass(); hilog.info(0x0000, 'testTag', 'Node-API napi_define_sendable_class: %{public}s', value.str); ``` - + #### napi_create_sendable_object_with_properties @@ -940,7 +940,7 @@ static napi_value GetSendableObject(napi_env env, napi_callback_info info) { return obj; } ``` - + 接口声明 @@ -948,7 +948,7 @@ static napi_value GetSendableObject(napi_env env, napi_callback_info info) { // index.d.ts export const getSendableObject: () => { x: true }; ``` - + ArkTS侧示例代码 @@ -959,7 +959,7 @@ import testNapi from 'libentry.so'; let value = testNapi.getSendableObject(); hilog.info(0x0000, 'testTag', 'Node-API napi_create_sendable_object_with_properties: %{public}s', JSON.stringify(value)); ``` - + #### napi_create_sendable_array @@ -976,7 +976,7 @@ static napi_value GetSendableArray(napi_env env, napi_callback_info info) { return result; } ``` - + 接口声明 @@ -984,7 +984,7 @@ static napi_value GetSendableArray(napi_env env, napi_callback_info info) { // index.d.ts export const getSendableArray: () => []; ``` - + ArkTS侧示例代码 @@ -995,7 +995,7 @@ import testNapi from 'libentry.so'; let value = testNapi.getSendableArray(); hilog.info(0x0000, 'testTag', 'Node-API napi_create_sendable_array: %{public}s', JSON.stringify(value)); ``` - + #### napi_create_sendable_array_with_length @@ -1010,7 +1010,7 @@ static napi_value GetSendableArrayWithLength(napi_env env, napi_callback_info in return result; } ``` - + 接口声明 @@ -1018,7 +1018,7 @@ static napi_value GetSendableArrayWithLength(napi_env env, napi_callback_info in // index.d.ts export const getSendableArrayWithLength: () => []; ``` - + ArkTS侧示例代码 @@ -1029,7 +1029,7 @@ import testNapi from 'libentry.so'; let value = testNapi.getSendableArrayWithLength(); hilog.info(0x0000, 'testTag', 'Node-API napi_create_sendable_array_with_length: %{public}s', JSON.stringify(value.length)); ``` - + #### napi_create_sendable_arraybuffer @@ -1052,7 +1052,7 @@ static napi_value GetSendableArrayBuffer(napi_env env, napi_callback_info info) return result; } ``` - + 接口声明 @@ -1060,7 +1060,7 @@ static napi_value GetSendableArrayBuffer(napi_env env, napi_callback_info info) // index.d.ts export const getSendableArrayBuffer: () => void; ``` - + ArkTS侧示例代码 @@ -1070,7 +1070,7 @@ import testNapi from 'libentry.so'; testNapi.getSendableArrayBuffer(); ``` - + #### napi_create_sendable_typedarray @@ -1097,7 +1097,7 @@ static napi_value GetSendableTypedArray(napi_env env, napi_callback_info info) { return result; } ``` - + 接口声明 @@ -1105,7 +1105,7 @@ static napi_value GetSendableTypedArray(napi_env env, napi_callback_info info) { // index.d.ts export const getSendableTypedArray: () => void; ``` - + ArkTS侧示例代码 @@ -1115,7 +1115,7 @@ import testNapi from 'libentry.so'; testNapi.getSendableTypedArray(); ``` - + #### napi_wrap_sendable @@ -1141,7 +1141,7 @@ static napi_value WrapSendable(napi_env env, napi_callback_info info) { return nullptr; } ``` - + 接口声明 @@ -1149,7 +1149,7 @@ static napi_value WrapSendable(napi_env env, napi_callback_info info) { // index.d.ts export const wrapSendable: () => void; ``` - + ArkTS侧示例代码 @@ -1159,7 +1159,7 @@ import testNapi from 'libentry.so'; testNapi.wrapSendable(); ``` - + #### napi_wrap_sendable_with_size @@ -1185,7 +1185,7 @@ static napi_value WrapSendableWithSize(napi_env env, napi_callback_info info) { return nullptr; } ``` - + 接口声明 @@ -1193,7 +1193,7 @@ static napi_value WrapSendableWithSize(napi_env env, napi_callback_info info) { // index.d.ts export const wrapSendableWithSize: () => void; ``` - + ArkTS侧示例代码 @@ -1203,7 +1203,7 @@ import testNapi from 'libentry.so'; testNapi.wrapSendableWithSize(); ``` - + #### napi_unwrap_sendable @@ -1233,7 +1233,7 @@ static napi_value UnwrapSendable(napi_env env, napi_callback_info info) { return nullptr; } ``` - + 接口声明 @@ -1241,7 +1241,7 @@ static napi_value UnwrapSendable(napi_env env, napi_callback_info info) { // index.d.ts export const unwrapSendable: () => void; ``` - + ArkTS侧示例代码 @@ -1251,7 +1251,7 @@ import testNapi from 'libentry.so'; testNapi.unwrapSendable(); ``` - + #### napi_remove_wrap_sendable @@ -1281,7 +1281,7 @@ static napi_value RemoveWrapSendable(napi_env env, napi_callback_info info) { return nullptr; } ``` - + 接口声明 @@ -1289,7 +1289,7 @@ static napi_value RemoveWrapSendable(napi_env env, napi_callback_info info) { // index.d.ts export const removeWrapSendable: () => void; ``` - + ArkTS侧示例代码 @@ -1299,7 +1299,7 @@ import testNapi from 'libentry.so'; testNapi.removeWrapSendable(); ``` - + 以上代码如果要在native cpp中打印日志,需在CMakeLists.txt文件中添加以下配置信息(并添加头文件:#include "hilog/log.h"): diff --git a/zh-cn/application-dev/napi/use-napi-basic-data-types.md b/zh-cn/application-dev/napi/use-napi-basic-data-types.md index e34b1348b9d..aefafdd28eb 100644 --- a/zh-cn/application-dev/napi/use-napi-basic-data-types.md +++ b/zh-cn/application-dev/napi/use-napi-basic-data-types.md @@ -60,7 +60,7 @@ static napi_value GetValueUint32(napi_env env, napi_callback_info info) return result; } ``` - + 接口声明 @@ -68,7 +68,7 @@ static napi_value GetValueUint32(napi_env env, napi_callback_info info) // index.d.ts export const getValueUint32: (data: T) => number | void; ``` - + ArkTS侧示例代码 @@ -84,7 +84,7 @@ hilog.info(0x0000, 'Node-API', 'get_value_uint32_number %{public}s', data); // 传入uint32范围内的数字100时函数返回原数字 hilog.info(0x0000, 'Node-API', 'get_value_uint32_number %{public}d', testNapi.getValueUint32(100)); ``` - + ### napi_get_value_int32 @@ -114,7 +114,7 @@ static napi_value GetValueInt32(napi_env env, napi_callback_info info) return napiResult32; } ``` - + 接口声明 @@ -122,7 +122,7 @@ static napi_value GetValueInt32(napi_env env, napi_callback_info info) // index.d.ts export const getValueInt32: (value: number | string) => number | void; ``` - + ArkTS侧示例代码 @@ -143,7 +143,7 @@ hilog.info(0x0000, 'Node-API', 'get_value_int32_number_NAN %{public}d', testNapi hilog.info(0x0000, 'Node-API', 'get_value_int32_number_+Infinity %{public}d', testNapi.getValueInt32(+Infinity)); hilog.info(0x0000, 'Node-API', 'get_value_int32_number_-Infinity %{public}d', testNapi.getValueInt32(-Infinity)); ``` - + ### napi_get_value_int64 @@ -173,7 +173,7 @@ static napi_value GetValueInt64(napi_env env, napi_callback_info info) return napiResult64; } ``` - + 接口声明 @@ -181,7 +181,7 @@ static napi_value GetValueInt64(napi_env env, napi_callback_info info) // index.d.ts export const getValueInt64: (value: number | string) => number | void; ``` - + ArkTS侧示例代码 @@ -200,7 +200,7 @@ hilog.info(0x0000, 'Node-API', 'get_value_int64_number_NAN %{public}d', testNapi hilog.info(0x0000, 'Node-API', 'get_value_int64_number_+Infinity %{public}d', testNapi.getValueInt64(+Infinity)); hilog.info(0x0000, 'Node-API', 'get_value_int64_number_-Infinity %{public}d', testNapi.getValueInt64(-Infinity)); ``` - + ### napi_get_value_double @@ -227,7 +227,7 @@ static napi_value GetDouble(napi_env env, napi_callback_info info) return result; } ``` - + 接口声明 @@ -235,7 +235,7 @@ static napi_value GetDouble(napi_env env, napi_callback_info info) // index.d.ts export const getDouble: (value: number | string) => number | void; ``` - + ArkTS侧示例代码 @@ -247,7 +247,7 @@ hilog.info(0x0000, 'Node-API', 'get_value_double_number %{public}d', testNapi.ge // 传入非数字,获得函数返回的值应为undefined hilog.info(0x0000, 'Node-API', 'get_value_double_not_number %{public}s', testNapi.getDouble('sAs')); ``` - + ### napi_create_int32 @@ -274,7 +274,7 @@ static napi_value CreateInt32(napi_env env, napi_callback_info info) return result; } ``` - + 接口声明 @@ -282,7 +282,7 @@ static napi_value CreateInt32(napi_env env, napi_callback_info info) // index.d.ts export const createInt32: () => number; ``` - + ArkTS侧示例代码 @@ -292,7 +292,7 @@ import testNapi from 'libentry.so'; hilog.info(0x0000, 'testTag','Test Node-API napi_create_int32:' + testNapi.createInt32()); ``` - + ### napi_create_uint32 @@ -320,7 +320,7 @@ static napi_value CreateUInt32(napi_env env, napi_callback_info info) return result; } ``` - + 接口声明 @@ -328,7 +328,7 @@ static napi_value CreateUInt32(napi_env env, napi_callback_info info) // index.d.ts export const createUInt32: () => number; ``` - + ArkTS侧示例代码 @@ -338,7 +338,7 @@ import testNapi from 'libentry.so'; hilog.info(0x0000, 'testTag','Test Node-API napi_create_uint32: ' + testNapi.createUInt32()); ``` - + ### napi_create_int64 @@ -364,7 +364,7 @@ static napi_value CreateInt64(napi_env env, napi_callback_info info) return result; } ``` - + 接口声明 @@ -372,7 +372,7 @@ static napi_value CreateInt64(napi_env env, napi_callback_info info) // index.d.ts export const createInt64: () => number; ``` - + ArkTS侧示例代码 @@ -382,7 +382,7 @@ import testNapi from 'libentry.so'; hilog.info(0x0000, 'testTag','Test Node-API napi_create_int64: ' + testNapi.createInt64()); ``` - + ### napi_create_double @@ -406,7 +406,7 @@ static napi_value CreateDouble(napi_env env, napi_callback_info info) return result; } ``` - + 接口声明 @@ -414,7 +414,7 @@ static napi_value CreateDouble(napi_env env, napi_callback_info info) // index.d.ts export const createDouble: () => number; ``` - + ArkTS侧示例代码 @@ -424,7 +424,7 @@ import testNapi from 'libentry.so'; hilog.info(0x0000, 'testTag','Test Node-API napi_create_double: ' + testNapi.createDouble()); ``` - + 以上代码如果要在native cpp中打印日志,需在CMakeLists.txt文件中添加以下配置信息(并添加头文件:#include "hilog/log.h"): diff --git a/zh-cn/application-dev/onlyfortest/arkts-utils/ason-parsing-generation-Abnormal-1.md b/zh-cn/application-dev/onlyfortest/arkts-utils/ason-parsing-generation-Abnormal-1.md index 78e788f7273..ef79ab092ba 100644 --- a/zh-cn/application-dev/onlyfortest/arkts-utils/ason-parsing-generation-Abnormal-1.md +++ b/zh-cn/application-dev/onlyfortest/arkts-utils/ason-parsing-generation-Abnormal-1.md @@ -17,7 +17,7 @@ const promise: Promise = new Promise((resolve: Function, reject: Functio }, 1000); }) ``` - + ## docs文档中的ID在Sample中不存在(不匹配) @@ -33,7 +33,7 @@ const promise: Promise = new Promise((resolve: Function, reject: Functio }, 1000); }) ``` - + ## 引用部分代码(Exclude字段) @@ -76,7 +76,7 @@ struct PromiseAsyncAwait { } // 结束--async_await_sync_operation ``` - + ### docs代码中未去除Exclude字段 @@ -134,7 +134,7 @@ struct Index { } } ``` - + ## 嵌套的ID,docs中不含嵌套部分(修改4的部分,是否因为空行导致的报错,此文档中,已经取消了空行) @@ -147,4 +147,4 @@ promise.then((result: number) => { console.error(error.message); }); ``` - \ No newline at end of file + \ No newline at end of file diff --git a/zh-cn/application-dev/onlyfortest/arkts-utils/ason-parsing-generation-Abnormal-2.md b/zh-cn/application-dev/onlyfortest/arkts-utils/ason-parsing-generation-Abnormal-2.md index f283ef14883..984fbbf7aa4 100644 --- a/zh-cn/application-dev/onlyfortest/arkts-utils/ason-parsing-generation-Abnormal-2.md +++ b/zh-cn/application-dev/onlyfortest/arkts-utils/ason-parsing-generation-Abnormal-2.md @@ -15,7 +15,7 @@ const promise: Promise = new Promise((resolve: Function, reject: Functio }, 1000); }) ``` - + ## 引用部分代码(Exclude字段) @@ -75,7 +75,7 @@ struct Index { } } ``` - + ## 文档代码块中,id重复(但是引用的内容一致),验证扫描结果 @@ -94,7 +94,7 @@ const promise: Promise = new Promise((resolve: Function, reject: Functio }, 1000); }) ``` - + ``` @@ -130,4 +130,4 @@ struct PromiseAsyncAwait { } } ``` - + diff --git a/zh-cn/application-dev/onlyfortest/arkts-utils/ason-parsing-generation-Abnormal-3.md b/zh-cn/application-dev/onlyfortest/arkts-utils/ason-parsing-generation-Abnormal-3.md index 3b337096c49..eeefc66812a 100644 --- a/zh-cn/application-dev/onlyfortest/arkts-utils/ason-parsing-generation-Abnormal-3.md +++ b/zh-cn/application-dev/onlyfortest/arkts-utils/ason-parsing-generation-Abnormal-3.md @@ -15,4 +15,4 @@ const promise: Promise = new Promise((resolve: Function, reject: Functio }, 1000); }) ``` - \ No newline at end of file + \ No newline at end of file diff --git a/zh-cn/application-dev/onlyfortest/arkts-utils/ason-parsing-generation-Abnormal-4.md b/zh-cn/application-dev/onlyfortest/arkts-utils/ason-parsing-generation-Abnormal-4.md index 02aadb0dee5..8c778e1b519 100644 --- a/zh-cn/application-dev/onlyfortest/arkts-utils/ason-parsing-generation-Abnormal-4.md +++ b/zh-cn/application-dev/onlyfortest/arkts-utils/ason-parsing-generation-Abnormal-4.md @@ -15,7 +15,7 @@ const promise: Promise\ = new Promise((resolve: Function, reject: Funct }, 1000); }) ``` - + 代码不一致(docs中只有开始的```) @@ -32,7 +32,7 @@ const promise: Promise\ = new Promise((resolve: Function, reject: Funct }, 1000); }) - + ## 嵌套的ID,docs中不含嵌套部分 @@ -47,7 +47,7 @@ promise.then((result: number) => { console.error(error.message); }); ``` - + ## 注释不一致(docs:行上 vs Sample:行),代码内容一致 @@ -86,7 +86,7 @@ struct PromiseAsyncAwait { } } ``` - + ### sample代码,start和end未同时出现 diff --git a/zh-cn/application-dev/onlyfortest/arkts-utils/ason-parsing-generation-Abnormal-5.md b/zh-cn/application-dev/onlyfortest/arkts-utils/ason-parsing-generation-Abnormal-5.md index bbb96bc628a..344c6b6d356 100644 --- a/zh-cn/application-dev/onlyfortest/arkts-utils/ason-parsing-generation-Abnormal-5.md +++ b/zh-cn/application-dev/onlyfortest/arkts-utils/ason-parsing-generation-Abnormal-5.md @@ -17,7 +17,7 @@ const promise: Promise = new Promise((resolve: Function, reject: Functio }, 1000); }) ``` - + ``` @@ -53,7 +53,7 @@ struct PromiseAsyncAwait { } } ``` - + @@ -67,4 +67,4 @@ promise.then((result: number) => { console.error(error.message); }); ``` - \ No newline at end of file + \ No newline at end of file diff --git a/zh-cn/application-dev/onlyfortest/arkts-utils/ason-parsing-generation-normal.md b/zh-cn/application-dev/onlyfortest/arkts-utils/ason-parsing-generation-normal.md index d6c82d8d685..d1bf2bd7a96 100644 --- a/zh-cn/application-dev/onlyfortest/arkts-utils/ason-parsing-generation-normal.md +++ b/zh-cn/application-dev/onlyfortest/arkts-utils/ason-parsing-generation-normal.md @@ -18,7 +18,7 @@ const promise: Promise = new Promise((resolve: Function, reject: Functio }, 1000); }) ``` - + ### ID无嵌套,整段代码缩进不一致 @@ -37,7 +37,7 @@ const promise: Promise = new Promise((resolve: Function, reject: Functio }, 1000); }) ``` - + * list 3 ### ID存在嵌套 @@ -62,7 +62,7 @@ promise.then((result: number) => { console.error(error.message); }); ``` - + ## 引用部分代码(Exclude字段) @@ -121,4 +121,4 @@ struct Index { } } ``` - \ No newline at end of file + \ No newline at end of file diff --git a/zh-cn/application-dev/onlyfortest/arkts-utils/async-concurrency-overview.md b/zh-cn/application-dev/onlyfortest/arkts-utils/async-concurrency-overview.md index c1b647558c6..2637b2cd74e 100644 --- a/zh-cn/application-dev/onlyfortest/arkts-utils/async-concurrency-overview.md +++ b/zh-cn/application-dev/onlyfortest/arkts-utils/async-concurrency-overview.md @@ -59,7 +59,7 @@ const promise: Promise = new Promise((resolve: Function, reject: Functio }) ``` - + ## docs代码和sample中不一致(单行缩进不一致),验证扫描结果 @@ -87,7 +87,7 @@ promise.then((result: number) => { console.error(error.message); }); ``` - + ## docs代码和sample中不一致(整段代码缩进不一致),验证扫描结果 @@ -128,7 +128,7 @@ docs代码和sample中不一致(整段代码缩进不一致),验证扫描 } } ``` - + * list 2 * list 3 @@ -152,7 +152,7 @@ const promise: Promise = new Promise((resolve: Function, reject: Functio }, 1000); }) ``` - + 上述代码中,setTimeout函数模拟了一个异步操作,并在1秒钟后随机生成一个数字。如果随机数大于0.5,则执行resolve回调函数并将随机数作为参数传递;否则执行reject回调函数并传递一个错误对象作为参数。 @@ -167,7 +167,7 @@ promise.then((result: number) => { console.error(error.message); }); ``` - + 上述代码中,then方法的回调函数接收Promise对象的成功结果作为参数,并将其输出到控制台上。如果Promise对象进入rejected状态,则catch方法的回调函数接收错误对象作为参数,并将其输出到控制台上。 @@ -216,7 +216,7 @@ struct Index { } } ``` - + 上述代码中,sample含有Exclude代码 @@ -237,7 +237,7 @@ async function myAsyncFunction(): Promise { myAsyncFunction(); ``` - + ## 验证注释格式不同 @@ -295,4 +295,4 @@ struct Index { } } ``` - \ No newline at end of file + \ No newline at end of file diff --git a/zh-cn/application-dev/onlyfortest/arkts-utils/multi-thread-concurrency-overview.md b/zh-cn/application-dev/onlyfortest/arkts-utils/multi-thread-concurrency-overview.md index 22cdcdbc6a6..2eb3bd3e520 100644 --- a/zh-cn/application-dev/onlyfortest/arkts-utils/multi-thread-concurrency-overview.md +++ b/zh-cn/application-dev/onlyfortest/arkts-utils/multi-thread-concurrency-overview.md @@ -175,7 +175,7 @@ struct Index { } } ``` - + 同时,也可等待生产者的生产任务全部执行完成,通过序列化通信将结果发送给UI线程,UI线程接收完毕后再由消费者统一消费结果。 -- Gitee