• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (c) 2025 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 */
15function assert(b) {
16    if (!b)
17        throw new Error("bad value")
18}
19
20function random() {
21    return "blah";
22}
23
24function foo(o) {
25    let x = o.g;
26    let y = o.y;
27    let j = random();
28    try {
29        j = o.f;
30    } catch(e) {
31        assert(j === "blah");
32        return x + y + 1;
33    }
34    return x + y;
35}
36
37var flag = false;
38
39let o2 = {
40    g: "g",
41    y: "y",
42    get f() {
43        if (flag)
44            throw new Error("blah");
45        return "get f";
46    }
47}
48
49for (let i = 0; i < 1; i++) {
50    assert(foo(o2) === "gy");
51}
52ArkTools.jitCompileAsync(foo);
53print(ArkTools.waitJitCompileFinish(foo));
54flag = true;
55print(foo(o2));