• 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// normal
17function foo0(a) {
18    return a;
19}
20
21// haveThis
22function foo1(a) {
23    this.a = a;
24}
25
26// haveNewTarget
27function foo2(a) {
28    if (!new.target) {
29        return a;
30    }
31}
32
33// haveThis, haveNewTarget
34function foo3(a) {
35    if (!new.target) {
36        return a;
37    }
38    this.a = a;
39}
40
41// haveExtra
42function foo4(a, ...args) {
43    return args[a];
44}
45
46// haveThis, haveExtra
47function foo5(a, ...args) {
48    this.a = args[a];
49}
50
51// haveNewTarget, haveExtra
52function foo6(a, ...args) {
53    if (!new.target) {
54        return args[a];
55    }
56}
57
58// haveThis, haveNewTarget, haveExtra
59function foo7(a, ...args) {
60    if (!new.target) {
61        return args[a];
62    }
63    this.a = args[a];
64}
65
66print(foo0(1,2,3));
67// print(foo1(1,2,3))  'this' is undefined in strict mode
68print(foo2(1,2,3));
69print(foo3(1,2,3));
70print(foo4(1,2,3));
71// print(foo5(1,2,3))  'this' is undefined in strict mode
72print(foo6(1,2,3));
73print(foo7(1,2,3));
74print(new foo0(1,2,3).a);
75print(new foo1(1,2,3).a);
76print(new foo2(1,2,3).a);
77print(new foo3(1,2,3).a);
78print(new foo4(1,2,3).a);
79print(new foo5(1,2,3).a);
80print(new foo6(1,2,3).a);
81print(new foo7(1,2,3).a);