diff --git a/src/spread/default/super-call.template b/src/spread/default/super-call.template index 88803a3ca9f074311a71dd399cd27d640ebf680e..87a11454fe86feaf58c2aa50578856c46d4afcd4 100644 --- a/src/spread/default/super-call.template +++ b/src/spread/default/super-call.template @@ -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 diff --git a/src/spread/error/super-call.template b/src/spread/error/super-call.template index efcb04fc096f4dbb99ebc1497b0faf1425821a70..6b64eb6b3c10d32830eee10f73bb28cad4368511 100644 --- a/src/spread/error/super-call.template +++ b/src/spread/error/super-call.template @@ -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 diff --git a/test/language/expressions/super/call-arg-evaluation-err.js b/test/language/expressions/super/call-arg-evaluation-err.js new file mode 100644 index 0000000000000000000000000000000000000000..06318df8e8102d5d4f1a6622a389bc3c932365c8 --- /dev/null +++ b/test/language/expressions/super/call-arg-evaluation-err.js @@ -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); diff --git a/test/language/expressions/super/call-bind-this-value-twice.js b/test/language/expressions/super/call-bind-this-value-twice.js new file mode 100644 index 0000000000000000000000000000000000000000..0ffab8b19b871fba1fa4ad5a4c28401ca4e72690 --- /dev/null +++ b/test/language/expressions/super/call-bind-this-value-twice.js @@ -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); diff --git a/test/language/expressions/super/call-bind-this-value.js b/test/language/expressions/super/call-bind-this-value.js new file mode 100644 index 0000000000000000000000000000000000000000..9c07eb3208ac59eebb6a33d8888333dc43f6a067 --- /dev/null +++ b/test/language/expressions/super/call-bind-this-value.js @@ -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); diff --git a/test/language/expressions/super/call-construct-error.js b/test/language/expressions/super/call-construct-error.js new file mode 100644 index 0000000000000000000000000000000000000000..bf24c8dbbacf9d51b975a8a142ad3021c9022871 --- /dev/null +++ b/test/language/expressions/super/call-construct-error.js @@ -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); diff --git a/test/language/expressions/super/call-construct-invocation.js b/test/language/expressions/super/call-construct-invocation.js new file mode 100644 index 0000000000000000000000000000000000000000..4b31ec43fca1532abfdcf668dee4006432f97a77 --- /dev/null +++ b/test/language/expressions/super/call-construct-invocation.js @@ -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'); diff --git a/test/language/expressions/super/call-expr-value.js b/test/language/expressions/super/call-expr-value.js new file mode 100644 index 0000000000000000000000000000000000000000..5cf3cc4706b3a34200a0d7220c60c8c72236165d --- /dev/null +++ b/test/language/expressions/super/call-expr-value.js @@ -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); diff --git a/test/language/expressions/super/call-new-target-undef.js b/test/language/expressions/super/call-new-target-undef.js new file mode 100644 index 0000000000000000000000000000000000000000..61994045a47c0d0f2edb3df4e51c840a5921bdb6 --- /dev/null +++ b/test/language/expressions/super/call-new-target-undef.js @@ -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' +); diff --git a/test/language/expressions/super/call-proto-not-ctor.js b/test/language/expressions/super/call-proto-not-ctor.js new file mode 100644 index 0000000000000000000000000000000000000000..024c10bdfed922ac99603383f5f5e30de2293158 --- /dev/null +++ b/test/language/expressions/super/call-proto-not-ctor.js @@ -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' +); diff --git a/test/language/expressions/super/spread-err-mult-err-expr-throws.js b/test/language/expressions/super/call-spread-err-mult-err-expr-throws.js similarity index 100% rename from test/language/expressions/super/spread-err-mult-err-expr-throws.js rename to test/language/expressions/super/call-spread-err-mult-err-expr-throws.js diff --git a/test/language/expressions/super/spread-err-mult-err-iter-get-value.js b/test/language/expressions/super/call-spread-err-mult-err-iter-get-value.js similarity index 100% rename from test/language/expressions/super/spread-err-mult-err-iter-get-value.js rename to test/language/expressions/super/call-spread-err-mult-err-iter-get-value.js diff --git a/test/language/expressions/super/spread-err-mult-err-itr-get-call.js b/test/language/expressions/super/call-spread-err-mult-err-itr-get-call.js similarity index 100% rename from test/language/expressions/super/spread-err-mult-err-itr-get-call.js rename to test/language/expressions/super/call-spread-err-mult-err-itr-get-call.js diff --git a/test/language/expressions/super/spread-err-mult-err-itr-get-get.js b/test/language/expressions/super/call-spread-err-mult-err-itr-get-get.js similarity index 100% rename from test/language/expressions/super/spread-err-mult-err-itr-get-get.js rename to test/language/expressions/super/call-spread-err-mult-err-itr-get-get.js diff --git a/test/language/expressions/super/spread-err-mult-err-itr-step.js b/test/language/expressions/super/call-spread-err-mult-err-itr-step.js similarity index 100% rename from test/language/expressions/super/spread-err-mult-err-itr-step.js rename to test/language/expressions/super/call-spread-err-mult-err-itr-step.js diff --git a/test/language/expressions/super/spread-err-mult-err-itr-value.js b/test/language/expressions/super/call-spread-err-mult-err-itr-value.js similarity index 100% rename from test/language/expressions/super/spread-err-mult-err-itr-value.js rename to test/language/expressions/super/call-spread-err-mult-err-itr-value.js diff --git a/test/language/expressions/super/spread-err-mult-err-unresolvable.js b/test/language/expressions/super/call-spread-err-mult-err-unresolvable.js similarity index 100% rename from test/language/expressions/super/spread-err-mult-err-unresolvable.js rename to test/language/expressions/super/call-spread-err-mult-err-unresolvable.js diff --git a/test/language/expressions/super/spread-err-sngl-err-expr-throws.js b/test/language/expressions/super/call-spread-err-sngl-err-expr-throws.js similarity index 100% rename from test/language/expressions/super/spread-err-sngl-err-expr-throws.js rename to test/language/expressions/super/call-spread-err-sngl-err-expr-throws.js diff --git a/test/language/expressions/super/spread-err-sngl-err-itr-get-call.js b/test/language/expressions/super/call-spread-err-sngl-err-itr-get-call.js similarity index 100% rename from test/language/expressions/super/spread-err-sngl-err-itr-get-call.js rename to test/language/expressions/super/call-spread-err-sngl-err-itr-get-call.js diff --git a/test/language/expressions/super/spread-err-sngl-err-itr-get-get.js b/test/language/expressions/super/call-spread-err-sngl-err-itr-get-get.js similarity index 100% rename from test/language/expressions/super/spread-err-sngl-err-itr-get-get.js rename to test/language/expressions/super/call-spread-err-sngl-err-itr-get-get.js diff --git a/test/language/expressions/super/spread-err-sngl-err-itr-get-value.js b/test/language/expressions/super/call-spread-err-sngl-err-itr-get-value.js similarity index 100% rename from test/language/expressions/super/spread-err-sngl-err-itr-get-value.js rename to test/language/expressions/super/call-spread-err-sngl-err-itr-get-value.js diff --git a/test/language/expressions/super/spread-err-sngl-err-itr-step.js b/test/language/expressions/super/call-spread-err-sngl-err-itr-step.js similarity index 100% rename from test/language/expressions/super/spread-err-sngl-err-itr-step.js rename to test/language/expressions/super/call-spread-err-sngl-err-itr-step.js diff --git a/test/language/expressions/super/spread-err-sngl-err-itr-value.js b/test/language/expressions/super/call-spread-err-sngl-err-itr-value.js similarity index 100% rename from test/language/expressions/super/spread-err-sngl-err-itr-value.js rename to test/language/expressions/super/call-spread-err-sngl-err-itr-value.js diff --git a/test/language/expressions/super/spread-err-sngl-err-unresolvable.js b/test/language/expressions/super/call-spread-err-sngl-err-unresolvable.js similarity index 100% rename from test/language/expressions/super/spread-err-sngl-err-unresolvable.js rename to test/language/expressions/super/call-spread-err-sngl-err-unresolvable.js diff --git a/test/language/expressions/super/spread-mult-empty.js b/test/language/expressions/super/call-spread-mult-empty.js similarity index 100% rename from test/language/expressions/super/spread-mult-empty.js rename to test/language/expressions/super/call-spread-mult-empty.js diff --git a/test/language/expressions/super/spread-mult-expr.js b/test/language/expressions/super/call-spread-mult-expr.js similarity index 100% rename from test/language/expressions/super/spread-mult-expr.js rename to test/language/expressions/super/call-spread-mult-expr.js diff --git a/test/language/expressions/super/spread-mult-iter.js b/test/language/expressions/super/call-spread-mult-iter.js similarity index 100% rename from test/language/expressions/super/spread-mult-iter.js rename to test/language/expressions/super/call-spread-mult-iter.js diff --git a/test/language/expressions/super/spread-mult-literal.js b/test/language/expressions/super/call-spread-mult-literal.js similarity index 100% rename from test/language/expressions/super/spread-mult-literal.js rename to test/language/expressions/super/call-spread-mult-literal.js diff --git a/test/language/expressions/super/spread-sngl-empty.js b/test/language/expressions/super/call-spread-sngl-empty.js similarity index 100% rename from test/language/expressions/super/spread-sngl-empty.js rename to test/language/expressions/super/call-spread-sngl-empty.js diff --git a/test/language/expressions/super/spread-sngl-expr.js b/test/language/expressions/super/call-spread-sngl-expr.js similarity index 100% rename from test/language/expressions/super/spread-sngl-expr.js rename to test/language/expressions/super/call-spread-sngl-expr.js diff --git a/test/language/expressions/super/spread-sngl-iter.js b/test/language/expressions/super/call-spread-sngl-iter.js similarity index 100% rename from test/language/expressions/super/spread-sngl-iter.js rename to test/language/expressions/super/call-spread-sngl-iter.js diff --git a/test/language/expressions/super/spread-sngl-literal.js b/test/language/expressions/super/call-spread-sngl-literal.js similarity index 100% rename from test/language/expressions/super/spread-sngl-literal.js rename to test/language/expressions/super/call-spread-sngl-literal.js diff --git a/test/language/expressions/super/prop-dot-cls-null-proto.js b/test/language/expressions/super/prop-dot-cls-null-proto.js new file mode 100644 index 0000000000000000000000000000000000000000..bdc62b6710718c6c6a459e3ee50a1e6f85bccbb7 --- /dev/null +++ b/test/language/expressions/super/prop-dot-cls-null-proto.js @@ -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); diff --git a/test/language/expressions/super/prop-dot-cls-ref-strict.js b/test/language/expressions/super/prop-dot-cls-ref-strict.js new file mode 100644 index 0000000000000000000000000000000000000000..c028b00298c3cdbe2892b711a353172b88f29b02 --- /dev/null +++ b/test/language/expressions/super/prop-dot-cls-ref-strict.js @@ -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); diff --git a/test/language/expressions/super/prop-dot-cls-ref-this.js b/test/language/expressions/super/prop-dot-cls-ref-this.js new file mode 100644 index 0000000000000000000000000000000000000000..8cdad40a316050968bc4285383db3a13267a62cd --- /dev/null +++ b/test/language/expressions/super/prop-dot-cls-ref-this.js @@ -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'); diff --git a/test/language/expressions/super/prop-dot-cls-this-uninit.js b/test/language/expressions/super/prop-dot-cls-this-uninit.js new file mode 100644 index 0000000000000000000000000000000000000000..931136b4b593601b746d115a9f1df343bc36cad0 --- /dev/null +++ b/test/language/expressions/super/prop-dot-cls-this-uninit.js @@ -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); diff --git a/test/language/expressions/super/prop-dot-cls-val-from-arrow.js b/test/language/expressions/super/prop-dot-cls-val-from-arrow.js new file mode 100644 index 0000000000000000000000000000000000000000..92f5357617723bfe310da5012b23154a03a7bcf7 --- /dev/null +++ b/test/language/expressions/super/prop-dot-cls-val-from-arrow.js @@ -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'); diff --git a/test/language/expressions/super/prop-dot-cls-val-from-eval.js b/test/language/expressions/super/prop-dot-cls-val-from-eval.js new file mode 100644 index 0000000000000000000000000000000000000000..81d0503558f1da891e929fddbc1f8c3e0c8d80b5 --- /dev/null +++ b/test/language/expressions/super/prop-dot-cls-val-from-eval.js @@ -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'); diff --git a/test/language/expressions/super/prop-dot-cls-val.js b/test/language/expressions/super/prop-dot-cls-val.js new file mode 100644 index 0000000000000000000000000000000000000000..3bac3b1a1c5b964b27cd620486e887416cb0a826 --- /dev/null +++ b/test/language/expressions/super/prop-dot-cls-val.js @@ -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'); diff --git a/test/language/expressions/super/prop-dot-fn-no-super-bndng.js b/test/language/expressions/super/prop-dot-fn-no-super-bndng.js new file mode 100644 index 0000000000000000000000000000000000000000..e376ce149b284e62b3c21749381c3e719d589991 --- /dev/null +++ b/test/language/expressions/super/prop-dot-fn-no-super-bndng.js @@ -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); diff --git a/test/language/expressions/super/prop-dot-obj-null-proto.js b/test/language/expressions/super/prop-dot-obj-null-proto.js new file mode 100644 index 0000000000000000000000000000000000000000..49f6fe37a1059c69407461dd9fe924a3933f484b --- /dev/null +++ b/test/language/expressions/super/prop-dot-obj-null-proto.js @@ -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); diff --git a/test/language/expressions/super/prop-dot-obj-ref-non-strict.js b/test/language/expressions/super/prop-dot-obj-ref-non-strict.js new file mode 100644 index 0000000000000000000000000000000000000000..215904d65577472dd470eb92d29f460d9a4ca1c0 --- /dev/null +++ b/test/language/expressions/super/prop-dot-obj-ref-non-strict.js @@ -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); diff --git a/test/language/expressions/super/prop-dot-obj-ref-strict.js b/test/language/expressions/super/prop-dot-obj-ref-strict.js new file mode 100644 index 0000000000000000000000000000000000000000..a66af291c272152f03ccd14cbf9adf495998691b --- /dev/null +++ b/test/language/expressions/super/prop-dot-obj-ref-strict.js @@ -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); diff --git a/test/language/expressions/super/prop-dot-obj-ref-this.js b/test/language/expressions/super/prop-dot-obj-ref-this.js new file mode 100644 index 0000000000000000000000000000000000000000..da880ceef8f119ff0825a3996fbe7fdcd77c52a7 --- /dev/null +++ b/test/language/expressions/super/prop-dot-obj-ref-this.js @@ -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'); diff --git a/test/language/expressions/super/prop-dot-obj-val-from-arrow.js b/test/language/expressions/super/prop-dot-obj-val-from-arrow.js new file mode 100644 index 0000000000000000000000000000000000000000..ac91a132c300328f7f81f5e6dd4b7db211d31d94 --- /dev/null +++ b/test/language/expressions/super/prop-dot-obj-val-from-arrow.js @@ -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'); diff --git a/test/language/expressions/super/prop-dot-obj-val-from-eval.js b/test/language/expressions/super/prop-dot-obj-val-from-eval.js new file mode 100644 index 0000000000000000000000000000000000000000..fd27897629a6fa86d4ce8489f2aa62e6c01bf279 --- /dev/null +++ b/test/language/expressions/super/prop-dot-obj-val-from-eval.js @@ -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'); diff --git a/test/language/expressions/super/prop-dot-obj-val.js b/test/language/expressions/super/prop-dot-obj-val.js new file mode 100644 index 0000000000000000000000000000000000000000..7714ea8f710c2857058d97524eeea91e0d6f1ca7 --- /dev/null +++ b/test/language/expressions/super/prop-dot-obj-val.js @@ -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'); diff --git a/test/language/expressions/super/prop-expr-cls-err.js b/test/language/expressions/super/prop-expr-cls-err.js new file mode 100644 index 0000000000000000000000000000000000000000..678e75ebeeb414488558dbfbca7d3e1673d7e7f1 --- /dev/null +++ b/test/language/expressions/super/prop-expr-cls-err.js @@ -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); diff --git a/test/language/expressions/super/prop-expr-cls-key-err.js b/test/language/expressions/super/prop-expr-cls-key-err.js new file mode 100644 index 0000000000000000000000000000000000000000..6be9bf874c27147d6b84d4749f3d73b95eb47cce --- /dev/null +++ b/test/language/expressions/super/prop-expr-cls-key-err.js @@ -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); diff --git a/test/language/expressions/super/prop-expr-cls-null-proto.js b/test/language/expressions/super/prop-expr-cls-null-proto.js new file mode 100644 index 0000000000000000000000000000000000000000..300698ebfbfa4c9fc7d357a407cddd4242f490de --- /dev/null +++ b/test/language/expressions/super/prop-expr-cls-null-proto.js @@ -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); diff --git a/test/language/expressions/super/prop-expr-cls-ref-strict.js b/test/language/expressions/super/prop-expr-cls-ref-strict.js new file mode 100644 index 0000000000000000000000000000000000000000..aab8f6c0dafd2fdf0275b6edec8d67279f35f7a5 --- /dev/null +++ b/test/language/expressions/super/prop-expr-cls-ref-strict.js @@ -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); diff --git a/test/language/expressions/super/prop-expr-cls-ref-this.js b/test/language/expressions/super/prop-expr-cls-ref-this.js new file mode 100644 index 0000000000000000000000000000000000000000..8ebf2781fb23057a6d9d18e9f0f8a4fb944e4f89 --- /dev/null +++ b/test/language/expressions/super/prop-expr-cls-ref-this.js @@ -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'); diff --git a/test/language/expressions/super/prop-expr-cls-this-uninit.js b/test/language/expressions/super/prop-expr-cls-this-uninit.js new file mode 100644 index 0000000000000000000000000000000000000000..fd2736755dd48ab15819e30efecdaa3a41914a5e --- /dev/null +++ b/test/language/expressions/super/prop-expr-cls-this-uninit.js @@ -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); diff --git a/test/language/expressions/super/prop-expr-cls-unresolvable.js b/test/language/expressions/super/prop-expr-cls-unresolvable.js new file mode 100644 index 0000000000000000000000000000000000000000..14c727a6ea8b18c5d50eac65996eae3e703c27ad --- /dev/null +++ b/test/language/expressions/super/prop-expr-cls-unresolvable.js @@ -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); diff --git a/test/language/expressions/super/prop-expr-cls-val-from-arrow.js b/test/language/expressions/super/prop-expr-cls-val-from-arrow.js new file mode 100644 index 0000000000000000000000000000000000000000..b2fcfdbb9bd9a5404cde2350e3dfd2b0b264a90d --- /dev/null +++ b/test/language/expressions/super/prop-expr-cls-val-from-arrow.js @@ -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'); diff --git a/test/language/expressions/super/prop-expr-cls-val-from-eval.js b/test/language/expressions/super/prop-expr-cls-val-from-eval.js new file mode 100644 index 0000000000000000000000000000000000000000..b7d556d1f4261c00191199ba52e99e7d1739fcd0 --- /dev/null +++ b/test/language/expressions/super/prop-expr-cls-val-from-eval.js @@ -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'); diff --git a/test/language/expressions/super/prop-expr-cls-val.js b/test/language/expressions/super/prop-expr-cls-val.js new file mode 100644 index 0000000000000000000000000000000000000000..3fd80280e9b0297c6c6c5bd42e2d412f7d147415 --- /dev/null +++ b/test/language/expressions/super/prop-expr-cls-val.js @@ -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'); diff --git a/test/language/expressions/super/prop-expr-fn-eval-before-has-super.js b/test/language/expressions/super/prop-expr-fn-eval-before-has-super.js new file mode 100644 index 0000000000000000000000000000000000000000..df93e61602c0f00b0657209c186cb1ac9ac0c8bd --- /dev/null +++ b/test/language/expressions/super/prop-expr-fn-eval-before-has-super.js @@ -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); diff --git a/test/language/expressions/super/prop-expr-fn-no-super-bndng.js b/test/language/expressions/super/prop-expr-fn-no-super-bndng.js new file mode 100644 index 0000000000000000000000000000000000000000..d56cd27b5c282c03bdd4054c38c1d932e6cd78aa --- /dev/null +++ b/test/language/expressions/super/prop-expr-fn-no-super-bndng.js @@ -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); diff --git a/test/language/expressions/super/prop-expr-obj-err.js b/test/language/expressions/super/prop-expr-obj-err.js new file mode 100644 index 0000000000000000000000000000000000000000..2a01f497a5890cbebd252ea10ca185219f15d848 --- /dev/null +++ b/test/language/expressions/super/prop-expr-obj-err.js @@ -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); diff --git a/test/language/expressions/super/prop-expr-obj-key-err.js b/test/language/expressions/super/prop-expr-obj-key-err.js new file mode 100644 index 0000000000000000000000000000000000000000..fd28b794375c55e5c17c9faf8eb89fcb9f2b6a6a --- /dev/null +++ b/test/language/expressions/super/prop-expr-obj-key-err.js @@ -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); diff --git a/test/language/expressions/super/prop-expr-obj-null-proto.js b/test/language/expressions/super/prop-expr-obj-null-proto.js new file mode 100644 index 0000000000000000000000000000000000000000..fe0bbf5596c07011014ee772a08d18df7f82a090 --- /dev/null +++ b/test/language/expressions/super/prop-expr-obj-null-proto.js @@ -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); diff --git a/test/language/expressions/super/prop-expr-obj-ref-non-strict.js b/test/language/expressions/super/prop-expr-obj-ref-non-strict.js new file mode 100644 index 0000000000000000000000000000000000000000..ca8f695dcd28ec66fc4939aee99cc5b32882e35f --- /dev/null +++ b/test/language/expressions/super/prop-expr-obj-ref-non-strict.js @@ -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); diff --git a/test/language/expressions/super/prop-expr-obj-ref-strict.js b/test/language/expressions/super/prop-expr-obj-ref-strict.js new file mode 100644 index 0000000000000000000000000000000000000000..7c65f88cb9f72aa02a32e925a7e7445df158a1ed --- /dev/null +++ b/test/language/expressions/super/prop-expr-obj-ref-strict.js @@ -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); diff --git a/test/language/expressions/super/prop-expr-obj-ref-this.js b/test/language/expressions/super/prop-expr-obj-ref-this.js new file mode 100644 index 0000000000000000000000000000000000000000..170d623dd13a37865fd46ed85fe5395c3fd3c96c --- /dev/null +++ b/test/language/expressions/super/prop-expr-obj-ref-this.js @@ -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'); diff --git a/test/language/expressions/super/prop-expr-obj-unresolvable.js b/test/language/expressions/super/prop-expr-obj-unresolvable.js new file mode 100644 index 0000000000000000000000000000000000000000..51daf5999d4ee7aebe77bd80843377a17e84225d --- /dev/null +++ b/test/language/expressions/super/prop-expr-obj-unresolvable.js @@ -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); diff --git a/test/language/expressions/super/prop-expr-obj-val-from-arrow.js b/test/language/expressions/super/prop-expr-obj-val-from-arrow.js new file mode 100644 index 0000000000000000000000000000000000000000..573bcd7aa0889b664d56a751a3815d0d35b78be9 --- /dev/null +++ b/test/language/expressions/super/prop-expr-obj-val-from-arrow.js @@ -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'); diff --git a/test/language/expressions/super/prop-expr-obj-val-from-eval.js b/test/language/expressions/super/prop-expr-obj-val-from-eval.js new file mode 100644 index 0000000000000000000000000000000000000000..15c0dddd713b5744845a61df028266c923d90774 --- /dev/null +++ b/test/language/expressions/super/prop-expr-obj-val-from-eval.js @@ -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'); diff --git a/test/language/expressions/super/prop-expr-obj-val.js b/test/language/expressions/super/prop-expr-obj-val.js new file mode 100644 index 0000000000000000000000000000000000000000..397547cc6ab2bc61d068ca53bad3493ba7d8079e --- /dev/null +++ b/test/language/expressions/super/prop-expr-obj-val.js @@ -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');