diff --git a/test/language/statements/class/subclass/builtin-objects/Array/contructor-calls-super-multiple-arguments.js b/test/language/statements/class/subclass/builtin-objects/Array/contructor-calls-super-multiple-arguments.js new file mode 100644 index 0000000000000000000000000000000000000000..30b7dcecceb2adfa5a7d20d17e6345fc9cc611c1 --- /dev/null +++ b/test/language/statements/class/subclass/builtin-objects/Array/contructor-calls-super-multiple-arguments.js @@ -0,0 +1,26 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 22.1.1 +description: > + Constructor calling super() with 2+ arguments creates an Array object +info: > + 22.1.1 The Array Constructor + + The Array constructor is designed to be subclassable. It may be used as the + value of an extends clause of a class definition. Subclass constructors that + intend to inherit the exotic Array behaviour must include a super call to the + Array constructor to initialize subclass instances that are exotic Array + objects. +includes: [compareArray.js] +---*/ + +class Sub extends Array { + constructor(a, b) { + super(a, b); + } +} + +var sub = new Sub(42, 'foo'); + +assert(compareArray(sub, [42, 'foo'])); diff --git a/test/language/statements/class/subclass/builtin-objects/Array/contructor-calls-super-single-argument.js b/test/language/statements/class/subclass/builtin-objects/Array/contructor-calls-super-single-argument.js new file mode 100644 index 0000000000000000000000000000000000000000..109dbc9e57b160e14efec70daf7e003cd706e17e --- /dev/null +++ b/test/language/statements/class/subclass/builtin-objects/Array/contructor-calls-super-single-argument.js @@ -0,0 +1,25 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 22.1.1 +description: > + Constructor calling super() with a single argument creates an Array object +info: > + 22.1.1 The Array Constructor + + The Array constructor is designed to be subclassable. It may be used as the + value of an extends clause of a class definition. Subclass constructors that + intend to inherit the exotic Array behaviour must include a super call to the + Array constructor to initialize subclass instances that are exotic Array + objects. +---*/ + +class Sub extends Array { + constructor(a) { + super(a); + } +} + +var sub = new Sub(42); + +assert.sameValue(sub.length, 42); diff --git a/test/language/statements/class/subclass/builtin-objects/Array/length.js b/test/language/statements/class/subclass/builtin-objects/Array/length.js new file mode 100644 index 0000000000000000000000000000000000000000..7bdefad315b8b16808b8c88f077952df567b6a07 --- /dev/null +++ b/test/language/statements/class/subclass/builtin-objects/Array/length.js @@ -0,0 +1,37 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 22.1.4.1 +description: > + Instances has the own property length +info: > + 22.1.4.1 length + + The length property of an Array instance is a data property whose value is + always numerically greater than the name of every configurable own property + whose name is an array index. + + The length property initially has the attributes { [[Writable]]: true, + [[Enumerable]]: false, [[Configurable]]: false }. +includes: [propertyHelper.js] +---*/ + +class Ar extends Array {} + +var arr = new Ar('foo', 'bar'); + +assert.sameValue(arr[0], 'foo'); +assert.sameValue(arr[1], 'bar'); + +var arrDesc = Object.getOwnPropertyDescriptor(arr, 'length'); + +assert.sameValue(arrDesc.writable, true); +assert.sameValue(arrDesc.enumerable, false); +assert.sameValue(arrDesc.configurable, false); + +assert.sameValue(arr[1], 'bar'); + +arr.length = 1; + +assert.sameValue(arr[0], 'foo'); +assert.sameValue(arr[1], undefined); diff --git a/test/language/statements/class/subclass/builtin-objects/Array/regular-subclassing.js b/test/language/statements/class/subclass/builtin-objects/Array/regular-subclassing.js new file mode 100644 index 0000000000000000000000000000000000000000..e29564a362ac2bf5d7e1fa23c4eebf843ce1ccd3 --- /dev/null +++ b/test/language/statements/class/subclass/builtin-objects/Array/regular-subclassing.js @@ -0,0 +1,33 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 22.1.1 +description: Subclassing Array +info: > + 22.1.1 The Array Constructor + + The Array constructor is designed to be subclassable. It may be used as the + value of an extends clause of a class definition. (...) +includes: [compareArray.js] +---*/ + +class Sub extends Array {} + +var a1 = new Sub(42, 'foo'); + +assert.sameValue(a1.length, 2); +assert.sameValue(a1[0], 42); +assert.sameValue(a1[1], 'foo'); + +a1.push(true); +assert.sameValue(a1.length, 3, 'Array#push updates the length property'); +assert.sameValue(a1[0], 42); +assert.sameValue(a1[1], 'foo'); +assert.sameValue(a1[2], true, 'Adds new item'); + +var a2 = new Sub(7); +assert.sameValue(a2.length, 7); + +var a3 = new Sub(); +assert(compareArray(a3, [])); +assert.sameValue(a3.length, 0); diff --git a/test/language/statements/class/subclass/builtin-objects/Array/super-must-be-called.js b/test/language/statements/class/subclass/builtin-objects/Array/super-must-be-called.js new file mode 100644 index 0000000000000000000000000000000000000000..328262a34d3b10eddd593b52424973a3bc88f106 --- /dev/null +++ b/test/language/statements/class/subclass/builtin-objects/Array/super-must-be-called.js @@ -0,0 +1,32 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 22.1.1 +description: Super need to be called to initialize internals +info: > + 22.1.1 The Array Constructor + + ... + + The Array constructor is designed to be subclassable. It may be used as the + value of an extends clause of a class definition. Subclass constructors that + intend to inherit the exotic Array behaviour must include a super call to the + Array constructor to initialize subclass instances that are exotic Array + objects. +---*/ + +class A extends Array { + constructor() {} +} + +assert.throws(ReferenceError, function() { + new A(); +}); + +class A2 extends Array { + constructor() { + super(); + } +} + +new A2(); diff --git a/test/language/statements/class/subclass/builtin-objects/ArrayBuffer/regular-subclassing.js b/test/language/statements/class/subclass/builtin-objects/ArrayBuffer/regular-subclassing.js new file mode 100644 index 0000000000000000000000000000000000000000..9df654ce51536ead088ddc26f101ad95c5211fbf --- /dev/null +++ b/test/language/statements/class/subclass/builtin-objects/ArrayBuffer/regular-subclassing.js @@ -0,0 +1,31 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 24.1.2 +description: Subclassing the ArrayBuffer object +info: > + 24.1.2 The ArrayBuffer Constructor + + ... + + The ArrayBuffer constructor is designed to be subclassable. It may be used as + the value of an extends clause of a class definition. Subclass constructors + that intend to inherit the specified ArrayBuffer behaviour must include a + super call to the ArrayBuffer constructor to create and initialize subclass + instances with the internal state necessary to support the + ArrayBuffer.prototype built-in methods. +---*/ + +class AB extends ArrayBuffer {} + +var ab = new AB(4); + +var sliced = ab.slice(0, 1); + +assert(sliced instanceof AB); +assert(sliced instanceof ArrayBuffer); +assert.notSameValue(ab, sliced); + +assert.throws(RangeError, function() { + new AB(); +}); diff --git a/test/language/statements/class/subclass/builtin-objects/ArrayBuffer/super-must-be-called.js b/test/language/statements/class/subclass/builtin-objects/ArrayBuffer/super-must-be-called.js new file mode 100644 index 0000000000000000000000000000000000000000..e58e694ba4051b463588a2280afc4194ace6c9c1 --- /dev/null +++ b/test/language/statements/class/subclass/builtin-objects/ArrayBuffer/super-must-be-called.js @@ -0,0 +1,33 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 24.1.2 +description: Super need to be called to initialize internals +info: > + 24.1.2 The ArrayBuffer Constructor + + ... + + The ArrayBuffer constructor is designed to be subclassable. It may be used as + the value of an extends clause of a class definition. Subclass constructors + that intend to inherit the specified ArrayBuffer behaviour must include a + super call to the ArrayBuffer constructor to create and initialize subclass + instances with the internal state necessary to support the + ArrayBuffer.prototype built-in methods. +---*/ + +class AB1 extends ArrayBuffer { + constructor() {} +} + +assert.throws(ReferenceError, function() { + new AB1(1); +}); + +class AB2 extends ArrayBuffer { + constructor(length) { + super(length); + } +} + +new AB2(1); diff --git a/test/language/statements/class/subclass/builtin-objects/Boolean/regular-subclassing.js b/test/language/statements/class/subclass/builtin-objects/Boolean/regular-subclassing.js new file mode 100644 index 0000000000000000000000000000000000000000..1ccaf9d9efc5308439cb6d657b7e740528408df4 --- /dev/null +++ b/test/language/statements/class/subclass/builtin-objects/Boolean/regular-subclassing.js @@ -0,0 +1,23 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 19.3.1 +description: Subclassing Function +info: > + 19.3.1 The Boolean Constructor + + The Boolean constructor is designed to be subclassable. It may be used as the + value of an extends clause of a class definition. + ... +---*/ + +class Bln extends Boolean {} + +var b1 = new Bln(1); + +assert.notSameValue(b1, true, 'b1 is an Boolean object'); +assert.sameValue(b1.valueOf(), true); + +var b2 = new Bln(0); +assert.notSameValue(b2, false, 'bln is an Boolean object'); +assert.sameValue(b2.valueOf(), false); diff --git a/test/language/statements/class/subclass/builtin-objects/Boolean/super-must-be-called.js b/test/language/statements/class/subclass/builtin-objects/Boolean/super-must-be-called.js new file mode 100644 index 0000000000000000000000000000000000000000..c384a2bc16dea908b28b12abc44a95f16a84f6de --- /dev/null +++ b/test/language/statements/class/subclass/builtin-objects/Boolean/super-must-be-called.js @@ -0,0 +1,31 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 19.3.1 +description: Super need to be called to initialize Boolean internals +info: > + 19.3.1 The Boolean Constructor + + ... + Subclass constructors that intend to inherit the specified Boolean behaviour + must include a super call to the Boolean constructor to create and initialize + the subclass instance with a [[BooleanData]] internal slot. +---*/ + +class Bln extends Boolean { + constructor() {} +} + +// Boolean internals are not initialized +assert.throws(ReferenceError, function() { + new Bln(1); +}); + +class Bln2 extends Boolean { + constructor() { + super(); + } +} + +var b = new Bln2(1); +assert(b instanceof Boolean); diff --git a/test/language/statements/class/subclass/builtin-objects/DataView/regular-subclassing.js b/test/language/statements/class/subclass/builtin-objects/DataView/regular-subclassing.js new file mode 100644 index 0000000000000000000000000000000000000000..e54a7de6b998ec6bc19156523777c06e25555267 --- /dev/null +++ b/test/language/statements/class/subclass/builtin-objects/DataView/regular-subclassing.js @@ -0,0 +1,28 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 24.2.2 +description: Subclassing the DataView object +info: > + 24.2.2 The DataView Constructor + + ... + + The DataView constructor is designed to be subclassable. It may be used as the + value of an extends clause of a class definition. Subclass constructors that + intend to inherit the specified DataView behaviour must include a super call + to the DataView constructor to create and initialize subclass instances with + the internal state necessary to support the DataView.prototype built-in + methods. +---*/ + +class DV extends DataView {} + +var buffer = new ArrayBuffer(1); + +var dv = new DV(buffer); +assert.sameValue(dv.buffer, buffer); + +assert.throws(TypeError, function() { + new DV(); +}); diff --git a/test/language/statements/class/subclass/builtin-objects/DataView/super-must-be-called.js b/test/language/statements/class/subclass/builtin-objects/DataView/super-must-be-called.js new file mode 100644 index 0000000000000000000000000000000000000000..34103c829d68538d2e608af027980a824e1d08ac --- /dev/null +++ b/test/language/statements/class/subclass/builtin-objects/DataView/super-must-be-called.js @@ -0,0 +1,35 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 24.2.2 +description: Super need to be called to initialize internals +info: > + 24.2.2 The DataView Constructor + + ... + + The DataView constructor is designed to be subclassable. It may be used as the + value of an extends clause of a class definition. Subclass constructors that + intend to inherit the specified DataView behaviour must include a super call + to the DataView constructor to create and initialize subclass instances with + the internal state necessary to support the DataView.prototype built-in + methods. +---*/ + +class DV1 extends DataView { + constructor() {} +} + +var buffer = new ArrayBuffer(1); + +assert.throws(ReferenceError, function() { + new DV1(buffer); +}); + +class DV2 extends DataView { + constructor(length) { + super(length); + } +} + +new DV2(buffer); diff --git a/test/language/statements/class/subclass/builtin-objects/Date/regular-subclassing.js b/test/language/statements/class/subclass/builtin-objects/Date/regular-subclassing.js new file mode 100644 index 0000000000000000000000000000000000000000..ded77ed37ee32ec014076830c8a5df1cc4ebdf03 --- /dev/null +++ b/test/language/statements/class/subclass/builtin-objects/Date/regular-subclassing.js @@ -0,0 +1,37 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 20.3.2 +description: Subclassing the String object +info: > + 20.3.2 The Date Constructor + + ... + + The Date constructor is a single function whose behaviour is overloaded based + upon the number and types of its arguments. + + The Date constructor is designed to be subclassable. It may be used as the + value of an extends clause of a class definition. Subclass constructors that + intend to inherit the specified Date behaviour must include a super call to + the Date constructor to create and initialize the subclass instance with a + [[DateValue]] internal slot. +---*/ + +class D extends Date {} + +var d1 = new D(1859, '10', 24); +assert.sameValue(d1.getUTCFullYear(), 1859); +assert.sameValue(d1.getUTCMonth(), 10); +assert.sameValue(d1.getUTCDate(), 24); + +var d2 = new D(-3474558000000); +assert.sameValue(d2.getUTCFullYear(), 1859); +assert.sameValue(d2.getUTCMonth(), 10); +assert.sameValue(d2.getUTCDate(), 24); + +var d3 = new D(); +var d4 = new Date(); +assert.sameValue(d3.getUTCFullYear(), d4.getUTCFullYear()); +assert.sameValue(d3.getUTCMonth(), d4.getUTCMonth()); +assert.sameValue(d3.getUTCDate(), d4.getUTCDate()); diff --git a/test/language/statements/class/subclass/builtin-objects/Date/super-must-be-called.js b/test/language/statements/class/subclass/builtin-objects/Date/super-must-be-called.js new file mode 100644 index 0000000000000000000000000000000000000000..cfc084d6409c0de92dc93d038c8e21293a5f669b --- /dev/null +++ b/test/language/statements/class/subclass/builtin-objects/Date/super-must-be-called.js @@ -0,0 +1,35 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 20.3.2 +description: Super need to be called to initialize internals +info: > + 20.3.2 The Date Constructor + + ... + + The Date constructor is a single function whose behaviour is overloaded based + upon the number and types of its arguments. + + The Date constructor is designed to be subclassable. It may be used as the + value of an extends clause of a class definition. Subclass constructors that + intend to inherit the specified Date behaviour must include a super call to + the Date constructor to create and initialize the subclass instance with a + [[DateValue]] internal slot. +---*/ + +class D extends Date { + constructor() {} +} + +assert.throws(ReferenceError, function() { + new D(); +}); + +class D2 extends Date { + constructor() { + super(); + } +} + +new D2(); diff --git a/test/language/statements/class/subclass/builtin-objects/Error/message-property-assignment.js b/test/language/statements/class/subclass/builtin-objects/Error/message-property-assignment.js new file mode 100644 index 0000000000000000000000000000000000000000..6a4c00dc4bdd41fd9a3b3e87c68ef1ec9530c385 --- /dev/null +++ b/test/language/statements/class/subclass/builtin-objects/Error/message-property-assignment.js @@ -0,0 +1,36 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 19.5.1.1 +description: > + A new instance has the message property if created with a parameter +info: > + 19.5.1.1 Error ( message ) + + ... + 4. If message is not undefined, then + a. Let msg be ToString(message). + b. ReturnIfAbrupt(msg). + c. Let msgDesc be the PropertyDescriptor{[[Value]]: msg, [[Writable]]: true, + [[Enumerable]]: false, [[Configurable]]: true}. + d. Let status be DefinePropertyOrThrow(O, "message", msgDesc). + ... +includes: [propertyHelper.js] + +---*/ + +class Err extends Error {} + +Err.prototype.message = 'custom-error'; + +var err1 = new Err('foo 42'); +assert.sameValue(err1.message, 'foo 42'); +assert(err1.hasOwnProperty('message')); + +verifyWritable(err1, 'message'); +verifyNotEnumerable(err1, 'message'); +verifyConfigurable(err1, 'message'); + +var err2 = new Err(); +assert.sameValue(err2.hasOwnProperty('message'), false); +assert.sameValue(err2.message, 'custom-error'); diff --git a/test/language/statements/class/subclass/builtin-objects/Error/regular-subclassing.js b/test/language/statements/class/subclass/builtin-objects/Error/regular-subclassing.js new file mode 100644 index 0000000000000000000000000000000000000000..2a073dc7e76be0c3e6103e8d7ff6a1a7cdf93793 --- /dev/null +++ b/test/language/statements/class/subclass/builtin-objects/Error/regular-subclassing.js @@ -0,0 +1,22 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 19.5.1 +description: Subclassing the Error object +info: > + 19.5.1 The Error Constructor + + ... + The Error constructor is designed to be subclassable. It may be used as the + alue of an extends clause of a class definition. Subclass constructors that + intend to inherit the specified Error behaviour must include a super call to + the Error constructor to create and initialize subclass instances with a + [[ErrorData]] internal slot. +---*/ + +class CustomError extends Error {} + +var err = new CustomError('foo 42'); + +assert.sameValue(err.message, 'foo 42'); +assert.sameValue(err.name, 'Error'); diff --git a/test/language/statements/class/subclass/builtin-objects/Error/super-must-be-called.js b/test/language/statements/class/subclass/builtin-objects/Error/super-must-be-called.js new file mode 100644 index 0000000000000000000000000000000000000000..2a83c18607c935dda67c67b91e92f78612ea9e78 --- /dev/null +++ b/test/language/statements/class/subclass/builtin-objects/Error/super-must-be-called.js @@ -0,0 +1,23 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 19.5.1 +description: Super need to be called to initialize internals +info: > + 19.5.1 The Error Constructor + + ... + The Error constructor is designed to be subclassable. It may be used as the + alue of an extends clause of a class definition. Subclass constructors that + intend to inherit the specified Error behaviour must include a super call to + the Error constructor to create and initialize subclass instances with a + [[ErrorData]] internal slot. +---*/ + +class CustomError extends Error { + constructor() {} +} + +assert.throws(ReferenceError, function() { + new CustomError('foo'); +}); diff --git a/test/language/statements/class/subclass/builtin-objects/Function/instance-length.js b/test/language/statements/class/subclass/builtin-objects/Function/instance-length.js new file mode 100644 index 0000000000000000000000000000000000000000..5cd0e35905b85b0ac268846433ea59ca20522937 --- /dev/null +++ b/test/language/statements/class/subclass/builtin-objects/Function/instance-length.js @@ -0,0 +1,27 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 19.2.4.1 +description: Subclassed Function instances has length and name properties +info: > + 19.2.4.1 length + + The value of the length property is an integer that indicates the typical + number of arguments expected by the function. However, the language permits + the function to be invoked with some other number of arguments. The behaviour + of a function when invoked on a number of arguments other than the number + specified by its length property depends on the function. This property has + the attributes { [[Writable]]: false, [[Enumerable]]: false, + [[Configurable]]: true }. +includes: [propertyHelper.js] +---*/ + +class Fn extends Function {} + +var fn = new Fn('a', 'b', 'return a + b'); + +assert.sameValue(fn.length, 2); + +verifyNotEnumerable(fn, 'length'); +verifyNotWritable(fn, 'length'); +verifyConfigurable(fn, 'length'); diff --git a/test/language/statements/class/subclass/builtin-objects/Function/instance-name.js b/test/language/statements/class/subclass/builtin-objects/Function/instance-name.js new file mode 100644 index 0000000000000000000000000000000000000000..fd4fca7c63da6ad1d2a6dc0d55eb6b5cacd05aef --- /dev/null +++ b/test/language/statements/class/subclass/builtin-objects/Function/instance-name.js @@ -0,0 +1,39 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 19.2.4.2 +description: Subclassed Function instances has length and name properties +info: > + 19.2.4.2 name + + The value of the name property is an String that is descriptive of the + function. The name has no semantic significance but is typically a variable or + property name that is used to refer to the function at its point of definition + in ECMAScript code. This property has the attributes { [[Writable]]: false, + [[Enumerable]]: false, [[Configurable]]: true }. + + Anonymous functions objects that do not have a contextual name associated with + them by this specification do not have a name own property but inherit the + name property of %FunctionPrototype%. + + 19.2.1.1.1 RuntimeSemantics: CreateDynamicFunction(constructor, newTarget, + kind, args) + + ... + 29. Perform SetFunctionName(F, "anonymous"). + ... +includes: [propertyHelper.js] +---*/ + +class Fn extends Function {} + +var fn = new Fn('a', 'b', 'return a + b'); + +assert.sameValue( + fn.name, 'anonymous', + 'Dynamic Functions are called anonymous' +); + +verifyNotEnumerable(fn, 'name'); +verifyNotWritable(fn, 'name'); +verifyConfigurable(fn, 'name'); diff --git a/test/language/statements/class/subclass/builtin-objects/Function/regular-subclassing.js b/test/language/statements/class/subclass/builtin-objects/Function/regular-subclassing.js new file mode 100644 index 0000000000000000000000000000000000000000..4791d4907cade6238acc0d61112a7d784b0446c6 --- /dev/null +++ b/test/language/statements/class/subclass/builtin-objects/Function/regular-subclassing.js @@ -0,0 +1,20 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 19.2.1 +description: Subclassing Function +info: > + 19.2.1 The Function Constructor + + ... + + The Function constructor is designed to be subclassable. It may be used as the + value of an extends clause of a class definition. + ... +---*/ + +class Fn extends Function {} + +var fn = new Fn('a', 'return a * 2'); + +assert.sameValue(fn(42), 84); diff --git a/test/language/statements/class/subclass/builtin-objects/Function/super-must-be-called.js b/test/language/statements/class/subclass/builtin-objects/Function/super-must-be-called.js new file mode 100644 index 0000000000000000000000000000000000000000..f86ea414472b9387c0fbf0e189b42bb7e5fce49c --- /dev/null +++ b/test/language/statements/class/subclass/builtin-objects/Function/super-must-be-called.js @@ -0,0 +1,35 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 19.2.1 +description: > + super must be called to initialize Function internal slots +info: > + 19.2.1 The Function Constructor + + ... + + The Function constructor is designed to be subclassable. It may be used as the + value of an extends clause of a class definition. Subclass constructors that + intend to inherit the specified Function behaviour must include a super call + to the Function constructor to create and initialize a subclass instances with + the internal slots necessary for built-in function behaviour. + ... +---*/ + +class Fn extends Function { + constructor() {} +} + +assert.throws(ReferenceError, function() { + new Fn(); +}); + +class Fn2 extends Function { + constructor() { + super(); + } +} + +var fn = new Fn2(); +assert(fn instanceof Function); diff --git a/test/language/statements/class/subclass/builtin-objects/GeneratorFunction/instance-length.js b/test/language/statements/class/subclass/builtin-objects/GeneratorFunction/instance-length.js new file mode 100644 index 0000000000000000000000000000000000000000..8fd184b872cb2d743e94e2a4edcba192c97da3ca --- /dev/null +++ b/test/language/statements/class/subclass/builtin-objects/GeneratorFunction/instance-length.js @@ -0,0 +1,31 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 25.2.4.1 +description: > + Subclassed GeneratorFunction instances `length` property +info: > + 25.2.4.1 length + + The value of the length property is an integer that indicates the typical + number of arguments expected by the GeneratorFunction. However, the language + permits the function to be invoked with some other number of arguments. The + behaviour of a GeneratorFunction when invoked on a number of arguments other + than the number specified by its length property depends on the function. + + This property has the attributes { [[Writable]]: false, [[Enumerable]]: false, + [[Configurable]]: true }. +includes: [propertyHelper.js] +---*/ + +var GeneratorFunction = Object.getPrototypeOf(function* () {}).constructor; + +class GFn extends GeneratorFunction {} + +var gfn = new GFn('a', 'b', 'return a + b'); + +assert.sameValue(gfn.length, 2); + +verifyNotEnumerable(gfn, 'length'); +verifyNotWritable(gfn, 'length'); +verifyConfigurable(gfn, 'length'); diff --git a/test/language/statements/class/subclass/builtin-objects/GeneratorFunction/instance-name.js b/test/language/statements/class/subclass/builtin-objects/GeneratorFunction/instance-name.js new file mode 100644 index 0000000000000000000000000000000000000000..2da93f505794dda146bf60273e88b845fbfe2d1e --- /dev/null +++ b/test/language/statements/class/subclass/builtin-objects/GeneratorFunction/instance-name.js @@ -0,0 +1,46 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 25.2.4.2 +description: Subclassed GeneratorFunction instances `name` property +info: > + 25.2.4.2 name + + The specification for the name property of Function instances given in + 19.2.4.2 also applies to GeneratorFunction instances. + + 19.2.4.2 name + + The value of the name property is an String that is descriptive of the + function. The name has no semantic significance but is typically a variable or + property name that is used to refer to the function at its point of definition + in ECMAScript code. This property has the attributes { [[Writable]]: false, + [[Enumerable]]: false, [[Configurable]]: true }. + + Anonymous functions objects that do not have a contextual name associated with + them by this specification do not have a name own property but inherit the + name property of %FunctionPrototype%. + + 19.2.1.1.1 RuntimeSemantics: CreateDynamicFunction(constructor, newTarget, + kind, args) + + ... + 29. Perform SetFunctionName(F, "anonymous"). + ... +includes: [propertyHelper.js] +---*/ + +var GeneratorFunction = Object.getPrototypeOf(function* () {}).constructor; + +class GFn extends GeneratorFunction {} + +var gfn = new GFn('a', 'b', 'return a + b'); + +assert.sameValue( + gfn.name, 'anonymous', + 'Dynamic Functions are called anonymous' +); + +verifyNotEnumerable(gfn, 'name'); +verifyNotWritable(gfn, 'name'); +verifyConfigurable(gfn, 'name'); diff --git a/test/language/statements/class/subclass/builtin-objects/GeneratorFunction/instance-prototype.js b/test/language/statements/class/subclass/builtin-objects/GeneratorFunction/instance-prototype.js new file mode 100644 index 0000000000000000000000000000000000000000..73889e76c54962492529aa0c3608af454ce8b3cd --- /dev/null +++ b/test/language/statements/class/subclass/builtin-objects/GeneratorFunction/instance-prototype.js @@ -0,0 +1,38 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 25.2.4.3 +description: > + Subclassed GeneratorFunction instances `prototype` property +info: > + 25.2.4.3 prototype + + Whenever a GeneratorFunction instance is created another ordinary object is + also created and is the initial value of the generator function’s prototype + property. The value of the prototype property is used to initialize the + [[Prototype]] internal slot of a newly created Generator object when the + generator function object is invoked using either [[Call]] or [[Construct]]. + + This property has the attributes { [[Writable]]: true, [[Enumerable]]: false, + [[Configurable]]: false }. +includes: [propertyHelper.js] +---*/ + +var GeneratorFunction = Object.getPrototypeOf(function* () {}).constructor; + +class GFn extends GeneratorFunction {} + +var gfn = new GFn(';'); + +assert.sameValue( + Object.keys(gfn.prototype).length, 0, + 'prototype is a new ordinary object' +); +assert.sameValue( + gfn.prototype.hasOwnProperty('constructor'), false, + 'prototype has no constructor reference' +); + +verifyNotEnumerable(gfn, 'prototype'); +verifyWritable(gfn, 'prototype'); +verifyNotConfigurable(gfn, 'prototype'); diff --git a/test/language/statements/class/subclass/builtin-objects/GeneratorFunction/regular-subclassing.js b/test/language/statements/class/subclass/builtin-objects/GeneratorFunction/regular-subclassing.js new file mode 100644 index 0000000000000000000000000000000000000000..cfbb473f9d999bfa9a0ef0584c0ce8c58d336dc7 --- /dev/null +++ b/test/language/statements/class/subclass/builtin-objects/GeneratorFunction/regular-subclassing.js @@ -0,0 +1,29 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 25.2.1 +description: Subclassing GeneratorFunction +info: > + 25.2.1 The GeneratorFunction Constructor + + ... + + GeneratorFunction is designed to be subclassable. It may be used as the value + of an extends clause of a class definition. Subclass constructors that intend + to inherit the specified GeneratorFunction behaviour must include a super call + to the GeneratorFunction constructor to create and initialize subclass + instances with the internal slots necessary for built-in GeneratorFunction + behaviour. + ... +---*/ + +var GeneratorFunction = Object.getPrototypeOf(function* () {}).constructor; + +class Gfn extends GeneratorFunction {} + +var gfn = new Gfn('a', 'yield a; yield a * 2;'); + +var iter = gfn(42); + +assert.sameValue(iter.next().value, 42); +assert.sameValue(iter.next().value, 84); diff --git a/test/language/statements/class/subclass/builtin-objects/GeneratorFunction/super-must-be-called.js b/test/language/statements/class/subclass/builtin-objects/GeneratorFunction/super-must-be-called.js new file mode 100644 index 0000000000000000000000000000000000000000..0288f95e1ede3c7e87597442d99bdfe22b55d715 --- /dev/null +++ b/test/language/statements/class/subclass/builtin-objects/GeneratorFunction/super-must-be-called.js @@ -0,0 +1,38 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 25.2.1 +description: > + super must be called to initialize GeneratorFunction internal slots +info: > + 25.2.1 The GeneratorFunction Constructor + + ... + + GeneratorFunction is designed to be subclassable. It may be used as the value + of an extends clause of a class definition. Subclass constructors that intend + to inherit the specified GeneratorFunction behaviour must include a super call + to the GeneratorFunction constructor to create and initialize subclass + instances with the internal slots necessary for built-in GeneratorFunction + behaviour. + ... +---*/ + +var GeneratorFunction = Object.getPrototypeOf(function* () {}).constructor; + +class GFn1 extends GeneratorFunction { + constructor() {} +} + +assert.throws(ReferenceError, function() { + new GFn1(); +}); + +class GFn2 extends GeneratorFunction { + constructor() { + super(); + } +} + +var fn = new GFn2(); +assert(fn instanceof GeneratorFunction); diff --git a/test/language/statements/class/subclass/builtin-objects/Map/regular-subclassing.js b/test/language/statements/class/subclass/builtin-objects/Map/regular-subclassing.js new file mode 100644 index 0000000000000000000000000000000000000000..c56ee113a16acbff93b791f196a68457c32efa8b --- /dev/null +++ b/test/language/statements/class/subclass/builtin-objects/Map/regular-subclassing.js @@ -0,0 +1,26 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 23.1.1 +description: Subclassing the Map object +info: > + 23.1.1 The Map Constructor + + ... + + The Map constructor is designed to be subclassable. It may be used as the + value in an extends clause of a class definition. Subclass constructors that + intend to inherit the specified Map behaviour must include a super call to the + Map constructor to create and initialize the subclass instance with the + internal state necessary to support the Map.prototype built-in methods. +---*/ + +class M extends Map {} + +var map = new M([{ 'foo': 'bar' }]); + +assert.sameValue(map.size, 1); + +map.set('bar', 'baz'); + +assert.sameValue(map.size, 2); diff --git a/test/language/statements/class/subclass/builtin-objects/Map/super-must-be-called.js b/test/language/statements/class/subclass/builtin-objects/Map/super-must-be-called.js new file mode 100644 index 0000000000000000000000000000000000000000..9af13ead4b0ccb3bc7ab254ccb319cdf02b2d992 --- /dev/null +++ b/test/language/statements/class/subclass/builtin-objects/Map/super-must-be-called.js @@ -0,0 +1,32 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 23.1.1 +description: Super need to be called to initialize internals +info: > + 23.1.1 The Map Constructor + + ... + + The Map constructor is designed to be subclassable. It may be used as the + value in an extends clause of a class definition. Subclass constructors that + intend to inherit the specified Map behaviour must include a super call to the + Map constructor to create and initialize the subclass instance with the + internal state necessary to support the Map.prototype built-in methods. +---*/ + +class M1 extends Map { + constructor() {} +} + +assert.throws(ReferenceError, function() { + new M1(); +}); + +class M2 extends Map { + constructor() { + super(); + } +} + +new M2(); diff --git a/test/language/statements/class/subclass/builtin-objects/NativeError/EvalError-message.js b/test/language/statements/class/subclass/builtin-objects/NativeError/EvalError-message.js new file mode 100644 index 0000000000000000000000000000000000000000..475b236b8fbaf69a13860eae3e21884bf837133b --- /dev/null +++ b/test/language/statements/class/subclass/builtin-objects/NativeError/EvalError-message.js @@ -0,0 +1,35 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 19.5.6.1.1 +description: > + A new instance has the message property if created with a parameter +info: > + 19.5.6.1.1 NativeError ( message ) + + ... + 4. If message is not undefined, then + a. Let msg be ToString(message). + b. Let msgDesc be the PropertyDescriptor{[[Value]]: msg, [[Writable]]: true, + [[Enumerable]]: false, [[Configurable]]: true}. + c. Let status be DefinePropertyOrThrow(O, "message", msgDesc). + ... +includes: [propertyHelper.js] + +---*/ + +class Err extends EvalError {} + +Err.prototype.message = 'custom-eval-error'; + +var err1 = new Err('foo 42'); +assert.sameValue(err1.message, 'foo 42'); +assert(err1.hasOwnProperty('message')); + +verifyWritable(err1, 'message'); +verifyNotEnumerable(err1, 'message'); +verifyConfigurable(err1, 'message'); + +var err2 = new Err(); +assert.sameValue(err2.hasOwnProperty('message'), false); +assert.sameValue(err2.message, 'custom-eval-error'); diff --git a/test/language/statements/class/subclass/builtin-objects/NativeError/EvalError-name.js b/test/language/statements/class/subclass/builtin-objects/NativeError/EvalError-name.js new file mode 100644 index 0000000000000000000000000000000000000000..cfd96de075b334b735e5e67f94d3ebdbd4b313ab --- /dev/null +++ b/test/language/statements/class/subclass/builtin-objects/NativeError/EvalError-name.js @@ -0,0 +1,18 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 19.5.6.1.1 +description: > + The name property on a new instance +info: > + 19.5.6.3.3 NativeError.prototype.name + + The initial value of the name property of the prototype for a given + NativeError constructor is a string consisting of the name of the constructor + (the name used instead of NativeError). +---*/ + +class Err extends EvalError {} + +var err1 = new Err(); +assert.sameValue(err1.name, 'EvalError'); diff --git a/test/language/statements/class/subclass/builtin-objects/NativeError/EvalError-super.js b/test/language/statements/class/subclass/builtin-objects/NativeError/EvalError-super.js new file mode 100644 index 0000000000000000000000000000000000000000..c55cbf0b16379c7d92f97443bb927f4034bb1096 --- /dev/null +++ b/test/language/statements/class/subclass/builtin-objects/NativeError/EvalError-super.js @@ -0,0 +1,23 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 19.5.6.1 +description: Super need to be called to initialize internals +info: > + 19.5.6.1 NativeError Constructors + + ... + Each NativeError constructor is designed to be subclassable. It may be used as + the value of an extends clause of a class definition. Subclass constructors + that intend to inherit the specified NativeError behaviour must include a + super call to the NativeError constructor to create and initialize subclass + instances with a [[ErrorData]] internal slot. +---*/ + +class CustomError extends EvalError { + constructor() {} +} + +assert.throws(ReferenceError, function() { + new CustomError(); +}); diff --git a/test/language/statements/class/subclass/builtin-objects/NativeError/RangeError-message.js b/test/language/statements/class/subclass/builtin-objects/NativeError/RangeError-message.js new file mode 100644 index 0000000000000000000000000000000000000000..f3f4150fcf93a31255be0185983c4d2ab7031111 --- /dev/null +++ b/test/language/statements/class/subclass/builtin-objects/NativeError/RangeError-message.js @@ -0,0 +1,35 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 19.5.6.1.1 +description: > + A new instance has the message property if created with a parameter +info: > + 19.5.6.1.1 NativeError ( message ) + + ... + 4. If message is not undefined, then + a. Let msg be ToString(message). + b. Let msgDesc be the PropertyDescriptor{[[Value]]: msg, [[Writable]]: true, + [[Enumerable]]: false, [[Configurable]]: true}. + c. Let status be DefinePropertyOrThrow(O, "message", msgDesc). + ... +includes: [propertyHelper.js] + +---*/ + +class Err extends RangeError {} + +Err.prototype.message = 'custom-range-error'; + +var err1 = new Err('foo 42'); +assert.sameValue(err1.message, 'foo 42'); +assert(err1.hasOwnProperty('message')); + +verifyWritable(err1, 'message'); +verifyNotEnumerable(err1, 'message'); +verifyConfigurable(err1, 'message'); + +var err2 = new Err(); +assert.sameValue(err2.hasOwnProperty('message'), false); +assert.sameValue(err2.message, 'custom-range-error'); diff --git a/test/language/statements/class/subclass/builtin-objects/NativeError/RangeError-name.js b/test/language/statements/class/subclass/builtin-objects/NativeError/RangeError-name.js new file mode 100644 index 0000000000000000000000000000000000000000..c676057e2bb22e6623dbccd7e6430867337bc5af --- /dev/null +++ b/test/language/statements/class/subclass/builtin-objects/NativeError/RangeError-name.js @@ -0,0 +1,18 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 19.5.6.1.1 +description: > + The name property on a new instance +info: > + 19.5.6.3.3 NativeError.prototype.name + + The initial value of the name property of the prototype for a given + NativeError constructor is a string consisting of the name of the constructor + (the name used instead of NativeError). +---*/ + +class Err extends RangeError {} + +var err1 = new Err(); +assert.sameValue(err1.name, 'RangeError'); diff --git a/test/language/statements/class/subclass/builtin-objects/NativeError/RangeError-super.js b/test/language/statements/class/subclass/builtin-objects/NativeError/RangeError-super.js new file mode 100644 index 0000000000000000000000000000000000000000..c02eec530d55a07336734d5ad7ddc0bb67fe8e57 --- /dev/null +++ b/test/language/statements/class/subclass/builtin-objects/NativeError/RangeError-super.js @@ -0,0 +1,23 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 19.5.6.1 +description: Super need to be called to initialize internals +info: > + 19.5.6.1 NativeError Constructors + + ... + Each NativeError constructor is designed to be subclassable. It may be used as + the value of an extends clause of a class definition. Subclass constructors + that intend to inherit the specified NativeError behaviour must include a + super call to the NativeError constructor to create and initialize subclass + instances with a [[ErrorData]] internal slot. +---*/ + +class CustomError extends RangeError { + constructor() {} +} + +assert.throws(ReferenceError, function() { + new CustomError(); +}); diff --git a/test/language/statements/class/subclass/builtin-objects/NativeError/ReferenceError-message.js b/test/language/statements/class/subclass/builtin-objects/NativeError/ReferenceError-message.js new file mode 100644 index 0000000000000000000000000000000000000000..d8ba34f1001f78324e5327e1731c2226e92903f1 --- /dev/null +++ b/test/language/statements/class/subclass/builtin-objects/NativeError/ReferenceError-message.js @@ -0,0 +1,35 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 19.5.6.1.1 +description: > + A new instance has the message property if created with a parameter +info: > + 19.5.6.1.1 NativeError ( message ) + + ... + 4. If message is not undefined, then + a. Let msg be ToString(message). + b. Let msgDesc be the PropertyDescriptor{[[Value]]: msg, [[Writable]]: true, + [[Enumerable]]: false, [[Configurable]]: true}. + c. Let status be DefinePropertyOrThrow(O, "message", msgDesc). + ... +includes: [propertyHelper.js] + +---*/ + +class Err extends ReferenceError {} + +Err.prototype.message = 'custom-reference-error'; + +var err1 = new Err('foo 42'); +assert.sameValue(err1.message, 'foo 42'); +assert(err1.hasOwnProperty('message')); + +verifyWritable(err1, 'message'); +verifyNotEnumerable(err1, 'message'); +verifyConfigurable(err1, 'message'); + +var err2 = new Err(); +assert.sameValue(err2.hasOwnProperty('message'), false); +assert.sameValue(err2.message, 'custom-reference-error'); diff --git a/test/language/statements/class/subclass/builtin-objects/NativeError/ReferenceError-name.js b/test/language/statements/class/subclass/builtin-objects/NativeError/ReferenceError-name.js new file mode 100644 index 0000000000000000000000000000000000000000..ca746745ad2f982048a3aef7d17ec7c2fef1a8bb --- /dev/null +++ b/test/language/statements/class/subclass/builtin-objects/NativeError/ReferenceError-name.js @@ -0,0 +1,18 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 19.5.6.1.1 +description: > + The name property on a new instance +info: > + 19.5.6.3.3 NativeError.prototype.name + + The initial value of the name property of the prototype for a given + NativeError constructor is a string consisting of the name of the constructor + (the name used instead of NativeError). +---*/ + +class Err extends ReferenceError {} + +var err1 = new Err(); +assert.sameValue(err1.name, 'ReferenceError'); diff --git a/test/language/statements/class/subclass/builtin-objects/NativeError/ReferenceError-super.js b/test/language/statements/class/subclass/builtin-objects/NativeError/ReferenceError-super.js new file mode 100644 index 0000000000000000000000000000000000000000..7ea1b66d188185eee846aac9866511801454a658 --- /dev/null +++ b/test/language/statements/class/subclass/builtin-objects/NativeError/ReferenceError-super.js @@ -0,0 +1,23 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 19.5.6.1 +description: Super need to be called to initialize internals +info: > + 19.5.6.1 NativeError Constructors + + ... + Each NativeError constructor is designed to be subclassable. It may be used as + the value of an extends clause of a class definition. Subclass constructors + that intend to inherit the specified NativeError behaviour must include a + super call to the NativeError constructor to create and initialize subclass + instances with a [[ErrorData]] internal slot. +---*/ + +class CustomError extends ReferenceError { + constructor() {} +} + +assert.throws(ReferenceError, function() { + new CustomError(); +}); diff --git a/test/language/statements/class/subclass/builtin-objects/NativeError/SyntaxError-message.js b/test/language/statements/class/subclass/builtin-objects/NativeError/SyntaxError-message.js new file mode 100644 index 0000000000000000000000000000000000000000..4a31b877396ef5afb3056b4de6d4c4113d482ca0 --- /dev/null +++ b/test/language/statements/class/subclass/builtin-objects/NativeError/SyntaxError-message.js @@ -0,0 +1,35 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 19.5.6.1.1 +description: > + A new instance has the message property if created with a parameter +info: > + 19.5.6.1.1 NativeError ( message ) + + ... + 4. If message is not undefined, then + a. Let msg be ToString(message). + b. Let msgDesc be the PropertyDescriptor{[[Value]]: msg, [[Writable]]: true, + [[Enumerable]]: false, [[Configurable]]: true}. + c. Let status be DefinePropertyOrThrow(O, "message", msgDesc). + ... +includes: [propertyHelper.js] + +---*/ + +class Err extends SyntaxError {} + +Err.prototype.message = 'custom-syntax-error'; + +var err1 = new Err('foo 42'); +assert.sameValue(err1.message, 'foo 42'); +assert(err1.hasOwnProperty('message')); + +verifyWritable(err1, 'message'); +verifyNotEnumerable(err1, 'message'); +verifyConfigurable(err1, 'message'); + +var err2 = new Err(); +assert.sameValue(err2.hasOwnProperty('message'), false); +assert.sameValue(err2.message, 'custom-syntax-error'); diff --git a/test/language/statements/class/subclass/builtin-objects/NativeError/SyntaxError-name.js b/test/language/statements/class/subclass/builtin-objects/NativeError/SyntaxError-name.js new file mode 100644 index 0000000000000000000000000000000000000000..658d59e5470b194048232834f6b18772ff7d607c --- /dev/null +++ b/test/language/statements/class/subclass/builtin-objects/NativeError/SyntaxError-name.js @@ -0,0 +1,18 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 19.5.6.1.1 +description: > + The name property on a new instance +info: > + 19.5.6.3.3 NativeError.prototype.name + + The initial value of the name property of the prototype for a given + NativeError constructor is a string consisting of the name of the constructor + (the name used instead of NativeError). +---*/ + +class Err extends SyntaxError {} + +var err1 = new Err(); +assert.sameValue(err1.name, 'SyntaxError'); diff --git a/test/language/statements/class/subclass/builtin-objects/NativeError/SyntaxError-super.js b/test/language/statements/class/subclass/builtin-objects/NativeError/SyntaxError-super.js new file mode 100644 index 0000000000000000000000000000000000000000..903f5337bf0e931b8bd37975b94dd7f1fb655d14 --- /dev/null +++ b/test/language/statements/class/subclass/builtin-objects/NativeError/SyntaxError-super.js @@ -0,0 +1,23 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 19.5.6.1 +description: Super need to be called to initialize internals +info: > + 19.5.6.1 NativeError Constructors + + ... + Each NativeError constructor is designed to be subclassable. It may be used as + the value of an extends clause of a class definition. Subclass constructors + that intend to inherit the specified NativeError behaviour must include a + super call to the NativeError constructor to create and initialize subclass + instances with a [[ErrorData]] internal slot. +---*/ + +class CustomError extends SyntaxError { + constructor() {} +} + +assert.throws(ReferenceError, function() { + new CustomError(); +}); diff --git a/test/language/statements/class/subclass/builtin-objects/NativeError/TypeError-message.js b/test/language/statements/class/subclass/builtin-objects/NativeError/TypeError-message.js new file mode 100644 index 0000000000000000000000000000000000000000..a8bdbb3c0a8261d89584bacb2fd34ea70de3fb42 --- /dev/null +++ b/test/language/statements/class/subclass/builtin-objects/NativeError/TypeError-message.js @@ -0,0 +1,35 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 19.5.6.1.1 +description: > + A new instance has the message property if created with a parameter +info: > + 19.5.6.1.1 NativeError ( message ) + + ... + 4. If message is not undefined, then + a. Let msg be ToString(message). + b. Let msgDesc be the PropertyDescriptor{[[Value]]: msg, [[Writable]]: true, + [[Enumerable]]: false, [[Configurable]]: true}. + c. Let status be DefinePropertyOrThrow(O, "message", msgDesc). + ... +includes: [propertyHelper.js] + +---*/ + +class Err extends TypeError {} + +Err.prototype.message = 'custom-type-error'; + +var err1 = new Err('foo 42'); +assert.sameValue(err1.message, 'foo 42'); +assert(err1.hasOwnProperty('message')); + +verifyWritable(err1, 'message'); +verifyNotEnumerable(err1, 'message'); +verifyConfigurable(err1, 'message'); + +var err2 = new Err(); +assert.sameValue(err2.hasOwnProperty('message'), false); +assert.sameValue(err2.message, 'custom-type-error'); diff --git a/test/language/statements/class/subclass/builtin-objects/NativeError/TypeError-name.js b/test/language/statements/class/subclass/builtin-objects/NativeError/TypeError-name.js new file mode 100644 index 0000000000000000000000000000000000000000..d84b419c982588b2883b297622f135c0df8606c7 --- /dev/null +++ b/test/language/statements/class/subclass/builtin-objects/NativeError/TypeError-name.js @@ -0,0 +1,18 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 19.5.6.1.1 +description: > + The name property on a new instance +info: > + 19.5.6.3.3 NativeError.prototype.name + + The initial value of the name property of the prototype for a given + NativeError constructor is a string consisting of the name of the constructor + (the name used instead of NativeError). +---*/ + +class Err extends TypeError {} + +var err1 = new Err(); +assert.sameValue(err1.name, 'TypeError'); diff --git a/test/language/statements/class/subclass/builtin-objects/NativeError/TypeError-super.js b/test/language/statements/class/subclass/builtin-objects/NativeError/TypeError-super.js new file mode 100644 index 0000000000000000000000000000000000000000..ee764f80d0da10b9de0f371e5142111954486109 --- /dev/null +++ b/test/language/statements/class/subclass/builtin-objects/NativeError/TypeError-super.js @@ -0,0 +1,23 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 19.5.6.1 +description: Super need to be called to initialize internals +info: > + 19.5.6.1 NativeError Constructors + + ... + Each NativeError constructor is designed to be subclassable. It may be used as + the value of an extends clause of a class definition. Subclass constructors + that intend to inherit the specified NativeError behaviour must include a + super call to the NativeError constructor to create and initialize subclass + instances with a [[ErrorData]] internal slot. +---*/ + +class CustomError extends TypeError { + constructor() {} +} + +assert.throws(ReferenceError, function() { + new CustomError(); +}); diff --git a/test/language/statements/class/subclass/builtin-objects/NativeError/URIError-message.js b/test/language/statements/class/subclass/builtin-objects/NativeError/URIError-message.js new file mode 100644 index 0000000000000000000000000000000000000000..214e73d3871b41798d06dcb64f1b5645735ca127 --- /dev/null +++ b/test/language/statements/class/subclass/builtin-objects/NativeError/URIError-message.js @@ -0,0 +1,35 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 19.5.6.1.1 +description: > + A new instance has the message property if created with a parameter +info: > + 19.5.6.1.1 NativeError ( message ) + + ... + 4. If message is not undefined, then + a. Let msg be ToString(message). + b. Let msgDesc be the PropertyDescriptor{[[Value]]: msg, [[Writable]]: true, + [[Enumerable]]: false, [[Configurable]]: true}. + c. Let status be DefinePropertyOrThrow(O, "message", msgDesc). + ... +includes: [propertyHelper.js] + +---*/ + +class Err extends URIError {} + +Err.prototype.message = 'custom-uri-error'; + +var err1 = new Err('foo 42'); +assert.sameValue(err1.message, 'foo 42'); +assert(err1.hasOwnProperty('message')); + +verifyWritable(err1, 'message'); +verifyNotEnumerable(err1, 'message'); +verifyConfigurable(err1, 'message'); + +var err2 = new Err(); +assert.sameValue(err2.hasOwnProperty('message'), false); +assert.sameValue(err2.message, 'custom-uri-error'); diff --git a/test/language/statements/class/subclass/builtin-objects/NativeError/URIError-name.js b/test/language/statements/class/subclass/builtin-objects/NativeError/URIError-name.js new file mode 100644 index 0000000000000000000000000000000000000000..78791e36d7240deb93709243041ad40f57efd0c8 --- /dev/null +++ b/test/language/statements/class/subclass/builtin-objects/NativeError/URIError-name.js @@ -0,0 +1,18 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 19.5.6.1.1 +description: > + The name property on a new instance +info: > + 19.5.6.3.3 NativeError.prototype.name + + The initial value of the name property of the prototype for a given + NativeError constructor is a string consisting of the name of the constructor + (the name used instead of NativeError). +---*/ + +class Err extends URIError {} + +var err1 = new Err(); +assert.sameValue(err1.name, 'URIError'); diff --git a/test/language/statements/class/subclass/builtin-objects/NativeError/URIError-super.js b/test/language/statements/class/subclass/builtin-objects/NativeError/URIError-super.js new file mode 100644 index 0000000000000000000000000000000000000000..ab21a7170af081b8323a63ddd037af593b1a89b6 --- /dev/null +++ b/test/language/statements/class/subclass/builtin-objects/NativeError/URIError-super.js @@ -0,0 +1,23 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 19.5.6.1 +description: Super need to be called to initialize internals +info: > + 19.5.6.1 NativeError Constructors + + ... + Each NativeError constructor is designed to be subclassable. It may be used as + the value of an extends clause of a class definition. Subclass constructors + that intend to inherit the specified NativeError behaviour must include a + super call to the NativeError constructor to create and initialize subclass + instances with a [[ErrorData]] internal slot. +---*/ + +class CustomError extends URIError { + constructor() {} +} + +assert.throws(ReferenceError, function() { + new CustomError(); +}); diff --git a/test/language/statements/class/subclass/builtin-objects/Number/regular-subclassing.js b/test/language/statements/class/subclass/builtin-objects/Number/regular-subclassing.js new file mode 100644 index 0000000000000000000000000000000000000000..7f5ce10fb8d7010cf2440eff70086ef98bb1e5a0 --- /dev/null +++ b/test/language/statements/class/subclass/builtin-objects/Number/regular-subclassing.js @@ -0,0 +1,23 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 20.1.1 +description: Subclassing the Number object +info: > + 20.1.1 The Number Constructor + + ... + + The Number constructor is designed to be subclassable. It may be used as the + value of an extends clause of a class definition. Subclass constructors that + intend to inherit the specified Number behaviour must include a super call to + the Number constructor to create and initialize the subclass instance with a + [[NumberData]] internal slot. +---*/ + +class N extends Number {} + +var n = new N(42); + +assert.sameValue(n.toFixed(2), '42.00'); +assert.sameValue(n.toExponential(2), '4.20e+1'); diff --git a/test/language/statements/class/subclass/builtin-objects/Number/super-must-be-called.js b/test/language/statements/class/subclass/builtin-objects/Number/super-must-be-called.js new file mode 100644 index 0000000000000000000000000000000000000000..bc702737f856e6afc78ee22122547c985803bc81 --- /dev/null +++ b/test/language/statements/class/subclass/builtin-objects/Number/super-must-be-called.js @@ -0,0 +1,32 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 20.1.1 +description: Super need to be called to initialize internals +info: > + 20.1.1 The Number Constructor + + ... + + The Number constructor is designed to be subclassable. It may be used as the + value of an extends clause of a class definition. Subclass constructors that + intend to inherit the specified Number behaviour must include a super call to + the Number constructor to create and initialize the subclass instance with a + [[NumberData]] internal slot. +---*/ + +class N extends Number { + constructor() {} +} + +assert.throws(ReferenceError, function() { + new N(); +}); + +class N2 extends Number { + constructor() { + super(); + } +} + +new N2(); diff --git a/test/language/statements/class/subclass/builtin-objects/Object/constructor-return-undefined-throws.js b/test/language/statements/class/subclass/builtin-objects/Object/constructor-return-undefined-throws.js new file mode 100644 index 0000000000000000000000000000000000000000..36d1f1c4c26d657c014df362fdc946583a256ff5 --- /dev/null +++ b/test/language/statements/class/subclass/builtin-objects/Object/constructor-return-undefined-throws.js @@ -0,0 +1,45 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 9.2.2 +description: Throws a ReferenceError if constructor result is undefined +info: > + 9.2.2 [[Construct]] ( argumentsList, newTarget) + + ... + 11. Let result be OrdinaryCallEvaluateBody(F, argumentsList). + ... + 13. If result.[[type]] is return, then + a. If Type(result.[[value]]) is Object, return + NormalCompletion(result.[[value]]). + ... + c. If result.[[value]] is not undefined, throw a TypeError exception. + ... + 15. Return envRec.GetThisBinding(). + + 8.1.1.3.4 GetThisBinding () + + ... + 3. If envRec.[[thisBindingStatus]] is "uninitialized", throw a ReferenceError + exception. + ... + +---*/ + +class Obj extends Object { + constructor() { + return undefined; + } +} + +class Obj2 extends Object { + constructor() {} +} + +assert.throws(ReferenceError, function() { + new Obj(); +}); + +assert.throws(ReferenceError, function() { + new Obj2(); +}); diff --git a/test/language/statements/class/subclass/builtin-objects/Object/constructor-returns-non-object.js b/test/language/statements/class/subclass/builtin-objects/Object/constructor-returns-non-object.js new file mode 100644 index 0000000000000000000000000000000000000000..ac361219c272a02308a2217e23307fdbcd9a0dea --- /dev/null +++ b/test/language/statements/class/subclass/builtin-objects/Object/constructor-returns-non-object.js @@ -0,0 +1,40 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 9.2.2 +description: The Type of the return value must be an Object +info: > + 9.2.2 [[Construct]] ( argumentsList, newTarget) + + ... + 11. Let result be OrdinaryCallEvaluateBody(F, argumentsList). + ... + 13. If result.[[type]] is return, then + a. If Type(result.[[value]]) is Object, return + NormalCompletion(result.[[value]]). + ... + c. If result.[[value]] is not undefined, throw a TypeError exception. + ... + + 6.1.7.2 Object Internal Methods and Internal Slots + + ... + If any specified use of an internal method of an exotic object is not + supported by an implementation, that usage must throw a TypeError exception + when attempted. + + 6.1.7.3 Invariants of the Essential Internal Methods + + [[Construct]] ( ) + - The Type of the return value must be Object. +---*/ + +class Obj extends Object { + constructor() { + return 42; + } +} + +assert.throws(TypeError, function() { + var obj = new Obj(); +}); diff --git a/test/language/statements/class/subclass/builtin-objects/Object/regular-subclassing.js b/test/language/statements/class/subclass/builtin-objects/Object/regular-subclassing.js new file mode 100644 index 0000000000000000000000000000000000000000..ab84a630e056053c020841d44ebc84e6de8ef63d --- /dev/null +++ b/test/language/statements/class/subclass/builtin-objects/Object/regular-subclassing.js @@ -0,0 +1,20 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 19.1.1 +description: Subclassing Object +info: > + 19.1.1 The Object Constructor + + The Object constructor is designed to be subclassable. It may be used as the + value of an extends clause of a class definition. +---*/ + +class Obj extends Object {} + +var obj = new Obj(); + +assert.notSameValue( + Object.getPrototypeOf(obj), Object.prototype, + 'returns the class prototype' +); diff --git a/test/language/statements/class/subclass/builtin-objects/Object/replacing-prototype.js b/test/language/statements/class/subclass/builtin-objects/Object/replacing-prototype.js new file mode 100644 index 0000000000000000000000000000000000000000..a3842d7eaddb8f76c0ab8c5ef401fa7ba4313474 --- /dev/null +++ b/test/language/statements/class/subclass/builtin-objects/Object/replacing-prototype.js @@ -0,0 +1,21 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 19.1.1 +description: Subclassing Object replacing a prototype method +info: > + 19.1.1 The Object Constructor + + The Object constructor is designed to be subclassable. It may be used as the + value of an extends clause of a class definition. +---*/ + +class Obj extends Object { + valueOf() { + return 42; + } +} + +var obj = new Obj(); + +assert.sameValue(obj.valueOf(), 42, 'Replaces prototype'); diff --git a/test/language/statements/class/subclass/builtin-objects/Promise/regular-subclassing.js b/test/language/statements/class/subclass/builtin-objects/Promise/regular-subclassing.js new file mode 100644 index 0000000000000000000000000000000000000000..d4a87192bba537c9d907b706b9602da2e347a4ab --- /dev/null +++ b/test/language/statements/class/subclass/builtin-objects/Promise/regular-subclassing.js @@ -0,0 +1,34 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 25.4.3 +description: Subclassing the Promise object +info: > + 25.4.3 The Promise Constructor + + ... + + The Promise constructor is designed to be subclassable. It may be used as the + value in an extends clause of a class definition. Subclass constructors that + intend to inherit the specified Promise behaviour must include a super call + to the Promise constructor to create and initialize the subclass instance with + the internal state necessary to support the Promise and Promise.prototype + built-in methods. +---*/ + +class Prom extends Promise {} + +assert.throws(TypeError, function() { + new Prom(); +}); + +var calledExecutor = false; + +var prom1 = new Prom(function(resolve) { + calledExecutor = true; + assert.sameValue(arguments.length, 2); + assert(arguments[0] === Promise.resolve); + assert(arguments[1] === Promise.reject); +}); + +assert(calledExecutor); diff --git a/test/language/statements/class/subclass/builtin-objects/Promise/super-must-be-called.js b/test/language/statements/class/subclass/builtin-objects/Promise/super-must-be-called.js new file mode 100644 index 0000000000000000000000000000000000000000..e863f33d4c3fee3a723240a56487fecf376696e6 --- /dev/null +++ b/test/language/statements/class/subclass/builtin-objects/Promise/super-must-be-called.js @@ -0,0 +1,33 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 25.4.3 +description: Super need to be called to initialize internals +info: > + 25.4.3 The Promise Constructor + + ... + + The Promise constructor is designed to be subclassable. It may be used as the + value in an extends clause of a class definition. Subclass constructors that + intend to inherit the specified Promise behaviour must include a super call + to the Promise constructor to create and initialize the subclass instance with + the internal state necessary to support the Promise and Promise.prototype + built-in methods. +---*/ + +class Prom1 extends Promise { + constructor() {} +} + +assert.throws(ReferenceError, function() { + new Prom1(); +}); + +class Prom2 extends Promise { + constructor(exec) { + super(exec); + } +} + +new Prom2(function() {}); diff --git a/test/language/statements/class/subclass/builtin-objects/Proxy/no-prototype-throws.js b/test/language/statements/class/subclass/builtin-objects/Proxy/no-prototype-throws.js new file mode 100644 index 0000000000000000000000000000000000000000..44859ca000ded3d99072311eeb78cdb5e3deacf8 --- /dev/null +++ b/test/language/statements/class/subclass/builtin-objects/Proxy/no-prototype-throws.js @@ -0,0 +1,32 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 14.5.14 +description: The Proxy Object is not subclasseable without a prototype +info: > + 14.5.14 Runtime Semantics: ClassDefinitionEvaluation + + 5. If ClassHeritageopt is not present, then + ... + 6. Else + ... + e. If superclass is null, then + ... + f. Else if IsConstructor(superclass) is false, throw a TypeError exception. + g. Else + ... + ii. Let protoParent be Get(superclass, "prototype"). + iii. ReturnIfAbrupt(protoParent). + iv. If Type(protoParent) is neither Object nor Null, throw a TypeError exception. + + 26.2.1 The Proxy Constructor + + The Proxy constructor is the %Proxy% intrinsic object and the initial value of + the Proxy property of the global object. When called as a constructor it + creates and initializes a new proxy exotic object. Proxy is not intended to be + called as a function and will throw an exception when called in that manner. +---*/ + +assert.throws(TypeError, function() { + class P extends Proxy {} +}); diff --git a/test/language/statements/class/subclass/builtin-objects/RegExp/lastIndex.js b/test/language/statements/class/subclass/builtin-objects/RegExp/lastIndex.js new file mode 100644 index 0000000000000000000000000000000000000000..2e2a05e4c84094ed7821e43899997602a2e6816f --- /dev/null +++ b/test/language/statements/class/subclass/builtin-objects/RegExp/lastIndex.js @@ -0,0 +1,26 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 21.2.6.1 +description: Instances has the own property lastIndex +info: > + 21.2.6.1 lastIndex + + The value of the lastIndex property specifies the String index at which to + start the next match. It is coerced to an integer when used (see 21.2.5.2.2). + This property shall have the attributes { [[Writable]]: true, [[Enumerable]]: + false, [[Configurable]]: false }. +includes: [propertyHelper.js] +---*/ + +class RE extends RegExp {} + +var re = new RE('39?'); + +re.exec('TC39'); + +assert.sameValue(re.lastIndex, 0); + +verifyWritable(re, 'lastIndex'); +verifyNotEnumerable(re, 'lastIndex'); +verifyNotConfigurable(re, 'lastIndex'); \ No newline at end of file diff --git a/test/language/statements/class/subclass/builtin-objects/RegExp/regular-subclassing.js b/test/language/statements/class/subclass/builtin-objects/RegExp/regular-subclassing.js new file mode 100644 index 0000000000000000000000000000000000000000..37245ba966a9518da1f45fae7525de97e7b55e66 --- /dev/null +++ b/test/language/statements/class/subclass/builtin-objects/RegExp/regular-subclassing.js @@ -0,0 +1,23 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 21.2.3 +description: Subclassing the RegExp object +info: > + 21.2.3 The RegExp Constructor + + ... + + The RegExp constructor is designed to be subclassable. It may be used as the + value of an extends clause of a class definition. Subclass constructors that + intend to inherit the specified RegExp behaviour must include a super call to + the RegExp constructor to create and initialize subclass instances with the + necessary internal slots. +---*/ + +class RE extends RegExp {} + +var re = new RE(39); + +assert.sameValue(re.test('TC39'), true); +assert.sameValue(re.test('42'), false); diff --git a/test/language/statements/class/subclass/builtin-objects/RegExp/super-must-be-called.js b/test/language/statements/class/subclass/builtin-objects/RegExp/super-must-be-called.js new file mode 100644 index 0000000000000000000000000000000000000000..30c067d91df7f1fde0ca9d59a92064ee1228f0bf --- /dev/null +++ b/test/language/statements/class/subclass/builtin-objects/RegExp/super-must-be-called.js @@ -0,0 +1,32 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 21.2.3 +description: Super need to be called to initialize internals +info: > + 21.2.3 The RegExp Constructor + + ... + + The RegExp constructor is designed to be subclassable. It may be used as the + value of an extends clause of a class definition. Subclass constructors that + intend to inherit the specified RegExp behaviour must include a super call to + the RegExp constructor to create and initialize subclass instances with the + necessary internal slots. +---*/ + +class RE1 extends RegExp { + constructor() {} +} + +assert.throws(ReferenceError, function() { + new RE1(); +}); + +class RE2 extends RegExp { + constructor() { + super(); + } +} + +new RE2(); diff --git a/test/language/statements/class/subclass/builtin-objects/Set/regular-subclassing.js b/test/language/statements/class/subclass/builtin-objects/Set/regular-subclassing.js new file mode 100644 index 0000000000000000000000000000000000000000..aca36227a64c660603572c418c4a8f3e5b4bb46b --- /dev/null +++ b/test/language/statements/class/subclass/builtin-objects/Set/regular-subclassing.js @@ -0,0 +1,26 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 23.2.1 +description: Subclassing the Set object +info: > + 23.2.1 The Set Constructor + + ... + + The Set constructor is designed to be subclassable. It may be used as the + value in an extends clause of a class definition. Subclass constructors that + intend to inherit the specified Set behaviour must include a super call to the + Set constructor to create and initialize the subclass instance with the + internal state necessary to support the Set.prototype built-in methods. +---*/ + +class S extends Set {} + +var set = new S([{}, {}]); + +assert.sameValue(set.size, 2); + +set.add({}); + +assert.sameValue(set.size, 3); diff --git a/test/language/statements/class/subclass/builtin-objects/Set/super-must-be-called.js b/test/language/statements/class/subclass/builtin-objects/Set/super-must-be-called.js new file mode 100644 index 0000000000000000000000000000000000000000..ee41c621fc284d170b59e99127346edbc60be0dc --- /dev/null +++ b/test/language/statements/class/subclass/builtin-objects/Set/super-must-be-called.js @@ -0,0 +1,32 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 23.2.1 +description: Super need to be called to initialize internals +info: > + 23.2.1 The Set Constructor + + ... + + The Set constructor is designed to be subclassable. It may be used as the + value in an extends clause of a class definition. Subclass constructors that + intend to inherit the specified Set behaviour must include a super call to the + Set constructor to create and initialize the subclass instance with the + internal state necessary to support the Set.prototype built-in methods. +---*/ + +class S1 extends Set { + constructor() {} +} + +assert.throws(ReferenceError, function() { + new S1(); +}); + +class S2 extends Set { + constructor() { + super(); + } +} + +new S2(); diff --git a/test/language/statements/class/subclass/builtin-objects/String/length.js b/test/language/statements/class/subclass/builtin-objects/String/length.js new file mode 100644 index 0000000000000000000000000000000000000000..94ca8f3cc443857d884bd2ba43986093bae9c841 --- /dev/null +++ b/test/language/statements/class/subclass/builtin-objects/String/length.js @@ -0,0 +1,30 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 21.1.4 +description: Instances has the own property length +info: > + 21.1.4 Properties of String Instances + + ... + + String instances have a length property, and a set of enumerable properties + with integer indexed names. +includes: [propertyHelper.js] +---*/ + +class S extends String {} + +var s1 = new S(); +assert.sameValue(s1.length, 0); + +verifyNotWritable(s1, 'length'); +verifyNotEnumerable(s1, 'length'); +verifyNotConfigurable(s1, 'length'); + +var s2 = new S('test262'); +assert.sameValue(s2.length, 7); + +verifyNotWritable(s2, 'length'); +verifyNotEnumerable(s2, 'length'); +verifyNotConfigurable(s2, 'length'); \ No newline at end of file diff --git a/test/language/statements/class/subclass/builtin-objects/String/regular-subclassing.js b/test/language/statements/class/subclass/builtin-objects/String/regular-subclassing.js new file mode 100644 index 0000000000000000000000000000000000000000..3fda01d2299f00ac14061ffb70231401c14680d5 --- /dev/null +++ b/test/language/statements/class/subclass/builtin-objects/String/regular-subclassing.js @@ -0,0 +1,22 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 21.1.1 +description: Subclassing the String object +info: > + 21.1.1 The String Constructor + + ... + The String constructor is designed to be subclassable. It may be used as the + value of an extends clause of a class definition. Subclass constructors that + intend to inherit the specified String behaviour must include a super call to + the String constructor to create and initialize the subclass instance with a + [[StringData]] internal slot. +---*/ + +class S extends String {} + +var s = new S(' test262 '); + +assert.sameValue(s.trim(), 'test262'); + diff --git a/test/language/statements/class/subclass/builtin-objects/String/super-must-be-called.js b/test/language/statements/class/subclass/builtin-objects/String/super-must-be-called.js new file mode 100644 index 0000000000000000000000000000000000000000..069d95a643668c46c71808d555beb1ea415dac9e --- /dev/null +++ b/test/language/statements/class/subclass/builtin-objects/String/super-must-be-called.js @@ -0,0 +1,31 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 21.1.1 +description: Super need to be called to initialize internals +info: > + 21.1.1 The String Constructor + + ... + The String constructor is designed to be subclassable. It may be used as the + value of an extends clause of a class definition. Subclass constructors that + intend to inherit the specified String behaviour must include a super call to + the String constructor to create and initialize the subclass instance with a + [[StringData]] internal slot. +---*/ + +class S1 extends String { + constructor() {} +} + +assert.throws(ReferenceError, function() { + new S1(); +}); + +class S2 extends String { + constructor() { + super(); + } +} + +new S2(); diff --git a/test/language/statements/class/subclass/builtin-objects/Symbol/new-symbol-with-super-throws.js b/test/language/statements/class/subclass/builtin-objects/Symbol/new-symbol-with-super-throws.js new file mode 100644 index 0000000000000000000000000000000000000000..202079b2f3b38ca569b024494ccaaea8a9d1c23f --- /dev/null +++ b/test/language/statements/class/subclass/builtin-objects/Symbol/new-symbol-with-super-throws.js @@ -0,0 +1,35 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 19.4.1 +description: Symbol subclass called with the new operator throws on super() +info: > + 19.4.1 The Symbol Constructor + + ... + The Symbol constructor is not intended to be used with the new operator or to + be subclassed. It may be used as the value of an extends clause of a class + definition but a super call to the Symbol constructor will cause an exception. + + 19.4.1.1 Symbol ( [ description ] ) + + ... + 1. If NewTarget is not undefined, throw a TypeError exception. +---*/ + +class S1 extends Symbol {} + +assert.throws(TypeError, function() { + new S1(); +}); + +class S2 extends Symbol { + constructor() { + super(); + } +} + +assert.throws(TypeError, function() { + new S2(); +}); + diff --git a/test/language/statements/class/subclass/builtin-objects/Symbol/symbol-valid-as-extends-value.js b/test/language/statements/class/subclass/builtin-objects/Symbol/symbol-valid-as-extends-value.js new file mode 100644 index 0000000000000000000000000000000000000000..d565efdcb4fdc2046d676f8f29b1219fc7dec23d --- /dev/null +++ b/test/language/statements/class/subclass/builtin-objects/Symbol/symbol-valid-as-extends-value.js @@ -0,0 +1,16 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 19.4.1 +description: Symbol can be used as the value of an extends +info: > + 19.4.1 The Symbol Constructor + + ... + The Symbol constructor is not intended to be used with the new operator or to + be subclassed. It may be used as the value of an extends clause of a class + definition but a super call to the Symbol constructor will cause an exception. + ... +---*/ + +class S extends Symbol {} diff --git a/test/language/statements/class/subclass/builtin-objects/TypedArray/regular-subclassing.js b/test/language/statements/class/subclass/builtin-objects/TypedArray/regular-subclassing.js new file mode 100644 index 0000000000000000000000000000000000000000..f1111e5e8ae86e209179b4a7fc65753a944c5e9c --- /dev/null +++ b/test/language/statements/class/subclass/builtin-objects/TypedArray/regular-subclassing.js @@ -0,0 +1,35 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 22.2.4 +description: Subclassing TypedArrays +info: > + 22.2.4 The TypedArray Constructors + + ... + + The TypedArray constructors are designed to be subclassable. They may be used + as the value of an extends clause of a class definition. Subclass constructors + that intend to inherit the specified TypedArray behaviour must include a super + call to the TypedArray constructor to create and initialize the subclass + instance with the internal state necessary to support the + %TypedArray%.prototype built-in methods. +---*/ + +[ + Int8Array, + Uint8Array, + Uint8ClampedArray, + Int16Array, + Uint16Array, + Int32Array, + Uint32Array, + Float32Array, + Float64Array +].forEach(function(Constructor) { + class Typed extends Constructor {} + + var arr = new Typed(2); + + assert.sameValue(arr.length, 2); +}); diff --git a/test/language/statements/class/subclass/builtin-objects/TypedArray/super-must-be-called.js b/test/language/statements/class/subclass/builtin-objects/TypedArray/super-must-be-called.js new file mode 100644 index 0000000000000000000000000000000000000000..912d9dc8deff88bc0f078b0fe34c0278ef631384 --- /dev/null +++ b/test/language/statements/class/subclass/builtin-objects/TypedArray/super-must-be-called.js @@ -0,0 +1,45 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 22.2.4 +description: Super need to be called to initialize internals +info: > + 22.2.4 The TypedArray Constructors + + ... + + The TypedArray constructors are designed to be subclassable. They may be used + as the value of an extends clause of a class definition. Subclass constructors + that intend to inherit the specified TypedArray behaviour must include a super + call to the TypedArray constructor to create and initialize the subclass + instance with the internal state necessary to support the + %TypedArray%.prototype built-in methods. +---*/ + +[ + Int8Array, + Uint8Array, + Uint8ClampedArray, + Int16Array, + Uint16Array, + Int32Array, + Uint32Array, + Float32Array, + Float64Array +].forEach(function(Constructor) { + class Typed extends Constructor { + constructor() {} + } + + assert.throws(ReferenceError, function() { + new Typed(); + }); + + class TypedWithSuper extends Constructor { + constructor() { + super(); + } + } + + new TypedWithSuper(); +}); diff --git a/test/language/statements/class/subclass/builtin-objects/WeakMap/regular-subclassing.js b/test/language/statements/class/subclass/builtin-objects/WeakMap/regular-subclassing.js new file mode 100644 index 0000000000000000000000000000000000000000..3cc6a9b23ffe69f7314231c780b9e37426f59fa0 --- /dev/null +++ b/test/language/statements/class/subclass/builtin-objects/WeakMap/regular-subclassing.js @@ -0,0 +1,28 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 23.3.1 +description: Subclassing the WeakMap object +info: > + 23.3.1 The WeakMap Constructor + + ... + + The WeakMap constructor is designed to be subclassable. It may be used as the + value in an extends clause of a class definition. Subclass constructors that + intend to inherit the specified WeakMap behaviour must include a super call to + the WeakMap constructor to create and initialize the subclass instance with + the internal state necessary to support the WeakMap.prototype built-in + methods. +---*/ + +class WM extends WeakMap {} + +var map = new WM(); +var obj = {}; + +assert.sameValue(map.has(obj), false); + +map.set(obj, 42); +assert.sameValue(map.has(obj), true); +assert.sameValue(map.get(obj), 42); diff --git a/test/language/statements/class/subclass/builtin-objects/WeakMap/super-must-be-called.js b/test/language/statements/class/subclass/builtin-objects/WeakMap/super-must-be-called.js new file mode 100644 index 0000000000000000000000000000000000000000..e277ff7d6d368b406797cf006d4f981d49bf52f6 --- /dev/null +++ b/test/language/statements/class/subclass/builtin-objects/WeakMap/super-must-be-called.js @@ -0,0 +1,33 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 23.3.1 +description: Super need to be called to initialize internals +info: > + 23.3.1 The WeakMap Constructor + + ... + + The WeakMap constructor is designed to be subclassable. It may be used as the + value in an extends clause of a class definition. Subclass constructors that + intend to inherit the specified WeakMap behaviour must include a super call to + the WeakMap constructor to create and initialize the subclass instance with + the internal state necessary to support the WeakMap.prototype built-in + methods. +---*/ + +class M1 extends WeakMap { + constructor() {} +} + +assert.throws(ReferenceError, function() { + new M1(); +}); + +class M2 extends WeakMap { + constructor() { + super(); + } +} + +new M2(); diff --git a/test/language/statements/class/subclass/builtin-objects/WeakSet/regular-subclassing.js b/test/language/statements/class/subclass/builtin-objects/WeakSet/regular-subclassing.js new file mode 100644 index 0000000000000000000000000000000000000000..555619a0385f8c53ba46b2523f41773fb8c9a787 --- /dev/null +++ b/test/language/statements/class/subclass/builtin-objects/WeakSet/regular-subclassing.js @@ -0,0 +1,27 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 23.4.1 +description: Subclassing the WeakSet object +info: > + 23.4.1 The WeakSet Constructor + + ... + + The WeakSet constructor is designed to be subclassable. It may be used as the + value in an extends clause of a class definition. Subclass constructors that + intend to inherit the specified WeakSet behaviour must include a super call to + the WeakSet constructor to create and initialize the subclass instance with + the internal state necessary to support the WeakSet.prototype built-in + methods. +---*/ + +class WS extends WeakSet {} + +var set = new WS(); +var obj = {}; + +assert.sameValue(set.has(obj), false); + +set.add(obj); +assert.sameValue(set.has(obj), true); diff --git a/test/language/statements/class/subclass/builtin-objects/WeakSet/super-must-be-called.js b/test/language/statements/class/subclass/builtin-objects/WeakSet/super-must-be-called.js new file mode 100644 index 0000000000000000000000000000000000000000..7fd5d929bda7f76e49b8e763a16ebbcf1760e26c --- /dev/null +++ b/test/language/statements/class/subclass/builtin-objects/WeakSet/super-must-be-called.js @@ -0,0 +1,33 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 23.4.1 +description: Super need to be called to initialize internals +info: > + 23.4.1 The WeakSet Constructor + + ... + + The WeakSet constructor is designed to be subclassable. It may be used as the + value in an extends clause of a class definition. Subclass constructors that + intend to inherit the specified WeakSet behaviour must include a super call to + the WeakSet constructor to create and initialize the subclass instance with + the internal state necessary to support the WeakSet.prototype built-in + methods. +---*/ + +class WS1 extends WeakSet { + constructor() {} +} + +assert.throws(ReferenceError, function() { + new WS1(); +}); + +class WS2 extends WeakSet { + constructor() { + super(); + } +} + +new WS2();