diff options
Diffstat (limited to 'js/src/tests/test262/language/expressions/super')
88 files changed, 4350 insertions, 0 deletions
diff --git a/js/src/tests/test262/language/expressions/super/browser.js b/js/src/tests/test262/language/expressions/super/browser.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/language/expressions/super/browser.js diff --git a/js/src/tests/test262/language/expressions/super/call-arg-evaluation-err.js b/js/src/tests/test262/language/expressions/super/call-arg-evaluation-err.js new file mode 100644 index 0000000000..bcab7d1c76 --- /dev/null +++ b/js/src/tests/test262/language/expressions/super/call-arg-evaluation-err.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: 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); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/super/call-bind-this-value-twice.js b/js/src/tests/test262/language/expressions/super/call-bind-this-value-twice.js new file mode 100644 index 0000000000..85fb75f893 --- /dev/null +++ b/js/src/tests/test262/language/expressions/super/call-bind-this-value-twice.js @@ -0,0 +1,42 @@ +// 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); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/super/call-bind-this-value.js b/js/src/tests/test262/language/expressions/super/call-bind-this-value.js new file mode 100644 index 0000000000..95cfe951f9 --- /dev/null +++ b/js/src/tests/test262/language/expressions/super/call-bind-this-value.js @@ -0,0 +1,32 @@ +// 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); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/super/call-construct-error.js b/js/src/tests/test262/language/expressions/super/call-construct-error.js new file mode 100644 index 0000000000..2ee588447f --- /dev/null +++ b/js/src/tests/test262/language/expressions/super/call-construct-error.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: > + 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); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/super/call-construct-invocation.js b/js/src/tests/test262/language/expressions/super/call-construct-invocation.js new file mode 100644 index 0000000000..36e72ccca7 --- /dev/null +++ b/js/src/tests/test262/language/expressions/super/call-construct-invocation.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: Invocation of "parent" constructor +info: | + [...] + 6. Let result be ? Construct(func, argList, newTarget). + [...] +features: [class, new.target, Reflect, Reflect.construct] +---*/ + +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'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/super/call-expr-value.js b/js/src/tests/test262/language/expressions/super/call-expr-value.js new file mode 100644 index 0000000000..e868298f1c --- /dev/null +++ b/js/src/tests/test262/language/expressions/super/call-expr-value.js @@ -0,0 +1,31 @@ +// 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); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/super/call-poisoned-underscore-proto.js b/js/src/tests/test262/language/expressions/super/call-poisoned-underscore-proto.js new file mode 100644 index 0000000000..61e68e3ed4 --- /dev/null +++ b/js/src/tests/test262/language/expressions/super/call-poisoned-underscore-proto.js @@ -0,0 +1,25 @@ +// Copyright (C) 2019 Alexey Shvayka. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: prod-SuperCall +description: > + SuperCall should directly invoke [[GetPrototypeOf]] internal method. +info: | + GetSuperConstructor ( ) + + [...] + 5. Let superConstructor be ! activeFunction.[[GetPrototypeOf]](). +features: [class] +---*/ + +Object.defineProperty(Object.prototype, '__proto__', { + get: function() { + throw new Test262Error('should not be called'); + }, +}); + +class A extends Array {} + +assert.sameValue(new A(1).length, 1); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/super/call-proto-not-ctor.js b/js/src/tests/test262/language/expressions/super/call-proto-not-ctor.js new file mode 100644 index 0000000000..d7728be750 --- /dev/null +++ b/js/src/tests/test262/language/expressions/super/call-proto-not-ctor.js @@ -0,0 +1,43 @@ +// 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 +description: SuperCall should evaluate Arguments prior to checking IsConstructor +info: | + SuperCall : `super` Arguments + + [...] + 3. Let _func_ be ! GetSuperConstructor(). + 4. Let _argList_ be ? ArgumentListEvaluation of |Arguments|. + 5. If IsConstructor(_func_) 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(evaluatedArg, 'performs ArgumentsListEvaluation'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/super/call-spread-err-mult-err-expr-throws.js b/js/src/tests/test262/language/expressions/super/call-spread-err-mult-err-expr-throws.js new file mode 100644 index 0000000000..a446bea44e --- /dev/null +++ b/js/src/tests/test262/language/expressions/super/call-spread-err-mult-err-expr-throws.js @@ -0,0 +1,44 @@ +// This file was procedurally generated from the following sources: +// - src/spread/mult-err-expr-throws.case +// - src/spread/error/super-call.template +/*--- +description: Spread operator following other arguments when evaluation throws (SuperCall) +esid: sec-super-keyword-runtime-semantics-evaluation +features: [generators] +flags: [generated] +info: | + SuperCall : super Arguments + + 1. Let newTarget be GetNewTarget(). + 2. If newTarget is undefined, throw a ReferenceError exception. + 3. Let func be GetSuperConstructor(). + 4. ReturnIfAbrupt(func). + 5. Let argList be ArgumentListEvaluation of Arguments. + [...] + + 12.3.6.1 Runtime Semantics: ArgumentListEvaluation + + ArgumentList : ArgumentList , ... AssignmentExpression + + 1. Let precedingArgs be the result of evaluating ArgumentList. + 2. Let spreadRef be the result of evaluating AssignmentExpression. + 3. Let iterator be GetIterator(GetValue(spreadRef) ). + 4. ReturnIfAbrupt(iterator). + +---*/ + +class Test262ParentClass { + constructor() {} +} + +class Test262ChildClass extends Test262ParentClass { + constructor() { + super(0, ...function*() { throw new Test262Error(); }()); + } +} + +assert.throws(Test262Error, function() { + new Test262ChildClass(); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/super/call-spread-err-mult-err-iter-get-value.js b/js/src/tests/test262/language/expressions/super/call-spread-err-mult-err-iter-get-value.js new file mode 100644 index 0000000000..8e1a4b5f4e --- /dev/null +++ b/js/src/tests/test262/language/expressions/super/call-spread-err-mult-err-iter-get-value.js @@ -0,0 +1,55 @@ +// This file was procedurally generated from the following sources: +// - src/spread/mult-err-iter-get-value.case +// - src/spread/error/super-call.template +/*--- +description: Spread operator following other arguments when GetIterator fails (@@iterator function return value) (SuperCall) +esid: sec-super-keyword-runtime-semantics-evaluation +features: [Symbol.iterator] +flags: [generated] +info: | + SuperCall : super Arguments + + 1. Let newTarget be GetNewTarget(). + 2. If newTarget is undefined, throw a ReferenceError exception. + 3. Let func be GetSuperConstructor(). + 4. ReturnIfAbrupt(func). + 5. Let argList be ArgumentListEvaluation of Arguments. + [...] + + 12.3.6.1 Runtime Semantics: ArgumentListEvaluation + + ArgumentList : ArgumentList , ... AssignmentExpression + + 1. Let precedingArgs be the result of evaluating ArgumentList. + 2. Let spreadRef be the result of evaluating AssignmentExpression. + 3. Let iterator be GetIterator(GetValue(spreadRef) ). + 4. ReturnIfAbrupt(iterator). + + 7.4.1 GetIterator ( obj, method ) + + [...] + 2. Let iterator be ? Call(method, obj). + 3. If Type(iterator) is not Object, throw a TypeError exception. +---*/ +var iter = {}; +Object.defineProperty(iter, Symbol.iterator, { + get: function() { + return null; + } +}); + +class Test262ParentClass { + constructor() {} +} + +class Test262ChildClass extends Test262ParentClass { + constructor() { + super(0, ...iter); + } +} + +assert.throws(TypeError, function() { + new Test262ChildClass(); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/super/call-spread-err-mult-err-itr-get-call.js b/js/src/tests/test262/language/expressions/super/call-spread-err-mult-err-itr-get-call.js new file mode 100644 index 0000000000..9e7104b9bc --- /dev/null +++ b/js/src/tests/test262/language/expressions/super/call-spread-err-mult-err-itr-get-call.js @@ -0,0 +1,53 @@ +// This file was procedurally generated from the following sources: +// - src/spread/mult-err-itr-get-call.case +// - src/spread/error/super-call.template +/*--- +description: Spread operator following other arguments when GetIterator fails (@@iterator function invocation) (SuperCall) +esid: sec-super-keyword-runtime-semantics-evaluation +features: [Symbol.iterator] +flags: [generated] +info: | + SuperCall : super Arguments + + 1. Let newTarget be GetNewTarget(). + 2. If newTarget is undefined, throw a ReferenceError exception. + 3. Let func be GetSuperConstructor(). + 4. ReturnIfAbrupt(func). + 5. Let argList be ArgumentListEvaluation of Arguments. + [...] + + 12.3.6.1 Runtime Semantics: ArgumentListEvaluation + + ArgumentList : ArgumentList , ... AssignmentExpression + + 1. Let precedingArgs be the result of evaluating ArgumentList. + 2. Let spreadRef be the result of evaluating AssignmentExpression. + 3. Let iterator be GetIterator(GetValue(spreadRef) ). + 4. ReturnIfAbrupt(iterator). + + 7.4.1 GetIterator ( obj, method ) + + [...] + 3. Let iterator be Call(method,obj). + 4. ReturnIfAbrupt(iterator). +---*/ +var iter = {}; +iter[Symbol.iterator] = function() { + throw new Test262Error(); +}; + +class Test262ParentClass { + constructor() {} +} + +class Test262ChildClass extends Test262ParentClass { + constructor() { + super(0, ...iter); + } +} + +assert.throws(Test262Error, function() { + new Test262ChildClass(); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/super/call-spread-err-mult-err-itr-get-get.js b/js/src/tests/test262/language/expressions/super/call-spread-err-mult-err-itr-get-get.js new file mode 100644 index 0000000000..3b46bf9f0a --- /dev/null +++ b/js/src/tests/test262/language/expressions/super/call-spread-err-mult-err-itr-get-get.js @@ -0,0 +1,54 @@ +// This file was procedurally generated from the following sources: +// - src/spread/mult-err-itr-get-get.case +// - src/spread/error/super-call.template +/*--- +description: Spread operator following other arguments when GetIterator fails (@@iterator property access) (SuperCall) +esid: sec-super-keyword-runtime-semantics-evaluation +features: [Symbol.iterator] +flags: [generated] +info: | + SuperCall : super Arguments + + 1. Let newTarget be GetNewTarget(). + 2. If newTarget is undefined, throw a ReferenceError exception. + 3. Let func be GetSuperConstructor(). + 4. ReturnIfAbrupt(func). + 5. Let argList be ArgumentListEvaluation of Arguments. + [...] + + 12.3.6.1 Runtime Semantics: ArgumentListEvaluation + + ArgumentList : ArgumentList , ... AssignmentExpression + + 1. Let precedingArgs be the result of evaluating ArgumentList. + 2. Let spreadRef be the result of evaluating AssignmentExpression. + 3. Let iterator be GetIterator(GetValue(spreadRef) ). + 4. ReturnIfAbrupt(iterator). + + 7.4.1 GetIterator ( obj, method ) + + 1. If method was not passed, then + a. Let method be ? GetMethod(obj, @@iterator). +---*/ +var iter = {}; +Object.defineProperty(iter, Symbol.iterator, { + get: function() { + throw new Test262Error(); + } +}); + +class Test262ParentClass { + constructor() {} +} + +class Test262ChildClass extends Test262ParentClass { + constructor() { + super(0, ...iter); + } +} + +assert.throws(Test262Error, function() { + new Test262ChildClass(); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/super/call-spread-err-mult-err-itr-step.js b/js/src/tests/test262/language/expressions/super/call-spread-err-mult-err-itr-step.js new file mode 100644 index 0000000000..847d69883b --- /dev/null +++ b/js/src/tests/test262/language/expressions/super/call-spread-err-mult-err-itr-step.js @@ -0,0 +1,63 @@ +// This file was procedurally generated from the following sources: +// - src/spread/mult-err-itr-step.case +// - src/spread/error/super-call.template +/*--- +description: Spread operator following other arguments when IteratorStep fails (SuperCall) +esid: sec-super-keyword-runtime-semantics-evaluation +features: [Symbol.iterator] +flags: [generated] +info: | + SuperCall : super Arguments + + 1. Let newTarget be GetNewTarget(). + 2. If newTarget is undefined, throw a ReferenceError exception. + 3. Let func be GetSuperConstructor(). + 4. ReturnIfAbrupt(func). + 5. Let argList be ArgumentListEvaluation of Arguments. + [...] + + 12.3.6.1 Runtime Semantics: ArgumentListEvaluation + + ArgumentList : ArgumentList , ... AssignmentExpression + + 1. Let precedingArgs be the result of evaluating ArgumentList. + 2. Let spreadRef be the result of evaluating AssignmentExpression. + 3. Let iterator be GetIterator(GetValue(spreadRef) ). + 4. ReturnIfAbrupt(iterator). + + 7.4.5 IteratorStep ( iterator ) + + 1. Let result be IteratorNext(iterator). + 2. ReturnIfAbrupt(result). + + 7.4.2 IteratorNext ( iterator, value ) + + 1. If value was not passed, then + a. Let result be Invoke(iterator, "next", « »). + [...] + 3. ReturnIfAbrupt(result). +---*/ +var iter = {}; +iter[Symbol.iterator] = function() { + return { + next: function() { + throw new Test262Error(); + } + }; +}; + +class Test262ParentClass { + constructor() {} +} + +class Test262ChildClass extends Test262ParentClass { + constructor() { + super(0, ...iter); + } +} + +assert.throws(Test262Error, function() { + new Test262ChildClass(); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/super/call-spread-err-mult-err-itr-value.js b/js/src/tests/test262/language/expressions/super/call-spread-err-mult-err-itr-value.js new file mode 100644 index 0000000000..4a258d936e --- /dev/null +++ b/js/src/tests/test262/language/expressions/super/call-spread-err-mult-err-itr-value.js @@ -0,0 +1,66 @@ +// This file was procedurally generated from the following sources: +// - src/spread/mult-err-itr-value.case +// - src/spread/error/super-call.template +/*--- +description: Spread operator following other arguments when IteratorValue fails (SuperCall) +esid: sec-super-keyword-runtime-semantics-evaluation +features: [Symbol.iterator] +flags: [generated] +info: | + SuperCall : super Arguments + + 1. Let newTarget be GetNewTarget(). + 2. If newTarget is undefined, throw a ReferenceError exception. + 3. Let func be GetSuperConstructor(). + 4. ReturnIfAbrupt(func). + 5. Let argList be ArgumentListEvaluation of Arguments. + [...] + + 12.3.6.1 Runtime Semantics: ArgumentListEvaluation + + ArgumentList : ArgumentList , ... AssignmentExpression + + 1. Let precedingArgs be the result of evaluating ArgumentList. + 2. Let spreadRef be the result of evaluating AssignmentExpression. + 3. Let iterator be GetIterator(GetValue(spreadRef) ). + 4. ReturnIfAbrupt(iterator). + + 7.4.4 IteratorValue ( iterResult ) + + 1. Assert: Type(iterResult) is Object. + 2. Return Get(iterResult, "value"). + + 7.3.1 Get (O, P) + + [...] + 3. Return O.[[Get]](P, O). +---*/ +var iter = {}; +var poisonedValue = Object.defineProperty({}, 'value', { + get: function() { + throw new Test262Error(); + } +}); +iter[Symbol.iterator] = function() { + return { + next: function() { + return poisonedValue; + } + }; +}; + +class Test262ParentClass { + constructor() {} +} + +class Test262ChildClass extends Test262ParentClass { + constructor() { + super(0, ...iter); + } +} + +assert.throws(Test262Error, function() { + new Test262ChildClass(); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/super/call-spread-err-mult-err-obj-unresolvable.js b/js/src/tests/test262/language/expressions/super/call-spread-err-mult-err-obj-unresolvable.js new file mode 100644 index 0000000000..de3e33f950 --- /dev/null +++ b/js/src/tests/test262/language/expressions/super/call-spread-err-mult-err-obj-unresolvable.js @@ -0,0 +1,45 @@ +// This file was procedurally generated from the following sources: +// - src/spread/mult-err-obj-unresolvable.case +// - src/spread/error/super-call.template +/*--- +description: Object Spread operator results in error when using an unresolvable reference (SuperCall) +esid: sec-super-keyword-runtime-semantics-evaluation +features: [object-spread] +flags: [generated] +info: | + SuperCall : super Arguments + + 1. Let newTarget be GetNewTarget(). + 2. If newTarget is undefined, throw a ReferenceError exception. + 3. Let func be GetSuperConstructor(). + 4. ReturnIfAbrupt(func). + 5. Let argList be ArgumentListEvaluation of Arguments. + [...] + + Pending Runtime Semantics: PropertyDefinitionEvaluation + + PropertyDefinition:...AssignmentExpression + + 1. Let exprValue be the result of evaluating AssignmentExpression. + 2. Let fromValue be GetValue(exprValue). + 3. ReturnIfAbrupt(fromValue). + 4. Let excludedNames be a new empty List. + 5. Return CopyDataProperties(object, fromValue, excludedNames). + +---*/ + +class Test262ParentClass { + constructor() {} +} + +class Test262ChildClass extends Test262ParentClass { + constructor() { + super({a: 0, ...unresolvableReference}); + } +} + +assert.throws(ReferenceError, function() { + new Test262ChildClass(); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/super/call-spread-err-mult-err-unresolvable.js b/js/src/tests/test262/language/expressions/super/call-spread-err-mult-err-unresolvable.js new file mode 100644 index 0000000000..63adc0ae05 --- /dev/null +++ b/js/src/tests/test262/language/expressions/super/call-spread-err-mult-err-unresolvable.js @@ -0,0 +1,49 @@ +// This file was procedurally generated from the following sources: +// - src/spread/mult-err-unresolvable.case +// - src/spread/error/super-call.template +/*--- +description: Spread operator following other arguments when reference is unresolvable (SuperCall) +esid: sec-super-keyword-runtime-semantics-evaluation +flags: [generated] +info: | + SuperCall : super Arguments + + 1. Let newTarget be GetNewTarget(). + 2. If newTarget is undefined, throw a ReferenceError exception. + 3. Let func be GetSuperConstructor(). + 4. ReturnIfAbrupt(func). + 5. Let argList be ArgumentListEvaluation of Arguments. + [...] + + 12.3.6.1 Runtime Semantics: ArgumentListEvaluation + + ArgumentList : ArgumentList , ... AssignmentExpression + + 1. Let precedingArgs be the result of evaluating ArgumentList. + 2. Let spreadRef be the result of evaluating AssignmentExpression. + 3. Let iterator be GetIterator(GetValue(spreadRef) ). + 4. ReturnIfAbrupt(iterator). + + 6.2.3.1 GetValue (V) + + 1. ReturnIfAbrupt(V). + 2. If Type(V) is not Reference, return V. + 3. Let base be GetBase(V). + 4. If IsUnresolvableReference(V), throw a ReferenceError exception. +---*/ + +class Test262ParentClass { + constructor() {} +} + +class Test262ChildClass extends Test262ParentClass { + constructor() { + super(0, ...unresolvableReference); + } +} + +assert.throws(ReferenceError, function() { + new Test262ChildClass(); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/super/call-spread-err-sngl-err-expr-throws.js b/js/src/tests/test262/language/expressions/super/call-spread-err-sngl-err-expr-throws.js new file mode 100644 index 0000000000..f48d6c35c9 --- /dev/null +++ b/js/src/tests/test262/language/expressions/super/call-spread-err-sngl-err-expr-throws.js @@ -0,0 +1,44 @@ +// This file was procedurally generated from the following sources: +// - src/spread/sngl-err-expr-throws.case +// - src/spread/error/super-call.template +/*--- +description: Spread operator applied to the only argument when evaluation throws (SuperCall) +esid: sec-super-keyword-runtime-semantics-evaluation +features: [generators] +flags: [generated] +info: | + SuperCall : super Arguments + + 1. Let newTarget be GetNewTarget(). + 2. If newTarget is undefined, throw a ReferenceError exception. + 3. Let func be GetSuperConstructor(). + 4. ReturnIfAbrupt(func). + 5. Let argList be ArgumentListEvaluation of Arguments. + [...] + + 12.3.6.1 Runtime Semantics: ArgumentListEvaluation + + ArgumentList : ... AssignmentExpression + + 1. Let list be an empty List. + 2. Let spreadRef be the result of evaluating AssignmentExpression. + 3. Let spreadObj be GetValue(spreadRef). + 4. Let iterator be GetIterator(spreadObj). + 5. ReturnIfAbrupt(iterator). +---*/ + +class Test262ParentClass { + constructor() {} +} + +class Test262ChildClass extends Test262ParentClass { + constructor() { + super(...function*() { throw new Test262Error(); }()); + } +} + +assert.throws(Test262Error, function() { + new Test262ChildClass(); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/super/call-spread-err-sngl-err-itr-get-call.js b/js/src/tests/test262/language/expressions/super/call-spread-err-sngl-err-itr-get-call.js new file mode 100644 index 0000000000..33418a9429 --- /dev/null +++ b/js/src/tests/test262/language/expressions/super/call-spread-err-sngl-err-itr-get-call.js @@ -0,0 +1,54 @@ +// This file was procedurally generated from the following sources: +// - src/spread/sngl-err-itr-get-call.case +// - src/spread/error/super-call.template +/*--- +description: Spread operator applied to the only argument when GetIterator fails (@@iterator function invocation) (SuperCall) +esid: sec-super-keyword-runtime-semantics-evaluation +features: [Symbol.iterator] +flags: [generated] +info: | + SuperCall : super Arguments + + 1. Let newTarget be GetNewTarget(). + 2. If newTarget is undefined, throw a ReferenceError exception. + 3. Let func be GetSuperConstructor(). + 4. ReturnIfAbrupt(func). + 5. Let argList be ArgumentListEvaluation of Arguments. + [...] + + 12.3.6.1 Runtime Semantics: ArgumentListEvaluation + + ArgumentList : ... AssignmentExpression + + 1. Let list be an empty List. + 2. Let spreadRef be the result of evaluating AssignmentExpression. + 3. Let spreadObj be GetValue(spreadRef). + 4. Let iterator be GetIterator(spreadObj). + 5. ReturnIfAbrupt(iterator). + + 7.4.1 GetIterator ( obj, method ) + + [...] + 3. Let iterator be Call(method,obj). + 4. ReturnIfAbrupt(iterator). +---*/ +var iter = {}; +iter[Symbol.iterator] = function() { + throw new Test262Error(); +}; + +class Test262ParentClass { + constructor() {} +} + +class Test262ChildClass extends Test262ParentClass { + constructor() { + super(...iter); + } +} + +assert.throws(Test262Error, function() { + new Test262ChildClass(); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/super/call-spread-err-sngl-err-itr-get-get.js b/js/src/tests/test262/language/expressions/super/call-spread-err-sngl-err-itr-get-get.js new file mode 100644 index 0000000000..5a88157c96 --- /dev/null +++ b/js/src/tests/test262/language/expressions/super/call-spread-err-sngl-err-itr-get-get.js @@ -0,0 +1,55 @@ +// This file was procedurally generated from the following sources: +// - src/spread/sngl-err-itr-get-get.case +// - src/spread/error/super-call.template +/*--- +description: Spread operator applied to the only argument when GetIterator fails (@@iterator property access) (SuperCall) +esid: sec-super-keyword-runtime-semantics-evaluation +features: [Symbol.iterator] +flags: [generated] +info: | + SuperCall : super Arguments + + 1. Let newTarget be GetNewTarget(). + 2. If newTarget is undefined, throw a ReferenceError exception. + 3. Let func be GetSuperConstructor(). + 4. ReturnIfAbrupt(func). + 5. Let argList be ArgumentListEvaluation of Arguments. + [...] + + 12.3.6.1 Runtime Semantics: ArgumentListEvaluation + + ArgumentList : ... AssignmentExpression + + 1. Let list be an empty List. + 2. Let spreadRef be the result of evaluating AssignmentExpression. + 3. Let spreadObj be GetValue(spreadRef). + 4. Let iterator be GetIterator(spreadObj). + 5. ReturnIfAbrupt(iterator). + + 7.4.1 GetIterator ( obj, method ) + + 1. If method was not passed, then + a. Let method be ? GetMethod(obj, @@iterator). +---*/ +var iter = {}; +Object.defineProperty(iter, Symbol.iterator, { + get: function() { + throw new Test262Error(); + } +}); + +class Test262ParentClass { + constructor() {} +} + +class Test262ChildClass extends Test262ParentClass { + constructor() { + super(...iter); + } +} + +assert.throws(Test262Error, function() { + new Test262ChildClass(); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/super/call-spread-err-sngl-err-itr-get-value.js b/js/src/tests/test262/language/expressions/super/call-spread-err-sngl-err-itr-get-value.js new file mode 100644 index 0000000000..ae8b50e91b --- /dev/null +++ b/js/src/tests/test262/language/expressions/super/call-spread-err-sngl-err-itr-get-value.js @@ -0,0 +1,54 @@ +// This file was procedurally generated from the following sources: +// - src/spread/sngl-err-itr-get-value.case +// - src/spread/error/super-call.template +/*--- +description: Spread operator applied to the only argument when GetIterator fails (@@iterator function return value) (SuperCall) +esid: sec-super-keyword-runtime-semantics-evaluation +features: [Symbol.iterator] +flags: [generated] +info: | + SuperCall : super Arguments + + 1. Let newTarget be GetNewTarget(). + 2. If newTarget is undefined, throw a ReferenceError exception. + 3. Let func be GetSuperConstructor(). + 4. ReturnIfAbrupt(func). + 5. Let argList be ArgumentListEvaluation of Arguments. + [...] + + 12.3.6.1 Runtime Semantics: ArgumentListEvaluation + + ArgumentList : ... AssignmentExpression + + 1. Let list be an empty List. + 2. Let spreadRef be the result of evaluating AssignmentExpression. + 3. Let spreadObj be GetValue(spreadRef). + 4. Let iterator be GetIterator(spreadObj). + 5. ReturnIfAbrupt(iterator). + + 7.4.1 GetIterator ( obj, method ) + + [...] + 2. Let iterator be ? Call(method, obj). + 3. If Type(iterator) is not Object, throw a TypeError exception. +---*/ +var iter = {}; +iter[Symbol.iterator] = function() { + return null; +}; + +class Test262ParentClass { + constructor() {} +} + +class Test262ChildClass extends Test262ParentClass { + constructor() { + super(...iter); + } +} + +assert.throws(TypeError, function() { + new Test262ChildClass(); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/super/call-spread-err-sngl-err-itr-step.js b/js/src/tests/test262/language/expressions/super/call-spread-err-sngl-err-itr-step.js new file mode 100644 index 0000000000..2c59552378 --- /dev/null +++ b/js/src/tests/test262/language/expressions/super/call-spread-err-sngl-err-itr-step.js @@ -0,0 +1,67 @@ +// This file was procedurally generated from the following sources: +// - src/spread/sngl-err-itr-step.case +// - src/spread/error/super-call.template +/*--- +description: Spread operator applied to the only argument when IteratorStep fails (SuperCall) +esid: sec-super-keyword-runtime-semantics-evaluation +features: [Symbol.iterator] +flags: [generated] +info: | + SuperCall : super Arguments + + 1. Let newTarget be GetNewTarget(). + 2. If newTarget is undefined, throw a ReferenceError exception. + 3. Let func be GetSuperConstructor(). + 4. ReturnIfAbrupt(func). + 5. Let argList be ArgumentListEvaluation of Arguments. + [...] + + 12.3.6.1 Runtime Semantics: ArgumentListEvaluation + + ArgumentList : ... AssignmentExpression + + 1. Let list be an empty List. + 2. Let spreadRef be the result of evaluating AssignmentExpression. + 3. Let spreadObj be GetValue(spreadRef). + 4. Let iterator be GetIterator(spreadObj). + 5. ReturnIfAbrupt(iterator). + 6. Repeat + a. Let next be IteratorStep(iterator). + b. ReturnIfAbrupt(next). + + 7.4.5 IteratorStep ( iterator ) + + 1. Let result be IteratorNext(iterator). + 2. ReturnIfAbrupt(result). + + 7.4.2 IteratorNext ( iterator, value ) + + 1. If value was not passed, then + a. Let result be Invoke(iterator, "next", « »). + [...] + 3. ReturnIfAbrupt(result). +---*/ +var iter = {}; +iter[Symbol.iterator] = function() { + return { + next: function() { + throw new Test262Error(); + } + }; +}; + +class Test262ParentClass { + constructor() {} +} + +class Test262ChildClass extends Test262ParentClass { + constructor() { + super(...iter); + } +} + +assert.throws(Test262Error, function() { + new Test262ChildClass(); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/super/call-spread-err-sngl-err-itr-value.js b/js/src/tests/test262/language/expressions/super/call-spread-err-sngl-err-itr-value.js new file mode 100644 index 0000000000..f4e39965bd --- /dev/null +++ b/js/src/tests/test262/language/expressions/super/call-spread-err-sngl-err-itr-value.js @@ -0,0 +1,73 @@ +// This file was procedurally generated from the following sources: +// - src/spread/sngl-err-itr-value.case +// - src/spread/error/super-call.template +/*--- +description: Spread operator applied to the only argument when IteratorValue fails (SuperCall) +esid: sec-super-keyword-runtime-semantics-evaluation +features: [Symbol.iterator] +flags: [generated] +info: | + SuperCall : super Arguments + + 1. Let newTarget be GetNewTarget(). + 2. If newTarget is undefined, throw a ReferenceError exception. + 3. Let func be GetSuperConstructor(). + 4. ReturnIfAbrupt(func). + 5. Let argList be ArgumentListEvaluation of Arguments. + [...] + + 12.3.6.1 Runtime Semantics: ArgumentListEvaluation + + ArgumentList : ... AssignmentExpression + + 1. Let list be an empty List. + 2. Let spreadRef be the result of evaluating AssignmentExpression. + 3. Let spreadObj be GetValue(spreadRef). + 4. Let iterator be GetIterator(spreadObj). + 5. ReturnIfAbrupt(iterator). + 6. Repeat + a. Let next be IteratorStep(iterator). + b. ReturnIfAbrupt(next). + c. If next is false, return list. + d. Let nextArg be IteratorValue(next). + e. ReturnIfAbrupt(nextArg). + + 7.4.4 IteratorValue ( iterResult ) + + 1. Assert: Type(iterResult) is Object. + 2. Return Get(iterResult, "value"). + + 7.3.1 Get (O, P) + + [...] + 3. Return O.[[Get]](P, O). +---*/ +var iter = {}; +var poisonedValue = Object.defineProperty({}, 'value', { + get: function() { + throw new Test262Error(); + } +}); +iter[Symbol.iterator] = function() { + return { + next: function() { + return poisonedValue; + } + }; +}; + +class Test262ParentClass { + constructor() {} +} + +class Test262ChildClass extends Test262ParentClass { + constructor() { + super(...iter); + } +} + +assert.throws(Test262Error, function() { + new Test262ChildClass(); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/super/call-spread-err-sngl-err-obj-unresolvable.js b/js/src/tests/test262/language/expressions/super/call-spread-err-sngl-err-obj-unresolvable.js new file mode 100644 index 0000000000..d6775ec75d --- /dev/null +++ b/js/src/tests/test262/language/expressions/super/call-spread-err-sngl-err-obj-unresolvable.js @@ -0,0 +1,45 @@ +// This file was procedurally generated from the following sources: +// - src/spread/sngl-err-obj-unresolvable.case +// - src/spread/error/super-call.template +/*--- +description: Object Spread operator results in error when using an unresolvable reference (SuperCall) +esid: sec-super-keyword-runtime-semantics-evaluation +features: [object-spread] +flags: [generated] +info: | + SuperCall : super Arguments + + 1. Let newTarget be GetNewTarget(). + 2. If newTarget is undefined, throw a ReferenceError exception. + 3. Let func be GetSuperConstructor(). + 4. ReturnIfAbrupt(func). + 5. Let argList be ArgumentListEvaluation of Arguments. + [...] + + Pending Runtime Semantics: PropertyDefinitionEvaluation + + PropertyDefinition:...AssignmentExpression + + 1. Let exprValue be the result of evaluating AssignmentExpression. + 2. Let fromValue be GetValue(exprValue). + 3. ReturnIfAbrupt(fromValue). + 4. Let excludedNames be a new empty List. + 5. Return CopyDataProperties(object, fromValue, excludedNames). + +---*/ + +class Test262ParentClass { + constructor() {} +} + +class Test262ChildClass extends Test262ParentClass { + constructor() { + super({...unresolvableReference}); + } +} + +assert.throws(ReferenceError, function() { + new Test262ChildClass(); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/super/call-spread-err-sngl-err-unresolvable.js b/js/src/tests/test262/language/expressions/super/call-spread-err-sngl-err-unresolvable.js new file mode 100644 index 0000000000..7e894853a4 --- /dev/null +++ b/js/src/tests/test262/language/expressions/super/call-spread-err-sngl-err-unresolvable.js @@ -0,0 +1,50 @@ +// This file was procedurally generated from the following sources: +// - src/spread/sngl-err-unresolvable.case +// - src/spread/error/super-call.template +/*--- +description: Spread operator applied to the only argument when reference is unresolvable (SuperCall) +esid: sec-super-keyword-runtime-semantics-evaluation +flags: [generated] +info: | + SuperCall : super Arguments + + 1. Let newTarget be GetNewTarget(). + 2. If newTarget is undefined, throw a ReferenceError exception. + 3. Let func be GetSuperConstructor(). + 4. ReturnIfAbrupt(func). + 5. Let argList be ArgumentListEvaluation of Arguments. + [...] + + 12.3.6.1 Runtime Semantics: ArgumentListEvaluation + + ArgumentList : ... AssignmentExpression + + 1. Let list be an empty List. + 2. Let spreadRef be the result of evaluating AssignmentExpression. + 3. Let spreadObj be GetValue(spreadRef). + 4. Let iterator be GetIterator(spreadObj). + 5. ReturnIfAbrupt(iterator). + + 6.2.3.1 GetValue (V) + + 1. ReturnIfAbrupt(V). + 2. If Type(V) is not Reference, return V. + 3. Let base be GetBase(V). + 4. If IsUnresolvableReference(V), throw a ReferenceError exception. +---*/ + +class Test262ParentClass { + constructor() {} +} + +class Test262ChildClass extends Test262ParentClass { + constructor() { + super(...unresolvableReference); + } +} + +assert.throws(ReferenceError, function() { + new Test262ChildClass(); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/super/call-spread-mult-empty.js b/js/src/tests/test262/language/expressions/super/call-spread-mult-empty.js new file mode 100644 index 0000000000..dfd1c3b8e8 --- /dev/null +++ b/js/src/tests/test262/language/expressions/super/call-spread-mult-empty.js @@ -0,0 +1,53 @@ +// This file was procedurally generated from the following sources: +// - src/spread/mult-empty.case +// - src/spread/default/super-call.template +/*--- +description: Spread operator following other arguments when no iteration occurs (SuperCall) +esid: sec-super-keyword-runtime-semantics-evaluation +flags: [generated] +info: | + SuperCall : super Arguments + + 1. Let newTarget be GetNewTarget(). + 2. If newTarget is undefined, throw a ReferenceError exception. + 3. Let func be GetSuperConstructor(). + 4. ReturnIfAbrupt(func). + 5. Let argList be ArgumentListEvaluation of Arguments. + [...] + + 12.3.6.1 Runtime Semantics: ArgumentListEvaluation + + ArgumentList : ArgumentList , ... AssignmentExpression + + 1. Let precedingArgs be the result of evaluating ArgumentList. + 2. Let spreadRef be the result of evaluating AssignmentExpression. + 3. Let iterator be GetIterator(GetValue(spreadRef) ). + 4. ReturnIfAbrupt(iterator). + 5. Repeat + a. Let next be IteratorStep(iterator). + b. ReturnIfAbrupt(next). + c. If next is false, return precedingArgs. +---*/ + +var callCount = 0; + +class Test262ParentClass { + constructor() { + assert.sameValue(arguments.length, 3); + assert.sameValue(arguments[0], 1); + assert.sameValue(arguments[1], 2); + assert.sameValue(arguments[2], 3); + callCount += 1; + } +} + +class Test262ChildClass extends Test262ParentClass { + constructor() { + super(1, 2, 3, ...[]); + } +} + +new Test262ChildClass(); +assert.sameValue(callCount, 1); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/super/call-spread-mult-expr.js b/js/src/tests/test262/language/expressions/super/call-spread-mult-expr.js new file mode 100644 index 0000000000..d903182e81 --- /dev/null +++ b/js/src/tests/test262/language/expressions/super/call-spread-mult-expr.js @@ -0,0 +1,58 @@ +// This file was procedurally generated from the following sources: +// - src/spread/mult-expr.case +// - src/spread/default/super-call.template +/*--- +description: Spread operator applied to AssignmentExpression following other elements (SuperCall) +esid: sec-super-keyword-runtime-semantics-evaluation +flags: [generated] +info: | + SuperCall : super Arguments + + 1. Let newTarget be GetNewTarget(). + 2. If newTarget is undefined, throw a ReferenceError exception. + 3. Let func be GetSuperConstructor(). + 4. ReturnIfAbrupt(func). + 5. Let argList be ArgumentListEvaluation of Arguments. + [...] + + 12.3.6.1 Runtime Semantics: ArgumentListEvaluation + + ArgumentList : ArgumentList , ... AssignmentExpression + + 1. Let precedingArgs be the result of evaluating ArgumentList. + 2. Let spreadRef be the result of evaluating AssignmentExpression. + 3. Let iterator be GetIterator(GetValue(spreadRef) ). + 4. ReturnIfAbrupt(iterator). + 5. Repeat + a. Let next be IteratorStep(iterator). + b. ReturnIfAbrupt(next). + c. If next is false, return precedingArgs. +---*/ +var source = [3, 4, 5]; +var target; + +var callCount = 0; + +class Test262ParentClass { + constructor() { + assert.sameValue(arguments.length, 5); + assert.sameValue(arguments[0], 1); + assert.sameValue(arguments[1], 2); + assert.sameValue(arguments[2], 3); + assert.sameValue(arguments[3], 4); + assert.sameValue(arguments[4], 5); + assert.sameValue(target, source); + callCount += 1; + } +} + +class Test262ChildClass extends Test262ParentClass { + constructor() { + super(1, 2, ...target = source); + } +} + +new Test262ChildClass(); +assert.sameValue(callCount, 1); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/super/call-spread-mult-iter.js b/js/src/tests/test262/language/expressions/super/call-spread-mult-iter.js new file mode 100644 index 0000000000..baff1fe32d --- /dev/null +++ b/js/src/tests/test262/language/expressions/super/call-spread-mult-iter.js @@ -0,0 +1,70 @@ +// This file was procedurally generated from the following sources: +// - src/spread/mult-iter.case +// - src/spread/default/super-call.template +/*--- +description: Spread operator following other arguments with a valid iterator (SuperCall) +esid: sec-super-keyword-runtime-semantics-evaluation +features: [Symbol.iterator] +flags: [generated] +info: | + SuperCall : super Arguments + + 1. Let newTarget be GetNewTarget(). + 2. If newTarget is undefined, throw a ReferenceError exception. + 3. Let func be GetSuperConstructor(). + 4. ReturnIfAbrupt(func). + 5. Let argList be ArgumentListEvaluation of Arguments. + [...] + + 12.3.6.1 Runtime Semantics: ArgumentListEvaluation + + ArgumentList : ... AssignmentExpression + + 1. Let list be an empty List. + 2. Let spreadRef be the result of evaluating AssignmentExpression. + 3. Let spreadObj be GetValue(spreadRef). + 4. Let iterator be GetIterator(spreadObj). + 5. ReturnIfAbrupt(iterator). + 6. Repeat + a. Let next be IteratorStep(iterator). + b. ReturnIfAbrupt(next). + c. If next is false, return list. + d. Let nextArg be IteratorValue(next). + e. ReturnIfAbrupt(nextArg). + f. Append nextArg as the last element of list. +---*/ +var iter = {}; +iter[Symbol.iterator] = function() { + var nextCount = 3; + return { + next: function() { + nextCount += 1; + return { done: nextCount === 6, value: nextCount }; + } + }; +}; + +var callCount = 0; + +class Test262ParentClass { + constructor() { + assert.sameValue(arguments.length, 5); + assert.sameValue(arguments[0], 1); + assert.sameValue(arguments[1], 2); + assert.sameValue(arguments[2], 3); + assert.sameValue(arguments[3], 4); + assert.sameValue(arguments[4], 5); + callCount += 1; + } +} + +class Test262ChildClass extends Test262ParentClass { + constructor() { + super(1, 2, 3, ...iter); + } +} + +new Test262ChildClass(); +assert.sameValue(callCount, 1); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/super/call-spread-mult-literal.js b/js/src/tests/test262/language/expressions/super/call-spread-mult-literal.js new file mode 100644 index 0000000000..81d08d39f7 --- /dev/null +++ b/js/src/tests/test262/language/expressions/super/call-spread-mult-literal.js @@ -0,0 +1,55 @@ +// This file was procedurally generated from the following sources: +// - src/spread/mult-literal.case +// - src/spread/default/super-call.template +/*--- +description: Spread operator applied to AssignmentExpression following other elements (SuperCall) +esid: sec-super-keyword-runtime-semantics-evaluation +flags: [generated] +info: | + SuperCall : super Arguments + + 1. Let newTarget be GetNewTarget(). + 2. If newTarget is undefined, throw a ReferenceError exception. + 3. Let func be GetSuperConstructor(). + 4. ReturnIfAbrupt(func). + 5. Let argList be ArgumentListEvaluation of Arguments. + [...] + + 12.3.6.1 Runtime Semantics: ArgumentListEvaluation + + ArgumentList : ArgumentList , ... AssignmentExpression + + 1. Let precedingArgs be the result of evaluating ArgumentList. + 2. Let spreadRef be the result of evaluating AssignmentExpression. + 3. Let iterator be GetIterator(GetValue(spreadRef) ). + 4. ReturnIfAbrupt(iterator). + 5. Repeat + a. Let next be IteratorStep(iterator). + b. ReturnIfAbrupt(next). + c. If next is false, return precedingArgs. +---*/ + +var callCount = 0; + +class Test262ParentClass { + constructor() { + assert.sameValue(arguments.length, 5); + assert.sameValue(arguments[0], 5); + assert.sameValue(arguments[1], 6); + assert.sameValue(arguments[2], 7); + assert.sameValue(arguments[3], 8); + assert.sameValue(arguments[4], 9); + callCount += 1; + } +} + +class Test262ChildClass extends Test262ParentClass { + constructor() { + super(5, ...[6, 7, 8], 9); + } +} + +new Test262ChildClass(); +assert.sameValue(callCount, 1); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/super/call-spread-mult-obj-ident.js b/js/src/tests/test262/language/expressions/super/call-spread-mult-obj-ident.js new file mode 100644 index 0000000000..14de6b5f15 --- /dev/null +++ b/js/src/tests/test262/language/expressions/super/call-spread-mult-obj-ident.js @@ -0,0 +1,80 @@ +// This file was procedurally generated from the following sources: +// - src/spread/mult-obj-ident.case +// - src/spread/default/super-call.template +/*--- +description: Object Spread operator following other properties (SuperCall) +esid: sec-super-keyword-runtime-semantics-evaluation +features: [object-spread] +flags: [generated] +includes: [propertyHelper.js] +info: | + SuperCall : super Arguments + + 1. Let newTarget be GetNewTarget(). + 2. If newTarget is undefined, throw a ReferenceError exception. + 3. Let func be GetSuperConstructor(). + 4. ReturnIfAbrupt(func). + 5. Let argList be ArgumentListEvaluation of Arguments. + [...] + + Pending Runtime Semantics: PropertyDefinitionEvaluation + + PropertyDefinition:...AssignmentExpression + + 1. Let exprValue be the result of evaluating AssignmentExpression. + 2. Let fromValue be GetValue(exprValue). + 3. ReturnIfAbrupt(fromValue). + 4. Let excludedNames be a new empty List. + 5. Return CopyDataProperties(object, fromValue, excludedNames). + +---*/ +let o = {c: 3, d: 4}; + + +var callCount = 0; + +class Test262ParentClass { + constructor(obj) { + assert.sameValue(Object.keys(obj).length, 4); + + verifyProperty(obj, "a", { + enumerable: true, + writable: true, + configurable: true, + value: 1 + }); + + verifyProperty(obj, "b", { + enumerable: true, + writable: true, + configurable: true, + value: 2 + }); + + verifyProperty(obj, "c", { + enumerable: true, + writable: true, + configurable: true, + value: 3 + }); + + verifyProperty(obj, "d", { + enumerable: true, + writable: true, + configurable: true, + value: 4 + }); + callCount += 1; + } +} + +class Test262ChildClass extends Test262ParentClass { + constructor() { + super({a: 1, b: 2, ...o}); + } +} + +new Test262ChildClass(); +assert.sameValue(callCount, 1); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/super/call-spread-mult-obj-null.js b/js/src/tests/test262/language/expressions/super/call-spread-mult-obj-null.js new file mode 100644 index 0000000000..80f0811ed7 --- /dev/null +++ b/js/src/tests/test262/language/expressions/super/call-spread-mult-obj-null.js @@ -0,0 +1,51 @@ +// This file was procedurally generated from the following sources: +// - src/spread/mult-obj-null.case +// - src/spread/default/super-call.template +/*--- +description: Object Spread operator following other arguments with null value (SuperCall) +esid: sec-super-keyword-runtime-semantics-evaluation +features: [object-spread] +flags: [generated] +info: | + SuperCall : super Arguments + + 1. Let newTarget be GetNewTarget(). + 2. If newTarget is undefined, throw a ReferenceError exception. + 3. Let func be GetSuperConstructor(). + 4. ReturnIfAbrupt(func). + 5. Let argList be ArgumentListEvaluation of Arguments. + [...] + + Pending Runtime Semantics: PropertyDefinitionEvaluation + + PropertyDefinition:...AssignmentExpression + + 1. Let exprValue be the result of evaluating AssignmentExpression. + 2. Let fromValue be GetValue(exprValue). + 3. ReturnIfAbrupt(fromValue). + 4. Let excludedNames be a new empty List. + 5. Return CopyDataProperties(object, fromValue, excludedNames). + +---*/ + +var callCount = 0; + +class Test262ParentClass { + constructor(obj) { + assert.sameValue(obj.a, 1); + assert.sameValue(obj.b, 2); + assert.sameValue(Object.keys(obj).length, 2); + callCount += 1; + } +} + +class Test262ChildClass extends Test262ParentClass { + constructor() { + super({a: 1, b: 2, ...null}); + } +} + +new Test262ChildClass(); +assert.sameValue(callCount, 1); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/super/call-spread-mult-obj-undefined.js b/js/src/tests/test262/language/expressions/super/call-spread-mult-obj-undefined.js new file mode 100644 index 0000000000..5df75b971b --- /dev/null +++ b/js/src/tests/test262/language/expressions/super/call-spread-mult-obj-undefined.js @@ -0,0 +1,51 @@ +// This file was procedurally generated from the following sources: +// - src/spread/mult-obj-undefined.case +// - src/spread/default/super-call.template +/*--- +description: Object Spread operator following other arguments with undefined (SuperCall) +esid: sec-super-keyword-runtime-semantics-evaluation +features: [object-spread] +flags: [generated] +info: | + SuperCall : super Arguments + + 1. Let newTarget be GetNewTarget(). + 2. If newTarget is undefined, throw a ReferenceError exception. + 3. Let func be GetSuperConstructor(). + 4. ReturnIfAbrupt(func). + 5. Let argList be ArgumentListEvaluation of Arguments. + [...] + + Pending Runtime Semantics: PropertyDefinitionEvaluation + + PropertyDefinition:...AssignmentExpression + + 1. Let exprValue be the result of evaluating AssignmentExpression. + 2. Let fromValue be GetValue(exprValue). + 3. ReturnIfAbrupt(fromValue). + 4. Let excludedNames be a new empty List. + 5. Return CopyDataProperties(object, fromValue, excludedNames). + +---*/ + +var callCount = 0; + +class Test262ParentClass { + constructor(obj) { + assert.sameValue(obj.a, 1); + assert.sameValue(obj.b, 2); + assert.sameValue(Object.keys(obj).length, 2); + callCount += 1; + } +} + +class Test262ChildClass extends Test262ParentClass { + constructor() { + super({a: 1, b: 2, ...undefined}); + } +} + +new Test262ChildClass(); +assert.sameValue(callCount, 1); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/super/call-spread-obj-getter-descriptor.js b/js/src/tests/test262/language/expressions/super/call-spread-obj-getter-descriptor.js new file mode 100644 index 0000000000..08d905b547 --- /dev/null +++ b/js/src/tests/test262/language/expressions/super/call-spread-obj-getter-descriptor.js @@ -0,0 +1,65 @@ +// This file was procedurally generated from the following sources: +// - src/spread/obj-getter-descriptor.case +// - src/spread/default/super-call.template +/*--- +description: Spread operation with getter results in data property descriptor (SuperCall) +esid: sec-super-keyword-runtime-semantics-evaluation +features: [object-spread] +flags: [generated] +includes: [propertyHelper.js] +info: | + SuperCall : super Arguments + + 1. Let newTarget be GetNewTarget(). + 2. If newTarget is undefined, throw a ReferenceError exception. + 3. Let func be GetSuperConstructor(). + 4. ReturnIfAbrupt(func). + 5. Let argList be ArgumentListEvaluation of Arguments. + [...] + + Pending Runtime Semantics: PropertyDefinitionEvaluation + + PropertyDefinition:...AssignmentExpression + + 1. Let exprValue be the result of evaluating AssignmentExpression. + 2. Let fromValue be GetValue(exprValue). + 3. ReturnIfAbrupt(fromValue). + 4. Let excludedNames be a new empty List. + 5. Return CopyDataProperties(object, fromValue, excludedNames). + +---*/ +let o = { + get a() { + return 42; + } +}; + + +var callCount = 0; + +class Test262ParentClass { + constructor(obj) { + assert.sameValue(obj.c, 4); + assert.sameValue(obj.d, 5); + assert.sameValue(Object.keys(obj).length, 3); + + verifyProperty(obj, "a", { + enumerable: true, + writable: true, + configurable: true, + value: 42 + }); + callCount += 1; + } +} + +class Test262ChildClass extends Test262ParentClass { + constructor() { + super({...o, c: 4, d: 5}); + } +} + +new Test262ChildClass(); +assert.sameValue(callCount, 1); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/super/call-spread-obj-getter-init.js b/js/src/tests/test262/language/expressions/super/call-spread-obj-getter-init.js new file mode 100644 index 0000000000..5c309d079e --- /dev/null +++ b/js/src/tests/test262/language/expressions/super/call-spread-obj-getter-init.js @@ -0,0 +1,45 @@ +// This file was procedurally generated from the following sources: +// - src/spread/obj-getter-init.case +// - src/spread/default/super-call.template +/*--- +description: Getter in object literal is not evaluated (SuperCall) +esid: sec-super-keyword-runtime-semantics-evaluation +features: [object-spread] +flags: [generated] +info: | + SuperCall : super Arguments + + 1. Let newTarget be GetNewTarget(). + 2. If newTarget is undefined, throw a ReferenceError exception. + 3. Let func be GetSuperConstructor(). + 4. ReturnIfAbrupt(func). + 5. Let argList be ArgumentListEvaluation of Arguments. + [...] +---*/ + +let o = {a: 2, b: 3}; +let executedGetter = false; + + +var callCount = 0; + +class Test262ParentClass { + constructor(obj) { + assert.sameValue(obj.a, 2); + assert.sameValue(obj.b, 3); + assert.sameValue(executedGetter, false) + assert.sameValue(Object.keys(obj).length, 3); + callCount += 1; + } +} + +class Test262ChildClass extends Test262ParentClass { + constructor() { + super({...o, get c() { executedGetter = true; }}); + } +} + +new Test262ChildClass(); +assert.sameValue(callCount, 1); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/super/call-spread-obj-manipulate-outter-obj-in-getter.js b/js/src/tests/test262/language/expressions/super/call-spread-obj-manipulate-outter-obj-in-getter.js new file mode 100644 index 0000000000..a143f085b9 --- /dev/null +++ b/js/src/tests/test262/language/expressions/super/call-spread-obj-manipulate-outter-obj-in-getter.js @@ -0,0 +1,59 @@ +// This file was procedurally generated from the following sources: +// - src/spread/obj-manipulate-outter-obj-in-getter.case +// - src/spread/default/super-call.template +/*--- +description: Getter manipulates outter object before it's spread operation (SuperCall) +esid: sec-super-keyword-runtime-semantics-evaluation +features: [object-spread] +flags: [generated] +info: | + SuperCall : super Arguments + + 1. Let newTarget be GetNewTarget(). + 2. If newTarget is undefined, throw a ReferenceError exception. + 3. Let func be GetSuperConstructor(). + 4. ReturnIfAbrupt(func). + 5. Let argList be ArgumentListEvaluation of Arguments. + [...] + + Pending Runtime Semantics: PropertyDefinitionEvaluation + + PropertyDefinition:...AssignmentExpression + + 1. Let exprValue be the result of evaluating AssignmentExpression. + 2. Let fromValue be GetValue(exprValue). + 3. ReturnIfAbrupt(fromValue). + 4. Let excludedNames be a new empty List. + 5. Return CopyDataProperties(object, fromValue, excludedNames). + +---*/ +var o = { a: 0, b: 1 }; +var cthulhu = { get x() { + delete o.a; + o.b = 42; + o.c = "ni"; +}}; + +var callCount = 0; + +class Test262ParentClass { + constructor(obj) { + assert.sameValue(obj.hasOwnProperty("a"), false); + assert.sameValue(obj.b, 42); + assert.sameValue(obj.c, "ni"); + assert(obj.hasOwnProperty("x")); + assert.sameValue(Object.keys(obj).length, 3); + callCount += 1; + } +} + +class Test262ChildClass extends Test262ParentClass { + constructor() { + super({...cthulhu, ...o}); + } +} + +new Test262ChildClass(); +assert.sameValue(callCount, 1); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/super/call-spread-obj-mult-spread-getter.js b/js/src/tests/test262/language/expressions/super/call-spread-obj-mult-spread-getter.js new file mode 100644 index 0000000000..0e6a3bd43d --- /dev/null +++ b/js/src/tests/test262/language/expressions/super/call-spread-obj-mult-spread-getter.js @@ -0,0 +1,59 @@ +// This file was procedurally generated from the following sources: +// - src/spread/obj-mult-spread-getter.case +// - src/spread/default/super-call.template +/*--- +description: Multiple Object Spread usage calls getter multiple times (SuperCall) +esid: sec-super-keyword-runtime-semantics-evaluation +features: [object-spread] +flags: [generated] +info: | + SuperCall : super Arguments + + 1. Let newTarget be GetNewTarget(). + 2. If newTarget is undefined, throw a ReferenceError exception. + 3. Let func be GetSuperConstructor(). + 4. ReturnIfAbrupt(func). + 5. Let argList be ArgumentListEvaluation of Arguments. + [...] + + Pending Runtime Semantics: PropertyDefinitionEvaluation + + PropertyDefinition:...AssignmentExpression + + 1. Let exprValue be the result of evaluating AssignmentExpression. + 2. Let fromValue be GetValue(exprValue). + 3. ReturnIfAbrupt(fromValue). + 4. Let excludedNames be a new empty List. + 5. Return CopyDataProperties(object, fromValue, excludedNames). + +---*/ +let getterCallCount = 0; +let o = { + get a() { + return ++getterCallCount; + } +}; + + +var callCount = 0; + +class Test262ParentClass { + constructor(obj) { + assert.sameValue(obj.a, 2); + assert.sameValue(obj.c, 4); + assert.sameValue(obj.d, 5); + assert.sameValue(Object.keys(obj).length, 3); + callCount += 1; + } +} + +class Test262ChildClass extends Test262ParentClass { + constructor() { + super({...o, c: 4, d: 5, a: 42, ...o}); + } +} + +new Test262ChildClass(); +assert.sameValue(callCount, 1); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/super/call-spread-obj-mult-spread.js b/js/src/tests/test262/language/expressions/super/call-spread-obj-mult-spread.js new file mode 100644 index 0000000000..38429148f7 --- /dev/null +++ b/js/src/tests/test262/language/expressions/super/call-spread-obj-mult-spread.js @@ -0,0 +1,57 @@ +// This file was procedurally generated from the following sources: +// - src/spread/obj-mult-spread.case +// - src/spread/default/super-call.template +/*--- +description: Multiple Object Spread operation (SuperCall) +esid: sec-super-keyword-runtime-semantics-evaluation +features: [object-spread] +flags: [generated] +info: | + SuperCall : super Arguments + + 1. Let newTarget be GetNewTarget(). + 2. If newTarget is undefined, throw a ReferenceError exception. + 3. Let func be GetSuperConstructor(). + 4. ReturnIfAbrupt(func). + 5. Let argList be ArgumentListEvaluation of Arguments. + [...] + + Pending Runtime Semantics: PropertyDefinitionEvaluation + + PropertyDefinition:...AssignmentExpression + + 1. Let exprValue be the result of evaluating AssignmentExpression. + 2. Let fromValue be GetValue(exprValue). + 3. ReturnIfAbrupt(fromValue). + 4. Let excludedNames be a new empty List. + 5. Return CopyDataProperties(object, fromValue, excludedNames). + +---*/ + +let o = {a: 2, b: 3}; +let o2 = {c: 4, d: 5}; + + +var callCount = 0; + +class Test262ParentClass { + constructor(obj) { + assert.sameValue(obj.a, 2); + assert.sameValue(obj.b, 3); + assert.sameValue(obj.c, 4); + assert.sameValue(obj.d, 5); + assert.sameValue(Object.keys(obj).length, 4); + callCount += 1; + } +} + +class Test262ChildClass extends Test262ParentClass { + constructor() { + super({...o, ...o2}); + } +} + +new Test262ChildClass(); +assert.sameValue(callCount, 1); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/super/call-spread-obj-null.js b/js/src/tests/test262/language/expressions/super/call-spread-obj-null.js new file mode 100644 index 0000000000..7f14e6d13b --- /dev/null +++ b/js/src/tests/test262/language/expressions/super/call-spread-obj-null.js @@ -0,0 +1,49 @@ +// This file was procedurally generated from the following sources: +// - src/spread/obj-null.case +// - src/spread/default/super-call.template +/*--- +description: Null Object Spread is ignored (SuperCall) +esid: sec-super-keyword-runtime-semantics-evaluation +features: [object-spread] +flags: [generated] +info: | + SuperCall : super Arguments + + 1. Let newTarget be GetNewTarget(). + 2. If newTarget is undefined, throw a ReferenceError exception. + 3. Let func be GetSuperConstructor(). + 4. ReturnIfAbrupt(func). + 5. Let argList be ArgumentListEvaluation of Arguments. + [...] + + Pending Runtime Semantics: PropertyDefinitionEvaluation + + PropertyDefinition:...AssignmentExpression + + 1. Let exprValue be the result of evaluating AssignmentExpression. + 2. Let fromValue be GetValue(exprValue). + 3. ReturnIfAbrupt(fromValue). + 4. Let excludedNames be a new empty List. + 5. Return CopyDataProperties(object, fromValue, excludedNames). + +---*/ + +var callCount = 0; + +class Test262ParentClass { + constructor(obj) { + assert.sameValue(Object.keys(obj).length, 0); + callCount += 1; + } +} + +class Test262ChildClass extends Test262ParentClass { + constructor() { + super({...null}); + } +} + +new Test262ChildClass(); +assert.sameValue(callCount, 1); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/super/call-spread-obj-override-immutable.js b/js/src/tests/test262/language/expressions/super/call-spread-obj-override-immutable.js new file mode 100644 index 0000000000..86f52a61f8 --- /dev/null +++ b/js/src/tests/test262/language/expressions/super/call-spread-obj-override-immutable.js @@ -0,0 +1,58 @@ +// This file was procedurally generated from the following sources: +// - src/spread/obj-override-immutable.case +// - src/spread/default/super-call.template +/*--- +description: Object Spread overriding immutable properties (SuperCall) +esid: sec-super-keyword-runtime-semantics-evaluation +features: [object-spread] +flags: [generated] +includes: [propertyHelper.js] +info: | + SuperCall : super Arguments + + 1. Let newTarget be GetNewTarget(). + 2. If newTarget is undefined, throw a ReferenceError exception. + 3. Let func be GetSuperConstructor(). + 4. ReturnIfAbrupt(func). + 5. Let argList be ArgumentListEvaluation of Arguments. + [...] +---*/ + +let o = {b: 2}; +Object.defineProperty(o, "a", {value: 1, enumerable: true, writable: false, configurable: true}); + + +var callCount = 0; + +class Test262ParentClass { + constructor(obj) { + assert.sameValue(obj.a, 3) + assert.sameValue(obj.b, 2); + + verifyProperty(obj, "a", { + enumerable: true, + writable: true, + configurable: true, + value: 3 + }); + + verifyProperty(obj, "b", { + enumerable: true, + writable: true, + configurable: true, + value: 2 + }); + callCount += 1; + } +} + +class Test262ChildClass extends Test262ParentClass { + constructor() { + super({...o, a: 3}); + } +} + +new Test262ChildClass(); +assert.sameValue(callCount, 1); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/super/call-spread-obj-overrides-prev-properties.js b/js/src/tests/test262/language/expressions/super/call-spread-obj-overrides-prev-properties.js new file mode 100644 index 0000000000..c42207485f --- /dev/null +++ b/js/src/tests/test262/language/expressions/super/call-spread-obj-overrides-prev-properties.js @@ -0,0 +1,55 @@ +// This file was procedurally generated from the following sources: +// - src/spread/obj-overrides-prev-properties.case +// - src/spread/default/super-call.template +/*--- +description: Object Spread properties overrides previous definitions (SuperCall) +esid: sec-super-keyword-runtime-semantics-evaluation +features: [object-spread] +flags: [generated] +info: | + SuperCall : super Arguments + + 1. Let newTarget be GetNewTarget(). + 2. If newTarget is undefined, throw a ReferenceError exception. + 3. Let func be GetSuperConstructor(). + 4. ReturnIfAbrupt(func). + 5. Let argList be ArgumentListEvaluation of Arguments. + [...] + + Pending Runtime Semantics: PropertyDefinitionEvaluation + + PropertyDefinition:...AssignmentExpression + + 1. Let exprValue be the result of evaluating AssignmentExpression. + 2. Let fromValue be GetValue(exprValue). + 3. ReturnIfAbrupt(fromValue). + 4. Let excludedNames be a new empty List. + 5. Return CopyDataProperties(object, fromValue, excludedNames). + +---*/ +let o = {a: 2, b: 3}; + + +var callCount = 0; + +class Test262ParentClass { + constructor(obj) { + assert.sameValue(obj.a, 2); + assert.sameValue(obj.b, 3); + assert.sameValue(Object.keys(obj).length, 2); + assert.sameValue(o.a, 2); + assert.sameValue(o.b, 3); + callCount += 1; + } +} + +class Test262ChildClass extends Test262ParentClass { + constructor() { + super({a: 1, b: 7, ...o}); + } +} + +new Test262ChildClass(); +assert.sameValue(callCount, 1); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/super/call-spread-obj-skip-non-enumerable.js b/js/src/tests/test262/language/expressions/super/call-spread-obj-skip-non-enumerable.js new file mode 100644 index 0000000000..8993f3c57c --- /dev/null +++ b/js/src/tests/test262/language/expressions/super/call-spread-obj-skip-non-enumerable.js @@ -0,0 +1,43 @@ +// This file was procedurally generated from the following sources: +// - src/spread/obj-skip-non-enumerable.case +// - src/spread/default/super-call.template +/*--- +description: Object Spread doesn't copy non-enumerable properties (SuperCall) +esid: sec-super-keyword-runtime-semantics-evaluation +features: [object-spread] +flags: [generated] +info: | + SuperCall : super Arguments + + 1. Let newTarget be GetNewTarget(). + 2. If newTarget is undefined, throw a ReferenceError exception. + 3. Let func be GetSuperConstructor(). + 4. ReturnIfAbrupt(func). + 5. Let argList be ArgumentListEvaluation of Arguments. + [...] +---*/ + +let o = {}; +Object.defineProperty(o, "b", {value: 3, enumerable: false}); + + +var callCount = 0; + +class Test262ParentClass { + constructor(obj) { + assert.sameValue(obj.hasOwnProperty("b"), false) + assert.sameValue(Object.keys(obj).length, 0); + callCount += 1; + } +} + +class Test262ChildClass extends Test262ParentClass { + constructor() { + super({...o}); + } +} + +new Test262ChildClass(); +assert.sameValue(callCount, 1); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/super/call-spread-obj-spread-order.js b/js/src/tests/test262/language/expressions/super/call-spread-obj-spread-order.js new file mode 100644 index 0000000000..096d65508b --- /dev/null +++ b/js/src/tests/test262/language/expressions/super/call-spread-obj-spread-order.js @@ -0,0 +1,56 @@ +// This file was procedurally generated from the following sources: +// - src/spread/obj-spread-order.case +// - src/spread/default/super-call.template +/*--- +description: Spread operation follows [[OwnPropertyKeys]] order (SuperCall) +esid: sec-super-keyword-runtime-semantics-evaluation +features: [Symbol, object-spread] +flags: [generated] +includes: [compareArray.js] +info: | + SuperCall : super Arguments + + 1. Let newTarget be GetNewTarget(). + 2. If newTarget is undefined, throw a ReferenceError exception. + 3. Let func be GetSuperConstructor(). + 4. ReturnIfAbrupt(func). + 5. Let argList be ArgumentListEvaluation of Arguments. + [...] + + Pending Runtime Semantics: PropertyDefinitionEvaluation + + PropertyDefinition:...AssignmentExpression + + 1. Let exprValue be the result of evaluating AssignmentExpression. + 2. Let fromValue be GetValue(exprValue). + 3. ReturnIfAbrupt(fromValue). + 4. Let excludedNames be a new empty List. + 5. Return CopyDataProperties(object, fromValue, excludedNames). + +---*/ +var calls = []; +var o = { get z() { calls.push('z') }, get a() { calls.push('a') } }; +Object.defineProperty(o, 1, { get: () => { calls.push(1) }, enumerable: true }); +Object.defineProperty(o, Symbol('foo'), { get: () => { calls.push("Symbol(foo)") }, enumerable: true }); + + +var callCount = 0; + +class Test262ParentClass { + constructor(obj) { + assert.compareArray(calls, [1, 'z', 'a', "Symbol(foo)"]); + assert.sameValue(Object.keys(obj).length, 3); + callCount += 1; + } +} + +class Test262ChildClass extends Test262ParentClass { + constructor() { + super({...o}); + } +} + +new Test262ChildClass(); +assert.sameValue(callCount, 1); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/super/call-spread-obj-symbol-property.js b/js/src/tests/test262/language/expressions/super/call-spread-obj-symbol-property.js new file mode 100644 index 0000000000..495d734229 --- /dev/null +++ b/js/src/tests/test262/language/expressions/super/call-spread-obj-symbol-property.js @@ -0,0 +1,57 @@ +// This file was procedurally generated from the following sources: +// - src/spread/obj-symbol-property.case +// - src/spread/default/super-call.template +/*--- +description: Spread operation where source object contains Symbol properties (SuperCall) +esid: sec-super-keyword-runtime-semantics-evaluation +features: [Symbol, object-spread] +flags: [generated] +info: | + SuperCall : super Arguments + + 1. Let newTarget be GetNewTarget(). + 2. If newTarget is undefined, throw a ReferenceError exception. + 3. Let func be GetSuperConstructor(). + 4. ReturnIfAbrupt(func). + 5. Let argList be ArgumentListEvaluation of Arguments. + [...] + + Pending Runtime Semantics: PropertyDefinitionEvaluation + + PropertyDefinition:...AssignmentExpression + + 1. Let exprValue be the result of evaluating AssignmentExpression. + 2. Let fromValue be GetValue(exprValue). + 3. ReturnIfAbrupt(fromValue). + 4. Let excludedNames be a new empty List. + 5. Return CopyDataProperties(object, fromValue, excludedNames). + +---*/ +let symbol = Symbol('foo'); +let o = {}; +o[symbol] = 1; + + +var callCount = 0; + +class Test262ParentClass { + constructor(obj) { + assert.sameValue(obj[symbol], 1); + assert(Object.prototype.hasOwnProperty.call(obj, symbol), "symbol is an own property"); + assert.sameValue(obj.c, 4); + assert.sameValue(obj.d, 5); + assert.sameValue(Object.keys(obj).length, 2); + callCount += 1; + } +} + +class Test262ChildClass extends Test262ParentClass { + constructor() { + super({...o, c: 4, d: 5}); + } +} + +new Test262ChildClass(); +assert.sameValue(callCount, 1); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/super/call-spread-obj-undefined.js b/js/src/tests/test262/language/expressions/super/call-spread-obj-undefined.js new file mode 100644 index 0000000000..c036ed1623 --- /dev/null +++ b/js/src/tests/test262/language/expressions/super/call-spread-obj-undefined.js @@ -0,0 +1,49 @@ +// This file was procedurally generated from the following sources: +// - src/spread/obj-undefined.case +// - src/spread/default/super-call.template +/*--- +description: Undefined Object Spread is ignored (SuperCall) +esid: sec-super-keyword-runtime-semantics-evaluation +features: [object-spread] +flags: [generated] +info: | + SuperCall : super Arguments + + 1. Let newTarget be GetNewTarget(). + 2. If newTarget is undefined, throw a ReferenceError exception. + 3. Let func be GetSuperConstructor(). + 4. ReturnIfAbrupt(func). + 5. Let argList be ArgumentListEvaluation of Arguments. + [...] + + Pending Runtime Semantics: PropertyDefinitionEvaluation + + PropertyDefinition:...AssignmentExpression + + 1. Let exprValue be the result of evaluating AssignmentExpression. + 2. Let fromValue be GetValue(exprValue). + 3. ReturnIfAbrupt(fromValue). + 4. Let excludedNames be a new empty List. + 5. Return CopyDataProperties(object, fromValue, excludedNames). + +---*/ + +var callCount = 0; + +class Test262ParentClass { + constructor(obj) { + assert.sameValue(Object.keys(obj).length, 0); + callCount += 1; + } +} + +class Test262ChildClass extends Test262ParentClass { + constructor() { + super({...undefined}); + } +} + +new Test262ChildClass(); +assert.sameValue(callCount, 1); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/super/call-spread-obj-with-overrides.js b/js/src/tests/test262/language/expressions/super/call-spread-obj-with-overrides.js new file mode 100644 index 0000000000..e6bc0b51e7 --- /dev/null +++ b/js/src/tests/test262/language/expressions/super/call-spread-obj-with-overrides.js @@ -0,0 +1,61 @@ +// This file was procedurally generated from the following sources: +// - src/spread/obj-with-overrides.case +// - src/spread/default/super-call.template +/*--- +description: Object Spread properties being overriden (SuperCall) +esid: sec-super-keyword-runtime-semantics-evaluation +features: [Symbol, object-spread] +flags: [generated] +info: | + SuperCall : super Arguments + + 1. Let newTarget be GetNewTarget(). + 2. If newTarget is undefined, throw a ReferenceError exception. + 3. Let func be GetSuperConstructor(). + 4. ReturnIfAbrupt(func). + 5. Let argList be ArgumentListEvaluation of Arguments. + [...] + + Pending Runtime Semantics: PropertyDefinitionEvaluation + + PropertyDefinition:...AssignmentExpression + + 1. Let exprValue be the result of evaluating AssignmentExpression. + 2. Let fromValue be GetValue(exprValue). + 3. ReturnIfAbrupt(fromValue). + 4. Let excludedNames be a new empty List. + 5. Return CopyDataProperties(object, fromValue, excludedNames). + +---*/ +let o = {a: 2, b: 3, c: 4, e: undefined, f: null, g: false}; + + +var callCount = 0; + +class Test262ParentClass { + constructor(obj) { + assert.sameValue(obj.a, 1); + assert.sameValue(obj.b, 7); + assert.sameValue(obj.c, 4); + assert.sameValue(obj.d, 5); + assert(obj.hasOwnProperty("e")); + assert.sameValue(obj.f, null); + assert.sameValue(obj.g, false); + assert.sameValue(obj.h, -0); + assert.sameValue(obj.i.toString(), "Symbol(foo)"); + assert(Object.is(obj.j, o)); + assert.sameValue(Object.keys(obj).length, 10); + callCount += 1; + } +} + +class Test262ChildClass extends Test262ParentClass { + constructor() { + super({...o, a: 1, b: 7, d: 5, h: -0, i: Symbol("foo"), j: o}); + } +} + +new Test262ChildClass(); +assert.sameValue(callCount, 1); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/super/call-spread-sngl-empty.js b/js/src/tests/test262/language/expressions/super/call-spread-sngl-empty.js new file mode 100644 index 0000000000..01a01f0466 --- /dev/null +++ b/js/src/tests/test262/language/expressions/super/call-spread-sngl-empty.js @@ -0,0 +1,52 @@ +// This file was procedurally generated from the following sources: +// - src/spread/sngl-empty.case +// - src/spread/default/super-call.template +/*--- +description: Spread operator applied to the only argument when no iteration occurs (SuperCall) +esid: sec-super-keyword-runtime-semantics-evaluation +flags: [generated] +info: | + SuperCall : super Arguments + + 1. Let newTarget be GetNewTarget(). + 2. If newTarget is undefined, throw a ReferenceError exception. + 3. Let func be GetSuperConstructor(). + 4. ReturnIfAbrupt(func). + 5. Let argList be ArgumentListEvaluation of Arguments. + [...] + + 12.3.6.1 Runtime Semantics: ArgumentListEvaluation + + ArgumentList : ... AssignmentExpression + + 1. Let list be an empty List. + 2. Let spreadRef be the result of evaluating AssignmentExpression. + 3. Let spreadObj be GetValue(spreadRef). + 4. Let iterator be GetIterator(spreadObj). + 5. ReturnIfAbrupt(iterator). + 6. Repeat + a. Let next be IteratorStep(iterator). + b. ReturnIfAbrupt(next). + c. If next is false, return list. + [...] +---*/ + +var callCount = 0; + +class Test262ParentClass { + constructor() { + assert.sameValue(arguments.length, 0); + callCount += 1; + } +} + +class Test262ChildClass extends Test262ParentClass { + constructor() { + super(...[]); + } +} + +new Test262ChildClass(); +assert.sameValue(callCount, 1); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/super/call-spread-sngl-expr.js b/js/src/tests/test262/language/expressions/super/call-spread-sngl-expr.js new file mode 100644 index 0000000000..2fa060ded9 --- /dev/null +++ b/js/src/tests/test262/language/expressions/super/call-spread-sngl-expr.js @@ -0,0 +1,60 @@ +// This file was procedurally generated from the following sources: +// - src/spread/sngl-expr.case +// - src/spread/default/super-call.template +/*--- +description: Spread operator applied to AssignmentExpression as only element (SuperCall) +esid: sec-super-keyword-runtime-semantics-evaluation +flags: [generated] +info: | + SuperCall : super Arguments + + 1. Let newTarget be GetNewTarget(). + 2. If newTarget is undefined, throw a ReferenceError exception. + 3. Let func be GetSuperConstructor(). + 4. ReturnIfAbrupt(func). + 5. Let argList be ArgumentListEvaluation of Arguments. + [...] + + 12.3.6.1 Runtime Semantics: ArgumentListEvaluation + + ArgumentList : ... AssignmentExpression + + 1. Let list be an empty List. + 2. Let spreadRef be the result of evaluating AssignmentExpression. + 3. Let spreadObj be GetValue(spreadRef). + 4. Let iterator be GetIterator(spreadObj). + 5. ReturnIfAbrupt(iterator). + 6. Repeat + a. Let next be IteratorStep(iterator). + b. ReturnIfAbrupt(next). + c. If next is false, return list. + d. Let nextArg be IteratorValue(next). + e. ReturnIfAbrupt(nextArg). + f. Append nextArg as the last element of list. +---*/ +var source = [2, 3, 4]; +var target; + +var callCount = 0; + +class Test262ParentClass { + constructor() { + assert.sameValue(arguments.length, 3); + assert.sameValue(arguments[0], 2); + assert.sameValue(arguments[1], 3); + assert.sameValue(arguments[2], 4); + assert.sameValue(target, source); + callCount += 1; + } +} + +class Test262ChildClass extends Test262ParentClass { + constructor() { + super(...target = source); + } +} + +new Test262ChildClass(); +assert.sameValue(callCount, 1); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/super/call-spread-sngl-iter.js b/js/src/tests/test262/language/expressions/super/call-spread-sngl-iter.js new file mode 100644 index 0000000000..48fa9301b5 --- /dev/null +++ b/js/src/tests/test262/language/expressions/super/call-spread-sngl-iter.js @@ -0,0 +1,67 @@ +// This file was procedurally generated from the following sources: +// - src/spread/sngl-iter.case +// - src/spread/default/super-call.template +/*--- +description: Spread operator applied to the only argument with a valid iterator (SuperCall) +esid: sec-super-keyword-runtime-semantics-evaluation +features: [Symbol.iterator] +flags: [generated] +info: | + SuperCall : super Arguments + + 1. Let newTarget be GetNewTarget(). + 2. If newTarget is undefined, throw a ReferenceError exception. + 3. Let func be GetSuperConstructor(). + 4. ReturnIfAbrupt(func). + 5. Let argList be ArgumentListEvaluation of Arguments. + [...] + + 12.3.6.1 Runtime Semantics: ArgumentListEvaluation + + ArgumentList : ... AssignmentExpression + + 1. Let list be an empty List. + 2. Let spreadRef be the result of evaluating AssignmentExpression. + 3. Let spreadObj be GetValue(spreadRef). + 4. Let iterator be GetIterator(spreadObj). + 5. ReturnIfAbrupt(iterator). + 6. Repeat + a. Let next be IteratorStep(iterator). + b. ReturnIfAbrupt(next). + c. If next is false, return list. + d. Let nextArg be IteratorValue(next). + e. ReturnIfAbrupt(nextArg). + f. Append nextArg as the last element of list. +---*/ +var iter = {}; +iter[Symbol.iterator] = function() { + var nextCount = 0; + return { + next: function() { + nextCount += 1; + return { done: nextCount === 3, value: nextCount }; + } + }; +}; + +var callCount = 0; + +class Test262ParentClass { + constructor() { + assert.sameValue(arguments.length, 2); + assert.sameValue(arguments[0], 1); + assert.sameValue(arguments[1], 2); + callCount += 1; + } +} + +class Test262ChildClass extends Test262ParentClass { + constructor() { + super(...iter); + } +} + +new Test262ChildClass(); +assert.sameValue(callCount, 1); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/super/call-spread-sngl-literal.js b/js/src/tests/test262/language/expressions/super/call-spread-sngl-literal.js new file mode 100644 index 0000000000..2f58ff416e --- /dev/null +++ b/js/src/tests/test262/language/expressions/super/call-spread-sngl-literal.js @@ -0,0 +1,57 @@ +// This file was procedurally generated from the following sources: +// - src/spread/sngl-literal.case +// - src/spread/default/super-call.template +/*--- +description: Spread operator applied to array literal as only element (SuperCall) +esid: sec-super-keyword-runtime-semantics-evaluation +flags: [generated] +info: | + SuperCall : super Arguments + + 1. Let newTarget be GetNewTarget(). + 2. If newTarget is undefined, throw a ReferenceError exception. + 3. Let func be GetSuperConstructor(). + 4. ReturnIfAbrupt(func). + 5. Let argList be ArgumentListEvaluation of Arguments. + [...] + + 12.3.6.1 Runtime Semantics: ArgumentListEvaluation + + ArgumentList : ... AssignmentExpression + + 1. Let list be an empty List. + 2. Let spreadRef be the result of evaluating AssignmentExpression. + 3. Let spreadObj be GetValue(spreadRef). + 4. Let iterator be GetIterator(spreadObj). + 5. ReturnIfAbrupt(iterator). + 6. Repeat + a. Let next be IteratorStep(iterator). + b. ReturnIfAbrupt(next). + c. If next is false, return list. + d. Let nextArg be IteratorValue(next). + e. ReturnIfAbrupt(nextArg). + f. Append nextArg as the last element of list. +---*/ + +var callCount = 0; + +class Test262ParentClass { + constructor() { + assert.sameValue(arguments.length, 3); + assert.sameValue(arguments[0], 3); + assert.sameValue(arguments[1], 4); + assert.sameValue(arguments[2], 5); + callCount += 1; + } +} + +class Test262ChildClass extends Test262ParentClass { + constructor() { + super(...[3, 4, 5]); + } +} + +new Test262ChildClass(); +assert.sameValue(callCount, 1); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/super/call-spread-sngl-obj-ident.js b/js/src/tests/test262/language/expressions/super/call-spread-sngl-obj-ident.js new file mode 100644 index 0000000000..1d59f891ed --- /dev/null +++ b/js/src/tests/test262/language/expressions/super/call-spread-sngl-obj-ident.js @@ -0,0 +1,66 @@ +// This file was procedurally generated from the following sources: +// - src/spread/sngl-obj-ident.case +// - src/spread/default/super-call.template +/*--- +description: Object Spread operator without other arguments (SuperCall) +esid: sec-super-keyword-runtime-semantics-evaluation +features: [object-spread] +flags: [generated] +includes: [propertyHelper.js] +info: | + SuperCall : super Arguments + + 1. Let newTarget be GetNewTarget(). + 2. If newTarget is undefined, throw a ReferenceError exception. + 3. Let func be GetSuperConstructor(). + 4. ReturnIfAbrupt(func). + 5. Let argList be ArgumentListEvaluation of Arguments. + [...] + + Pending Runtime Semantics: PropertyDefinitionEvaluation + + PropertyDefinition:...AssignmentExpression + + 1. Let exprValue be the result of evaluating AssignmentExpression. + 2. Let fromValue be GetValue(exprValue). + 3. ReturnIfAbrupt(fromValue). + 4. Let excludedNames be a new empty List. + 5. Return CopyDataProperties(object, fromValue, excludedNames). + +---*/ +let o = {c: 3, d: 4}; + + +var callCount = 0; + +class Test262ParentClass { + constructor(obj) { + assert.sameValue(Object.keys(obj).length, 2); + + verifyProperty(obj, "c", { + enumerable: true, + writable: true, + configurable: true, + value: 3 + }); + + verifyProperty(obj, "d", { + enumerable: true, + writable: true, + configurable: true, + value: 4 + }); + callCount += 1; + } +} + +class Test262ChildClass extends Test262ParentClass { + constructor() { + super({...o}); + } +} + +new Test262ChildClass(); +assert.sameValue(callCount, 1); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/super/prop-dot-cls-null-proto.js b/js/src/tests/test262/language/expressions/super/prop-dot-cls-null-proto.js new file mode 100644 index 0000000000..5ac418985d --- /dev/null +++ b/js/src/tests/test262/language/expressions/super/prop-dot-cls-null-proto.js @@ -0,0 +1,41 @@ +// 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); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/super/prop-dot-cls-ref-strict.js b/js/src/tests/test262/language/expressions/super/prop-dot-cls-ref-strict.js new file mode 100644 index 0000000000..9f01b7a429 --- /dev/null +++ b/js/src/tests/test262/language/expressions/super/prop-dot-cls-ref-strict.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 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); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/super/prop-dot-cls-ref-this.js b/js/src/tests/test262/language/expressions/super/prop-dot-cls-ref-this.js new file mode 100644 index 0000000000..04c073c60c --- /dev/null +++ b/js/src/tests/test262/language/expressions/super/prop-dot-cls-ref-this.js @@ -0,0 +1,60 @@ +// 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'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/super/prop-dot-cls-this-uninit.js b/js/src/tests/test262/language/expressions/super/prop-dot-cls-this-uninit.js new file mode 100644 index 0000000000..9e539bd295 --- /dev/null +++ b/js/src/tests/test262/language/expressions/super/prop-dot-cls-this-uninit.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 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); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/super/prop-dot-cls-val-from-arrow.js b/js/src/tests/test262/language/expressions/super/prop-dot-cls-val-from-arrow.js new file mode 100644 index 0000000000..98608db201 --- /dev/null +++ b/js/src/tests/test262/language/expressions/super/prop-dot-cls-val-from-arrow.js @@ -0,0 +1,48 @@ +// 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'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/super/prop-dot-cls-val-from-eval.js b/js/src/tests/test262/language/expressions/super/prop-dot-cls-val-from-eval.js new file mode 100644 index 0000000000..f24d975f83 --- /dev/null +++ b/js/src/tests/test262/language/expressions/super/prop-dot-cls-val-from-eval.js @@ -0,0 +1,49 @@ +// 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'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/super/prop-dot-cls-val.js b/js/src/tests/test262/language/expressions/super/prop-dot-cls-val.js new file mode 100644 index 0000000000..5697c74129 --- /dev/null +++ b/js/src/tests/test262/language/expressions/super/prop-dot-cls-val.js @@ -0,0 +1,48 @@ +// 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'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/super/prop-dot-obj-null-proto.js b/js/src/tests/test262/language/expressions/super/prop-dot-obj-null-proto.js new file mode 100644 index 0000000000..03094e0ab1 --- /dev/null +++ b/js/src/tests/test262/language/expressions/super/prop-dot-obj-null-proto.js @@ -0,0 +1,41 @@ +// 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); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/super/prop-dot-obj-ref-non-strict.js b/js/src/tests/test262/language/expressions/super/prop-dot-obj-ref-non-strict.js new file mode 100644 index 0000000000..ea3c3efd2c --- /dev/null +++ b/js/src/tests/test262/language/expressions/super/prop-dot-obj-ref-non-strict.js @@ -0,0 +1,60 @@ +// 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( + Object.prototype.hasOwnProperty.call(obj, 'x'), + "x is defined as an own property" +); +assert( + !Object.prototype.hasOwnProperty.call(obj, 'y'), + "y is not defined as an own property after the object is frozen" +); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/super/prop-dot-obj-ref-strict-strict.js b/js/src/tests/test262/language/expressions/super/prop-dot-obj-ref-strict-strict.js new file mode 100644 index 0000000000..f4e8aef8cf --- /dev/null +++ b/js/src/tests/test262/language/expressions/super/prop-dot-obj-ref-strict-strict.js @@ -0,0 +1,59 @@ +'use strict'; +// 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); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/super/prop-dot-obj-ref-this.js b/js/src/tests/test262/language/expressions/super/prop-dot-obj-ref-this.js new file mode 100644 index 0000000000..8ecc3b278f --- /dev/null +++ b/js/src/tests/test262/language/expressions/super/prop-dot-obj-ref-this.js @@ -0,0 +1,61 @@ +// 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'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/super/prop-dot-obj-val-from-arrow.js b/js/src/tests/test262/language/expressions/super/prop-dot-obj-val-from-arrow.js new file mode 100644 index 0000000000..c7eee9f550 --- /dev/null +++ b/js/src/tests/test262/language/expressions/super/prop-dot-obj-val-from-arrow.js @@ -0,0 +1,48 @@ +// 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'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/super/prop-dot-obj-val-from-eval.js b/js/src/tests/test262/language/expressions/super/prop-dot-obj-val-from-eval.js new file mode 100644 index 0000000000..ac5788d687 --- /dev/null +++ b/js/src/tests/test262/language/expressions/super/prop-dot-obj-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. +---*/ + +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'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/super/prop-dot-obj-val.js b/js/src/tests/test262/language/expressions/super/prop-dot-obj-val.js new file mode 100644 index 0000000000..429bb339ef --- /dev/null +++ b/js/src/tests/test262/language/expressions/super/prop-dot-obj-val.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 +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'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/super/prop-expr-cls-err.js b/js/src/tests/test262/language/expressions/super/prop-expr-cls-err.js new file mode 100644 index 0000000000..ddcec4c5f2 --- /dev/null +++ b/js/src/tests/test262/language/expressions/super/prop-expr-cls-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 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); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/super/prop-expr-cls-key-err.js b/js/src/tests/test262/language/expressions/super/prop-expr-cls-key-err.js new file mode 100644 index 0000000000..fe1bc2b748 --- /dev/null +++ b/js/src/tests/test262/language/expressions/super/prop-expr-cls-key-err.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: 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); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/super/prop-expr-cls-null-proto.js b/js/src/tests/test262/language/expressions/super/prop-expr-cls-null-proto.js new file mode 100644 index 0000000000..3bc2ef5db2 --- /dev/null +++ b/js/src/tests/test262/language/expressions/super/prop-expr-cls-null-proto.js @@ -0,0 +1,41 @@ +// 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); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/super/prop-expr-cls-ref-strict.js b/js/src/tests/test262/language/expressions/super/prop-expr-cls-ref-strict.js new file mode 100644 index 0000000000..2d98bdffc8 --- /dev/null +++ b/js/src/tests/test262/language/expressions/super/prop-expr-cls-ref-strict.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 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); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/super/prop-expr-cls-ref-this.js b/js/src/tests/test262/language/expressions/super/prop-expr-cls-ref-this.js new file mode 100644 index 0000000000..ba90b3758c --- /dev/null +++ b/js/src/tests/test262/language/expressions/super/prop-expr-cls-ref-this.js @@ -0,0 +1,60 @@ +// 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'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/super/prop-expr-cls-this-uninit.js b/js/src/tests/test262/language/expressions/super/prop-expr-cls-this-uninit.js new file mode 100644 index 0000000000..5e336cf3af --- /dev/null +++ b/js/src/tests/test262/language/expressions/super/prop-expr-cls-this-uninit.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 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); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/super/prop-expr-cls-unresolvable.js b/js/src/tests/test262/language/expressions/super/prop-expr-cls-unresolvable.js new file mode 100644 index 0000000000..b9f912d031 --- /dev/null +++ b/js/src/tests/test262/language/expressions/super/prop-expr-cls-unresolvable.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 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); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/super/prop-expr-cls-val-from-arrow.js b/js/src/tests/test262/language/expressions/super/prop-expr-cls-val-from-arrow.js new file mode 100644 index 0000000000..7a4ef1840e --- /dev/null +++ b/js/src/tests/test262/language/expressions/super/prop-expr-cls-val-from-arrow.js @@ -0,0 +1,48 @@ +// 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'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/super/prop-expr-cls-val-from-eval.js b/js/src/tests/test262/language/expressions/super/prop-expr-cls-val-from-eval.js new file mode 100644 index 0000000000..ada830f3fb --- /dev/null +++ b/js/src/tests/test262/language/expressions/super/prop-expr-cls-val-from-eval.js @@ -0,0 +1,48 @@ +// 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'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/super/prop-expr-cls-val.js b/js/src/tests/test262/language/expressions/super/prop-expr-cls-val.js new file mode 100644 index 0000000000..0b29e92331 --- /dev/null +++ b/js/src/tests/test262/language/expressions/super/prop-expr-cls-val.js @@ -0,0 +1,48 @@ +// 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'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/super/prop-expr-obj-err.js b/js/src/tests/test262/language/expressions/super/prop-expr-obj-err.js new file mode 100644 index 0000000000..ea3402dcca --- /dev/null +++ b/js/src/tests/test262/language/expressions/super/prop-expr-obj-err.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: 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); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/super/prop-expr-obj-key-err.js b/js/src/tests/test262/language/expressions/super/prop-expr-obj-key-err.js new file mode 100644 index 0000000000..1c70d642e7 --- /dev/null +++ b/js/src/tests/test262/language/expressions/super/prop-expr-obj-key-err.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: 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); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/super/prop-expr-obj-null-proto.js b/js/src/tests/test262/language/expressions/super/prop-expr-obj-null-proto.js new file mode 100644 index 0000000000..885a98f2d4 --- /dev/null +++ b/js/src/tests/test262/language/expressions/super/prop-expr-obj-null-proto.js @@ -0,0 +1,41 @@ +// 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); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/super/prop-expr-obj-ref-non-strict.js b/js/src/tests/test262/language/expressions/super/prop-expr-obj-ref-non-strict.js new file mode 100644 index 0000000000..eb8a13ec76 --- /dev/null +++ b/js/src/tests/test262/language/expressions/super/prop-expr-obj-ref-non-strict.js @@ -0,0 +1,60 @@ +// 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( + Object.prototype.hasOwnProperty.call(obj, 'x'), + "x is defined as an own property" +); +assert( + !Object.prototype.hasOwnProperty.call(obj, 'y'), + "y is not defined as an own property after the object is frozen" +); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/super/prop-expr-obj-ref-strict-strict.js b/js/src/tests/test262/language/expressions/super/prop-expr-obj-ref-strict-strict.js new file mode 100644 index 0000000000..98a6123ee9 --- /dev/null +++ b/js/src/tests/test262/language/expressions/super/prop-expr-obj-ref-strict-strict.js @@ -0,0 +1,59 @@ +'use strict'; +// 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); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/super/prop-expr-obj-ref-this.js b/js/src/tests/test262/language/expressions/super/prop-expr-obj-ref-this.js new file mode 100644 index 0000000000..a25a743037 --- /dev/null +++ b/js/src/tests/test262/language/expressions/super/prop-expr-obj-ref-this.js @@ -0,0 +1,61 @@ +// 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'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/super/prop-expr-obj-unresolvable.js b/js/src/tests/test262/language/expressions/super/prop-expr-obj-unresolvable.js new file mode 100644 index 0000000000..1c2dbc93cc --- /dev/null +++ b/js/src/tests/test262/language/expressions/super/prop-expr-obj-unresolvable.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: 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); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/super/prop-expr-obj-val-from-arrow.js b/js/src/tests/test262/language/expressions/super/prop-expr-obj-val-from-arrow.js new file mode 100644 index 0000000000..9d7087d80a --- /dev/null +++ b/js/src/tests/test262/language/expressions/super/prop-expr-obj-val-from-arrow.js @@ -0,0 +1,48 @@ +// 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'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/super/prop-expr-obj-val-from-eval.js b/js/src/tests/test262/language/expressions/super/prop-expr-obj-val-from-eval.js new file mode 100644 index 0000000000..c7526febb6 --- /dev/null +++ b/js/src/tests/test262/language/expressions/super/prop-expr-obj-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: | + [...] + 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'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/super/prop-expr-obj-val.js b/js/src/tests/test262/language/expressions/super/prop-expr-obj-val.js new file mode 100644 index 0000000000..b336e6ceae --- /dev/null +++ b/js/src/tests/test262/language/expressions/super/prop-expr-obj-val.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 +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'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/super/prop-poisoned-underscore-proto.js b/js/src/tests/test262/language/expressions/super/prop-poisoned-underscore-proto.js new file mode 100644 index 0000000000..435d8b877b --- /dev/null +++ b/js/src/tests/test262/language/expressions/super/prop-poisoned-underscore-proto.js @@ -0,0 +1,37 @@ +// Copyright (C) 2019 Alexey Shvayka. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: prod-SuperProperty +description: > + SuperProperty should directly call [[GetPrototypeOf]] internal method. +info: | + MakeSuperPropertyReference ( actualThis, propertyKey, strict ) + + [...] + 3. Let baseValue be ? env.GetSuperBase(). + + GetSuperBase ( ) + + [...] + 5. Return ? home.[[GetPrototypeOf]](). +---*/ + +Object.defineProperty(Object.prototype, '__proto__', { + get: function() { + throw new Test262Error('should not be called'); + }, +}); + +var obj = { + superExpression() { + return super['CONSTRUCTOR'.toLowerCase()]; + }, + superIdentifierName() { + return super.toString(); + }, +}; + +assert.sameValue(obj.superExpression(), Object); +assert.sameValue(obj.superIdentifierName(), '[object Object]'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/super/realm.js b/js/src/tests/test262/language/expressions/super/realm.js new file mode 100644 index 0000000000..2a019bf7ec --- /dev/null +++ b/js/src/tests/test262/language/expressions/super/realm.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: > + Default [[Prototype]] value derived from realm of the newTarget value +info: | + 1. Let newTarget be GetNewTarget(). + [...] + 6. Let result be ? Construct(func, argList, newTarget). + [...] + + 9.1.14 GetPrototypeFromConstructor + + [...] + 3. Let proto be ? Get(constructor, "prototype"). + 4. If Type(proto) is not Object, then + a. Let realm be ? GetFunctionRealm(constructor). + b. Let proto be realm's intrinsic object named intrinsicDefaultProto. + [...] +features: [cross-realm, Reflect] +---*/ + +var other = $262.createRealm().global; +var C = new other.Function(); +C.prototype = null; + +class B extends function() {} { + constructor() { + super(); + } +} + +var b = Reflect.construct(B, [], C); + +assert.sameValue(Object.getPrototypeOf(b), other.Object.prototype); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/super/shell.js b/js/src/tests/test262/language/expressions/super/shell.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/language/expressions/super/shell.js diff --git a/js/src/tests/test262/language/expressions/super/super-reference-resolution.js b/js/src/tests/test262/language/expressions/super/super-reference-resolution.js new file mode 100644 index 0000000000..6dba5ac52a --- /dev/null +++ b/js/src/tests/test262/language/expressions/super/super-reference-resolution.js @@ -0,0 +1,25 @@ +// Copyright (C) 2020 Rick Waldron. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-super-keyword +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] +---*/ + +class X { + method() { return this; } +} + +class Y extends X { + method() { return super.method(); } +} + +const y = new Y(); + +assert.sameValue(y.method(), y); + +reportCompare(0, 0); |