You need to sign in or sign up before continuing.
提交 0859dfe5 编写于 作者: L lengchangjing

modify sample code for docs

Signed-off-by: Nlengchangjing <lengchangjing@huawei.com>
上级 85593757
......@@ -99,7 +99,7 @@ add(element: T): boolean
let result3 = arrayList.add(c);
let result4 = arrayList.add(false);
try {
arraylist.add.bind({}, "b")(); // bind为JS标准内置对象Function的方法,用于改变this的指向,测试异常捕获
arrayList.add.bind({}, "b")(); // bind为JS标准内置对象Function的方法,用于改变this的指向,测试异常捕获
} catch(err) {
console.log(`${err.code} - ${err.name} - ${err.message}`);
}
......@@ -137,7 +137,7 @@ arrayList.insert("A", 0);
arrayList.insert(0, 1);
arrayList.insert(true, 2);
try {
arraylist.insert.bind({}, 1, 2)(); // bind为JS标准内置对象Function的方法,用于改变this的指向,测试异常捕获
arrayList.insert.bind({}, 1, 2)(); // bind为JS标准内置对象Function的方法,用于改变this的指向,测试异常捕获
} catch(err) {
console.log(`${err.code} - ${err.name} - ${err.message}`);
}
......@@ -189,7 +189,7 @@ let result = arrayList.has("squirrel");
arrayList.add("squirrel");
let result1 = arrayList.has("squirrel");
try {
arraylist.has.bind({}, "squirrel")(); // bind为JS标准内置对象Function的方法,用于改变this的指向,测试异常捕获
arrayList.has.bind({}, "squirrel")(); // bind为JS标准内置对象Function的方法,用于改变this的指向,测试异常捕获
} catch(err) {
console.log(`${err.code} - ${err.name} - ${err.message}`);
}
......@@ -236,7 +236,7 @@ arrayList.add(2);
arrayList.add(4);
let result = arrayList.getIndexOf(2);
try {
arraylist.getIndexOf.bind({}, 2)(); // bind为JS标准内置对象Function的方法,用于改变this的指向,测试异常捕获
arrayList.getIndexOf.bind({}, 2)(); // bind为JS标准内置对象Function的方法,用于改变this的指向,测试异常捕获
} catch(err) {
console.log(`${err.code} - ${err.name} - ${err.message}`);
}
......@@ -283,7 +283,7 @@ arrayList.add(2);
arrayList.add(4);
let result = arrayList.getLastIndexOf(2);
try {
arraylist.getLastIndexOf.bind({}, 2)(); // bind为JS标准内置对象Function的方法,用于改变this的指向,测试异常捕获
arrayList.getLastIndexOf.bind({}, 2)(); // bind为JS标准内置对象Function的方法,用于改变this的指向,测试异常捕获
} catch(err) {
console.log(`${err.code} - ${err.name} - ${err.message}`);
}
......@@ -329,17 +329,17 @@ arrayList.add(2);
arrayList.add(4);
let result = arrayList.removeByIndex(2);
try {
arraylist.removeByIndex.bind({}, 2)(); // bind为JS标准内置对象Function的方法,用于改变this的指向,测试异常捕获
arrayList.removeByIndex.bind({}, 2)(); // bind为JS标准内置对象Function的方法,用于改变this的指向,测试异常捕获
} catch(err) {
console.log(`${err.code} - ${err.name} - ${err.message}`);
}
try {
arraylist.removeByIndex("a"); // 测试类型异常
arrayList.removeByIndex("a"); // 测试类型异常
} catch(err) {
console.log(`${err.code} - ${err.name} - ${err.message}`);
}
try {
arraylist.removeByIndex(8); // 测试越界异常
arrayList.removeByIndex(8); // 测试越界异常
} catch(err) {
console.log(`${err.code} - ${err.name} - ${err.message}`);
}
......@@ -383,7 +383,7 @@ arrayList.add(5);
arrayList.add(4);
let result = arrayList.remove(2);
try {
arraylist.remove.bind({}, 2)(); // bind为JS标准内置对象Function的方法,用于改变this的指向,测试异常捕获
arrayList.remove.bind({}, 2)(); // bind为JS标准内置对象Function的方法,用于改变this的指向,测试异常捕获
} catch(err) {
console.log(`${err.code} - ${err.name} - ${err.message}`);
}
......@@ -423,12 +423,12 @@ arrayList.add(5);
arrayList.add(4);
arrayList.removeByRange(2, 4);
try {
arraylist.removeByRange.bind({}, 2, 4)(); // bind为JS标准内置对象Function的方法,用于改变this的指向,测试异常捕获
arrayList.removeByRange.bind({}, 2, 4)(); // bind为JS标准内置对象Function的方法,用于改变this的指向,测试异常捕获
} catch(err) {
console.log(`${err.code} - ${err.name} - ${err.message}`);
}
try {
arraylist.removeByRange(8, 4); // 测试越界异常
arrayList.removeByRange(8, 4); // 测试越界异常
} catch(err) {
console.log(`${err.code} - ${err.name} - ${err.message}`);
}
......@@ -481,7 +481,7 @@ arrayList.replaceAllElements((value: number, index: number) => {
return value = value - 2;
});
try {
arraylist.replaceAllElements.bind({}, (value: number, index: number)=> {
arrayList.replaceAllElements.bind({}, (value: number, index: number)=> {
return value = 2 * value;
})(); // bind为JS标准内置对象Function的方法,用于改变this的指向,测试异常捕获
} catch(err) {
......@@ -533,7 +533,7 @@ arrayList.forEach((value, index) => {
console.log(`value:${value}`, index);
});
try {
arraylist.forEach.bind({}, (value, index) => {
arrayList.forEach.bind({}, (value, index) => {
console.log(`value:${value}`, index);
})(); // bind为JS标准内置对象Function的方法,用于改变this的指向,测试异常捕获
} catch(err) {
......@@ -582,7 +582,7 @@ arrayList.sort((a: number, b: number) => a - b);
arrayList.sort((a: number, b: number) => b - a);
arrayList.sort();
try {
arraylist.sort.bind({})(); // bind为JS标准内置对象Function的方法,用于改变this的指向,测试异常捕获
arrayList.sort.bind({})(); // bind为JS标准内置对象Function的方法,用于改变this的指向,测试异常捕获
} catch(err) {
console.log(`${err.code} - ${err.name} - ${err.message}`);
}
......@@ -630,12 +630,12 @@ let result1 = arrayList.subArrayList(2, 4);
let result2 = arrayList.subArrayList(4, 3);
let result3 = arrayList.subArrayList(2, 6);
try {
arraylist.subArrayList.bind({}, 2, 4)(); // bind为JS标准内置对象Function的方法,用于改变this的指向,测试异常捕获
arrayList.subArrayList.bind({}, 2, 4)(); // bind为JS标准内置对象Function的方法,用于改变this的指向,测试异常捕获
} catch(err) {
console.log(`${err.code} - ${err.name} - ${err.message}`);
}
try {
arraylist.subArrayList(6, 4);
arrayList.subArrayList(6, 4);
} catch(err) {
console.log(`${err.code} - ${err.name} - ${err.message}`);
}
......@@ -667,7 +667,7 @@ arrayList.add(5);
arrayList.add(4);
arrayList.clear();
try {
arraylist.clear.bind({})(); // bind为JS标准内置对象Function的方法,用于改变this的指向,测试异常捕获
arrayList.clear.bind({})(); // bind为JS标准内置对象Function的方法,用于改变this的指向,测试异常捕获
} catch(err) {
console.log(`${err.code} - ${err.name} - ${err.message}`);
}
......@@ -706,7 +706,7 @@ arrayList.add(5);
arrayList.add(4);
let result = arrayList.clone();
try {
arraylist.clone.bind({})(); // bind为JS标准内置对象Function的方法,用于改变this的指向,测试异常捕获
arrayList.clone.bind({})(); // bind为JS标准内置对象Function的方法,用于改变this的指向,测试异常捕获
} catch(err) {
console.log(`${err.code} - ${err.name} - ${err.message}`);
}
......@@ -744,7 +744,7 @@ arrayList.add(5);
arrayList.add(4);
let result = arrayList.getCapacity();
try {
arraylist.getCapacity.bind({})(); // bind为JS标准内置对象Function的方法,用于改变this的指向,测试异常捕获
arrayList.getCapacity.bind({})(); // bind为JS标准内置对象Function的方法,用于改变this的指向,测试异常捕获
} catch(err) {
console.log(`${err.code} - ${err.name} - ${err.message}`);
}
......@@ -782,7 +782,7 @@ arrayList.add(5);
arrayList.add(4);
let result = arrayList.convertToArray();
try {
arraylist.convertToArray.bind({})(); // bind为JS标准内置对象Function的方法,用于改变this的指向,测试异常捕获
arrayList.convertToArray.bind({})(); // bind为JS标准内置对象Function的方法,用于改变this的指向,测试异常捕获
} catch(err) {
console.log(`${err.code} - ${err.name} - ${err.message}`);
}
......@@ -820,7 +820,7 @@ arrayList.add(5);
arrayList.add(4);
let result = arrayList.isEmpty();
try {
arraylist.isEmpty.bind({})(); // bind为JS标准内置对象Function的方法,用于改变this的指向,测试异常捕获
arrayList.isEmpty.bind({})(); // bind为JS标准内置对象Function的方法,用于改变this的指向,测试异常捕获
} catch(err) {
console.log(`${err.code} - ${err.name} - ${err.message}`);
}
......@@ -859,7 +859,7 @@ arrayList.add(4);
arrayList.increaseCapacityTo(2);
arrayList.increaseCapacityTo(8);
try {
arraylist.increaseCapacityTo.bind({}, 5)(); // bind为JS标准内置对象Function的方法,用于改变this的指向,测试异常捕获
arrayList.increaseCapacityTo.bind({}, 5)(); // bind为JS标准内置对象Function的方法,用于改变this的指向,测试异常捕获
} catch(err) {
console.log(`${err.code} - ${err.name} - ${err.message}`);
}
......@@ -891,7 +891,7 @@ arrayList.add(5);
arrayList.add(4);
arrayList.trimToCurrentLength();
try {
arraylist.trimToCurrentLength.bind({})(); // bind为JS标准内置对象Function的方法,用于改变this的指向,测试异常捕获
arrayList.trimToCurrentLength.bind({})(); // bind为JS标准内置对象Function的方法,用于改变this的指向,测试异常捕获
} catch(err) {
console.log(`${err.code} - ${err.name} - ${err.message}`);
}
......@@ -941,7 +941,7 @@ while(temp != undefined) {
temp = iter.next().value;
}
try {
arraylist[Symbol.iterator].bind({})(); // bind为JS标准内置对象Function的方法,用于改变this的指向,测试异常捕获
arrayList[Symbol.iterator].bind({})(); // bind为JS标准内置对象Function的方法,用于改变this的指向,测试异常捕获
} catch(err) {
console.log(`${err.code} - ${err.name} - ${err.message}`);
}
......
......@@ -371,6 +371,13 @@ import buffer from '@ohos.buffer';
let ab = new ArrayBuffer(10);
let buf = buffer.from(ab, 0, 2);
let arrayBuffer = new ArrayBuffer(5);
let array = new Int8Array(arrayBuffer);
array[0] = '1';
array[1] = '2';
array[2] = '3';
array[3] = '4';
array[4] = '5';
try {
const buf = buffer.from(arrayBuffer, 6, 1);
} catch (err) {
......@@ -1644,10 +1651,10 @@ let buf = buffer.from([1, -2]);
console.log(buf.readUInt8(0).toString());
console.log(buf.readUInt8(1).toString());
let buf = buffer.allocUninitializedFromPool(4);
buf.writeUInt8(0x42);
let buf1 = buffer.allocUninitializedFromPool(4);
buf1.writeUInt8(0x42);
try {
let ref = buf.readUInt8(4).toString(16);
let ref = buf1.readUInt8(4).toString(16);
} catch (err) {
console.log("readUInt8 exception: " + JSON.stringify(err));
}
......@@ -2430,9 +2437,9 @@ import buffer from '@ohos.buffer';
let buf = buffer.allocUninitializedFromPool(8);
buf.writeBigUInt64LE(0xdecafafecacefaden, 0);
let buf = buffer.allocUninitializedFromPool(8);
let buf1 = buffer.allocUninitializedFromPool(8);
try {
let ref = buf.writeBigUInt64LE(0xdecafafecacefaden, 1);
let ref = buf1.writeBigUInt64LE(0xdecafafecacefaden, 1);
} catch (err) {
console.log("writeBigUInt64LE exception: " + JSON.stringify(err));
}
......@@ -2522,9 +2529,9 @@ import buffer from '@ohos.buffer';
let buf = buffer.allocUninitializedFromPool(8);
buf.writeDoubleLE(123.456, 0);
let buf = buffer.allocUninitializedFromPool(8);
let buf1 = buffer.allocUninitializedFromPool(8);
try {
let ref = buf.writeDoubleLE(123.456, 1);
let ref = buf1.writeDoubleLE(123.456, 1);
} catch (err) {
console.log("writeDoubleLE exception: " + JSON.stringify(err));
}
......
......@@ -594,7 +594,7 @@ removeFirstFound(element: T): boolean
```ts
let linkedList = new LinkedList();
try {
linkedList.removeFirstFound();
linkedList.removeFirstFound(4);
} catch(err) {
console.log(`${err.code} - ${err.name} - ${err.message}`);
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册