| 1 |
// Copyright (C) 2016 the V8 project authors. All rights reserved. |
| 2 |
// This code is governed by the BSD license found in the LICENSE file. |
| 3 |
/*--- |
| 4 |
esid: sec-super-keyword |
| 5 |
es6id: 12.3.5 |
| 6 |
description: SuperProperty's "this" value |
| 7 |
info: | |
| 8 |
[...] |
| 9 |
4. If the code matched by the syntactic production that is being evaluated is |
| 10 |
strict mode code, let strict be true, else let strict be false. |
| 11 |
5. Return ? MakeSuperPropertyReference(propertyKey, strict). |
| 12 |
|
| 13 |
12.3.5.3 Runtime Semantics: MakeSuperPropertyReference |
| 14 |
|
| 15 |
1. Let env be GetThisEnvironment( ). |
| 16 |
2. If env.HasSuperBinding() is false, throw a ReferenceError exception. |
| 17 |
3. Let actualThis be ? env.GetThisBinding(). |
| 18 |
4. Let baseValue be ? env.GetSuperBase(). |
| 19 |
5. Let bv be ? RequireObjectCoercible(baseValue). |
| 20 |
6. Return a value of type Reference that is a Super Reference whose base |
| 21 |
value component is bv, whose referenced name component is propertyKey, |
| 22 |
whose thisValue component is actualThis, and whose strict reference flag |
| 23 |
is strict. |
| 24 |
|
| 25 |
GetValue (V) |
| 26 |
|
| 27 |
1. ReturnIfAbrupt(V). |
| 28 |
2. If Type(V) is not Reference, return V. |
| 29 |
3. Let base be GetBase(V). |
| 30 |
4. If IsUnresolvableReference(V) is true, throw a ReferenceError exception. |
| 31 |
5. If IsPropertyReference(V) is true, then |
| 32 |
a. If HasPrimitiveBase(V) is true, then |
| 33 |
i. Assert: In this case, base will never be null or undefined. |
| 34 |
ii. Let base be ! ToObject(base). |
| 35 |
b. Return ? base.[[Get]](GetReferencedName(V), GetThisValue(V)). |
| 36 |
---*/ |
| 37 |
|
| 38 |
var viaCall; |
| 39 |
var viaMember; |
| 40 |
class Parent { |
| 41 |
getThis() { |
| 42 |
return this; |
| 43 |
} |
| 44 |
get This() { |
| 45 |
return this; |
| 46 |
} |
| 47 |
} |
| 48 |
class C extends Parent { |
| 49 |
method() { |
| 50 |
viaCall = super['getThis'](); |
| 51 |
viaMember = super['This']; |
| 52 |
} |
| 53 |
} |
| 54 |
|
| 55 |
C.prototype.method(); |
| 56 |
|
| 57 |
assert.sameValue(viaCall, C.prototype, 'via CallExpression'); |
| 58 |
assert.sameValue(viaMember, C.prototype, 'via MemberExpression'); |