diff options
Diffstat (limited to 'js/src/tests/test262/language/statements/class/definition')
67 files changed, 2531 insertions, 0 deletions
diff --git a/js/src/tests/test262/language/statements/class/definition/accessors.js b/js/src/tests/test262/language/statements/class/definition/accessors.js new file mode 100644 index 0000000000..aea9a74946 --- /dev/null +++ b/js/src/tests/test262/language/statements/class/definition/accessors.js @@ -0,0 +1,54 @@ +// Copyright (C) 2014 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 14.5 +description: > + class accessors +---*/ + +function assertAccessorDescriptor(object, name) { + var desc = Object.getOwnPropertyDescriptor(object, name); + assert.sameValue(desc.configurable, true, "The value of `desc.configurable` is `true`"); + assert.sameValue(desc.enumerable, false, "The value of `desc.enumerable` is `false`"); + assert.sameValue(typeof desc.get, 'function', "`typeof desc.get` is `'function'`"); + assert.sameValue(typeof desc.set, 'function', "`typeof desc.set` is `'function'`"); + assert.sameValue( + 'prototype' in desc.get, + false, + "The result of `'prototype' in desc.get` is `false`" + ); + assert.sameValue( + 'prototype' in desc.set, + false, + "The result of `'prototype' in desc.set` is `false`" + ); +} + + +class C { + constructor(x) { + this._x = x; + } + + get x() { return this._x; } + set x(v) { this._x = v; } + + static get staticX() { return this._x; } + static set staticX(v) { this._x = v; } +} + +assertAccessorDescriptor(C.prototype, 'x'); +assertAccessorDescriptor(C, 'staticX'); + +var c = new C(1); +c._x = 1; +assert.sameValue(c.x, 1, "The value of `c.x` is `1`, after executing `c._x = 1;`"); +c.x = 2; +assert.sameValue(c._x, 2, "The value of `c._x` is `2`, after executing `c.x = 2;`"); + +C._x = 3; +assert.sameValue(C.staticX, 3, "The value of `C.staticX` is `3`, after executing `C._x = 3;`"); +C._x = 4; +assert.sameValue(C.staticX, 4, "The value of `C.staticX` is `4`, after executing `C._x = 4;`"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/class/definition/basics.js b/js/src/tests/test262/language/statements/class/definition/basics.js new file mode 100644 index 0000000000..bead8794e5 --- /dev/null +++ b/js/src/tests/test262/language/statements/class/definition/basics.js @@ -0,0 +1,45 @@ +// Copyright (C) 2014 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 14.5 +description: > + class basics +---*/ +var C = class C {} +assert.sameValue(typeof C, 'function', "`typeof C` is `'function'`"); +assert.sameValue( + Object.getPrototypeOf(C.prototype), + Object.prototype, + "`Object.getPrototypeOf(C.prototype)` returns `Object.prototype`" +); +assert.sameValue( + Object.getPrototypeOf(C), + Function.prototype, + "`Object.getPrototypeOf(C)` returns `Function.prototype`" +); +assert.sameValue(C.name, 'C', "The value of `C.name` is `'C'`"); + +class D {} +assert.sameValue(typeof D, 'function', "`typeof D` is `'function'`"); +assert.sameValue( + Object.getPrototypeOf(D.prototype), + Object.prototype, + "`Object.getPrototypeOf(D.prototype)` returns `Object.prototype`" +); +assert.sameValue( + Object.getPrototypeOf(D), + Function.prototype, + "`Object.getPrototypeOf(D)` returns `Function.prototype`" +); +assert.sameValue(D.name, 'D', "The value of `D.name` is `'D'`"); + +class D2 { constructor() {} } +assert.sameValue(D2.name, 'D2', "The value of `D2.name` is `'D2'`"); + +var E = class {} +assert.sameValue(E.name, 'E', "The value of `E.name` is `'E'`"); + +var F = class { constructor() {} }; +assert.sameValue(F.name, 'F', "The value of `F.name` is `'F'`"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/class/definition/browser.js b/js/src/tests/test262/language/statements/class/definition/browser.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/language/statements/class/definition/browser.js diff --git a/js/src/tests/test262/language/statements/class/definition/class-method-returns-promise.js b/js/src/tests/test262/language/statements/class/definition/class-method-returns-promise.js new file mode 100644 index 0000000000..faa55ae7a0 --- /dev/null +++ b/js/src/tests/test262/language/statements/class/definition/class-method-returns-promise.js @@ -0,0 +1,17 @@ +// Copyright 2016 Microsoft, Inc. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +author: Brian Terlson <brian.terlson@microsoft.com> +esid: pending +features: [async-functions] +description: > + Async function expressions return promises +---*/ +class Foo { + async method() {}; +} +var p = new Foo().method(); +assert(p instanceof Promise, "async functions return promise instances"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/class/definition/constructable-but-no-prototype.js b/js/src/tests/test262/language/statements/class/definition/constructable-but-no-prototype.js new file mode 100644 index 0000000000..f765200b24 --- /dev/null +++ b/js/src/tests/test262/language/statements/class/definition/constructable-but-no-prototype.js @@ -0,0 +1,13 @@ +// Copyright (C) 2014 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 14.5 +description: > + class constructable but no prototype +---*/ +var Base = function() {}.bind(); +assert.throws(TypeError, function() { + class C extends Base {} +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/class/definition/constructor-property.js b/js/src/tests/test262/language/statements/class/definition/constructor-property.js new file mode 100644 index 0000000000..d19269c38e --- /dev/null +++ b/js/src/tests/test262/language/statements/class/definition/constructor-property.js @@ -0,0 +1,19 @@ +// Copyright (C) 2014 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 14.5 +description: > + class constructor property +---*/ +class C {} +assert.sameValue( + C, + C.prototype.constructor, + "The value of `C` is `C.prototype.constructor`" +); +var desc = Object.getOwnPropertyDescriptor(C.prototype, 'constructor'); +assert.sameValue(desc.configurable, true, "The value of `desc.configurable` is `true`, after executing `var desc = Object.getOwnPropertyDescriptor(C.prototype, 'constructor');`"); +assert.sameValue(desc.enumerable, false, "The value of `desc.enumerable` is `false`, after executing `var desc = Object.getOwnPropertyDescriptor(C.prototype, 'constructor');`"); +assert.sameValue(desc.writable, true, "The value of `desc.writable` is `true`, after executing `var desc = Object.getOwnPropertyDescriptor(C.prototype, 'constructor');`"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/class/definition/constructor-strict-by-default.js b/js/src/tests/test262/language/statements/class/definition/constructor-strict-by-default.js new file mode 100644 index 0000000000..5680bfcc05 --- /dev/null +++ b/js/src/tests/test262/language/statements/class/definition/constructor-strict-by-default.js @@ -0,0 +1,17 @@ +// Copyright (C) 2014 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 14.5 +description: > + class constructor strict +---*/ +class C { + constructor() { + assert.throws(ReferenceError, function() { + nonExistingBinding = 42; + }); + } +} +new C(); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/class/definition/constructor.js b/js/src/tests/test262/language/statements/class/definition/constructor.js new file mode 100644 index 0000000000..c084dbdb29 --- /dev/null +++ b/js/src/tests/test262/language/statements/class/definition/constructor.js @@ -0,0 +1,37 @@ +// Copyright (C) 2014 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 14.5 +description: > + class constructor +---*/ +var count = 0; +class C { + constructor() { + assert.sameValue( + Object.getPrototypeOf(this), + C.prototype, + "`Object.getPrototypeOf(this)` returns `C.prototype`" + ); + count++; + } +} +assert.sameValue( + C, + C.prototype.constructor, + "The value of `C` is `C.prototype.constructor`" +); +var desc = Object.getOwnPropertyDescriptor(C.prototype, 'constructor'); +assert.sameValue(desc.configurable, true, "The value of `desc.configurable` is `true`, after executing `var desc = Object.getOwnPropertyDescriptor(C.prototype, 'constructor');`"); +assert.sameValue(desc.enumerable, false, "The value of `desc.enumerable` is `false`, after executing `var desc = Object.getOwnPropertyDescriptor(C.prototype, 'constructor');`"); +assert.sameValue(desc.writable, true, "The value of `descr.writable` is `true`, after executing `var desc = Object.getOwnPropertyDescriptor(C.prototype, 'constructor');`"); + +var c = new C(); +assert.sameValue(count, 1, "The value of `count` is `1`"); +assert.sameValue( + Object.getPrototypeOf(c), + C.prototype, + "`Object.getPrototypeOf(c)` returns `C.prototype`" +); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/class/definition/early-errors-class-async-method-duplicate-parameters.js b/js/src/tests/test262/language/statements/class/definition/early-errors-class-async-method-duplicate-parameters.js new file mode 100644 index 0000000000..58ec8e3d98 --- /dev/null +++ b/js/src/tests/test262/language/statements/class/definition/early-errors-class-async-method-duplicate-parameters.js @@ -0,0 +1,30 @@ +// |reftest| error:SyntaxError +// Copyright 2016 Microsoft, Inc. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +author: Brian Terlson <brian.terlson@microsoft.com> +esid: sec-async-function-definitions +description: Formal parameters may not contain duplicates +info: | + # 14.7 Arrow Function Definitions + + AsyncMethod[Yield, Await]: + async[no LineTerminator here]PropertyName[?Yield, ?Await](UniqueFormalParameters[~Yield, +Await]){AsyncFunctionBody} + + # 14.1.2 Static Semantics: Early Errors + + UniqueFormalParameters:FormalParameters + + - It is a Syntax Error if BoundNames of FormalParameters contains any + duplicate elements. +negative: + phase: parse + type: SyntaxError +---*/ + +$DONOTEVALUATE(); + +class Foo { + async foo(a, a) { } +} diff --git a/js/src/tests/test262/language/statements/class/definition/early-errors-class-method-NSPL-with-USD.js b/js/src/tests/test262/language/statements/class/definition/early-errors-class-method-NSPL-with-USD.js new file mode 100644 index 0000000000..49482b14a3 --- /dev/null +++ b/js/src/tests/test262/language/statements/class/definition/early-errors-class-method-NSPL-with-USD.js @@ -0,0 +1,18 @@ +// |reftest| error:SyntaxError +// Copyright 2016 Microsoft, Inc. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +author: Brian Terlson <brian.terlson@microsoft.com> +esid: pending +description: > + It is a Syntax Error if ContainsUseStrict of AsyncConciseBody is *true* and IsSimpleParameterList of ArrowParameters is *false*. +negative: + phase: parse + type: SyntaxError +---*/ + +$DONOTEVALUATE(); +class Foo { + async bar(x = 1) {"use strict"} +} diff --git a/js/src/tests/test262/language/statements/class/definition/early-errors-class-method-arguments-in-formal-parameters.js b/js/src/tests/test262/language/statements/class/definition/early-errors-class-method-arguments-in-formal-parameters.js new file mode 100644 index 0000000000..08efd9e9b6 --- /dev/null +++ b/js/src/tests/test262/language/statements/class/definition/early-errors-class-method-arguments-in-formal-parameters.js @@ -0,0 +1,17 @@ +// |reftest| error:SyntaxError +// Copyright 2016 Microsoft, Inc. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +author: Brian Terlson <brian.terlson@microsoft.com> +esid: pending +description: It is a SyntaxError if FormalParameters contains arguments +negative: + phase: parse + type: SyntaxError +---*/ + +$DONOTEVALUATE(); +class Foo { + async foo (arguments) { } +} diff --git a/js/src/tests/test262/language/statements/class/definition/early-errors-class-method-await-in-formals-default.js b/js/src/tests/test262/language/statements/class/definition/early-errors-class-method-await-in-formals-default.js new file mode 100644 index 0000000000..c4a99c4b58 --- /dev/null +++ b/js/src/tests/test262/language/statements/class/definition/early-errors-class-method-await-in-formals-default.js @@ -0,0 +1,18 @@ +// |reftest| error:SyntaxError +// Copyright 2016 Microsoft, Inc. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +author: Brian Terlson <brian.terlson@microsoft.com> +esid: pending +description: It is a SyntaxError if FormalParameters' default expressions contains await +negative: + phase: parse + type: SyntaxError +---*/ + +$DONOTEVALUATE(); +class Foo { + async foo (x = await) { } +} + diff --git a/js/src/tests/test262/language/statements/class/definition/early-errors-class-method-await-in-formals.js b/js/src/tests/test262/language/statements/class/definition/early-errors-class-method-await-in-formals.js new file mode 100644 index 0000000000..67641cd169 --- /dev/null +++ b/js/src/tests/test262/language/statements/class/definition/early-errors-class-method-await-in-formals.js @@ -0,0 +1,17 @@ +// |reftest| error:SyntaxError +// Copyright 2016 Microsoft, Inc. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +author: Brian Terlson <brian.terlson@microsoft.com> +esid: pending +description: It is a SyntaxError if FormalParameters contains await +negative: + phase: parse + type: SyntaxError +---*/ + +$DONOTEVALUATE(); +class Foo { + async foo (await) { } +} diff --git a/js/src/tests/test262/language/statements/class/definition/early-errors-class-method-body-contains-super-call.js b/js/src/tests/test262/language/statements/class/definition/early-errors-class-method-body-contains-super-call.js new file mode 100644 index 0000000000..61fc064ca4 --- /dev/null +++ b/js/src/tests/test262/language/statements/class/definition/early-errors-class-method-body-contains-super-call.js @@ -0,0 +1,17 @@ +// |reftest| error:SyntaxError +// Copyright 2016 Microsoft, Inc. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +author: Brian Terlson <brian.terlson@microsoft.com> +esid: pending +description: It is a SyntaxError if AsyncFunctionBody contains SuperCall is true +negative: + phase: parse + type: SyntaxError +---*/ + +$DONOTEVALUATE(); +class Foo { + async foo () { super() } +} diff --git a/js/src/tests/test262/language/statements/class/definition/early-errors-class-method-duplicate-parameters.js b/js/src/tests/test262/language/statements/class/definition/early-errors-class-method-duplicate-parameters.js new file mode 100644 index 0000000000..b92ae46a08 --- /dev/null +++ b/js/src/tests/test262/language/statements/class/definition/early-errors-class-method-duplicate-parameters.js @@ -0,0 +1,29 @@ +// |reftest| error:SyntaxError +// Copyright 2019 Mike Pennisi. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-method-definitions +description: Formal parameters may not contain duplicates +info: | + # 14.3 Method Definitions + + MethodDefinition[Yield, Await]: + PropertyName[?Yield, ?Await](UniqueFormalParameters[~Yield, ~Await]){FunctionBody[~Yield, ~Await]} + + # 14.1.2 Static Semantics: Early Errors + + UniqueFormalParameters:FormalParameters + + - It is a Syntax Error if BoundNames of FormalParameters contains any + duplicate elements. +negative: + phase: parse + type: SyntaxError +---*/ + +$DONOTEVALUATE(); + +class Foo { + foo(a, a) { } +} diff --git a/js/src/tests/test262/language/statements/class/definition/early-errors-class-method-eval-in-formal-parameters.js b/js/src/tests/test262/language/statements/class/definition/early-errors-class-method-eval-in-formal-parameters.js new file mode 100644 index 0000000000..16f456926e --- /dev/null +++ b/js/src/tests/test262/language/statements/class/definition/early-errors-class-method-eval-in-formal-parameters.js @@ -0,0 +1,17 @@ +// |reftest| error:SyntaxError +// Copyright 2016 Microsoft, Inc. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +author: Brian Terlson <brian.terlson@microsoft.com> +esid: pending +description: It is a SyntaxError if FormalParameters contains eval in strict mode +negative: + phase: parse + type: SyntaxError +---*/ + +$DONOTEVALUATE(); +class Foo { + async foo(eval) { } +} diff --git a/js/src/tests/test262/language/statements/class/definition/early-errors-class-method-formals-body-duplicate.js b/js/src/tests/test262/language/statements/class/definition/early-errors-class-method-formals-body-duplicate.js new file mode 100644 index 0000000000..e1986d88ac --- /dev/null +++ b/js/src/tests/test262/language/statements/class/definition/early-errors-class-method-formals-body-duplicate.js @@ -0,0 +1,19 @@ +// |reftest| error:SyntaxError +// Copyright 2016 Microsoft, Inc. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +author: Brian Terlson <brian.terlson@microsoft.com> +esid: pending +description: > + It is a SyntaxError if BoundNames of FormalParameters also occurs in the LexicallyDeclaredNames of AsyncFunctionBody +negative: + phase: parse + type: SyntaxError +---*/ + +$DONOTEVALUATE(); + +class Foo { + async function foo(bar) { let bar; } +} diff --git a/js/src/tests/test262/language/statements/class/definition/early-errors-class-method-formals-contains-super-call.js b/js/src/tests/test262/language/statements/class/definition/early-errors-class-method-formals-contains-super-call.js new file mode 100644 index 0000000000..ebcc041b35 --- /dev/null +++ b/js/src/tests/test262/language/statements/class/definition/early-errors-class-method-formals-contains-super-call.js @@ -0,0 +1,17 @@ +// |reftest| error:SyntaxError +// Copyright 2016 Microsoft, Inc. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +author: Brian Terlson <brian.terlson@microsoft.com> +esid: pending +description: It is a syntax error if FormalParameters contains SuperCall is true +negative: + phase: parse + type: SyntaxError +---*/ + +$DONOTEVALUATE(); +class Foo { + async foo(foo = super()) { } +} diff --git a/js/src/tests/test262/language/statements/class/definition/fn-length-static-precedence-order.js b/js/src/tests/test262/language/statements/class/definition/fn-length-static-precedence-order.js new file mode 100644 index 0000000000..ec6501c61f --- /dev/null +++ b/js/src/tests/test262/language/statements/class/definition/fn-length-static-precedence-order.js @@ -0,0 +1,74 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-runtime-semantics-classdefinitionevaluation +description: > + Function `length` attribute not inferred in presence of static `length` method +info: | + ClassTail : ClassHeritage_opt { ClassBody_opt } + + 14. If constructor is empty, then [...] + b. Let F be ! CreateBuiltinFunction(steps, 0, className, « [[ConstructorKind]], [[SourceText]] », empty, constructorParent). + 15. Else, + a. Let constructorInfo be ! DefineMethod of constructor with arguments proto and constructorParent. + [ This sets the length property on constructorInfo.[[Closure]]. ] + b. Let F be constructorInfo.[[Closure]]. + [...] + 25. For each ClassElement e of elements, do + a. If IsStatic of e is false, then [...] + b. Else, + i. Let field be ClassElementEvaluation of e with arguments F and false. + [ This overwrites the length property on F. ] +includes: [compareArray.js] +features: [generators] +---*/ + +class A { + static method() { + throw new Test262Error('Static method should not be executed during definition'); + } + static length() { + throw new Test262Error('Static method should not be executed during definition'); + } +} + +assert.compareArray(Object.getOwnPropertyNames(A), ['length', 'name', 'prototype', 'method']) + +var attr = 'length'; +class B { + static [attr]() { + throw new Test262Error( + 'Static method defined via computed property should not be executed ' + + 'during definition' + ); + } +} + +assert.compareArray(Object.getOwnPropertyNames(B), ['length', 'name', 'prototype']) + +class C { + static get length() { + throw new Test262Error('Static `get` accessor should not be executed during definition'); + } +} + +assert.compareArray(Object.getOwnPropertyNames(C), ['length', 'name', 'prototype']) + +class D { + static set length(_) { + throw new Test262Error('Static `set` accessor should not be executed during definition'); + } +} + +assert.compareArray(Object.getOwnPropertyNames(D), ['length', 'name', 'prototype']) + +class E { + static *length() { + throw new Test262Error('Static GeneratorMethod should not be executed during definition'); + } +} + +assert.compareArray(Object.getOwnPropertyNames(E), ['length', 'name', 'prototype']) + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/class/definition/fn-length-static-precedence.js b/js/src/tests/test262/language/statements/class/definition/fn-length-static-precedence.js new file mode 100644 index 0000000000..51ac1bf7aa --- /dev/null +++ b/js/src/tests/test262/language/statements/class/definition/fn-length-static-precedence.js @@ -0,0 +1,78 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-runtime-semantics-classdefinitionevaluation +description: > + Function `length` attribute not inferred in presence of static `length` method +info: | + ClassTail : ClassHeritage_opt { ClassBody_opt } + + 14. If constructor is empty, then [...] + b. Let F be ! CreateBuiltinFunction(steps, 0, className, « [[ConstructorKind]], [[SourceText]] », empty, constructorParent). + 15. Else, + a. Let constructorInfo be ! DefineMethod of constructor with arguments proto and constructorParent. + [ This sets the length property on constructorInfo.[[Closure]]. ] + b. Let F be constructorInfo.[[Closure]]. + [...] + 25. For each ClassElement e of elements, do + a. If IsStatic of e is false, then [...] + b. Else, + i. Let field be ClassElementEvaluation of e with arguments F and false. + [ This overwrites the length property on F. ] +features: [generators] +---*/ + +class A { + static method() { + throw new Test262Error('Static method should not be executed during definition'); + } + static length() { + throw new Test262Error('Static method should not be executed during definition'); + } +} + +assert.sameValue(typeof A.length, 'function'); + +var attr = 'length'; +class B { + static [attr]() { + throw new Test262Error( + 'Static method defined via computed property should not be executed ' + + 'during definition' + ); + } +} + +assert.sameValue(typeof B.length, 'function'); + +var isDefined = false; +class C { + static get length() { + if (isDefined) { + return 'pass'; + } + throw new Test262Error('Static `get` accessor should not be executed during definition'); + } +} + +isDefined = true; +assert.sameValue(C.length, 'pass'); + +class D { + static set length(_) { + throw new Test262Error('Static `set` accessor should not be executed during definition'); + } +} + +assert.sameValue(D.length, undefined); + +class E { + static *length() { + throw new Test262Error('Static GeneratorMethod should not be executed during definition'); + } +} + +assert.sameValue(typeof E.length, 'function'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/class/definition/fn-name-accessor-get.js b/js/src/tests/test262/language/statements/class/definition/fn-name-accessor-get.js new file mode 100644 index 0000000000..8d329f0de5 --- /dev/null +++ b/js/src/tests/test262/language/statements/class/definition/fn-name-accessor-get.js @@ -0,0 +1,65 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +es6id: 14.3.9 +description: Assignment of function `name` attribute ("get" accessor) +info: | + MethodDefinition : get PropertyName ( ) { FunctionBody } + + [...] + 8. Perform SetFunctionName(closure, propKey, "get"). +includes: [propertyHelper.js] +features: [Symbol] +---*/ + +var namedSym = Symbol('test262'); +var anonSym = Symbol(); +var getter; + +class A { + get id() {} + get [anonSym]() {} + get [namedSym]() {} + static get id() {} + static get [anonSym]() {} + static get [namedSym]() {} +} + +getter = Object.getOwnPropertyDescriptor(A.prototype, 'id').get; +assert.sameValue(getter.name, 'get id'); +verifyNotEnumerable(getter, 'name'); +verifyNotWritable(getter, 'name'); +verifyConfigurable(getter, 'name'); + +getter = Object.getOwnPropertyDescriptor(A.prototype, anonSym).get; +assert.sameValue(getter.name, 'get '); +verifyNotEnumerable(getter, 'name'); +verifyNotWritable(getter, 'name'); +verifyConfigurable(getter, 'name'); + +getter = Object.getOwnPropertyDescriptor(A.prototype, namedSym).get; +assert.sameValue(getter.name, 'get [test262]'); +verifyNotEnumerable(getter, 'name'); +verifyNotWritable(getter, 'name'); +verifyConfigurable(getter, 'name'); + +getter = Object.getOwnPropertyDescriptor(A, 'id').get; +assert.sameValue(getter.name, 'get id'); +verifyNotEnumerable(getter, 'name'); +verifyNotWritable(getter, 'name'); +verifyConfigurable(getter, 'name'); + +getter = Object.getOwnPropertyDescriptor(A, anonSym).get; +assert.sameValue(getter.name, 'get '); +verifyNotEnumerable(getter, 'name'); +verifyNotWritable(getter, 'name'); +verifyConfigurable(getter, 'name'); + +getter = Object.getOwnPropertyDescriptor(A, namedSym).get; +assert.sameValue(getter.name, 'get [test262]'); +verifyNotEnumerable(getter, 'name'); +verifyNotWritable(getter, 'name'); +verifyConfigurable(getter, 'name'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/class/definition/fn-name-accessor-set.js b/js/src/tests/test262/language/statements/class/definition/fn-name-accessor-set.js new file mode 100644 index 0000000000..22d97ca844 --- /dev/null +++ b/js/src/tests/test262/language/statements/class/definition/fn-name-accessor-set.js @@ -0,0 +1,66 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +es6id: 14.3.9 +description: Assignment of function `name` attribute ("set" accessor) +info: | + MethodDefinition : + set PropertyName ( PropertySetParameterList ) { FunctionBody } + + [...] + 7. Perform SetFunctionName(closure, propKey, "set"). +includes: [propertyHelper.js] +features: [Symbol] +---*/ + +var namedSym = Symbol('test262'); +var anonSym = Symbol(); +var setter; + +class A { + set id(_) {} + set [anonSym](_) {} + set [namedSym](_) {} + static set id(_) {} + static set [anonSym](_) {} + static set [namedSym](_) {} +} + +setter = Object.getOwnPropertyDescriptor(A.prototype, 'id').set; +assert.sameValue(setter.name, 'set id'); +verifyNotEnumerable(setter, 'name'); +verifyNotWritable(setter, 'name'); +verifyConfigurable(setter, 'name'); + +setter = Object.getOwnPropertyDescriptor(A.prototype, anonSym).set; +assert.sameValue(setter.name, 'set '); +verifyNotEnumerable(setter, 'name'); +verifyNotWritable(setter, 'name'); +verifyConfigurable(setter, 'name'); + +setter = Object.getOwnPropertyDescriptor(A.prototype, namedSym).set; +assert.sameValue(setter.name, 'set [test262]'); +verifyNotEnumerable(setter, 'name'); +verifyNotWritable(setter, 'name'); +verifyConfigurable(setter, 'name'); + +setter = Object.getOwnPropertyDescriptor(A, 'id').set; +assert.sameValue(setter.name, 'set id'); +verifyNotEnumerable(setter, 'name'); +verifyNotWritable(setter, 'name'); +verifyConfigurable(setter, 'name'); + +setter = Object.getOwnPropertyDescriptor(A, anonSym).set; +assert.sameValue(setter.name, 'set '); +verifyNotEnumerable(setter, 'name'); +verifyNotWritable(setter, 'name'); +verifyConfigurable(setter, 'name'); + +setter = Object.getOwnPropertyDescriptor(A, namedSym).set; +assert.sameValue(setter.name, 'set [test262]'); +verifyNotEnumerable(setter, 'name'); +verifyNotWritable(setter, 'name'); +verifyConfigurable(setter, 'name'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/class/definition/fn-name-gen-method.js b/js/src/tests/test262/language/statements/class/definition/fn-name-gen-method.js new file mode 100644 index 0000000000..f6bb4781af --- /dev/null +++ b/js/src/tests/test262/language/statements/class/definition/fn-name-gen-method.js @@ -0,0 +1,60 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +es6id: 14.4.13 +description: > + Assignment of function `name` attribute (GeneratorMethod) +info: | + GeneratorMethod : + * PropertyName ( StrictFormalParameters ) { GeneratorBody } + + [...] + 9. Perform SetFunctionName(closure, propKey). +includes: [propertyHelper.js] +features: [generators, Symbol] +---*/ + +var namedSym = Symbol('test262'); +var anonSym = Symbol(); + +class A { + *id() {} + *[anonSym]() {} + *[namedSym]() {} + static *id() {} + static *[anonSym]() {} + static *[namedSym]() {} +} + +assert.sameValue(A.prototype.id.name, 'id', 'via IdentifierName'); +verifyNotEnumerable(A.prototype.id, 'name'); +verifyNotWritable(A.prototype.id, 'name'); +verifyConfigurable(A.prototype.id, 'name'); + +assert.sameValue(A.prototype[anonSym].name, '', 'via anonymous Symbol'); +verifyNotEnumerable(A.prototype[anonSym], 'name'); +verifyNotWritable(A.prototype[anonSym], 'name'); +verifyConfigurable(A.prototype[anonSym], 'name'); + +assert.sameValue(A.prototype[namedSym].name, '[test262]', 'via Symbol'); +verifyNotEnumerable(A.prototype[namedSym], 'name'); +verifyNotWritable(A.prototype[namedSym], 'name'); +verifyConfigurable(A.prototype[namedSym], 'name'); + +assert.sameValue(A.id.name, 'id', 'static via IdentifierName'); +verifyNotEnumerable(A.id, 'name'); +verifyNotWritable(A.id, 'name'); +verifyConfigurable(A.id, 'name'); + +assert.sameValue(A[anonSym].name, '', 'static via anonymous Symbol'); +verifyNotEnumerable(A[anonSym], 'name'); +verifyNotWritable(A[anonSym], 'name'); +verifyConfigurable(A[anonSym], 'name'); + +assert.sameValue(A[namedSym].name, '[test262]', 'static via Symbol'); +verifyNotEnumerable(A[namedSym], 'name'); +verifyNotWritable(A[namedSym], 'name'); +verifyConfigurable(A[namedSym], 'name'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/class/definition/fn-name-method.js b/js/src/tests/test262/language/statements/class/definition/fn-name-method.js new file mode 100644 index 0000000000..f01641f5c0 --- /dev/null +++ b/js/src/tests/test262/language/statements/class/definition/fn-name-method.js @@ -0,0 +1,59 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +es6id: 12.2.6.9 +description: Assignment of function `name` attribute (MethodDefinition) +info: | + 6. If IsAnonymousFunctionDefinition(AssignmentExpression) is true, then + a. Let hasNameProperty be HasOwnProperty(propValue, "name"). + b. ReturnIfAbrupt(hasNameProperty). + c. If hasNameProperty is false, perform SetFunctionName(propValue, + propKey). +includes: [propertyHelper.js] +features: [Symbol] +---*/ + +var namedSym = Symbol('test262'); +var anonSym = Symbol(); + +class A { + id() {} + [anonSym]() {} + [namedSym]() {} + static id() {} + static [anonSym]() {} + static [namedSym]() {} +} + +assert.sameValue(A.prototype.id.name, 'id', 'via IdentifierName'); +verifyNotEnumerable(A.prototype.id, 'name'); +verifyNotWritable(A.prototype.id, 'name'); +verifyConfigurable(A.prototype.id, 'name'); + +assert.sameValue(A.prototype[anonSym].name, '', 'via anonymous Symbol'); +verifyNotEnumerable(A.prototype[anonSym], 'name'); +verifyNotWritable(A.prototype[anonSym], 'name'); +verifyConfigurable(A.prototype[anonSym], 'name'); + +assert.sameValue(A.prototype[namedSym].name, '[test262]', 'via Symbol'); +verifyNotEnumerable(A.prototype[namedSym], 'name'); +verifyNotWritable(A.prototype[namedSym], 'name'); +verifyConfigurable(A.prototype[namedSym], 'name'); + +assert.sameValue(A.id.name, 'id', 'static via IdentifierName'); +verifyNotEnumerable(A.id, 'name'); +verifyNotWritable(A.id, 'name'); +verifyConfigurable(A.id, 'name'); + +assert.sameValue(A[anonSym].name, '', 'static via anonymous Symbol'); +verifyNotEnumerable(A[anonSym], 'name'); +verifyNotWritable(A[anonSym], 'name'); +verifyConfigurable(A[anonSym], 'name'); + +assert.sameValue(A[namedSym].name, '[test262]', 'static via Symbol'); +verifyNotEnumerable(A[namedSym], 'name'); +verifyNotWritable(A[namedSym], 'name'); +verifyConfigurable(A[namedSym], 'name'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/class/definition/fn-name-static-precedence-order.js b/js/src/tests/test262/language/statements/class/definition/fn-name-static-precedence-order.js new file mode 100644 index 0000000000..b9e64a64b6 --- /dev/null +++ b/js/src/tests/test262/language/statements/class/definition/fn-name-static-precedence-order.js @@ -0,0 +1,71 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-runtime-semantics-classdefinitionevaluation +description: > + Function `name` attribute not inferred in presence of static `name` method +info: | + ClassTail : ClassHeritage_opt { ClassBody_opt } + + 14. If constructor is empty, then [...] + b. Let F be ! CreateBuiltinFunction(steps, 0, className, « [[ConstructorKind]], [[SourceText]] », empty, constructorParent). + 15. Else, [...] + d. Perform ! SetFunctionName(F, className). + 25. For each ClassElement e of elements, do + a. If IsStatic of e is false, then [...] + b. Else, + i. Let field be ClassElementEvaluation of e with arguments F and false. + [ This overwrites the name property on F. ] +includes: [compareArray.js] +features: [generators] +---*/ + +class A { + static method() { + throw new Test262Error('Static method should not be executed during definition'); + } + static name() { + throw new Test262Error('Static method should not be executed during definition'); + } +} + +assert.compareArray(Object.getOwnPropertyNames(A), ['length', 'name', 'prototype', 'method']) + +var attr = 'name'; +class B { + static [attr]() { + throw new Test262Error( + 'Static method defined via computed property should not be executed ' + + 'during definition' + ); + } +} + +assert.compareArray(Object.getOwnPropertyNames(B), ['length', 'name', 'prototype']) + +class C { + static get name() { + throw new Test262Error('Static `get` accessor should not be executed during definition'); + } +} + +assert.compareArray(Object.getOwnPropertyNames(C), ['length', 'name', 'prototype']) + +class D { + static set name(_) { + throw new Test262Error('Static `set` accessor should not be executed during definition'); + } +} + +assert.compareArray(Object.getOwnPropertyNames(D), ['length', 'name', 'prototype']) + +class E { + static *name() { + throw new Test262Error('Static GeneratorMethod should not be executed during definition'); + } +} + +assert.compareArray(Object.getOwnPropertyNames(E), ['length', 'name', 'prototype']) + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/class/definition/fn-name-static-precedence.js b/js/src/tests/test262/language/statements/class/definition/fn-name-static-precedence.js new file mode 100644 index 0000000000..0521ae7681 --- /dev/null +++ b/js/src/tests/test262/language/statements/class/definition/fn-name-static-precedence.js @@ -0,0 +1,75 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-runtime-semantics-classdefinitionevaluation +description: > + Function `name` attribute not inferred in presence of static `name` method +info: | + ClassTail : ClassHeritage_opt { ClassBody_opt } + + 14. If constructor is empty, then [...] + b. Let F be ! CreateBuiltinFunction(steps, 0, className, « [[ConstructorKind]], [[SourceText]] », empty, constructorParent). + 15. Else, [...] + d. Perform ! SetFunctionName(F, className). + 25. For each ClassElement e of elements, do + a. If IsStatic of e is false, then [...] + b. Else, + i. Let field be ClassElementEvaluation of e with arguments F and false. + [ This overwrites the name property on F. ] +features: [generators] +---*/ + +class A { + static method() { + throw new Test262Error('Static method should not be executed during definition'); + } + static name() { + throw new Test262Error('Static method should not be executed during definition'); + } +} + +assert.sameValue(typeof A.name, 'function'); + +var attr = 'name'; +class B { + static [attr]() { + throw new Test262Error( + 'Static method defined via computed property should not be executed ' + + 'during definition' + ); + } +} + +assert.sameValue(typeof B.name, 'function'); + +var isDefined = false; +class C { + static get name() { + if (isDefined) { + return 'pass'; + } + throw new Test262Error('Static `get` accessor should not be executed during definition'); + } +} + +isDefined = true; +assert.sameValue(C.name, 'pass'); + +class D { + static set name(_) { + throw new Test262Error('Static `set` accessor should not be executed during definition'); + } +} + +assert.sameValue(D.name, undefined); + +class E { + static *name() { + throw new Test262Error('Static GeneratorMethod should not be executed during definition'); + } +} + +assert.sameValue(typeof E.name, 'function'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/class/definition/getters-non-configurable-err.js b/js/src/tests/test262/language/statements/class/definition/getters-non-configurable-err.js new file mode 100644 index 0000000000..90745ff901 --- /dev/null +++ b/js/src/tests/test262/language/statements/class/definition/getters-non-configurable-err.js @@ -0,0 +1,19 @@ +// 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-method-definitions-runtime-semantics-propertydefinitionevaluation +es6id: 14.3.9 +description: Failure to define property for static method +info: | + [...] + 9. Let desc be the PropertyDescriptor{[[Get]]: closure, [[Enumerable]]: + enumerable, [[Configurable]]: true}. + 10. Return ? DefinePropertyOrThrow(object, propKey, desc). +features: [generators] +---*/ + +assert.throws(TypeError, function() { + class C { static get ['prototype']() {} } +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/class/definition/getters-prop-desc.js b/js/src/tests/test262/language/statements/class/definition/getters-prop-desc.js new file mode 100644 index 0000000000..f541118067 --- /dev/null +++ b/js/src/tests/test262/language/statements/class/definition/getters-prop-desc.js @@ -0,0 +1,36 @@ +// Copyright (C) 2014 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-class-definitions +es6id: 14.5 +description: Class methods - "get" accessors +includes: [propertyHelper.js] +---*/ + +function assertGetterDescriptor(object, name) { + var desc = Object.getOwnPropertyDescriptor(object, name); + verifyNotEnumerable(object, name); + verifyConfigurable(object, name); + assert.sameValue(typeof desc.get, 'function', "`typeof desc.get` is `'function'`"); + assert.sameValue('prototype' in desc.get, false, "The result of `'prototype' in desc.get` is `false`"); + assert.sameValue(desc.set, undefined, "The value of `desc.set` is `undefined`"); +} + +class C { + get x() { return 1; } + static get staticX() { return 2; } + get y() { return 3; } + static get staticY() { return 4; } +} + +assert.sameValue(new C().x, 1, "The value of `new C().x` is `1`. Defined as `get x() { return 1; }`"); +assert.sameValue(C.staticX, 2, "The value of `C.staticX` is `2`. Defined as `static get staticX() { return 2; }`"); +assert.sameValue(new C().y, 3, "The value of `new C().y` is `3`. Defined as `get y() { return 3; }`"); +assert.sameValue(C.staticY, 4, "The value of `C.staticY` is `4`. Defined as `static get staticY() { return 4; }`"); + +assertGetterDescriptor(C.prototype, 'x'); +assertGetterDescriptor(C.prototype, 'y'); +assertGetterDescriptor(C, 'staticX'); +assertGetterDescriptor(C, 'staticY'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/class/definition/getters-restricted-ids.js b/js/src/tests/test262/language/statements/class/definition/getters-restricted-ids.js new file mode 100644 index 0000000000..ab41252801 --- /dev/null +++ b/js/src/tests/test262/language/statements/class/definition/getters-restricted-ids.js @@ -0,0 +1,28 @@ +// Copyright (C) 2014 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 14.5 +description: > + class getters 2 +---*/ +class C { + get eval() { + return 1; + } + get arguments() { + return 2; + } + static get eval() { + return 3; + } + static get arguments() { + return 4; + } +}; + +assert.sameValue(new C().eval, 1, "The value of `new C().eval` is `1`"); +assert.sameValue(new C().arguments, 2, "The value of `new C().arguments` is `2`"); +assert.sameValue(C.eval, 3, "The value of `C.eval` is `3`"); +assert.sameValue(C.arguments, 4, "The value of `C.arguments` is `4`"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/class/definition/implicit-constructor.js b/js/src/tests/test262/language/statements/class/definition/implicit-constructor.js new file mode 100644 index 0000000000..1d9d689c48 --- /dev/null +++ b/js/src/tests/test262/language/statements/class/definition/implicit-constructor.js @@ -0,0 +1,16 @@ +// Copyright (C) 2014 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 14.5 +description: > + class implicit constructor +---*/ +class C {} +var c = new C(); +assert.sameValue( + Object.getPrototypeOf(c), + C.prototype, + "`Object.getPrototypeOf(c)` returns `C.prototype`" +); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/class/definition/invalid-extends.js b/js/src/tests/test262/language/statements/class/definition/invalid-extends.js new file mode 100644 index 0000000000..3bd1f15781 --- /dev/null +++ b/js/src/tests/test262/language/statements/class/definition/invalid-extends.js @@ -0,0 +1,23 @@ +// Copyright (C) 2014 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 14.5 +description: > + class invalid extends +---*/ +assert.throws(TypeError, function() { + class C extends 42 {} +}); + +assert.throws(TypeError, function() { + // Function but its .prototype is not null or a function. + class C extends Math.abs {} +}); + +assert.throws(TypeError, function() { + Math.abs.prototype = 42; + class C extends Math.abs {} +}); +delete Math.abs.prototype; + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/class/definition/methods-async-super-call-body.js b/js/src/tests/test262/language/statements/class/definition/methods-async-super-call-body.js new file mode 100644 index 0000000000..36930de14e --- /dev/null +++ b/js/src/tests/test262/language/statements/class/definition/methods-async-super-call-body.js @@ -0,0 +1,27 @@ +// |reftest| async +// Copyright 2016 Microsoft, Inc. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +author: Brian Terlson <brian.terlson@microsoft.com> +esid: pending +description: > + Super calls work in body of async methods +flags: [async] +features: [async-functions] +---*/ +class A { + async method() { + return 'sup'; + } +} + +class B extends A { + async method() { + var x = await super.method(); + assert.sameValue(x, 'sup'); + } +} +var child = new B(); +child.method().then($DONE, $DONE); + diff --git a/js/src/tests/test262/language/statements/class/definition/methods-async-super-call-param.js b/js/src/tests/test262/language/statements/class/definition/methods-async-super-call-param.js new file mode 100644 index 0000000000..a2ca86be8d --- /dev/null +++ b/js/src/tests/test262/language/statements/class/definition/methods-async-super-call-param.js @@ -0,0 +1,26 @@ +// |reftest| async +// Copyright 2016 Microsoft, Inc. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +author: Brian Terlson <brian.terlson@microsoft.com> +esid: pending +description: > + Super calls work in the parameter list of async methods +flags: [async] +features: [async-functions] +---*/ + +class A { + async method() { + return 'sup'; + } +} + +class B extends A { + async method(x = super.method()) { + assert.sameValue(await x, 'sup'); + } +} +var child = new B(); +child.method().then($DONE, $DONE); diff --git a/js/src/tests/test262/language/statements/class/definition/methods-gen-no-yield.js b/js/src/tests/test262/language/statements/class/definition/methods-gen-no-yield.js new file mode 100644 index 0000000000..8979af1c48 --- /dev/null +++ b/js/src/tests/test262/language/statements/class/definition/methods-gen-no-yield.js @@ -0,0 +1,22 @@ +// Copyright (C) 2013 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- + description: > + Generators declared with GeneratorMethod syntax do not require a + `yield` expression. + features: [generators] + es6id: 14.4 +---*/ + +var result; +class A { + *foo(a) {} +} + +result = A.prototype.foo(3).next(); + +assert.sameValue(result.value, undefined); +assert.sameValue(result.done, true); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/class/definition/methods-gen-return.js b/js/src/tests/test262/language/statements/class/definition/methods-gen-return.js new file mode 100644 index 0000000000..06d4d4cddb --- /dev/null +++ b/js/src/tests/test262/language/statements/class/definition/methods-gen-return.js @@ -0,0 +1,25 @@ +// Copyright (C) 2013 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- + description: > + `return` is a valid statement within generator function bodies. + features: [generators] + es6id: 14.4 +---*/ + +var result; +class A { + *g1() { return; } + *g2() { return 1; } +} + +result = A.prototype.g1().next(); +assert.sameValue(result.value, undefined); +assert.sameValue(result.done, true); + +result = A.prototype.g2().next(); +assert.sameValue(result.value, 1); +assert.sameValue(result.done, true); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/class/definition/methods-gen-yield-as-expression-with-rhs.js b/js/src/tests/test262/language/statements/class/definition/methods-gen-yield-as-expression-with-rhs.js new file mode 100644 index 0000000000..953152207c --- /dev/null +++ b/js/src/tests/test262/language/statements/class/definition/methods-gen-yield-as-expression-with-rhs.js @@ -0,0 +1,120 @@ +// Copyright (C) 2013 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- + description: > + `yield` is a valid expression within generator function bodies. + features: [generators] + es6id: 14.4 +---*/ + +var iter, result; +class A { + *g1() { (yield 1) } + *g2() { [yield 1] } + *g3() { {yield 1} } + *g4() { yield 1, yield 2; } + *g5() { (yield 1) ? yield 2 : yield 3; } +} + +iter = A.prototype.g1(); +result = iter.next(); +assert.sameValue(result.value, 1, 'Within grouping operator: result `value`'); +assert.sameValue( + result.done, false, 'Within grouping operator: result `done` flag' +); +result = iter.next(); +assert.sameValue( + result.value, undefined, 'Following grouping operator: result `value`' +); +assert.sameValue( + result.done, true, 'Following grouping operator: result `done` flag' +); + +iter = A.prototype.g2(); +result = iter.next(); +assert.sameValue(result.value, 1, 'Within array literal: result `value`'); +assert.sameValue( + result.done, false, 'Within array literal: result `done` flag' +); +result = iter.next(); +assert.sameValue( + result.value, undefined, 'Following array literal: result `value`' +); +assert.sameValue( + result.done, true, 'Following array literal: result `done` flag' +); + +iter = A.prototype.g3(); +result = iter.next(); +assert.sameValue(result.value, 1, 'Within object literal: result `value`'); +assert.sameValue( + result.done, false, 'Within object literal: result `done` flag' +); +result = iter.next(); +assert.sameValue( + result.value, undefined, 'Following object literal: result `value`' +); +assert.sameValue( + result.done, true, 'Following object literal: result `done` flag' +); + +iter = A.prototype.g4(); +result = iter.next(); +assert.sameValue( + result.value, 1, 'First expression in comma expression: result `value`' +); +assert.sameValue( + result.done, + false, + 'First expression in comma expression: result `done` flag' +); +result = iter.next(); +assert.sameValue( + result.value, 2, 'Second expression in comma expression: result `value`' +); +assert.sameValue( + result.done, + false, + 'Second expression in comma expression: result `done` flag' +); +result = iter.next(); +assert.sameValue( + result.value, undefined, 'Following comma expression: result `value`' +); +assert.sameValue( + result.done, true, 'Following comma expression: result `done` flag' +); + +iter = A.prototype.g5(); +result = iter.next(); +assert.sameValue( + result.value, + 1, + 'Conditional expression in conditional operator: result `value`' +); +assert.sameValue( + result.done, + false, + 'Conditional expression in conditional operator: result `done` flag' +); +result = iter.next(); +assert.sameValue( + result.value, + 3, + 'Branch in conditional operator: result `value`' +); +assert.sameValue( + result.done, + false, + 'Branch in conditional operator: result `done` flag' +); +result = iter.next(); +assert.sameValue( + result.value, undefined, 'Following conditional operator: result `value`' +); +assert.sameValue( + result.done, true, 'Following conditional operator: result `done` flag' +); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/class/definition/methods-gen-yield-as-expression-without-rhs.js b/js/src/tests/test262/language/statements/class/definition/methods-gen-yield-as-expression-without-rhs.js new file mode 100644 index 0000000000..b42c406358 --- /dev/null +++ b/js/src/tests/test262/language/statements/class/definition/methods-gen-yield-as-expression-without-rhs.js @@ -0,0 +1,130 @@ +// Copyright (C) 2013 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- + description: > + `yield` is a valid expression within generator function bodies. + features: [generators] + es6id: 14.4 +---*/ + +var iter, result; +class A { + *g1() { (yield) } + *g2() { [yield] } + *g3() { {yield} } + *g4() { yield, yield; } + *g5() { (yield) ? yield : yield; } +} + +iter = A.prototype.g1(); +result = iter.next(); +assert.sameValue( + result.value, undefined, 'Within grouping operator: result `value`' +); +assert.sameValue( + result.done, false, 'Within grouping operator: result `done` flag' +); +result = iter.next(); +assert.sameValue( + result.value, undefined, 'Following grouping operator: result `value`' +); +assert.sameValue( + result.done, true, 'Following grouping operator: result `done` flag' +); + +iter = A.prototype.g2(); +result = iter.next(); +assert.sameValue( + result.value, undefined, 'Within array literal: result `value`' +); +assert.sameValue( + result.done, false, 'Within array literal: result `done` flag' +); +result = iter.next(); +assert.sameValue( + result.value, undefined, 'Following array literal: result `value`' +); +assert.sameValue( + result.done, true, 'Following array literal: result `done` flag' +); + +iter = A.prototype.g3(); +result = iter.next(); +assert.sameValue( + result.value, undefined, 'Within object literal: result `value`' +); +assert.sameValue( + result.done, false, 'Within object literal: result `done` flag' +); +result = iter.next(); +assert.sameValue( + result.value, undefined, 'Following object literal: result `value`' +); +assert.sameValue( + result.done, true, 'Following object literal: result `done` flag' +); + +iter = A.prototype.g4(); +result = iter.next(); +assert.sameValue( + result.value, + undefined, + 'First expression in comma expression: result `value`' +); +assert.sameValue( + result.done, + false, + 'First expression in comma expression: result `done` flag' +); +result = iter.next(); +assert.sameValue( + result.value, + undefined, + 'Second expression in comma expression: result `value`' +); +assert.sameValue( + result.done, + false, + 'Second expression in comma expression: result `done` flag' +); +result = iter.next(); +assert.sameValue( + result.value, undefined, 'Following comma expression: result `value`' +); +assert.sameValue( + result.done, true, 'Following comma expression: result `done` flag' +); + +iter = A.prototype.g5(); +result = iter.next(); +assert.sameValue( + result.value, + undefined, + 'Conditional expression in conditional operator: result `value`' +); +assert.sameValue( + result.done, + false, + 'Conditional expression in conditional operator: result `done` flag' +); +result = iter.next(); +assert.sameValue( + result.value, + undefined, + 'Branch in conditional operator: result `value`' +); +assert.sameValue( + result.done, + false, + 'Branch in conditional operator: result `done` flag' +); +result = iter.next(); +assert.sameValue( + result.value, undefined, 'Following conditional operator: result `value`' +); +assert.sameValue( + result.done, true, 'Following conditional operator: result `done` flag' +); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/class/definition/methods-gen-yield-as-function-expression-binding-identifier.js b/js/src/tests/test262/language/statements/class/definition/methods-gen-yield-as-function-expression-binding-identifier.js new file mode 100644 index 0000000000..40ef23222f --- /dev/null +++ b/js/src/tests/test262/language/statements/class/definition/methods-gen-yield-as-function-expression-binding-identifier.js @@ -0,0 +1,22 @@ +// |reftest| error:SyntaxError +// Copyright (C) 2013 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- + description: > + `yield` may not be used as the binding identifier of a function + expression within classes. + features: [generators] + es6id: 14.1 + negative: + phase: parse + type: SyntaxError +---*/ + +$DONOTEVALUATE(); + +class A { + *g() { + (function yield() {}); + } +} diff --git a/js/src/tests/test262/language/statements/class/definition/methods-gen-yield-as-generator-method-binding-identifier.js b/js/src/tests/test262/language/statements/class/definition/methods-gen-yield-as-generator-method-binding-identifier.js new file mode 100644 index 0000000000..6f0dfff5a1 --- /dev/null +++ b/js/src/tests/test262/language/statements/class/definition/methods-gen-yield-as-generator-method-binding-identifier.js @@ -0,0 +1,31 @@ +// Copyright (C) 2013 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- + description: > + `yield` is a valid BindingIdentifier for GeneratorMethods outside of + strict mode. + features: [generators] + es6id: 12.1.1 +---*/ + +var iter, result; +class A { + *yield() { (yield 3) + (yield 4); } +} + +iter = A.prototype.yield(); + +result = iter.next(); +assert.sameValue(result.value, 3, 'First result `value`'); +assert.sameValue(result.done, false, 'First result `done` flag'); + +result = iter.next(); +assert.sameValue(result.value, 4, 'Second result `value`'); +assert.sameValue(result.done, false, 'Second result `done` flag'); + +result = iter.next(); +assert.sameValue(result.value, undefined, 'Third result `value`'); +assert.sameValue(result.done, true, 'Third result `done` flag'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/class/definition/methods-gen-yield-as-identifier-in-nested-function.js b/js/src/tests/test262/language/statements/class/definition/methods-gen-yield-as-identifier-in-nested-function.js new file mode 100644 index 0000000000..eb35c7cb3a --- /dev/null +++ b/js/src/tests/test262/language/statements/class/definition/methods-gen-yield-as-identifier-in-nested-function.js @@ -0,0 +1,24 @@ +// |reftest| error:SyntaxError +// Copyright (C) 2013 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- + description: > + `yield` is a reserved keyword within normal function bodies declared + within classes. + features: [generators] + es6id: 12.1.1 + negative: + phase: parse + type: SyntaxError +---*/ + +$DONOTEVALUATE(); + +class A { + *g() { + function h() { + yield = 1; + } + } +} diff --git a/js/src/tests/test262/language/statements/class/definition/methods-gen-yield-as-literal-property-name.js b/js/src/tests/test262/language/statements/class/definition/methods-gen-yield-as-literal-property-name.js new file mode 100644 index 0000000000..ce60db6fb7 --- /dev/null +++ b/js/src/tests/test262/language/statements/class/definition/methods-gen-yield-as-literal-property-name.js @@ -0,0 +1,23 @@ +// Copyright (C) 2013 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- + description: > + `yield` may be used as a literal property name in an object literal + within generator function bodies. + features: [generators] + es6id: 12.1.1 +---*/ + +var result; +class A { + *g() { + ({ get yield() { return 1 } }); + } +} + +result = A.prototype.g().next(); +assert.sameValue(result.value, undefined); +assert.sameValue(result.done, true); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/class/definition/methods-gen-yield-as-logical-or-expression.js b/js/src/tests/test262/language/statements/class/definition/methods-gen-yield-as-logical-or-expression.js new file mode 100644 index 0000000000..5edac93178 --- /dev/null +++ b/js/src/tests/test262/language/statements/class/definition/methods-gen-yield-as-logical-or-expression.js @@ -0,0 +1,21 @@ +// |reftest| error:SyntaxError +// Copyright (C) 2013 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- + description: > + `yield` expressions are not LogicalOrExpressions. + features: [generators] + es6id: 12.1.1 + negative: + phase: parse + type: SyntaxError +---*/ + +$DONOTEVALUATE(); + +class A { + *g() { + yield ? yield : yield; + } +} diff --git a/js/src/tests/test262/language/statements/class/definition/methods-gen-yield-as-parameter.js b/js/src/tests/test262/language/statements/class/definition/methods-gen-yield-as-parameter.js new file mode 100644 index 0000000000..f4cf062cf4 --- /dev/null +++ b/js/src/tests/test262/language/statements/class/definition/methods-gen-yield-as-parameter.js @@ -0,0 +1,20 @@ +// |reftest| error:SyntaxError +// Copyright (C) 2013 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- + description: > + `yield` is a reserved keyword within generator function bodies and may + not be used as the binding identifier of a parameter. + features: [generators] + es6id: 12.1.1 + negative: + phase: parse + type: SyntaxError +---*/ + +$DONOTEVALUATE(); + +class A { + *g(yield) {} +} diff --git a/js/src/tests/test262/language/statements/class/definition/methods-gen-yield-as-property-name.js b/js/src/tests/test262/language/statements/class/definition/methods-gen-yield-as-property-name.js new file mode 100644 index 0000000000..60f99d9b29 --- /dev/null +++ b/js/src/tests/test262/language/statements/class/definition/methods-gen-yield-as-property-name.js @@ -0,0 +1,23 @@ +// Copyright (C) 2013 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- + description: > + `yield` may be used as a literal property name in an object literal + within generator function bodies. + features: [generators] + es6id: 12.1.1 +---*/ + +var result; +class A { + *g() { + ({ yield: 1 }); + } +} + +result = A.prototype.g().next(); +assert.sameValue(result.value, undefined); +assert.sameValue(result.done, true); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/class/definition/methods-gen-yield-as-statement.js b/js/src/tests/test262/language/statements/class/definition/methods-gen-yield-as-statement.js new file mode 100644 index 0000000000..605fc0f6fb --- /dev/null +++ b/js/src/tests/test262/language/statements/class/definition/methods-gen-yield-as-statement.js @@ -0,0 +1,49 @@ +// Copyright (C) 2013 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- + description: > + `yield` is a valid statement within generator function bodies. + features: [generators] + es6id: 14.4 +---*/ + +var iter, result; +class A { + *g1() { yield; } + *g2() { yield 1; } +} + +iter = A.prototype.g1(); +result = iter.next(); +assert.sameValue( + result.value, undefined, 'Without right-hand-side: first result `value`' +); +assert.sameValue( + result.done, false, 'Without right-hand-side: first result `done` flag' +); +result = iter.next(); +assert.sameValue( + result.value, undefined, 'Without right-hand-side: second result `value`' +); +assert.sameValue( + result.done, true, 'Without right-hand-eside: second result `done` flag' +); + +iter = A.prototype.g2(); +result = iter.next(); +assert.sameValue( + result.value, 1, 'With right-hand-side: first result `value`' +); +assert.sameValue( + result.done, false, 'With right-hand-side: first result `done` flag' +); +result = iter.next(); +assert.sameValue( + result.value, undefined, 'With right-hand-side: second result `value`' +); +assert.sameValue( + result.done, true, 'With right-hand-eside: second result `done` flag' +); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/class/definition/methods-gen-yield-as-yield-operand.js b/js/src/tests/test262/language/statements/class/definition/methods-gen-yield-as-yield-operand.js new file mode 100644 index 0000000000..a440f04d0a --- /dev/null +++ b/js/src/tests/test262/language/statements/class/definition/methods-gen-yield-as-yield-operand.js @@ -0,0 +1,33 @@ +// Copyright (C) 2013 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- + description: > + `yield` expressions may be used as the right-hand-side of other `yield` + expressions. + features: [generators] + es6id: 14.4 +---*/ + +var iter, result; +class A { + *g() { + yield yield 1; + } +} + +iter = A.prototype.g(); + +result = iter.next(); +assert.sameValue(result.value, 1, 'First result `value`'); +assert.sameValue(result.done, false, 'First result `done` flag'); + +result = iter.next(); +assert.sameValue(result.value, undefined, 'Second result `value`'); +assert.sameValue(result.done, false, 'Second result `done` flag'); + +result = iter.next(); +assert.sameValue(result.value, undefined, 'Third result `value`'); +assert.sameValue(result.done, true, 'Thid result `done` flag'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/class/definition/methods-gen-yield-newline.js b/js/src/tests/test262/language/statements/class/definition/methods-gen-yield-newline.js new file mode 100644 index 0000000000..b2f23da27d --- /dev/null +++ b/js/src/tests/test262/language/statements/class/definition/methods-gen-yield-newline.js @@ -0,0 +1,29 @@ +// Copyright (C) 2013 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- + description: > + Newlines terminate `yield` expressions. + features: [generators] + es6id: 14.4 +---*/ + +var iter, result; +class A { + *g() { + yield + 1 + } +} + +iter = A.prototype.g(); + +result = iter.next(); +assert.sameValue(result.value, undefined, 'First result `value`'); +assert.sameValue(result.done, false, 'First result `done` flag'); + +result = iter.next(); +assert.sameValue(result.value, undefined, 'Second result `value`'); +assert.sameValue(result.done, true, 'Second result `done` flag'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/class/definition/methods-gen-yield-star-after-newline.js b/js/src/tests/test262/language/statements/class/definition/methods-gen-yield-star-after-newline.js new file mode 100644 index 0000000000..ca1913c00a --- /dev/null +++ b/js/src/tests/test262/language/statements/class/definition/methods-gen-yield-star-after-newline.js @@ -0,0 +1,22 @@ +// |reftest| error:SyntaxError +// Copyright (C) 2013 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- + description: > + A newline may not precede the `*` token in a `yield` expression. + features: [generators] + es6id: 14.4 + negative: + phase: parse + type: SyntaxError +---*/ + +$DONOTEVALUATE(); + +class A { + *g() { + yield + * 1 + } +} diff --git a/js/src/tests/test262/language/statements/class/definition/methods-gen-yield-star-before-newline.js b/js/src/tests/test262/language/statements/class/definition/methods-gen-yield-star-before-newline.js new file mode 100644 index 0000000000..bc68cbbdb2 --- /dev/null +++ b/js/src/tests/test262/language/statements/class/definition/methods-gen-yield-star-before-newline.js @@ -0,0 +1,24 @@ +// Copyright (C) 2013 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- + description: > + The right-hand side of a `yield *` expression may appear on a new line. + features: [generators] + es6id: 14.4 +---*/ + +var result; +class A { + *g() { + yield * + g2() + } +} +var g2 = function*() {}; + +result = A.prototype.g().next(); +assert.sameValue(result.value, undefined); +assert.sameValue(result.done, true); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/class/definition/methods-gen-yield-weak-binding.js b/js/src/tests/test262/language/statements/class/definition/methods-gen-yield-weak-binding.js new file mode 100644 index 0000000000..0c2f54376a --- /dev/null +++ b/js/src/tests/test262/language/statements/class/definition/methods-gen-yield-weak-binding.js @@ -0,0 +1,19 @@ +// |reftest| error:SyntaxError +// Copyright (C) 2013 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- + description: > + `yield` expressions bind weakly + features: [generators] + es6id: 14.4 + negative: + phase: parse + type: SyntaxError +---*/ + +$DONOTEVALUATE(); + +class A { + *g() { yield 3 + yield 4; } +} diff --git a/js/src/tests/test262/language/statements/class/definition/methods-named-eval-arguments.js b/js/src/tests/test262/language/statements/class/definition/methods-named-eval-arguments.js new file mode 100644 index 0000000000..bb99527117 --- /dev/null +++ b/js/src/tests/test262/language/statements/class/definition/methods-named-eval-arguments.js @@ -0,0 +1,28 @@ +// Copyright (C) 2014 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 14.5 +description: > + class methods 2 +---*/ +class C { + eval() { + return 1; + } + arguments() { + return 2; + } + static eval() { + return 3; + } + static arguments() { + return 4; + } +}; + +assert.sameValue(new C().eval(), 1, "`new C().eval()` returns `1`"); +assert.sameValue(new C().arguments(), 2, "`new C().arguments()` returns `2`"); +assert.sameValue(C.eval(), 3, "`C.eval()` returns `3`"); +assert.sameValue(C.arguments(), 4, "`C.arguments()` returns `4`"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/class/definition/methods-restricted-properties.js b/js/src/tests/test262/language/statements/class/definition/methods-restricted-properties.js new file mode 100644 index 0000000000..f01bb2a643 --- /dev/null +++ b/js/src/tests/test262/language/statements/class/definition/methods-restricted-properties.js @@ -0,0 +1,106 @@ +// Copyright (C) 2015 Caitlin Potter. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +description: > + Functions created using MethodDefinition syntactic form do not have own + properties "caller" or "arguments", but inherit them from + %FunctionPrototype%. +es6id: 16.1 +---*/ + +class Class { + method() {} + get accessor() {} + set accessor(x) {} +}; + +var instance = new Class; +var accessor = Object.getOwnPropertyDescriptor(Class.prototype, "accessor"); + +assert.sameValue( + instance.method.hasOwnProperty('caller'), + false, + 'No "caller" own property (method)' +); +assert.sameValue( + instance.method.hasOwnProperty('arguments'), + false, + 'No "arguments" own property (method)' +); +assert.sameValue( + accessor.get.hasOwnProperty('caller'), + false, + 'No "caller" own property ("get" accessor)' +); +assert.sameValue( + accessor.get.hasOwnProperty('arguments'), + false, + 'No "arguments" own property ("get" accessor)' +); +assert.sameValue( + accessor.set.hasOwnProperty('caller'), + false, + 'No "caller" own property ("set" accessor)' +); +assert.sameValue( + accessor.set.hasOwnProperty('arguments'), + false, + 'No "arguments" own property ("set" accessor)' +); + +// --- Test method restricted properties throw + +assert.throws(TypeError, function() { + return instance.method.caller; +}); + +assert.throws(TypeError, function() { + instance.method.caller = {}; +}); + +assert.throws(TypeError, function() { + return instance.method.arguments; +}); + +assert.throws(TypeError, function() { + instance.method.arguments = {}; +}); + +// --- Test getter restricted properties throw + +assert.throws(TypeError, function() { + return accessor.get.caller; +}); + +assert.throws(TypeError, function() { + accessor.get.caller = {}; +}); + +assert.throws(TypeError, function() { + return accessor.get.arguments; +}); + +assert.throws(TypeError, function() { + accessor.get.arguments = {}; +}); + +// --- Test setter restricted properties throw + +assert.throws(TypeError, function() { + return accessor.set.caller; +}); + +assert.throws(TypeError, function() { + accessor.set.caller = {}; +}); + +assert.throws(TypeError, function() { + return accessor.set.arguments; +}); + +assert.throws(TypeError, function() { + accessor.set.arguments = {}; +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/class/definition/methods.js b/js/src/tests/test262/language/statements/class/definition/methods.js new file mode 100644 index 0000000000..66ad98189a --- /dev/null +++ b/js/src/tests/test262/language/statements/class/definition/methods.js @@ -0,0 +1,34 @@ +// Copyright (C) 2014 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 14.5 +description: > + class methods +---*/ +function assertMethodDescriptor(object, name) { + var desc = Object.getOwnPropertyDescriptor(object, name); + assert.sameValue(desc.configurable, true, "The value of `desc.configurable` is `true`"); + assert.sameValue(desc.enumerable, false, "The value of `desc.enumerable` is `false`"); + assert.sameValue(desc.writable, true, "The value of `desc.writable` is `true`"); + assert.sameValue(typeof desc.value, 'function', "`typeof desc.value` is `'function'`"); + assert.sameValue('prototype' in desc.value, false, "The result of `'prototype' in desc.value` is `false`"); +} + +class C { + method() { return 1; } + static staticMethod() { return 2; } + method2() { return 3; } + static staticMethod2() { return 4; } +} + +assertMethodDescriptor(C.prototype, 'method'); +assertMethodDescriptor(C.prototype, 'method2'); +assertMethodDescriptor(C, 'staticMethod'); +assertMethodDescriptor(C, 'staticMethod2'); + +assert.sameValue(new C().method(), 1, "`new C().method()` returns `1`. Defined as `method() { return 1; }`"); +assert.sameValue(C.staticMethod(), 2, "`C.staticMethod()` returns `2`. Defined as `static staticMethod() { return 2; }`"); +assert.sameValue(new C().method2(), 3, "`new C().method2()` returns `3`. Defined as `method2() { return 3; }`"); +assert.sameValue(C.staticMethod2(), 4, "`C.staticMethod2()` returns `4`. Defined as `static staticMethod2() { return 4; }`"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/class/definition/numeric-property-names.js b/js/src/tests/test262/language/statements/class/definition/numeric-property-names.js new file mode 100644 index 0000000000..f974c11a88 --- /dev/null +++ b/js/src/tests/test262/language/statements/class/definition/numeric-property-names.js @@ -0,0 +1,65 @@ +// Copyright (C) 2014 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 14.5 +description: > + class numeric property names +---*/ +function assertMethodDescriptor(object, name) { + var desc = Object.getOwnPropertyDescriptor(object, name); + assert.sameValue(desc.configurable, true, "The value of `desc.configurable` is `true`"); + assert.sameValue(desc.enumerable, false, "The value of `desc.enumerable` is `false`"); + assert.sameValue(desc.writable, true, "The value of `desc.writable` is `true`"); + assert.sameValue(typeof desc.value, 'function', "`typeof desc.value` is `'function'`"); + assert.sameValue('prototype' in desc.value, false, "The result of `'prototype' in desc.value` is `false`"); +} + +function assertGetterDescriptor(object, name) { + var desc = Object.getOwnPropertyDescriptor(object, name); + assert.sameValue(desc.configurable, true, "The value of `desc.configurable` is `true`"); + assert.sameValue(desc.enumerable, false, "The value of `desc.enumerable` is `false`"); + assert.sameValue(typeof desc.get, 'function', "`typeof desc.get` is `'function'`"); + assert.sameValue('prototype' in desc.get, false, "The result of `'prototype' in desc.get` is `false`"); + assert.sameValue(desc.set, undefined, "The value of `desc.set` is `undefined`"); +} + +function assertSetterDescriptor(object, name) { + var desc = Object.getOwnPropertyDescriptor(object, name); + assert.sameValue(desc.configurable, true, "The value of `desc.configurable` is `true`"); + assert.sameValue(desc.enumerable, false, "The value of `desc.enumerable` is `false`"); + assert.sameValue(typeof desc.set, 'function', "`typeof desc.set` is `'function'`"); + assert.sameValue('prototype' in desc.set, false, "The result of `'prototype' in desc.set` is `false`"); + assert.sameValue(desc.get, undefined, "The value of `desc.get` is `undefined`"); +} + +class B { + 1() { return 1; } + get 2() { return 2; } + set 3(_) {} + + static 4() { return 4; } + static get 5() { return 5; } + static set 6(_) {} +} + +assertMethodDescriptor(B.prototype, '1'); +assertGetterDescriptor(B.prototype, '2'); +assertSetterDescriptor(B.prototype, '3'); + +assertMethodDescriptor(B, '4'); +assertGetterDescriptor(B, '5'); +assertSetterDescriptor(B, '6'); + +class C extends B { + 1() { return super[1](); } + get 2() { return super[2]; } + static 4() { return super[4](); } + static get 5() { return super[5]; } +} + +assert.sameValue(new C()[1](), 1, "`new C()[1]()` returns `1`. Defined as `1() { return super[1](); }`"); +assert.sameValue(new C()[2], 2, "The value of `new C()[2]` is `2`. Defined as `get 2() { return super[2]; }`"); +assert.sameValue(C[4](), 4, "`C[4]()` returns `4`. Defined as `static 4() { return super[4](); }`"); +assert.sameValue(C[5], 5, "The value of `C[5]` is `5`. Defined as `static get 5() { return super[5]; }`"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/class/definition/prototype-getter.js b/js/src/tests/test262/language/statements/class/definition/prototype-getter.js new file mode 100644 index 0000000000..cbfe6ac1b7 --- /dev/null +++ b/js/src/tests/test262/language/statements/class/definition/prototype-getter.js @@ -0,0 +1,33 @@ +// Copyright (C) 2014 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 14.5 +description: > + class prototype getter +---*/ +var calls = 0; +var Base = function() {}.bind(); +Object.defineProperty(Base, 'prototype', { + get: function() { + calls++; + return null; + }, + configurable: true +}); +class C extends Base {} +assert.sameValue(calls, 1, "The value of `calls` is `1`"); + +calls = 0; +Object.defineProperty(Base, 'prototype', { + get: function() { + calls++; + return 42; + }, + configurable: true +}); +assert.throws(TypeError, function() { + class C extends Base {} +}); +assert.sameValue(calls, 1, "The value of `calls` is `1`"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/class/definition/prototype-property.js b/js/src/tests/test262/language/statements/class/definition/prototype-property.js new file mode 100644 index 0000000000..1c9110ca04 --- /dev/null +++ b/js/src/tests/test262/language/statements/class/definition/prototype-property.js @@ -0,0 +1,14 @@ +// Copyright (C) 2014 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 14.5 +description: > + class prototype property +---*/ +class C {} +var descr = Object.getOwnPropertyDescriptor(C, 'prototype'); +assert.sameValue(descr.configurable, false, "The value of `descr.configurable` is `false`"); +assert.sameValue(descr.enumerable, false, "The value of `descr.enumerable` is `false`"); +assert.sameValue(descr.writable, false, "The value of `descr.writable` is `false`"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/class/definition/prototype-setter.js b/js/src/tests/test262/language/statements/class/definition/prototype-setter.js new file mode 100644 index 0000000000..f6618c5a9c --- /dev/null +++ b/js/src/tests/test262/language/statements/class/definition/prototype-setter.js @@ -0,0 +1,18 @@ +// Copyright (C) 2014 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 14.5 +description: > + class prototype setter +---*/ +var Base = function() {}.bind(); +Object.defineProperty(Base, 'prototype', { + set: function() { + throw new Test262Error("Cannot create a setter property named `prototype`"); + } +}); +assert.throws(TypeError, function() { + class C extends Base {} +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/class/definition/prototype-wiring.js b/js/src/tests/test262/language/statements/class/definition/prototype-wiring.js new file mode 100644 index 0000000000..608bde0586 --- /dev/null +++ b/js/src/tests/test262/language/statements/class/definition/prototype-wiring.js @@ -0,0 +1,75 @@ +// Copyright (C) 2014 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 14.5 +description: > + class prototype wiring +---*/ + +class Base { + constructor(x) { + this.foobar = x; + } +} + +class Subclass extends Base { + constructor(x) { + super(x); + } +} + +var s = new Subclass(1); +assert.sameValue(s.foobar, 1, "The value of `s.foobar` is `1`"); +assert.sameValue( + Object.getPrototypeOf(s), + Subclass.prototype, + "`Object.getPrototypeOf(s)` returns `Subclass.prototype`" +); + +var s1 = new Subclass(1, 2); +assert.sameValue(s1.foobar, 1, "The value of `s1.foobar` is `1`"); +assert.sameValue( + Object.getPrototypeOf(s1) === Subclass.prototype, + true, + "The result of `Object.getPrototypeOf(s1) === Subclass.prototype` is `true`" +); + +var s2 = new Subclass(); +assert.sameValue(s2.foobar, undefined, "The value of `s2.foobar` is `undefined`"); +assert.sameValue( + Object.getPrototypeOf(s2), + Subclass.prototype, + "`Object.getPrototypeOf(s2)` returns `Subclass.prototype`" +); +assert.throws(TypeError, function() { Subclass(1); }); +assert.throws(TypeError, function() { Subclass(1,2,3,4); }); + +class Subclass2 extends Subclass { + constructor() { + super(5, 6, 7); + } +} + +var ss2 = new Subclass2(); +assert.sameValue(ss2.foobar, 5, "The value of `ss2.foobar` is `5`"); +assert.sameValue( + Object.getPrototypeOf(ss2), + Subclass2.prototype, + "`Object.getPrototypeOf(ss2)` returns `Subclass2.prototype`" +); + +class Subclass3 extends Base { + constructor(x, y) { + super(x + y); + } +} + +var ss3 = new Subclass3(27,42-27); +assert.sameValue(ss3.foobar, 42, "The value of `ss3.foobar` is `42`"); +assert.sameValue( + Object.getPrototypeOf(ss3), + Subclass3.prototype, + "`Object.getPrototypeOf(ss3)` returns `Subclass3.prototype`" +); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/class/definition/setters-non-configurable-err.js b/js/src/tests/test262/language/statements/class/definition/setters-non-configurable-err.js new file mode 100644 index 0000000000..69e2dac8e6 --- /dev/null +++ b/js/src/tests/test262/language/statements/class/definition/setters-non-configurable-err.js @@ -0,0 +1,19 @@ +// 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-method-definitions-runtime-semantics-propertydefinitionevaluation +es6id: 14.3.9 +description: Failure to define property for static method +info: | + [...] + 8. Let desc be the PropertyDescriptor{[[Set]]: closure, [[Enumerable]]: + enumerable, [[Configurable]]: true}. + 9. Return ? DefinePropertyOrThrow(object, propKey, desc). +features: [generators] +---*/ + +assert.throws(TypeError, function() { + class C { static set ['prototype'](_) {} } +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/class/definition/setters-prop-desc.js b/js/src/tests/test262/language/statements/class/definition/setters-prop-desc.js new file mode 100644 index 0000000000..46b2e0a3c7 --- /dev/null +++ b/js/src/tests/test262/language/statements/class/definition/setters-prop-desc.js @@ -0,0 +1,41 @@ +// Copyright (C) 2014 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-class-definitions +es6id: 14.5 +description: Class methods - "set" accessors +includes: [propertyHelper.js] +---*/ + +function assertSetterDescriptor(object, name) { + var descr = Object.getOwnPropertyDescriptor(object, name); + verifyNotEnumerable(object, name); + verifyConfigurable(object, name); + assert.sameValue(typeof descr.set, 'function', "`typeof descr.set` is `'function'`"); + assert.sameValue('prototype' in descr.set, false, "The result of `'prototype' in descr.set` is `false`"); + assert.sameValue(descr.get, undefined, "The value of `descr.get` is `undefined`"); +} + +var x, staticX, y, staticY; +class C { + set x(v) { x = v; } + static set staticX(v) { staticX = v; } + set y(v) { y = v; } + static set staticY(v) { staticY = v; } +} + +assert.sameValue(new C().x = 1, 1, "`new C().x = 1` is `1`"); +assert.sameValue(x, 1, "The value of `x` is `1`"); +assert.sameValue(C.staticX = 2, 2, "`C.staticX = 2` is `2`"); +assert.sameValue(staticX, 2, "The value of `staticX` is `2`"); +assert.sameValue(new C().y = 3, 3, "`new C().y = 3` is `3`"); +assert.sameValue(y, 3, "The value of `y` is `3`"); +assert.sameValue(C.staticY = 4, 4, "`C.staticY = 4` is `4`"); +assert.sameValue(staticY, 4, "The value of `staticY` is `4`"); + +assertSetterDescriptor(C.prototype, 'x'); +assertSetterDescriptor(C.prototype, 'y'); +assertSetterDescriptor(C, 'staticX'); +assertSetterDescriptor(C, 'staticY'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/class/definition/setters-restricted-ids.js b/js/src/tests/test262/language/statements/class/definition/setters-restricted-ids.js new file mode 100644 index 0000000000..9e2e3c69b9 --- /dev/null +++ b/js/src/tests/test262/language/statements/class/definition/setters-restricted-ids.js @@ -0,0 +1,33 @@ +// Copyright (C) 2014 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 14.5 +description: > + class setters 2 +---*/ +var x = 0; +class C { + set eval(v) { + x = v; + } + set arguments(v) { + x = v; + } + static set eval(v) { + x = v; + } + static set arguments(v) { + x = v; + } +}; + +new C().eval = 1; +assert.sameValue(x, 1, "The value of `x` is `1`"); +new C().arguments = 2; +assert.sameValue(x, 2, "The value of `x` is `2`"); +C.eval = 3; +assert.sameValue(x, 3, "The value of `x` is `3`"); +C.arguments = 4; +assert.sameValue(x, 4, "The value of `x` is `4`"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/class/definition/shell.js b/js/src/tests/test262/language/statements/class/definition/shell.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/language/statements/class/definition/shell.js diff --git a/js/src/tests/test262/language/statements/class/definition/side-effects-in-extends.js b/js/src/tests/test262/language/statements/class/definition/side-effects-in-extends.js new file mode 100644 index 0000000000..bdbd255ef9 --- /dev/null +++ b/js/src/tests/test262/language/statements/class/definition/side-effects-in-extends.js @@ -0,0 +1,20 @@ +// Copyright (C) 2014 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 14.5 +description: > + class side effect in extends +---*/ +var calls = 0; +class C {} +class D extends (calls++, C) {} +assert.sameValue(calls, 1, "The value of `calls` is `1`"); +assert.sameValue(typeof D, 'function', "`typeof D` is `'function'`"); +assert.sameValue(Object.getPrototypeOf(D), C, "`Object.getPrototypeOf(D)` returns `C`"); +assert.sameValue( + C.prototype, + Object.getPrototypeOf(D.prototype), + "The value of `C.prototype` is `Object.getPrototypeOf(D.prototype)`" +); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/class/definition/side-effects-in-property-define.js b/js/src/tests/test262/language/statements/class/definition/side-effects-in-property-define.js new file mode 100644 index 0000000000..616797b19b --- /dev/null +++ b/js/src/tests/test262/language/statements/class/definition/side-effects-in-property-define.js @@ -0,0 +1,22 @@ +// Copyright (C) 2014 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 14.5 +description: > + class side effects in property define +---*/ +function B() {} +B.prototype = { + constructor: B, + set m(v) { + throw Error(); + } +}; + +class C extends B { + m() { return 1; } +} + +assert.sameValue(new C().m(), 1, "`new C().m()` returns `1`"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/class/definition/this-access-restriction-2.js b/js/src/tests/test262/language/statements/class/definition/this-access-restriction-2.js new file mode 100644 index 0000000000..e1f855aa1c --- /dev/null +++ b/js/src/tests/test262/language/statements/class/definition/this-access-restriction-2.js @@ -0,0 +1,90 @@ +// Copyright (C) 2014 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 14.5 +description: > + class this access restriction 2 +---*/ +class Base { + constructor(a, b) { + var o = new Object(); + o.prp = a + b; + return o; + } +} + +class Subclass extends Base { + constructor(a, b) { + var exn; + try { + this.prp1 = 3; + } catch (e) { + exn = e; + } + assert.sameValue( + exn instanceof ReferenceError, + true, + "The result of `exn instanceof ReferenceError` is `true`" + ); + super(a, b); + assert.sameValue(this.prp, a + b, "The value of `this.prp` is `a + b`"); + assert.sameValue(this.prp1, undefined, "The value of `this.prp1` is `undefined`"); + assert.sameValue( + this.hasOwnProperty("prp1"), + false, + "`this.hasOwnProperty(\"prp1\")` returns `false`" + ); + return this; + } +} + +var b = new Base(1, 2); +assert.sameValue(b.prp, 3, "The value of `b.prp` is `3`"); + + +var s = new Subclass(2, -1); +assert.sameValue(s.prp, 1, "The value of `s.prp` is `1`"); +assert.sameValue(s.prp1, undefined, "The value of `s.prp1` is `undefined`"); +assert.sameValue( + s.hasOwnProperty("prp1"), + false, + "`s.hasOwnProperty(\"prp1\")` returns `false`" +); + +class Subclass2 extends Base { + constructor(x) { + super(1,2); + + if (x < 0) return; + + var called = false; + function tmp() { called = true; return 3; } + var exn = null; + try { + super(tmp(),4); + } catch (e) { exn = e; } + assert.sameValue( + exn instanceof ReferenceError, + true, + "The result of `exn instanceof ReferenceError` is `true`" + ); + assert.sameValue(called, true, "The value of `called` is `true`"); + } +} + +var s2 = new Subclass2(1); +assert.sameValue(s2.prp, 3, "The value of `s2.prp` is `3`"); + +var s3 = new Subclass2(-1); +assert.sameValue(s3.prp, 3, "The value of `s3.prp` is `3`"); + +assert.throws(TypeError, function() { Subclass.call(new Object(), 1, 2); }); +assert.throws(TypeError, function() { Base.call(new Object(), 1, 2); }); + +class BadSubclass extends Base { + constructor() {} +} + +assert.throws(ReferenceError, function() { new BadSubclass(); }); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/class/definition/this-access-restriction.js b/js/src/tests/test262/language/statements/class/definition/this-access-restriction.js new file mode 100644 index 0000000000..ce13e6a343 --- /dev/null +++ b/js/src/tests/test262/language/statements/class/definition/this-access-restriction.js @@ -0,0 +1,100 @@ +// Copyright (C) 2014 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 14.5 +description: > + class this access restriction +---*/ +class Base {} +(function() { + class C extends Base { + constructor() { + var y; + super(); + } + }; new C(); +}()); +assert.throws(ReferenceError, function() { + class C extends Base { + constructor() { + super(this.x); + } + }; new C(); +}); +assert.throws(ReferenceError, function() { + class C extends Base { + constructor() { + super(this); + } + }; new C(); +}); +assert.throws(ReferenceError, function() { + class C extends Base { + constructor() { + super.method(); + super(this); + } + }; new C(); +}); +assert.throws(ReferenceError, function() { + class C extends Base { + constructor() { + super(super.method()); + } + }; new C(); +}); +assert.throws(ReferenceError, function() { + class C extends Base { + constructor() { + super(super()); + } + }; new C(); +}); +assert.throws(ReferenceError, function() { + class C extends Base { + constructor() { + super(1, 2, Object.getPrototypeOf(this)); + } + }; new C(); +}); +(function() { + class C extends Base { + constructor() { + { super(1, 2); } + } + }; new C(); +}()); +(function() { + class C extends Base { + constructor() { + if (1) super(); + } + }; new C(); +}()); + +class C1 extends Object { + constructor() { + 'use strict'; + super(); + } +}; +new C1(); + +class C2 extends Object { + constructor() { + ; 'use strict';;;;; + super(); + } +}; +new C2(); + +class C3 extends Object { + constructor() { + ; 'use strict';;;;; + // This is a comment. + super(); + } +}; +new C3(); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/class/definition/this-check-ordering.js b/js/src/tests/test262/language/statements/class/definition/this-check-ordering.js new file mode 100644 index 0000000000..c7f867db9b --- /dev/null +++ b/js/src/tests/test262/language/statements/class/definition/this-check-ordering.js @@ -0,0 +1,72 @@ +// Copyright (C) 2014 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 14.5 +description: > + class this check ordering +---*/ +var baseCalled = 0; +class Base { + constructor() { baseCalled++ } +} + +var fCalled = 0; +function f() { fCalled++; return 3; } + +class Subclass1 extends Base { + constructor() { + baseCalled = 0; + super(); + assert.sameValue(baseCalled, 1, "The value of `baseCalled` is `1`"); + var obj = this; + + var exn = null; + baseCalled = 0; + fCalled = 0; + try { + super(f()); + } catch (e) { exn = e; } + assert.sameValue( + exn instanceof ReferenceError, + true, + "The result of `exn instanceof ReferenceError` is `true`" + ); + assert.sameValue(fCalled, 1, "The value of `fCalled` is `1`"); + assert.sameValue(baseCalled, 1, "The value of `baseCalled` is `1`"); + assert.sameValue(this, obj, "`this` is `obj`"); + + exn = null; + baseCalled = 0; + fCalled = 0; + try { + super(super(), f()); + } catch (e) { exn = e; } + assert.sameValue( + exn instanceof ReferenceError, + true, + "The result of `exn instanceof ReferenceError` is `true`" + ); + assert.sameValue(fCalled, 0, "The value of `fCalled` is `0`"); + assert.sameValue(baseCalled, 1, "The value of `baseCalled` is `1`"); + assert.sameValue(this, obj, "`this` is `obj`"); + + exn = null; + baseCalled = 0; + fCalled = 0; + try { + super(f(), super()); + } catch (e) { exn = e; } + assert.sameValue( + exn instanceof ReferenceError, + true, + "The result of `exn instanceof ReferenceError` is `true`" + ); + assert.sameValue(fCalled, 1, "The value of `fCalled` is `1`"); + assert.sameValue(baseCalled, 1, "The value of `baseCalled` is `1`"); + assert.sameValue(this, obj, "`this` is `obj`"); + } +} + +new Subclass1(); + +reportCompare(0, 0); |