• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (c) 2024 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 *     http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16let res1 = true;
17for (let i = 0; i < 20; i++) {
18    var sample1 = new Uint8ClampedArray([0]);
19    var result1 = sample1.map(function() {
20        return 123.622223;
21    });
22    if (result1 != 124) {
23        res1 = false;
24    }
25}
26assert_equal(res1, true);
27
28let res2 = true;
29for (let i = 0; i < 20; i++) {
30    var sample2 = new Uint8ClampedArray([0]);
31    var result2 = sample2.map(function() {
32        return 32768;
33    });
34    if (result2 != 255) {
35        res2 = false;
36    }
37}
38assert_equal(res2, true);
39
40let res3 = true;
41for (let i = 0; i < 20; i++) {
42    var sample3 = new Uint8ClampedArray([0]);
43    var result3 = sample3.map(function() {
44        return -32769;
45    });
46    if (result3 != 0) {
47        res3 = false;
48    }
49}
50assert_equal(res3, true);
51
52{
53    let arr1 = new Uint8Array(512);
54    let i = 0;
55    while (i < 128) {
56        i++;
57    }
58    let arr2 = new Uint16Array(930);
59    function myFunc() {
60        let tmp = arr2[0];
61    }
62    arr2.__proto__ = arr1;
63    let newArr = arr2.map(myFunc);
64    assert_equal(newArr instanceof Uint8Array, true);
65}
66
67test_end();
68