1// Copyright JS Foundation and other contributors, http://js.foundation
2//
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
15class Base {
16  constructor () {
17    this.parent_value = 100;
18  }
19
20  parent_value () {
21    return this.parent_value;
22  }
23
24  parent_value_arg (a, b, c) {
25    if (c) {
26      return this.parent_value + a + b + c;
27    } else if (b) {
28      return this.parent_value + a + b;
29    } else {
30      return this.parent_value + a;
31    }
32  }
33
34  method () {
35    return {
36      method: function (a, b, c, d, e) { return -50 + a + b + c + d + e; }
37    }
38  }
39}
40
41class Target extends Base {
42  constructor () {
43    super ();
44    this.parent_value = -10;
45  }
46
47  parent_value () {
48    throw new Error ('(parent_value)');
49  }
50
51  parent_value_direct () {
52    return super.parent_value ();
53  }
54
55  parent_value_direct_arg (a, b, c) {
56    if (c) {
57      return super.parent_value_arg (a, b, c);
58    } else if (b) {
59      return super.parent_value_arg (a, b);
60    } else {
61      return super.parent_value_arg (a);
62    }
63  }
64
65  method () {
66    throw new Error ("(method)");
67  }
68
69  parent_method_dot () {
70    return super.method ().method (1, 2, 3, 4, 5)
71  }
72
73  parent_method_index () {
74    return super['method']()['method'](1, 2, 3, 4, 5);
75  }
76}
77
78
79var obj = new Target ();
80
81assert (obj.parent_value_direct () === -10);
82assert (obj.parent_value_direct_arg (1) === -9);
83assert (obj.parent_value_direct_arg (1, 2) === -7);
84assert (obj.parent_value_direct_arg (1, 2, 3) === -4);
85
86try {
87  obj.parent_value();
88  assert (false)
89} catch (ex) {
90  /* 'obj.parent_value is a number! */
91  assert (ex instanceof TypeError);
92}
93
94assert (obj.parent_method_dot () === -35);
95assert (obj.parent_method_index () === -35);
96
97try {
98  obj.method ();
99  assert (false);
100} catch (ex) {
101  assert (ex.message === '(method)');
102}
103