• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (c) 2021 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
16/*
17 * @tc.name:callframe
18 * @tc.desc:test different kinds of call frames
19 * @tc.type: FUNC
20 * @tc.require: issueI5NO8G
21 */
22// normal
23function foo0(a) {
24    return a;
25}
26
27// haveThis
28function foo1(a) {
29    if (!this) {
30        return a;
31    }
32    this.a = a;
33}
34
35// haveNewTarget
36function foo2(a) {
37    if (!new.target) {
38        return a;
39    }
40}
41
42// haveThis, haveNewTarget
43function foo3(a) {
44    if (!new.target) {
45        return a;
46    }
47    this.a = a;
48}
49
50// haveExtra
51function foo4(a, ...args) {
52    return args[a];
53}
54
55// haveThis, haveExtra
56function foo5(a, ...args) {
57    if (!this) {
58        return a;
59    }
60    this.a = args[a];
61}
62
63// haveNewTarget, haveExtra
64function foo6(a, ...args) {
65    if (!new.target) {
66        return args[a];
67    }
68}
69
70// haveThis, haveNewTarget, haveExtra
71function foo7(a, ...args) {
72    if (!new.target) {
73        return args[a];
74    }
75    this.a = args[a];
76}
77
78// arguments
79function foo8() {
80    return arguments;
81}
82
83print(foo0(1,2,3));
84print(foo1(1,2,3));  // 'this' is undefined in strict mode
85print(foo2(1,2,3));
86print(foo3(1,2,3));
87print(foo4(1,2,3));
88print(foo5(1,2,3));  // 'this' is undefined in strict mode
89print(foo6(1,2,3));
90print(foo7(1,2,3));
91print(new foo0(1,2,3).a);
92print(new foo1(1,2,3).a);
93print(new foo2(1,2,3).a);
94print(new foo3(1,2,3).a);
95print(new foo4(1,2,3).a);
96print(new foo5(1,2,3).a);
97print(new foo6(1,2,3).a);
98print(new foo7(1,2,3).a);
99print("arguments");
100var arg = foo8(1,2,3);
101print(arg.length);
102print(arg[0]);
103print(arg[1]);
104print(arg[2]);
105print(arg[3]);