mirror of
https://github.com/tc39/test262.git
synced 2025-07-21 21:14:45 +02:00
Improve coverage for "super" keyword (#687)
* Improve test coverage for `super` keyword Add tests for SuperCall and SuperProperty, organized together in the `test/language/expressions/super/` directory. For SuperProperty, include tests for usage from within Object initializers and class bodies because a different set of semantics are observable from each context.
This commit is contained in:
parent
23efc2c96a
commit
a3fffa754b
@ -1,7 +1,7 @@
|
||||
// Copyright (C) 2016 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
/*---
|
||||
path: language/expressions/super/spread-
|
||||
path: language/expressions/super/call-spread-
|
||||
name: SuperCall
|
||||
esid: sec-super-keyword-runtime-semantics-evaluation
|
||||
es6id: 12.3.5.1
|
||||
|
@ -1,7 +1,7 @@
|
||||
// Copyright (C) 2016 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
/*---
|
||||
path: language/expressions/super/spread-err-
|
||||
path: language/expressions/super/call-spread-err-
|
||||
name: SuperCall
|
||||
esid: sec-super-keyword-runtime-semantics-evaluation
|
||||
es6id: 12.3.5.1
|
||||
|
37
test/language/expressions/super/call-arg-evaluation-err.js
Normal file
37
test/language/expressions/super/call-arg-evaluation-err.js
Normal file
@ -0,0 +1,37 @@
|
||||
// Copyright (C) 2016 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
/*---
|
||||
esid: sec-super-keyword
|
||||
es6id: 12.3.5
|
||||
description: Returns abrupt completion resulting from ArgumentListEvaluation
|
||||
info: |
|
||||
[...]
|
||||
4. Let argList be ArgumentListEvaluation of Arguments.
|
||||
5. ReturnIfAbrupt(argList).
|
||||
features: [class]
|
||||
---*/
|
||||
|
||||
var thrown = new Test262Error();
|
||||
var thrower = function() {
|
||||
throw thrown;
|
||||
};
|
||||
var caught;
|
||||
class C extends Object {
|
||||
constructor() {
|
||||
try {
|
||||
super(thrower());
|
||||
} catch (err) {
|
||||
caught = err;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// When the "construct" invocation completes and the "this" value is
|
||||
// uninitialized, the specification dictates that a ReferenceError must be
|
||||
// thrown. That behavior is tested elsewhere, so the error is ignored (if it is
|
||||
// produced at all).
|
||||
try {
|
||||
new C();
|
||||
} catch (_) {}
|
||||
|
||||
assert.sameValue(caught, thrown);
|
@ -0,0 +1,40 @@
|
||||
// Copyright (C) 2016 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
/*---
|
||||
esid: sec-super-keyword
|
||||
es6id: 12.3.5
|
||||
description: Abrupt completion from re-binding "this" value
|
||||
info: |
|
||||
[...]
|
||||
6. Let result be ? Construct(func, argList, newTarget).
|
||||
7. Let thisER be GetThisEnvironment( ).
|
||||
8. Return ? thisER.BindThisValue(result).
|
||||
|
||||
8.1.1.3.1 BindThisValue
|
||||
|
||||
1. Let envRec be the function Environment Record for which the method was
|
||||
invoked.
|
||||
2. Assert: envRec.[[ThisBindingStatus]] is not "lexical".
|
||||
3. If envRec.[[ThisBindingStatus]] is "initialized", throw a ReferenceError
|
||||
exception.
|
||||
features: [class]
|
||||
---*/
|
||||
|
||||
var caught;
|
||||
function Parent() {}
|
||||
|
||||
class Child extends Parent {
|
||||
constructor() {
|
||||
super();
|
||||
try {
|
||||
super();
|
||||
} catch (err) {
|
||||
caught = err;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
new Child();
|
||||
|
||||
assert.sameValue(typeof caught, 'object');
|
||||
assert.sameValue(caught.constructor, ReferenceError);
|
30
test/language/expressions/super/call-bind-this-value.js
Normal file
30
test/language/expressions/super/call-bind-this-value.js
Normal file
@ -0,0 +1,30 @@
|
||||
// Copyright (C) 2016 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
/*---
|
||||
esid: sec-super-keyword
|
||||
es6id: 12.3.5
|
||||
description: Binds the "this" value to value returned by "parent" constructor
|
||||
info: |
|
||||
[...]
|
||||
6. Let result be ? Construct(func, argList, newTarget).
|
||||
7. Let thisER be GetThisEnvironment( ).
|
||||
8. Return ? thisER.BindThisValue(result).
|
||||
features: [class]
|
||||
---*/
|
||||
|
||||
var customThisValue = {};
|
||||
var boundThisValue;
|
||||
function Parent() {
|
||||
return customThisValue;
|
||||
}
|
||||
|
||||
class Child extends Parent {
|
||||
constructor() {
|
||||
super();
|
||||
boundThisValue = this;
|
||||
}
|
||||
}
|
||||
|
||||
new Child();
|
||||
|
||||
assert.sameValue(boundThisValue, customThisValue);
|
38
test/language/expressions/super/call-construct-error.js
Normal file
38
test/language/expressions/super/call-construct-error.js
Normal file
@ -0,0 +1,38 @@
|
||||
// Copyright (C) 2016 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
/*---
|
||||
esid: sec-super-keyword
|
||||
es6id: 12.3.5
|
||||
description: >
|
||||
Behavior when invocation of "parent" constructor returns an abrupt completion
|
||||
info: |
|
||||
[...]
|
||||
6. Let result be ? Construct(func, argList, newTarget).
|
||||
features: [class]
|
||||
---*/
|
||||
|
||||
var thrown = new Test262Error();
|
||||
var caught;
|
||||
function Parent() {
|
||||
throw thrown;
|
||||
}
|
||||
|
||||
class Child extends Parent {
|
||||
constructor() {
|
||||
try {
|
||||
super();
|
||||
} catch (err) {
|
||||
caught = err;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// When the "construct" invocation completes and the "this" value is
|
||||
// uninitialized, the specification dictates that a ReferenceError must be
|
||||
// thrown. That behavior is tested elsewhere, so the error is ignored (if it is
|
||||
// produced at all).
|
||||
try {
|
||||
new Child();
|
||||
} catch (_) {}
|
||||
|
||||
assert.sameValue(caught, thrown);
|
35
test/language/expressions/super/call-construct-invocation.js
Normal file
35
test/language/expressions/super/call-construct-invocation.js
Normal file
@ -0,0 +1,35 @@
|
||||
// Copyright (C) 2016 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
/*---
|
||||
esid: sec-super-keyword
|
||||
es6id: 12.3.5
|
||||
description: Invocation of "parent" constructor
|
||||
info: |
|
||||
[...]
|
||||
6. Let result be ? Construct(func, argList, newTarget).
|
||||
[...]
|
||||
features: [class, Reflect]
|
||||
---*/
|
||||
|
||||
var expectedNewTarget = function() {};
|
||||
var thisValue, instance, args, actualNewTarget;
|
||||
function Parent() {
|
||||
thisValue = this;
|
||||
args = arguments;
|
||||
actualNewTarget = new.target;
|
||||
}
|
||||
|
||||
class Child extends Parent {
|
||||
constructor() {
|
||||
super(1, 2, 3);
|
||||
}
|
||||
}
|
||||
|
||||
instance = Reflect.construct(Child, [4, 5, 6], expectedNewTarget);
|
||||
|
||||
assert.sameValue(thisValue, instance);
|
||||
assert.sameValue(args.length, 3, 'length of provided arguments object');
|
||||
assert.sameValue(args[0], 1, 'first argument');
|
||||
assert.sameValue(args[1], 2, 'second argument');
|
||||
assert.sameValue(args[2], 3, 'third argument');
|
||||
assert.sameValue(actualNewTarget, expectedNewTarget, 'new.target value');
|
29
test/language/expressions/super/call-expr-value.js
Normal file
29
test/language/expressions/super/call-expr-value.js
Normal file
@ -0,0 +1,29 @@
|
||||
// Copyright (C) 2016 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
/*---
|
||||
esid: sec-super-keyword
|
||||
es6id: 12.3.5
|
||||
description: Evaluates to the new "this" value
|
||||
info: |
|
||||
[...]
|
||||
6. Let result be ? Construct(func, argList, newTarget).
|
||||
7. Let thisER be GetThisEnvironment( ).
|
||||
8. Return ? thisER.BindThisValue(result).
|
||||
features: [class]
|
||||
---*/
|
||||
|
||||
var customThisValue = {};
|
||||
var value;
|
||||
function Parent() {
|
||||
return customThisValue;
|
||||
}
|
||||
|
||||
class Child extends Parent {
|
||||
constructor() {
|
||||
value = super();
|
||||
}
|
||||
}
|
||||
|
||||
new Child();
|
||||
|
||||
assert.sameValue(value, customThisValue);
|
25
test/language/expressions/super/call-new-target-undef.js
Normal file
25
test/language/expressions/super/call-new-target-undef.js
Normal file
@ -0,0 +1,25 @@
|
||||
// Copyright (C) 2016 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
/*---
|
||||
esid: sec-super-keyword
|
||||
es6id: 12.3.5
|
||||
description: SuperCall requires that NewTarget is defined
|
||||
info: |
|
||||
1. Let newTarget be GetNewTarget().
|
||||
2. If newTarget is undefined, throw a ReferenceError exception.
|
||||
---*/
|
||||
|
||||
var evaluatedArg = false;
|
||||
function f() {
|
||||
// Early errors restricting the usage of SuperCall necessitate the use of
|
||||
// `eval`.
|
||||
eval('super(evaluatedArg = true);');
|
||||
}
|
||||
|
||||
assert.throws(ReferenceError, function() {
|
||||
f();
|
||||
});
|
||||
|
||||
assert.sameValue(
|
||||
evaluatedArg, false, 'did not perform ArgumentsListEvaluation'
|
||||
);
|
45
test/language/expressions/super/call-proto-not-ctor.js
Normal file
45
test/language/expressions/super/call-proto-not-ctor.js
Normal file
@ -0,0 +1,45 @@
|
||||
// Copyright (C) 2016 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
/*---
|
||||
esid: sec-super-keyword
|
||||
es6id: 12.3.5
|
||||
description: Prototype of active function object must be a constructor
|
||||
info: |
|
||||
[...]
|
||||
3. Let func be ? GetSuperConstructor().
|
||||
|
||||
12.3.5.2 Runtime Semantics: GetSuperConstructor
|
||||
|
||||
[...]
|
||||
4. Let superConstructor be ? activeFunction.[[GetPrototypeOf]]().
|
||||
5. If IsConstructor(superConstructor) is false, throw a TypeError exception.
|
||||
features: [class]
|
||||
---*/
|
||||
|
||||
var evaluatedArg = false;
|
||||
var caught;
|
||||
class C extends Object {
|
||||
constructor() {
|
||||
try {
|
||||
super(evaluatedArg = true);
|
||||
} catch (err) {
|
||||
caught = err;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Object.setPrototypeOf(C, parseInt);
|
||||
|
||||
// When the "construct" invocation completes and the "this" value is
|
||||
// uninitialized, the specification dictates that a ReferenceError must be
|
||||
// thrown. That behavior is tested elsewhere, so the error is ignored (if it is
|
||||
// produced at all).
|
||||
try {
|
||||
new C();
|
||||
} catch (_) {}
|
||||
|
||||
assert.sameValue(typeof caught, 'object');
|
||||
assert.sameValue(caught.constructor, TypeError);
|
||||
assert.sameValue(
|
||||
evaluatedArg, false, 'did not perform ArgumentsListEvaluation'
|
||||
);
|
39
test/language/expressions/super/prop-dot-cls-null-proto.js
Normal file
39
test/language/expressions/super/prop-dot-cls-null-proto.js
Normal file
@ -0,0 +1,39 @@
|
||||
// Copyright (C) 2016 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
/*---
|
||||
esid: sec-super-keyword
|
||||
es6id: 12.3.5
|
||||
description: >
|
||||
SuperProperty evaluation when the "home" object's prototype is not
|
||||
object-coercible.
|
||||
info: |
|
||||
1. Let propertyKey be StringValue of IdentifierName.
|
||||
2. If the code matched by the syntactic production that is being evaluated is
|
||||
strict mode code, let strict be true, else let strict be false.
|
||||
3. Return ? MakeSuperPropertyReference(propertyKey, strict).
|
||||
|
||||
12.3.5.3 Runtime Semantics: MakeSuperPropertyReference
|
||||
|
||||
1. Let env be GetThisEnvironment( ).
|
||||
2. If env.HasSuperBinding() is false, throw a ReferenceError exception.
|
||||
3. Let actualThis be ? env.GetThisBinding().
|
||||
4. Let baseValue be ? env.GetSuperBase().
|
||||
5. Let bv be ? RequireObjectCoercible(baseValue).
|
||||
features: [class]
|
||||
---*/
|
||||
|
||||
var caught;
|
||||
class C extends null {
|
||||
method() {
|
||||
try {
|
||||
super.x;
|
||||
} catch (err) {
|
||||
caught = err;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
C.prototype.method();
|
||||
|
||||
assert.sameValue(typeof caught, 'object');
|
||||
assert.sameValue(caught.constructor, TypeError);
|
56
test/language/expressions/super/prop-dot-cls-ref-strict.js
Normal file
56
test/language/expressions/super/prop-dot-cls-ref-strict.js
Normal file
@ -0,0 +1,56 @@
|
||||
// Copyright (C) 2016 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
/*---
|
||||
esid: sec-super-keyword
|
||||
es6id: 12.3.5
|
||||
description: SuperProperty's behavior as a strict reference
|
||||
info: |
|
||||
1. Let propertyKey be StringValue of IdentifierName.
|
||||
2. If the code matched by the syntactic production that is being evaluated is
|
||||
strict mode code, let strict be true, else let strict be false.
|
||||
3. Return ? MakeSuperPropertyReference(propertyKey, strict).
|
||||
|
||||
12.3.5.3 Runtime Semantics: MakeSuperPropertyReference
|
||||
|
||||
1. Let env be GetThisEnvironment( ).
|
||||
2. If env.HasSuperBinding() is false, throw a ReferenceError exception.
|
||||
3. Let actualThis be ? env.GetThisBinding().
|
||||
4. Let baseValue be ? env.GetSuperBase().
|
||||
5. Let bv be ? RequireObjectCoercible(baseValue).
|
||||
6. Return a value of type Reference that is a Super Reference whose base
|
||||
value component is bv, whose referenced name component is propertyKey,
|
||||
whose thisValue component is actualThis, and whose strict reference flag
|
||||
is strict.
|
||||
|
||||
6.2.3.2 PutValue
|
||||
|
||||
[...]
|
||||
5. If IsUnresolvableReference(V) is true, then
|
||||
[...]
|
||||
6. Else if IsPropertyReference(V) is true, then
|
||||
a. If HasPrimitiveBase(V) is true, then
|
||||
[...]
|
||||
b. Let succeeded be ? base.[[Set]](GetReferencedName(V), W,
|
||||
GetThisValue(V)).
|
||||
c. If succeeded is false and IsStrictReference(V) is true, throw a
|
||||
TypeError exception.
|
||||
features: [class]
|
||||
---*/
|
||||
|
||||
var caught;
|
||||
class C {
|
||||
method() {
|
||||
super.x = 8;
|
||||
Object.freeze(C.prototype);
|
||||
try {
|
||||
super.y = 9;
|
||||
} catch (err) {
|
||||
caught = err;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
C.prototype.method();
|
||||
|
||||
assert.sameValue(typeof caught, 'object');
|
||||
assert.sameValue(caught.constructor, TypeError);
|
58
test/language/expressions/super/prop-dot-cls-ref-this.js
Normal file
58
test/language/expressions/super/prop-dot-cls-ref-this.js
Normal file
@ -0,0 +1,58 @@
|
||||
// Copyright (C) 2016 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
/*---
|
||||
esid: sec-super-keyword
|
||||
es6id: 12.3.5
|
||||
description: SuperProperty's "this" value
|
||||
info: |
|
||||
1. Let propertyKey be StringValue of IdentifierName.
|
||||
2. If the code matched by the syntactic production that is being evaluated is
|
||||
strict mode code, let strict be true, else let strict be false.
|
||||
3. Return ? MakeSuperPropertyReference(propertyKey, strict).
|
||||
|
||||
12.3.5.3 Runtime Semantics: MakeSuperPropertyReference
|
||||
|
||||
1. Let env be GetThisEnvironment( ).
|
||||
2. If env.HasSuperBinding() is false, throw a ReferenceError exception.
|
||||
3. Let actualThis be ? env.GetThisBinding().
|
||||
4. Let baseValue be ? env.GetSuperBase().
|
||||
5. Let bv be ? RequireObjectCoercible(baseValue).
|
||||
6. Return a value of type Reference that is a Super Reference whose base
|
||||
value component is bv, whose referenced name component is propertyKey,
|
||||
whose thisValue component is actualThis, and whose strict reference flag
|
||||
is strict.
|
||||
|
||||
GetValue (V)
|
||||
|
||||
1. ReturnIfAbrupt(V).
|
||||
2. If Type(V) is not Reference, return V.
|
||||
3. Let base be GetBase(V).
|
||||
4. If IsUnresolvableReference(V) is true, throw a ReferenceError exception.
|
||||
5. If IsPropertyReference(V) is true, then
|
||||
a. If HasPrimitiveBase(V) is true, then
|
||||
i. Assert: In this case, base will never be null or undefined.
|
||||
ii. Let base be ! ToObject(base).
|
||||
b. Return ? base.[[Get]](GetReferencedName(V), GetThisValue(V)).
|
||||
---*/
|
||||
|
||||
var viaCall;
|
||||
var viaMember;
|
||||
class Parent {
|
||||
getThis() {
|
||||
return this;
|
||||
}
|
||||
get This() {
|
||||
return this;
|
||||
}
|
||||
}
|
||||
class C extends Parent {
|
||||
method() {
|
||||
viaCall = super.getThis();
|
||||
viaMember = super.This;
|
||||
}
|
||||
}
|
||||
|
||||
C.prototype.method();
|
||||
|
||||
assert.sameValue(viaCall, C.prototype, 'via CallExpression');
|
||||
assert.sameValue(viaMember, C.prototype, 'via MemberExpression');
|
50
test/language/expressions/super/prop-dot-cls-this-uninit.js
Normal file
50
test/language/expressions/super/prop-dot-cls-this-uninit.js
Normal file
@ -0,0 +1,50 @@
|
||||
// Copyright (C) 2016 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
/*---
|
||||
esid: sec-super-keyword
|
||||
es6id: 12.3.5
|
||||
description: >
|
||||
SuperProperty evaluation when "this" binding has not been initialized
|
||||
info: |
|
||||
1. Let propertyKey be StringValue of IdentifierName.
|
||||
2. If the code matched by the syntactic production that is being evaluated is
|
||||
strict mode code, let strict be true, else let strict be false.
|
||||
3. Return ? MakeSuperPropertyReference(propertyKey, strict).
|
||||
|
||||
12.3.5.3 Runtime Semantics: MakeSuperPropertyReference
|
||||
|
||||
1. Let env be GetThisEnvironment( ).
|
||||
2. If env.HasSuperBinding() is false, throw a ReferenceError exception.
|
||||
3. Let actualThis be ? env.GetThisBinding().
|
||||
|
||||
8.1.1.3.4 GetThisBinding
|
||||
|
||||
1. Let envRec be the function Environment Record for which the method was
|
||||
invoked.
|
||||
2. Assert: envRec.[[ThisBindingStatus]] is not "lexical".
|
||||
3. If envRec.[[ThisBindingStatus]] is "uninitialized", throw a ReferenceError
|
||||
exception.
|
||||
features: [class]
|
||||
---*/
|
||||
|
||||
var caught;
|
||||
class C extends Object {
|
||||
constructor() {
|
||||
try {
|
||||
super.x;
|
||||
} catch (err) {
|
||||
caught = err;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// When the "construct" invocation completes and the "this" value is
|
||||
// uninitialized, the specification dictates that a ReferenceError must be
|
||||
// thrown. That behavior is tested elsewhere, so the error is ignored (if it is
|
||||
// produced at all).
|
||||
try {
|
||||
new C();
|
||||
} catch (_) {}
|
||||
|
||||
assert.sameValue(typeof caught, 'object');
|
||||
assert.sameValue(caught.constructor, ReferenceError);
|
@ -0,0 +1,46 @@
|
||||
// Copyright (C) 2016 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
/*---
|
||||
esid: sec-super-keyword
|
||||
es6id: 12.3.5
|
||||
description: Value of reference returned by SuperProperty (from arrow function)
|
||||
info: |
|
||||
1. Let propertyKey be StringValue of IdentifierName.
|
||||
2. If the code matched by the syntactic production that is being evaluated is
|
||||
strict mode code, let strict be true, else let strict be false.
|
||||
3. Return ? MakeSuperPropertyReference(propertyKey, strict).
|
||||
|
||||
12.3.5.3 Runtime Semantics: MakeSuperPropertyReference
|
||||
|
||||
1. Let env be GetThisEnvironment( ).
|
||||
2. If env.HasSuperBinding() is false, throw a ReferenceError exception.
|
||||
3. Let actualThis be ? env.GetThisBinding().
|
||||
4. Let baseValue be ? env.GetSuperBase().
|
||||
5. Let bv be ? RequireObjectCoercible(baseValue).
|
||||
6. Return a value of type Reference that is a Super Reference whose base
|
||||
value component is bv, whose referenced name component is propertyKey,
|
||||
whose thisValue component is actualThis, and whose strict reference flag
|
||||
is strict.
|
||||
features: [class, arrow-function]
|
||||
---*/
|
||||
|
||||
var fromA, fromB;
|
||||
class A {}
|
||||
class B extends A {}
|
||||
class C extends B {
|
||||
method() {
|
||||
fromA = (() => { return super.fromA; })();
|
||||
fromB = (() => { return super.fromB; })();
|
||||
}
|
||||
}
|
||||
|
||||
A.prototype.fromA = 'a';
|
||||
A.prototype.fromB = 'a';
|
||||
B.prototype.fromB = 'b';
|
||||
C.prototype.fromA = 'c';
|
||||
C.prototype.fromB = 'c';
|
||||
|
||||
C.prototype.method();
|
||||
|
||||
assert.sameValue(fromA, 'a');
|
||||
assert.sameValue(fromB, 'b');
|
@ -0,0 +1,47 @@
|
||||
// Copyright (C) 2016 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
/*---
|
||||
esid: sec-super-keyword
|
||||
es6id: 12.3.5
|
||||
description: >
|
||||
Value of reference returned by SuperProperty (from eval code)
|
||||
info: |
|
||||
1. Let propertyKey be StringValue of IdentifierName.
|
||||
2. If the code matched by the syntactic production that is being evaluated is
|
||||
strict mode code, let strict be true, else let strict be false.
|
||||
3. Return ? MakeSuperPropertyReference(propertyKey, strict).
|
||||
|
||||
12.3.5.3 Runtime Semantics: MakeSuperPropertyReference
|
||||
|
||||
1. Let env be GetThisEnvironment( ).
|
||||
2. If env.HasSuperBinding() is false, throw a ReferenceError exception.
|
||||
3. Let actualThis be ? env.GetThisBinding().
|
||||
4. Let baseValue be ? env.GetSuperBase().
|
||||
5. Let bv be ? RequireObjectCoercible(baseValue).
|
||||
6. Return a value of type Reference that is a Super Reference whose base
|
||||
value component is bv, whose referenced name component is propertyKey,
|
||||
whose thisValue component is actualThis, and whose strict reference flag
|
||||
is strict.
|
||||
features: [class]
|
||||
---*/
|
||||
|
||||
var fromA, fromB;
|
||||
class A {}
|
||||
class B extends A {}
|
||||
class C extends B {
|
||||
method() {
|
||||
fromA = eval('super.fromA;');
|
||||
fromB = eval('super.fromB;');
|
||||
}
|
||||
}
|
||||
|
||||
A.prototype.fromA = 'a';
|
||||
A.prototype.fromB = 'a';
|
||||
B.prototype.fromB = 'b';
|
||||
C.prototype.fromA = 'c';
|
||||
C.prototype.fromB = 'c';
|
||||
|
||||
C.prototype.method();
|
||||
|
||||
assert.sameValue(fromA, 'a');
|
||||
assert.sameValue(fromB, 'b');
|
46
test/language/expressions/super/prop-dot-cls-val.js
Normal file
46
test/language/expressions/super/prop-dot-cls-val.js
Normal file
@ -0,0 +1,46 @@
|
||||
// Copyright (C) 2016 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
/*---
|
||||
esid: sec-super-keyword
|
||||
es6id: 12.3.5
|
||||
description: Value of reference returned by SuperProperty
|
||||
info: |
|
||||
1. Let propertyKey be StringValue of IdentifierName.
|
||||
2. If the code matched by the syntactic production that is being evaluated is
|
||||
strict mode code, let strict be true, else let strict be false.
|
||||
3. Return ? MakeSuperPropertyReference(propertyKey, strict).
|
||||
|
||||
12.3.5.3 Runtime Semantics: MakeSuperPropertyReference
|
||||
|
||||
1. Let env be GetThisEnvironment( ).
|
||||
2. If env.HasSuperBinding() is false, throw a ReferenceError exception.
|
||||
3. Let actualThis be ? env.GetThisBinding().
|
||||
4. Let baseValue be ? env.GetSuperBase().
|
||||
5. Let bv be ? RequireObjectCoercible(baseValue).
|
||||
6. Return a value of type Reference that is a Super Reference whose base
|
||||
value component is bv, whose referenced name component is propertyKey,
|
||||
whose thisValue component is actualThis, and whose strict reference flag
|
||||
is strict.
|
||||
features: [class]
|
||||
---*/
|
||||
|
||||
var fromA, fromB;
|
||||
class A {}
|
||||
class B extends A {}
|
||||
class C extends B {
|
||||
method() {
|
||||
fromA = super.fromA;
|
||||
fromB = super.fromB;
|
||||
}
|
||||
}
|
||||
|
||||
A.prototype.fromA = 'a';
|
||||
A.prototype.fromB = 'a';
|
||||
B.prototype.fromB = 'b';
|
||||
C.prototype.fromA = 'c';
|
||||
C.prototype.fromB = 'c';
|
||||
|
||||
C.prototype.method();
|
||||
|
||||
assert.sameValue(fromA, 'a');
|
||||
assert.sameValue(fromB, 'b');
|
@ -0,0 +1,33 @@
|
||||
// Copyright (C) 2016 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
/*---
|
||||
esid: sec-super-keyword
|
||||
es6id: 12.3.5
|
||||
description: ReferenceError is thrown when environment has no "super" binding
|
||||
info: |
|
||||
1. Let propertyKey be StringValue of IdentifierName.
|
||||
2. If the code matched by the syntactic production that is being evaluated is
|
||||
strict mode code, let strict be true, else let strict be false.
|
||||
3. Return ? MakeSuperPropertyReference(propertyKey, strict).
|
||||
|
||||
12.3.5.3 Runtime Semantics: MakeSuperPropertyReference
|
||||
|
||||
1. Let env be GetThisEnvironment( ).
|
||||
2. If env.HasSuperBinding() is false, throw a ReferenceError exception.
|
||||
---*/
|
||||
|
||||
var caught;
|
||||
function f() {
|
||||
// Early errors restricting the usage of SuperProperty necessitate the use of
|
||||
// `eval`.
|
||||
try {
|
||||
eval('super.x;');
|
||||
} catch (err) {
|
||||
caught = err;
|
||||
}
|
||||
}
|
||||
|
||||
f();
|
||||
|
||||
assert.sameValue(typeof caught, 'object');
|
||||
assert.sameValue(caught.constructor, ReferenceError);
|
39
test/language/expressions/super/prop-dot-obj-null-proto.js
Normal file
39
test/language/expressions/super/prop-dot-obj-null-proto.js
Normal file
@ -0,0 +1,39 @@
|
||||
// Copyright (C) 2016 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
/*---
|
||||
esid: sec-super-keyword
|
||||
es6id: 12.3.5
|
||||
description: >
|
||||
SuperProperty evaluation when the "home" object's prototype is not
|
||||
object-coercible.
|
||||
info: |
|
||||
1. Let propertyKey be StringValue of IdentifierName.
|
||||
2. If the code matched by the syntactic production that is being evaluated is
|
||||
strict mode code, let strict be true, else let strict be false.
|
||||
3. Return ? MakeSuperPropertyReference(propertyKey, strict).
|
||||
|
||||
12.3.5.3 Runtime Semantics: MakeSuperPropertyReference
|
||||
|
||||
1. Let env be GetThisEnvironment( ).
|
||||
2. If env.HasSuperBinding() is false, throw a ReferenceError exception.
|
||||
3. Let actualThis be ? env.GetThisBinding().
|
||||
4. Let baseValue be ? env.GetSuperBase().
|
||||
5. Let bv be ? RequireObjectCoercible(baseValue).
|
||||
---*/
|
||||
|
||||
var caught;
|
||||
var obj = {
|
||||
method() {
|
||||
try {
|
||||
super.x;
|
||||
} catch (err) {
|
||||
caught = err;
|
||||
}
|
||||
}
|
||||
};
|
||||
Object.setPrototypeOf(obj, null);
|
||||
|
||||
obj.method();
|
||||
|
||||
assert.sameValue(typeof caught, 'object');
|
||||
assert.sameValue(caught.constructor, TypeError);
|
@ -0,0 +1,52 @@
|
||||
// Copyright (C) 2016 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
/*---
|
||||
esid: sec-super-keyword
|
||||
es6id: 12.3.5
|
||||
description: SuperProperty's behavior as a non-strict reference
|
||||
info: |
|
||||
1. Let propertyKey be StringValue of IdentifierName.
|
||||
2. If the code matched by the syntactic production that is being evaluated is
|
||||
strict mode code, let strict be true, else let strict be false.
|
||||
3. Return ? MakeSuperPropertyReference(propertyKey, strict).
|
||||
|
||||
12.3.5.3 Runtime Semantics: MakeSuperPropertyReference
|
||||
|
||||
1. Let env be GetThisEnvironment( ).
|
||||
2. If env.HasSuperBinding() is false, throw a ReferenceError exception.
|
||||
3. Let actualThis be ? env.GetThisBinding().
|
||||
4. Let baseValue be ? env.GetSuperBase().
|
||||
5. Let bv be ? RequireObjectCoercible(baseValue).
|
||||
6. Return a value of type Reference that is a Super Reference whose base
|
||||
value component is bv, whose referenced name component is propertyKey,
|
||||
whose thisValue component is actualThis, and whose strict reference flag
|
||||
is strict.
|
||||
|
||||
6.2.3.2 PutValue
|
||||
|
||||
[...]
|
||||
5. If IsUnresolvableReference(V) is true, then
|
||||
[...]
|
||||
6. Else if IsPropertyReference(V) is true, then
|
||||
a. If HasPrimitiveBase(V) is true, then
|
||||
[...]
|
||||
b. Let succeeded be ? base.[[Set]](GetReferencedName(V), W,
|
||||
GetThisValue(V)).
|
||||
c. If succeeded is false and IsStrictReference(V) is true, throw a
|
||||
TypeError exception.
|
||||
d. Return.
|
||||
flags: [noStrict]
|
||||
---*/
|
||||
|
||||
var obj = {
|
||||
method() {
|
||||
super.x = 8;
|
||||
Object.freeze(obj);
|
||||
super.y = 9;
|
||||
}
|
||||
};
|
||||
|
||||
obj.method();
|
||||
|
||||
assert.sameValue(Object.hasOwnProperty.call(obj, 'x'), true);
|
||||
assert.sameValue(Object.hasOwnProperty.call(obj, 'y'), false);
|
56
test/language/expressions/super/prop-dot-obj-ref-strict.js
Normal file
56
test/language/expressions/super/prop-dot-obj-ref-strict.js
Normal file
@ -0,0 +1,56 @@
|
||||
// Copyright (C) 2016 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
/*---
|
||||
esid: sec-super-keyword
|
||||
es6id: 12.3.5
|
||||
description: SuperProperty's behavior as a strict reference
|
||||
info: |
|
||||
1. Let propertyKey be StringValue of IdentifierName.
|
||||
2. If the code matched by the syntactic production that is being evaluated is
|
||||
strict mode code, let strict be true, else let strict be false.
|
||||
3. Return ? MakeSuperPropertyReference(propertyKey, strict).
|
||||
|
||||
12.3.5.3 Runtime Semantics: MakeSuperPropertyReference
|
||||
|
||||
1. Let env be GetThisEnvironment( ).
|
||||
2. If env.HasSuperBinding() is false, throw a ReferenceError exception.
|
||||
3. Let actualThis be ? env.GetThisBinding().
|
||||
4. Let baseValue be ? env.GetSuperBase().
|
||||
5. Let bv be ? RequireObjectCoercible(baseValue).
|
||||
6. Return a value of type Reference that is a Super Reference whose base
|
||||
value component is bv, whose referenced name component is propertyKey,
|
||||
whose thisValue component is actualThis, and whose strict reference flag
|
||||
is strict.
|
||||
|
||||
6.2.3.2 PutValue
|
||||
|
||||
[...]
|
||||
5. If IsUnresolvableReference(V) is true, then
|
||||
[...]
|
||||
6. Else if IsPropertyReference(V) is true, then
|
||||
a. If HasPrimitiveBase(V) is true, then
|
||||
[...]
|
||||
b. Let succeeded be ? base.[[Set]](GetReferencedName(V), W,
|
||||
GetThisValue(V)).
|
||||
c. If succeeded is false and IsStrictReference(V) is true, throw a
|
||||
TypeError exception.
|
||||
flags: [onlyStrict]
|
||||
---*/
|
||||
|
||||
var caught;
|
||||
var obj = {
|
||||
method() {
|
||||
super.x = 8;
|
||||
Object.freeze(obj);
|
||||
try {
|
||||
super.y = 9;
|
||||
} catch (err) {
|
||||
caught = err;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
obj.method();
|
||||
|
||||
assert.sameValue(typeof caught, 'object');
|
||||
assert.sameValue(caught.constructor, TypeError);
|
59
test/language/expressions/super/prop-dot-obj-ref-this.js
Normal file
59
test/language/expressions/super/prop-dot-obj-ref-this.js
Normal file
@ -0,0 +1,59 @@
|
||||
// Copyright (C) 2016 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
/*---
|
||||
esid: sec-super-keyword
|
||||
es6id: 12.3.5
|
||||
description: SuperProperty's "this" value
|
||||
info: |
|
||||
1. Let propertyKey be StringValue of IdentifierName.
|
||||
2. If the code matched by the syntactic production that is being evaluated is
|
||||
strict mode code, let strict be true, else let strict be false.
|
||||
3. Return ? MakeSuperPropertyReference(propertyKey, strict).
|
||||
|
||||
12.3.5.3 Runtime Semantics: MakeSuperPropertyReference
|
||||
|
||||
1. Let env be GetThisEnvironment( ).
|
||||
2. If env.HasSuperBinding() is false, throw a ReferenceError exception.
|
||||
3. Let actualThis be ? env.GetThisBinding().
|
||||
4. Let baseValue be ? env.GetSuperBase().
|
||||
5. Let bv be ? RequireObjectCoercible(baseValue).
|
||||
6. Return a value of type Reference that is a Super Reference whose base
|
||||
value component is bv, whose referenced name component is propertyKey,
|
||||
whose thisValue component is actualThis, and whose strict reference flag
|
||||
is strict.
|
||||
|
||||
GetValue (V)
|
||||
|
||||
1. ReturnIfAbrupt(V).
|
||||
2. If Type(V) is not Reference, return V.
|
||||
3. Let base be GetBase(V).
|
||||
4. If IsUnresolvableReference(V) is true, throw a ReferenceError exception.
|
||||
5. If IsPropertyReference(V) is true, then
|
||||
a. If HasPrimitiveBase(V) is true, then
|
||||
i. Assert: In this case, base will never be null or undefined.
|
||||
ii. Let base be ! ToObject(base).
|
||||
b. Return ? base.[[Get]](GetReferencedName(V), GetThisValue(V)).
|
||||
---*/
|
||||
|
||||
var viaCall;
|
||||
var viaMember;
|
||||
var parent = {
|
||||
getThis: function() {
|
||||
return this;
|
||||
},
|
||||
get This() {
|
||||
return this;
|
||||
}
|
||||
};
|
||||
var obj = {
|
||||
method() {
|
||||
viaCall = super.getThis();
|
||||
viaMember = super.This;
|
||||
}
|
||||
};
|
||||
Object.setPrototypeOf(obj, parent);
|
||||
|
||||
obj.method();
|
||||
|
||||
assert.sameValue(viaCall, obj, 'via CallExpression');
|
||||
assert.sameValue(viaMember, obj, 'via MemberExpression');
|
@ -0,0 +1,46 @@
|
||||
// Copyright (C) 2016 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
/*---
|
||||
esid: sec-super-keyword
|
||||
es6id: 12.3.5
|
||||
description: Value of reference returned by SuperProperty (from arrow function)
|
||||
info: |
|
||||
1. Let propertyKey be StringValue of IdentifierName.
|
||||
2. If the code matched by the syntactic production that is being evaluated is
|
||||
strict mode code, let strict be true, else let strict be false.
|
||||
3. Return ? MakeSuperPropertyReference(propertyKey, strict).
|
||||
|
||||
12.3.5.3 Runtime Semantics: MakeSuperPropertyReference
|
||||
|
||||
1. Let env be GetThisEnvironment( ).
|
||||
2. If env.HasSuperBinding() is false, throw a ReferenceError exception.
|
||||
3. Let actualThis be ? env.GetThisBinding().
|
||||
4. Let baseValue be ? env.GetSuperBase().
|
||||
5. Let bv be ? RequireObjectCoercible(baseValue).
|
||||
6. Return a value of type Reference that is a Super Reference whose base
|
||||
value component is bv, whose referenced name component is propertyKey,
|
||||
whose thisValue component is actualThis, and whose strict reference flag
|
||||
is strict.
|
||||
features: [arrow-function]
|
||||
---*/
|
||||
|
||||
var fromA, fromB;
|
||||
var A = { fromA: 'a', fromB: 'a' };
|
||||
var B = { fromB: 'b' };
|
||||
Object.setPrototypeOf(B, A);
|
||||
|
||||
var obj = {
|
||||
fromA: 'c',
|
||||
fromB: 'c',
|
||||
method() {
|
||||
fromA = (() => { return super.fromA; })();
|
||||
fromB = (() => { return super.fromB; })();
|
||||
}
|
||||
};
|
||||
|
||||
Object.setPrototypeOf(obj, B);
|
||||
|
||||
obj.method();
|
||||
|
||||
assert.sameValue(fromA, 'a');
|
||||
assert.sameValue(fromB, 'b');
|
@ -0,0 +1,45 @@
|
||||
// Copyright (C) 2016 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
/*---
|
||||
esid: sec-super-keyword
|
||||
es6id: 12.3.5
|
||||
description: Value of reference returned by SuperProperty (from eval code)
|
||||
info: |
|
||||
1. Let propertyKey be StringValue of IdentifierName.
|
||||
2. If the code matched by the syntactic production that is being evaluated is
|
||||
strict mode code, let strict be true, else let strict be false.
|
||||
3. Return ? MakeSuperPropertyReference(propertyKey, strict).
|
||||
|
||||
12.3.5.3 Runtime Semantics: MakeSuperPropertyReference
|
||||
|
||||
1. Let env be GetThisEnvironment( ).
|
||||
2. If env.HasSuperBinding() is false, throw a ReferenceError exception.
|
||||
3. Let actualThis be ? env.GetThisBinding().
|
||||
4. Let baseValue be ? env.GetSuperBase().
|
||||
5. Let bv be ? RequireObjectCoercible(baseValue).
|
||||
6. Return a value of type Reference that is a Super Reference whose base
|
||||
value component is bv, whose referenced name component is propertyKey,
|
||||
whose thisValue component is actualThis, and whose strict reference flag
|
||||
is strict.
|
||||
---*/
|
||||
|
||||
var fromA, fromB;
|
||||
var A = { fromA: 'a', fromB: 'a' };
|
||||
var B = { fromB: 'b' };
|
||||
Object.setPrototypeOf(B, A);
|
||||
|
||||
var obj = {
|
||||
fromA: 'c',
|
||||
fromB: 'c',
|
||||
method() {
|
||||
fromA = eval('super.fromA;');
|
||||
fromB = eval('super.fromB;');
|
||||
}
|
||||
};
|
||||
|
||||
Object.setPrototypeOf(obj, B);
|
||||
|
||||
obj.method();
|
||||
|
||||
assert.sameValue(fromA, 'a');
|
||||
assert.sameValue(fromB, 'b');
|
45
test/language/expressions/super/prop-dot-obj-val.js
Normal file
45
test/language/expressions/super/prop-dot-obj-val.js
Normal file
@ -0,0 +1,45 @@
|
||||
// Copyright (C) 2016 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
/*---
|
||||
esid: sec-super-keyword
|
||||
es6id: 12.3.5
|
||||
description: Value of reference returned by SuperProperty
|
||||
info: |
|
||||
1. Let propertyKey be StringValue of IdentifierName.
|
||||
2. If the code matched by the syntactic production that is being evaluated is
|
||||
strict mode code, let strict be true, else let strict be false.
|
||||
3. Return ? MakeSuperPropertyReference(propertyKey, strict).
|
||||
|
||||
12.3.5.3 Runtime Semantics: MakeSuperPropertyReference
|
||||
|
||||
1. Let env be GetThisEnvironment( ).
|
||||
2. If env.HasSuperBinding() is false, throw a ReferenceError exception.
|
||||
3. Let actualThis be ? env.GetThisBinding().
|
||||
4. Let baseValue be ? env.GetSuperBase().
|
||||
5. Let bv be ? RequireObjectCoercible(baseValue).
|
||||
6. Return a value of type Reference that is a Super Reference whose base
|
||||
value component is bv, whose referenced name component is propertyKey,
|
||||
whose thisValue component is actualThis, and whose strict reference flag
|
||||
is strict.
|
||||
---*/
|
||||
|
||||
var fromA, fromB;
|
||||
var A = { fromA: 'a', fromB: 'a' };
|
||||
var B = { fromB: 'b' };
|
||||
Object.setPrototypeOf(B, A);
|
||||
|
||||
var obj = {
|
||||
fromA: 'c',
|
||||
fromB: 'c',
|
||||
method() {
|
||||
fromA = super.fromA;
|
||||
fromB = super.fromB;
|
||||
}
|
||||
};
|
||||
|
||||
Object.setPrototypeOf(obj, B);
|
||||
|
||||
obj.method();
|
||||
|
||||
assert.sameValue(fromA, 'a');
|
||||
assert.sameValue(fromB, 'b');
|
34
test/language/expressions/super/prop-expr-cls-err.js
Normal file
34
test/language/expressions/super/prop-expr-cls-err.js
Normal file
@ -0,0 +1,34 @@
|
||||
// Copyright (C) 2016 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
/*---
|
||||
esid: sec-super-keyword
|
||||
es6id: 12.3.5
|
||||
description: Abrupt completion from Expression evaluation
|
||||
info: |
|
||||
1. Let propertyNameReference be the result of evaluating Expression.
|
||||
2. Let propertyNameValue be ? GetValue(propertyNameReference).
|
||||
|
||||
6.2.3.1 GetValue
|
||||
|
||||
1. ReturnIfAbrupt(V).
|
||||
features: [class]
|
||||
---*/
|
||||
|
||||
var thrown = new Test262Error();
|
||||
var caught;
|
||||
function thrower() {
|
||||
throw thrown;
|
||||
}
|
||||
class C {
|
||||
method() {
|
||||
try {
|
||||
super[thrower()];
|
||||
} catch (err) {
|
||||
caught = err;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
C.prototype.method();
|
||||
|
||||
assert.sameValue(caught, thrown);
|
37
test/language/expressions/super/prop-expr-cls-key-err.js
Normal file
37
test/language/expressions/super/prop-expr-cls-key-err.js
Normal file
@ -0,0 +1,37 @@
|
||||
// Copyright (C) 2016 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
/*---
|
||||
esid: sec-super-keyword
|
||||
es6id: 12.3.5
|
||||
description: Abrupt completion from type coercion of property key
|
||||
info: |
|
||||
1. Let propertyNameReference be the result of evaluating Expression.
|
||||
2. Let propertyNameValue be ? GetValue(propertyNameReference).
|
||||
3. Let propertyKey be ? ToPropertyKey(propertyNameValue).
|
||||
|
||||
7.1.14 ToPropertyKey
|
||||
|
||||
1. Let key be ? ToPrimitive(argument, hint String).
|
||||
features: [class]
|
||||
---*/
|
||||
|
||||
var thrown = new Test262Error();
|
||||
var badToString = {
|
||||
toString: function() {
|
||||
throw thrown;
|
||||
}
|
||||
};
|
||||
var caught;
|
||||
class C {
|
||||
method() {
|
||||
try {
|
||||
super[badToString];
|
||||
} catch (err) {
|
||||
caught = err;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
C.prototype.method();
|
||||
|
||||
assert.sameValue(caught, thrown);
|
39
test/language/expressions/super/prop-expr-cls-null-proto.js
Normal file
39
test/language/expressions/super/prop-expr-cls-null-proto.js
Normal file
@ -0,0 +1,39 @@
|
||||
// Copyright (C) 2016 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
/*---
|
||||
esid: sec-super-keyword
|
||||
es6id: 12.3.5
|
||||
description: >
|
||||
SuperProperty evaluation when the "home" object's prototype is not
|
||||
object-coercible.
|
||||
info: |
|
||||
[...]
|
||||
4. If the code matched by the syntactic production that is being evaluated is
|
||||
strict mode code, let strict be true, else let strict be false.
|
||||
5. Return ? MakeSuperPropertyReference(propertyKey, strict).
|
||||
|
||||
12.3.5.3 Runtime Semantics: MakeSuperPropertyReference
|
||||
|
||||
1. Let env be GetThisEnvironment( ).
|
||||
2. If env.HasSuperBinding() is false, throw a ReferenceError exception.
|
||||
3. Let actualThis be ? env.GetThisBinding().
|
||||
4. Let baseValue be ? env.GetSuperBase().
|
||||
5. Let bv be ? RequireObjectCoercible(baseValue).
|
||||
features: [class]
|
||||
---*/
|
||||
|
||||
var caught;
|
||||
class C extends null {
|
||||
method() {
|
||||
try {
|
||||
super['x'];
|
||||
} catch (err) {
|
||||
caught = err;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
C.prototype.method();
|
||||
|
||||
assert.sameValue(typeof caught, 'object');
|
||||
assert.sameValue(caught.constructor, TypeError);
|
56
test/language/expressions/super/prop-expr-cls-ref-strict.js
Normal file
56
test/language/expressions/super/prop-expr-cls-ref-strict.js
Normal file
@ -0,0 +1,56 @@
|
||||
// Copyright (C) 2016 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
/*---
|
||||
esid: sec-super-keyword
|
||||
es6id: 12.3.5
|
||||
description: SuperProperty's behavior as a strict reference
|
||||
info: |
|
||||
[...]
|
||||
4. If the code matched by the syntactic production that is being evaluated is
|
||||
strict mode code, let strict be true, else let strict be false.
|
||||
5. Return ? MakeSuperPropertyReference(propertyKey, strict).
|
||||
|
||||
12.3.5.3 Runtime Semantics: MakeSuperPropertyReference
|
||||
|
||||
1. Let env be GetThisEnvironment( ).
|
||||
2. If env.HasSuperBinding() is false, throw a ReferenceError exception.
|
||||
3. Let actualThis be ? env.GetThisBinding().
|
||||
4. Let baseValue be ? env.GetSuperBase().
|
||||
5. Let bv be ? RequireObjectCoercible(baseValue).
|
||||
6. Return a value of type Reference that is a Super Reference whose base
|
||||
value component is bv, whose referenced name component is propertyKey,
|
||||
whose thisValue component is actualThis, and whose strict reference flag
|
||||
is strict.
|
||||
|
||||
6.2.3.2 PutValue
|
||||
|
||||
[...]
|
||||
5. If IsUnresolvableReference(V) is true, then
|
||||
[...]
|
||||
6. Else if IsPropertyReference(V) is true, then
|
||||
a. If HasPrimitiveBase(V) is true, then
|
||||
[...]
|
||||
b. Let succeeded be ? base.[[Set]](GetReferencedName(V), W,
|
||||
GetThisValue(V)).
|
||||
c. If succeeded is false and IsStrictReference(V) is true, throw a
|
||||
TypeError exception.
|
||||
features: [class]
|
||||
---*/
|
||||
|
||||
var caught;
|
||||
class C {
|
||||
method() {
|
||||
super['x'] = 8;
|
||||
Object.freeze(C.prototype);
|
||||
try {
|
||||
super['y'] = 9;
|
||||
} catch (err) {
|
||||
caught = err;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
C.prototype.method();
|
||||
|
||||
assert.sameValue(typeof caught, 'object');
|
||||
assert.sameValue(caught.constructor, TypeError);
|
58
test/language/expressions/super/prop-expr-cls-ref-this.js
Normal file
58
test/language/expressions/super/prop-expr-cls-ref-this.js
Normal file
@ -0,0 +1,58 @@
|
||||
// Copyright (C) 2016 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
/*---
|
||||
esid: sec-super-keyword
|
||||
es6id: 12.3.5
|
||||
description: SuperProperty's "this" value
|
||||
info: |
|
||||
[...]
|
||||
4. If the code matched by the syntactic production that is being evaluated is
|
||||
strict mode code, let strict be true, else let strict be false.
|
||||
5. Return ? MakeSuperPropertyReference(propertyKey, strict).
|
||||
|
||||
12.3.5.3 Runtime Semantics: MakeSuperPropertyReference
|
||||
|
||||
1. Let env be GetThisEnvironment( ).
|
||||
2. If env.HasSuperBinding() is false, throw a ReferenceError exception.
|
||||
3. Let actualThis be ? env.GetThisBinding().
|
||||
4. Let baseValue be ? env.GetSuperBase().
|
||||
5. Let bv be ? RequireObjectCoercible(baseValue).
|
||||
6. Return a value of type Reference that is a Super Reference whose base
|
||||
value component is bv, whose referenced name component is propertyKey,
|
||||
whose thisValue component is actualThis, and whose strict reference flag
|
||||
is strict.
|
||||
|
||||
GetValue (V)
|
||||
|
||||
1. ReturnIfAbrupt(V).
|
||||
2. If Type(V) is not Reference, return V.
|
||||
3. Let base be GetBase(V).
|
||||
4. If IsUnresolvableReference(V) is true, throw a ReferenceError exception.
|
||||
5. If IsPropertyReference(V) is true, then
|
||||
a. If HasPrimitiveBase(V) is true, then
|
||||
i. Assert: In this case, base will never be null or undefined.
|
||||
ii. Let base be ! ToObject(base).
|
||||
b. Return ? base.[[Get]](GetReferencedName(V), GetThisValue(V)).
|
||||
---*/
|
||||
|
||||
var viaCall;
|
||||
var viaMember;
|
||||
class Parent {
|
||||
getThis() {
|
||||
return this;
|
||||
}
|
||||
get This() {
|
||||
return this;
|
||||
}
|
||||
}
|
||||
class C extends Parent {
|
||||
method() {
|
||||
viaCall = super['getThis']();
|
||||
viaMember = super['This'];
|
||||
}
|
||||
}
|
||||
|
||||
C.prototype.method();
|
||||
|
||||
assert.sameValue(viaCall, C.prototype, 'via CallExpression');
|
||||
assert.sameValue(viaMember, C.prototype, 'via MemberExpression');
|
50
test/language/expressions/super/prop-expr-cls-this-uninit.js
Normal file
50
test/language/expressions/super/prop-expr-cls-this-uninit.js
Normal file
@ -0,0 +1,50 @@
|
||||
// Copyright (C) 2016 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
/*---
|
||||
esid: sec-super-keyword
|
||||
es6id: 12.3.5
|
||||
description: >
|
||||
SuperProperty evaluation when "this" binding has not been initialized
|
||||
info: |
|
||||
[...]
|
||||
4. If the code matched by the syntactic production that is being evaluated is
|
||||
strict mode code, let strict be true, else let strict be false.
|
||||
5. Return ? MakeSuperPropertyReference(propertyKey, strict).
|
||||
|
||||
12.3.5.3 Runtime Semantics: MakeSuperPropertyReference
|
||||
|
||||
1. Let env be GetThisEnvironment( ).
|
||||
2. If env.HasSuperBinding() is false, throw a ReferenceError exception.
|
||||
3. Let actualThis be ? env.GetThisBinding().
|
||||
|
||||
8.1.1.3.4 GetThisBinding
|
||||
|
||||
1. Let envRec be the function Environment Record for which the method was
|
||||
invoked.
|
||||
2. Assert: envRec.[[ThisBindingStatus]] is not "lexical".
|
||||
3. If envRec.[[ThisBindingStatus]] is "uninitialized", throw a ReferenceError
|
||||
exception.
|
||||
features: [class]
|
||||
---*/
|
||||
|
||||
var caught;
|
||||
class C extends Object {
|
||||
constructor() {
|
||||
try {
|
||||
super['x'];
|
||||
} catch (err) {
|
||||
caught = err;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// When the "construct" invocation completes and the "this" value is
|
||||
// uninitialized, the specification dictates that a ReferenceError must be
|
||||
// thrown. That behavior is tested elsewhere, so the error is ignored (if it is
|
||||
// produced at all).
|
||||
try {
|
||||
new C();
|
||||
} catch (_) {}
|
||||
|
||||
assert.sameValue(typeof caught, 'object');
|
||||
assert.sameValue(caught.constructor, ReferenceError);
|
@ -0,0 +1,34 @@
|
||||
// Copyright (C) 2016 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
/*---
|
||||
esid: sec-super-keyword
|
||||
es6id: 12.3.5
|
||||
description: Abrupt completion from Reference resolution
|
||||
info: |
|
||||
1. Let propertyNameReference be the result of evaluating Expression.
|
||||
2. Let propertyNameValue be ? GetValue(propertyNameReference).
|
||||
|
||||
6.2.3.1 GetValue
|
||||
|
||||
1. ReturnIfAbrupt(V).
|
||||
2. If Type(V) is not Reference, return V.
|
||||
3. Let base be GetBase(V).
|
||||
4. If IsUnresolvableReference(V) is true, throw a ReferenceError exception.
|
||||
features: [class]
|
||||
---*/
|
||||
|
||||
var caught;
|
||||
class C {
|
||||
method() {
|
||||
try {
|
||||
super[test262unresolvable];
|
||||
} catch (err) {
|
||||
caught = err;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
C.prototype.method();
|
||||
|
||||
assert.sameValue(typeof caught, 'object');
|
||||
assert.sameValue(caught.constructor, ReferenceError);
|
@ -0,0 +1,46 @@
|
||||
// Copyright (C) 2016 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
/*---
|
||||
esid: sec-super-keyword
|
||||
es6id: 12.3.5
|
||||
description: Value of reference returned by SuperProperty (from arrow function)
|
||||
info: |
|
||||
[...]
|
||||
4. If the code matched by the syntactic production that is being evaluated is
|
||||
strict mode code, let strict be true, else let strict be false.
|
||||
5. Return ? MakeSuperPropertyReference(propertyKey, strict).
|
||||
|
||||
12.3.5.3 Runtime Semantics: MakeSuperPropertyReference
|
||||
|
||||
1. Let env be GetThisEnvironment( ).
|
||||
2. If env.HasSuperBinding() is false, throw a ReferenceError exception.
|
||||
3. Let actualThis be ? env.GetThisBinding().
|
||||
4. Let baseValue be ? env.GetSuperBase().
|
||||
5. Let bv be ? RequireObjectCoercible(baseValue).
|
||||
6. Return a value of type Reference that is a Super Reference whose base
|
||||
value component is bv, whose referenced name component is propertyKey,
|
||||
whose thisValue component is actualThis, and whose strict reference flag
|
||||
is strict.
|
||||
features: [class, arrow-function]
|
||||
---*/
|
||||
|
||||
var fromA, fromB;
|
||||
class A {}
|
||||
class B extends A {}
|
||||
class C extends B {
|
||||
method() {
|
||||
fromA = (() => { return super['fromA']; })();
|
||||
fromB = (() => { return super['fromB']; })();
|
||||
}
|
||||
}
|
||||
|
||||
A.prototype.fromA = 'a';
|
||||
A.prototype.fromB = 'a';
|
||||
B.prototype.fromB = 'b';
|
||||
C.prototype.fromA = 'c';
|
||||
C.prototype.fromB = 'c';
|
||||
|
||||
C.prototype.method();
|
||||
|
||||
assert.sameValue(fromA, 'a');
|
||||
assert.sameValue(fromB, 'b');
|
@ -0,0 +1,46 @@
|
||||
// Copyright (C) 2016 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
/*---
|
||||
esid: sec-super-keyword
|
||||
es6id: 12.3.5
|
||||
description: Value of reference returned by SuperProperty (from eval code)
|
||||
info: |
|
||||
[...]
|
||||
4. If the code matched by the syntactic production that is being evaluated is
|
||||
strict mode code, let strict be true, else let strict be false.
|
||||
5. Return ? MakeSuperPropertyReference(propertyKey, strict).
|
||||
|
||||
12.3.5.3 Runtime Semantics: MakeSuperPropertyReference
|
||||
|
||||
1. Let env be GetThisEnvironment( ).
|
||||
2. If env.HasSuperBinding() is false, throw a ReferenceError exception.
|
||||
3. Let actualThis be ? env.GetThisBinding().
|
||||
4. Let baseValue be ? env.GetSuperBase().
|
||||
5. Let bv be ? RequireObjectCoercible(baseValue).
|
||||
6. Return a value of type Reference that is a Super Reference whose base
|
||||
value component is bv, whose referenced name component is propertyKey,
|
||||
whose thisValue component is actualThis, and whose strict reference flag
|
||||
is strict.
|
||||
features: [class]
|
||||
---*/
|
||||
|
||||
var fromA, fromB;
|
||||
class A {}
|
||||
class B extends A {}
|
||||
class C extends B {
|
||||
method() {
|
||||
fromA = eval('super["fromA"];');
|
||||
fromB = eval('super["fromB"];');
|
||||
}
|
||||
}
|
||||
|
||||
A.prototype.fromA = 'a';
|
||||
A.prototype.fromB = 'a';
|
||||
B.prototype.fromB = 'b';
|
||||
C.prototype.fromA = 'c';
|
||||
C.prototype.fromB = 'c';
|
||||
|
||||
C.prototype.method();
|
||||
|
||||
assert.sameValue(fromA, 'a');
|
||||
assert.sameValue(fromB, 'b');
|
46
test/language/expressions/super/prop-expr-cls-val.js
Normal file
46
test/language/expressions/super/prop-expr-cls-val.js
Normal file
@ -0,0 +1,46 @@
|
||||
// Copyright (C) 2016 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
/*---
|
||||
esid: sec-super-keyword
|
||||
es6id: 12.3.5
|
||||
description: Value of reference returned by SuperProperty
|
||||
info: |
|
||||
[...]
|
||||
4. If the code matched by the syntactic production that is being evaluated is
|
||||
strict mode code, let strict be true, else let strict be false.
|
||||
5. Return ? MakeSuperPropertyReference(propertyKey, strict).
|
||||
|
||||
12.3.5.3 Runtime Semantics: MakeSuperPropertyReference
|
||||
|
||||
1. Let env be GetThisEnvironment( ).
|
||||
2. If env.HasSuperBinding() is false, throw a ReferenceError exception.
|
||||
3. Let actualThis be ? env.GetThisBinding().
|
||||
4. Let baseValue be ? env.GetSuperBase().
|
||||
5. Let bv be ? RequireObjectCoercible(baseValue).
|
||||
6. Return a value of type Reference that is a Super Reference whose base
|
||||
value component is bv, whose referenced name component is propertyKey,
|
||||
whose thisValue component is actualThis, and whose strict reference flag
|
||||
is strict.
|
||||
features: [class]
|
||||
---*/
|
||||
|
||||
var fromA, fromB;
|
||||
class A {}
|
||||
class B extends A {}
|
||||
class C extends B {
|
||||
method() {
|
||||
fromA = super['fromA'];
|
||||
fromB = super['fromB'];
|
||||
}
|
||||
}
|
||||
|
||||
A.prototype.fromA = 'a';
|
||||
A.prototype.fromB = 'a';
|
||||
B.prototype.fromB = 'b';
|
||||
C.prototype.fromA = 'c';
|
||||
C.prototype.fromB = 'c';
|
||||
|
||||
C.prototype.method();
|
||||
|
||||
assert.sameValue(fromA, 'a');
|
||||
assert.sameValue(fromB, 'b');
|
@ -0,0 +1,24 @@
|
||||
// Copyright (C) 2016 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
/*---
|
||||
esid: sec-super-keyword
|
||||
es6id: 12.3.5
|
||||
description: Expression is evaluated prior to verification of "super" binding
|
||||
info: |
|
||||
1. Let propertyNameReference be the result of evaluating Expression.
|
||||
---*/
|
||||
|
||||
var evaluated = false;
|
||||
function f() {
|
||||
// Early errors restricting the usage of SuperProperty necessitate the use of
|
||||
// `eval`.
|
||||
try {
|
||||
eval('super[evaluated = true];');
|
||||
// Evaluation of SuperProperty is expected to fail in this context, but that
|
||||
// behavior is tested elsewhere, so the error is discarded.
|
||||
} catch (_) {}
|
||||
}
|
||||
|
||||
f();
|
||||
|
||||
assert.sameValue(evaluated, true);
|
@ -0,0 +1,33 @@
|
||||
// Copyright (C) 2016 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
/*---
|
||||
esid: sec-super-keyword
|
||||
es6id: 12.3.5
|
||||
description: ReferenceError is thrown when environment has no "super" binding
|
||||
info: |
|
||||
[...]
|
||||
4. If the code matched by the syntactic production that is being evaluated is
|
||||
strict mode code, let strict be true, else let strict be false.
|
||||
5. Return ? MakeSuperPropertyReference(propertyKey, strict).
|
||||
|
||||
12.3.5.3 Runtime Semantics: MakeSuperPropertyReference
|
||||
|
||||
1. Let env be GetThisEnvironment( ).
|
||||
2. If env.HasSuperBinding() is false, throw a ReferenceError exception.
|
||||
---*/
|
||||
|
||||
var caught;
|
||||
function f() {
|
||||
// Early errors restricting the usage of SuperProperty necessitate the use of
|
||||
// `eval`.
|
||||
try {
|
||||
eval('super["x"];');
|
||||
} catch (err) {
|
||||
caught = err;
|
||||
}
|
||||
}
|
||||
|
||||
f();
|
||||
|
||||
assert.sameValue(typeof caught, 'object');
|
||||
assert.sameValue(caught.constructor, ReferenceError);
|
33
test/language/expressions/super/prop-expr-obj-err.js
Normal file
33
test/language/expressions/super/prop-expr-obj-err.js
Normal file
@ -0,0 +1,33 @@
|
||||
// Copyright (C) 2016 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
/*---
|
||||
esid: sec-super-keyword
|
||||
es6id: 12.3.5
|
||||
description: Abrupt completion from Expression evaluation
|
||||
info: |
|
||||
1. Let propertyNameReference be the result of evaluating Expression.
|
||||
2. Let propertyNameValue be ? GetValue(propertyNameReference).
|
||||
|
||||
6.2.3.1 GetValue
|
||||
|
||||
1. ReturnIfAbrupt(V).
|
||||
---*/
|
||||
|
||||
var thrown = new Test262Error();
|
||||
var caught;
|
||||
function thrower() {
|
||||
throw thrown;
|
||||
}
|
||||
var obj = {
|
||||
method() {
|
||||
try {
|
||||
super[thrower()];
|
||||
} catch (err) {
|
||||
caught = err;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
obj.method();
|
||||
|
||||
assert.sameValue(caught, thrown);
|
36
test/language/expressions/super/prop-expr-obj-key-err.js
Normal file
36
test/language/expressions/super/prop-expr-obj-key-err.js
Normal file
@ -0,0 +1,36 @@
|
||||
// Copyright (C) 2016 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
/*---
|
||||
esid: sec-super-keyword
|
||||
es6id: 12.3.5
|
||||
description: Abrupt completion from type coercion of property key
|
||||
info: |
|
||||
1. Let propertyNameReference be the result of evaluating Expression.
|
||||
2. Let propertyNameValue be ? GetValue(propertyNameReference).
|
||||
3. Let propertyKey be ? ToPropertyKey(propertyNameValue).
|
||||
|
||||
7.1.14 ToPropertyKey
|
||||
|
||||
1. Let key be ? ToPrimitive(argument, hint String).
|
||||
---*/
|
||||
|
||||
var thrown = new Test262Error();
|
||||
var badToString = {
|
||||
toString: function() {
|
||||
throw thrown;
|
||||
}
|
||||
};
|
||||
var caught;
|
||||
var obj = {
|
||||
method() {
|
||||
try {
|
||||
super[badToString];
|
||||
} catch (err) {
|
||||
caught = err;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
obj.method();
|
||||
|
||||
assert.sameValue(caught, thrown);
|
39
test/language/expressions/super/prop-expr-obj-null-proto.js
Normal file
39
test/language/expressions/super/prop-expr-obj-null-proto.js
Normal file
@ -0,0 +1,39 @@
|
||||
// Copyright (C) 2016 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
/*---
|
||||
esid: sec-super-keyword
|
||||
es6id: 12.3.5
|
||||
description: >
|
||||
SuperProperty evaluation when the "home" object's prototype is not
|
||||
object-coercible.
|
||||
info: |
|
||||
[...]
|
||||
4. If the code matched by the syntactic production that is being evaluated is
|
||||
strict mode code, let strict be true, else let strict be false.
|
||||
5. Return ? MakeSuperPropertyReference(propertyKey, strict).
|
||||
|
||||
12.3.5.3 Runtime Semantics: MakeSuperPropertyReference
|
||||
|
||||
1. Let env be GetThisEnvironment( ).
|
||||
2. If env.HasSuperBinding() is false, throw a ReferenceError exception.
|
||||
3. Let actualThis be ? env.GetThisBinding().
|
||||
4. Let baseValue be ? env.GetSuperBase().
|
||||
5. Let bv be ? RequireObjectCoercible(baseValue).
|
||||
---*/
|
||||
|
||||
var caught;
|
||||
var obj = {
|
||||
method() {
|
||||
try {
|
||||
super['x'];
|
||||
} catch (err) {
|
||||
caught = err;
|
||||
}
|
||||
}
|
||||
};
|
||||
Object.setPrototypeOf(obj, null);
|
||||
|
||||
obj.method();
|
||||
|
||||
assert.sameValue(typeof caught, 'object');
|
||||
assert.sameValue(caught.constructor, TypeError);
|
@ -0,0 +1,52 @@
|
||||
// Copyright (C) 2016 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
/*---
|
||||
esid: sec-super-keyword
|
||||
es6id: 12.3.5
|
||||
description: SuperProperty's behavior as a non-strict reference
|
||||
info: |
|
||||
[...]
|
||||
4. If the code matched by the syntactic production that is being evaluated is
|
||||
strict mode code, let strict be true, else let strict be false.
|
||||
5. Return ? MakeSuperPropertyReference(propertyKey, strict).
|
||||
|
||||
12.3.5.3 Runtime Semantics: MakeSuperPropertyReference
|
||||
|
||||
1. Let env be GetThisEnvironment( ).
|
||||
2. If env.HasSuperBinding() is false, throw a ReferenceError exception.
|
||||
3. Let actualThis be ? env.GetThisBinding().
|
||||
4. Let baseValue be ? env.GetSuperBase().
|
||||
5. Let bv be ? RequireObjectCoercible(baseValue).
|
||||
6. Return a value of type Reference that is a Super Reference whose base
|
||||
value component is bv, whose referenced name component is propertyKey,
|
||||
whose thisValue component is actualThis, and whose strict reference flag
|
||||
is strict.
|
||||
|
||||
6.2.3.2 PutValue
|
||||
|
||||
[...]
|
||||
5. If IsUnresolvableReference(V) is true, then
|
||||
[...]
|
||||
6. Else if IsPropertyReference(V) is true, then
|
||||
a. If HasPrimitiveBase(V) is true, then
|
||||
[...]
|
||||
b. Let succeeded be ? base.[[Set]](GetReferencedName(V), W,
|
||||
GetThisValue(V)).
|
||||
c. If succeeded is false and IsStrictReference(V) is true, throw a
|
||||
TypeError exception.
|
||||
d. Return.
|
||||
flags: [noStrict]
|
||||
---*/
|
||||
|
||||
var obj = {
|
||||
method() {
|
||||
super['x'] = 8;
|
||||
Object.freeze(obj);
|
||||
super['y'] = 9;
|
||||
}
|
||||
};
|
||||
|
||||
obj.method();
|
||||
|
||||
assert.sameValue(Object.hasOwnProperty.call(obj, 'x'), true);
|
||||
assert.sameValue(Object.hasOwnProperty.call(obj, 'y'), false);
|
56
test/language/expressions/super/prop-expr-obj-ref-strict.js
Normal file
56
test/language/expressions/super/prop-expr-obj-ref-strict.js
Normal file
@ -0,0 +1,56 @@
|
||||
// Copyright (C) 2016 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
/*---
|
||||
esid: sec-super-keyword
|
||||
es6id: 12.3.5
|
||||
description: SuperProperty's behavior as a strict reference
|
||||
info: |
|
||||
[...]
|
||||
4. If the code matched by the syntactic production that is being evaluated is
|
||||
strict mode code, let strict be true, else let strict be false.
|
||||
5. Return ? MakeSuperPropertyReference(propertyKey, strict).
|
||||
|
||||
12.3.5.3 Runtime Semantics: MakeSuperPropertyReference
|
||||
|
||||
1. Let env be GetThisEnvironment( ).
|
||||
2. If env.HasSuperBinding() is false, throw a ReferenceError exception.
|
||||
3. Let actualThis be ? env.GetThisBinding().
|
||||
4. Let baseValue be ? env.GetSuperBase().
|
||||
5. Let bv be ? RequireObjectCoercible(baseValue).
|
||||
6. Return a value of type Reference that is a Super Reference whose base
|
||||
value component is bv, whose referenced name component is propertyKey,
|
||||
whose thisValue component is actualThis, and whose strict reference flag
|
||||
is strict.
|
||||
|
||||
6.2.3.2 PutValue
|
||||
|
||||
[...]
|
||||
5. If IsUnresolvableReference(V) is true, then
|
||||
[...]
|
||||
6. Else if IsPropertyReference(V) is true, then
|
||||
a. If HasPrimitiveBase(V) is true, then
|
||||
[...]
|
||||
b. Let succeeded be ? base.[[Set]](GetReferencedName(V), W,
|
||||
GetThisValue(V)).
|
||||
c. If succeeded is false and IsStrictReference(V) is true, throw a
|
||||
TypeError exception.
|
||||
flags: [onlyStrict]
|
||||
---*/
|
||||
|
||||
var caught;
|
||||
var obj = {
|
||||
method() {
|
||||
super['x'] = 8;
|
||||
Object.freeze(obj);
|
||||
try {
|
||||
super['y'] = 9;
|
||||
} catch (err) {
|
||||
caught = err;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
obj.method();
|
||||
|
||||
assert.sameValue(typeof caught, 'object');
|
||||
assert.sameValue(caught.constructor, TypeError);
|
59
test/language/expressions/super/prop-expr-obj-ref-this.js
Normal file
59
test/language/expressions/super/prop-expr-obj-ref-this.js
Normal file
@ -0,0 +1,59 @@
|
||||
// Copyright (C) 2016 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
/*---
|
||||
esid: sec-super-keyword
|
||||
es6id: 12.3.5
|
||||
description: SuperProperty's "this" value
|
||||
info: |
|
||||
[...]
|
||||
4. If the code matched by the syntactic production that is being evaluated is
|
||||
strict mode code, let strict be true, else let strict be false.
|
||||
5. Return ? MakeSuperPropertyReference(propertyKey, strict).
|
||||
|
||||
12.3.5.3 Runtime Semantics: MakeSuperPropertyReference
|
||||
|
||||
1. Let env be GetThisEnvironment( ).
|
||||
2. If env.HasSuperBinding() is false, throw a ReferenceError exception.
|
||||
3. Let actualThis be ? env.GetThisBinding().
|
||||
4. Let baseValue be ? env.GetSuperBase().
|
||||
5. Let bv be ? RequireObjectCoercible(baseValue).
|
||||
6. Return a value of type Reference that is a Super Reference whose base
|
||||
value component is bv, whose referenced name component is propertyKey,
|
||||
whose thisValue component is actualThis, and whose strict reference flag
|
||||
is strict.
|
||||
|
||||
GetValue (V)
|
||||
|
||||
1. ReturnIfAbrupt(V).
|
||||
2. If Type(V) is not Reference, return V.
|
||||
3. Let base be GetBase(V).
|
||||
4. If IsUnresolvableReference(V) is true, throw a ReferenceError exception.
|
||||
5. If IsPropertyReference(V) is true, then
|
||||
a. If HasPrimitiveBase(V) is true, then
|
||||
i. Assert: In this case, base will never be null or undefined.
|
||||
ii. Let base be ! ToObject(base).
|
||||
b. Return ? base.[[Get]](GetReferencedName(V), GetThisValue(V)).
|
||||
---*/
|
||||
|
||||
var viaCall;
|
||||
var viaMember;
|
||||
var parent = {
|
||||
getThis: function() {
|
||||
return this;
|
||||
},
|
||||
get This() {
|
||||
return this;
|
||||
}
|
||||
};
|
||||
var obj = {
|
||||
method() {
|
||||
viaCall = super['getThis']();
|
||||
viaMember = super['This'];
|
||||
}
|
||||
};
|
||||
Object.setPrototypeOf(obj, parent);
|
||||
|
||||
obj.method();
|
||||
|
||||
assert.sameValue(viaCall, obj, 'via CallExpression');
|
||||
assert.sameValue(viaMember, obj, 'via MemberExpression');
|
@ -0,0 +1,33 @@
|
||||
// Copyright (C) 2016 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
/*---
|
||||
esid: sec-super-keyword
|
||||
es6id: 12.3.5
|
||||
description: Abrupt completion from Reference resolution
|
||||
info: |
|
||||
1. Let propertyNameReference be the result of evaluating Expression.
|
||||
2. Let propertyNameValue be ? GetValue(propertyNameReference).
|
||||
|
||||
6.2.3.1 GetValue
|
||||
|
||||
1. ReturnIfAbrupt(V).
|
||||
2. If Type(V) is not Reference, return V.
|
||||
3. Let base be GetBase(V).
|
||||
4. If IsUnresolvableReference(V) is true, throw a ReferenceError exception.
|
||||
---*/
|
||||
|
||||
var caught;
|
||||
var obj = {
|
||||
method() {
|
||||
try {
|
||||
super[test262unresolvable];
|
||||
} catch (err) {
|
||||
caught = err;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
obj.method();
|
||||
|
||||
assert.sameValue(typeof caught, 'object');
|
||||
assert.sameValue(caught.constructor, ReferenceError);
|
@ -0,0 +1,46 @@
|
||||
// Copyright (C) 2016 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
/*---
|
||||
esid: sec-super-keyword
|
||||
es6id: 12.3.5
|
||||
description: Value of reference returned by SuperProperty (from arrow function)
|
||||
info: |
|
||||
[...]
|
||||
4. If the code matched by the syntactic production that is being evaluated is
|
||||
strict mode code, let strict be true, else let strict be false.
|
||||
5. Return ? MakeSuperPropertyReference(propertyKey, strict).
|
||||
|
||||
12.3.5.3 Runtime Semantics: MakeSuperPropertyReference
|
||||
|
||||
1. Let env be GetThisEnvironment( ).
|
||||
2. If env.HasSuperBinding() is false, throw a ReferenceError exception.
|
||||
3. Let actualThis be ? env.GetThisBinding().
|
||||
4. Let baseValue be ? env.GetSuperBase().
|
||||
5. Let bv be ? RequireObjectCoercible(baseValue).
|
||||
6. Return a value of type Reference that is a Super Reference whose base
|
||||
value component is bv, whose referenced name component is propertyKey,
|
||||
whose thisValue component is actualThis, and whose strict reference flag
|
||||
is strict.
|
||||
features: [arrow-function]
|
||||
---*/
|
||||
|
||||
var fromA, fromB;
|
||||
var A = { fromA: 'a', fromB: 'a' };
|
||||
var B = { fromB: 'b' };
|
||||
Object.setPrototypeOf(B, A);
|
||||
|
||||
var obj = {
|
||||
fromA: 'c',
|
||||
fromB: 'c',
|
||||
method() {
|
||||
fromA = (() => { return super['fromA']; })();
|
||||
fromB = (() => { return super['fromB']; })();
|
||||
}
|
||||
};
|
||||
|
||||
Object.setPrototypeOf(obj, B);
|
||||
|
||||
obj.method();
|
||||
|
||||
assert.sameValue(fromA, 'a');
|
||||
assert.sameValue(fromB, 'b');
|
@ -0,0 +1,45 @@
|
||||
// Copyright (C) 2016 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
/*---
|
||||
esid: sec-super-keyword
|
||||
es6id: 12.3.5
|
||||
description: Value of reference returned by SuperProperty (from eval code)
|
||||
info: |
|
||||
[...]
|
||||
4. If the code matched by the syntactic production that is being evaluated is
|
||||
strict mode code, let strict be true, else let strict be false.
|
||||
5. Return ? MakeSuperPropertyReference(propertyKey, strict).
|
||||
|
||||
12.3.5.3 Runtime Semantics: MakeSuperPropertyReference
|
||||
|
||||
1. Let env be GetThisEnvironment( ).
|
||||
2. If env.HasSuperBinding() is false, throw a ReferenceError exception.
|
||||
3. Let actualThis be ? env.GetThisBinding().
|
||||
4. Let baseValue be ? env.GetSuperBase().
|
||||
5. Let bv be ? RequireObjectCoercible(baseValue).
|
||||
6. Return a value of type Reference that is a Super Reference whose base
|
||||
value component is bv, whose referenced name component is propertyKey,
|
||||
whose thisValue component is actualThis, and whose strict reference flag
|
||||
is strict.
|
||||
---*/
|
||||
|
||||
var fromA, fromB;
|
||||
var A = { fromA: 'a', fromB: 'a' };
|
||||
var B = { fromB: 'b' };
|
||||
Object.setPrototypeOf(B, A);
|
||||
|
||||
var obj = {
|
||||
fromA: 'c',
|
||||
fromB: 'c',
|
||||
method() {
|
||||
fromA = eval('super["fromA"];');
|
||||
fromB = eval('super["fromB"];');
|
||||
}
|
||||
};
|
||||
|
||||
Object.setPrototypeOf(obj, B);
|
||||
|
||||
obj.method();
|
||||
|
||||
assert.sameValue(fromA, 'a');
|
||||
assert.sameValue(fromB, 'b');
|
45
test/language/expressions/super/prop-expr-obj-val.js
Normal file
45
test/language/expressions/super/prop-expr-obj-val.js
Normal file
@ -0,0 +1,45 @@
|
||||
// Copyright (C) 2016 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
/*---
|
||||
esid: sec-super-keyword
|
||||
es6id: 12.3.5
|
||||
description: Value of reference returned by SuperProperty
|
||||
info: |
|
||||
[...]
|
||||
4. If the code matched by the syntactic production that is being evaluated is
|
||||
strict mode code, let strict be true, else let strict be false.
|
||||
5. Return ? MakeSuperPropertyReference(propertyKey, strict).
|
||||
|
||||
12.3.5.3 Runtime Semantics: MakeSuperPropertyReference
|
||||
|
||||
1. Let env be GetThisEnvironment( ).
|
||||
2. If env.HasSuperBinding() is false, throw a ReferenceError exception.
|
||||
3. Let actualThis be ? env.GetThisBinding().
|
||||
4. Let baseValue be ? env.GetSuperBase().
|
||||
5. Let bv be ? RequireObjectCoercible(baseValue).
|
||||
6. Return a value of type Reference that is a Super Reference whose base
|
||||
value component is bv, whose referenced name component is propertyKey,
|
||||
whose thisValue component is actualThis, and whose strict reference flag
|
||||
is strict.
|
||||
---*/
|
||||
|
||||
var fromA, fromB;
|
||||
var A = { fromA: 'a', fromB: 'a' };
|
||||
var B = { fromB: 'b' };
|
||||
Object.setPrototypeOf(B, A);
|
||||
|
||||
var obj = {
|
||||
fromA: 'c',
|
||||
fromB: 'c',
|
||||
method() {
|
||||
fromA = super['fromA'];
|
||||
fromB = super['fromB'];
|
||||
}
|
||||
};
|
||||
|
||||
Object.setPrototypeOf(obj, B);
|
||||
|
||||
obj.method();
|
||||
|
||||
assert.sameValue(fromA, 'a');
|
||||
assert.sameValue(fromB, 'b');
|
Loading…
x
Reference in New Issue
Block a user