diff options
Diffstat (limited to 'js/src/tests/test262/language/statements/class/subclass/builtin-objects')
114 files changed, 2200 insertions, 0 deletions
diff --git a/js/src/tests/test262/language/statements/class/subclass/builtin-objects/Array/browser.js b/js/src/tests/test262/language/statements/class/subclass/builtin-objects/Array/browser.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/language/statements/class/subclass/builtin-objects/Array/browser.js diff --git a/js/src/tests/test262/language/statements/class/subclass/builtin-objects/Array/contructor-calls-super-multiple-arguments.js b/js/src/tests/test262/language/statements/class/subclass/builtin-objects/Array/contructor-calls-super-multiple-arguments.js new file mode 100644 index 0000000000..e1d285b914 --- /dev/null +++ b/js/src/tests/test262/language/statements/class/subclass/builtin-objects/Array/contructor-calls-super-multiple-arguments.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: 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']); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/class/subclass/builtin-objects/Array/contructor-calls-super-single-argument.js b/js/src/tests/test262/language/statements/class/subclass/builtin-objects/Array/contructor-calls-super-single-argument.js new file mode 100644 index 0000000000..9311d7f278 --- /dev/null +++ b/js/src/tests/test262/language/statements/class/subclass/builtin-objects/Array/contructor-calls-super-single-argument.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: 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); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/class/subclass/builtin-objects/Array/length.js b/js/src/tests/test262/language/statements/class/subclass/builtin-objects/Array/length.js new file mode 100644 index 0000000000..e19bc322a6 --- /dev/null +++ b/js/src/tests/test262/language/statements/class/subclass/builtin-objects/Array/length.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: 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 }. +---*/ + +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); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/class/subclass/builtin-objects/Array/regular-subclassing.js b/js/src/tests/test262/language/statements/class/subclass/builtin-objects/Array/regular-subclassing.js new file mode 100644 index 0000000000..3b5df29719 --- /dev/null +++ b/js/src/tests/test262/language/statements/class/subclass/builtin-objects/Array/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.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); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/class/subclass/builtin-objects/Array/shell.js b/js/src/tests/test262/language/statements/class/subclass/builtin-objects/Array/shell.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/language/statements/class/subclass/builtin-objects/Array/shell.js diff --git a/js/src/tests/test262/language/statements/class/subclass/builtin-objects/Array/super-must-be-called.js b/js/src/tests/test262/language/statements/class/subclass/builtin-objects/Array/super-must-be-called.js new file mode 100644 index 0000000000..134c3a7702 --- /dev/null +++ b/js/src/tests/test262/language/statements/class/subclass/builtin-objects/Array/super-must-be-called.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: 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(); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/class/subclass/builtin-objects/ArrayBuffer/browser.js b/js/src/tests/test262/language/statements/class/subclass/builtin-objects/ArrayBuffer/browser.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/language/statements/class/subclass/builtin-objects/ArrayBuffer/browser.js diff --git a/js/src/tests/test262/language/statements/class/subclass/builtin-objects/ArrayBuffer/regular-subclassing.js b/js/src/tests/test262/language/statements/class/subclass/builtin-objects/ArrayBuffer/regular-subclassing.js new file mode 100644 index 0000000000..d2b319173a --- /dev/null +++ b/js/src/tests/test262/language/statements/class/subclass/builtin-objects/ArrayBuffer/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.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); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/class/subclass/builtin-objects/ArrayBuffer/shell.js b/js/src/tests/test262/language/statements/class/subclass/builtin-objects/ArrayBuffer/shell.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/language/statements/class/subclass/builtin-objects/ArrayBuffer/shell.js diff --git a/js/src/tests/test262/language/statements/class/subclass/builtin-objects/ArrayBuffer/super-must-be-called.js b/js/src/tests/test262/language/statements/class/subclass/builtin-objects/ArrayBuffer/super-must-be-called.js new file mode 100644 index 0000000000..232c344cee --- /dev/null +++ b/js/src/tests/test262/language/statements/class/subclass/builtin-objects/ArrayBuffer/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.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); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/class/subclass/builtin-objects/Boolean/browser.js b/js/src/tests/test262/language/statements/class/subclass/builtin-objects/Boolean/browser.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/language/statements/class/subclass/builtin-objects/Boolean/browser.js diff --git a/js/src/tests/test262/language/statements/class/subclass/builtin-objects/Boolean/regular-subclassing.js b/js/src/tests/test262/language/statements/class/subclass/builtin-objects/Boolean/regular-subclassing.js new file mode 100644 index 0000000000..e296c1d4e3 --- /dev/null +++ b/js/src/tests/test262/language/statements/class/subclass/builtin-objects/Boolean/regular-subclassing.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: 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); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/class/subclass/builtin-objects/Boolean/shell.js b/js/src/tests/test262/language/statements/class/subclass/builtin-objects/Boolean/shell.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/language/statements/class/subclass/builtin-objects/Boolean/shell.js diff --git a/js/src/tests/test262/language/statements/class/subclass/builtin-objects/Boolean/super-must-be-called.js b/js/src/tests/test262/language/statements/class/subclass/builtin-objects/Boolean/super-must-be-called.js new file mode 100644 index 0000000000..fde940702f --- /dev/null +++ b/js/src/tests/test262/language/statements/class/subclass/builtin-objects/Boolean/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: 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); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/class/subclass/builtin-objects/DataView/browser.js b/js/src/tests/test262/language/statements/class/subclass/builtin-objects/DataView/browser.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/language/statements/class/subclass/builtin-objects/DataView/browser.js diff --git a/js/src/tests/test262/language/statements/class/subclass/builtin-objects/DataView/regular-subclassing.js b/js/src/tests/test262/language/statements/class/subclass/builtin-objects/DataView/regular-subclassing.js new file mode 100644 index 0000000000..fe91d32a2b --- /dev/null +++ b/js/src/tests/test262/language/statements/class/subclass/builtin-objects/DataView/regular-subclassing.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: 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(); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/class/subclass/builtin-objects/DataView/shell.js b/js/src/tests/test262/language/statements/class/subclass/builtin-objects/DataView/shell.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/language/statements/class/subclass/builtin-objects/DataView/shell.js diff --git a/js/src/tests/test262/language/statements/class/subclass/builtin-objects/DataView/super-must-be-called.js b/js/src/tests/test262/language/statements/class/subclass/builtin-objects/DataView/super-must-be-called.js new file mode 100644 index 0000000000..9693b9a205 --- /dev/null +++ b/js/src/tests/test262/language/statements/class/subclass/builtin-objects/DataView/super-must-be-called.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: 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); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/class/subclass/builtin-objects/Date/browser.js b/js/src/tests/test262/language/statements/class/subclass/builtin-objects/Date/browser.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/language/statements/class/subclass/builtin-objects/Date/browser.js diff --git a/js/src/tests/test262/language/statements/class/subclass/builtin-objects/Date/regular-subclassing.js b/js/src/tests/test262/language/statements/class/subclass/builtin-objects/Date/regular-subclassing.js new file mode 100644 index 0000000000..41619f26b4 --- /dev/null +++ b/js/src/tests/test262/language/statements/class/subclass/builtin-objects/Date/regular-subclassing.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: 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, 11); +assert.sameValue(d1.getFullYear(), 1859); +assert.sameValue(d1.getMonth(), 10); +assert.sameValue(d1.getDate(), 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.getFullYear(), d4.getFullYear()); +assert.sameValue(d3.getMonth(), d4.getMonth()); +assert.sameValue(d3.getDate(), d4.getDate()); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/class/subclass/builtin-objects/Date/shell.js b/js/src/tests/test262/language/statements/class/subclass/builtin-objects/Date/shell.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/language/statements/class/subclass/builtin-objects/Date/shell.js diff --git a/js/src/tests/test262/language/statements/class/subclass/builtin-objects/Date/super-must-be-called.js b/js/src/tests/test262/language/statements/class/subclass/builtin-objects/Date/super-must-be-called.js new file mode 100644 index 0000000000..8099ac871f --- /dev/null +++ b/js/src/tests/test262/language/statements/class/subclass/builtin-objects/Date/super-must-be-called.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: 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(); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/class/subclass/builtin-objects/Error/browser.js b/js/src/tests/test262/language/statements/class/subclass/builtin-objects/Error/browser.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/language/statements/class/subclass/builtin-objects/Error/browser.js diff --git a/js/src/tests/test262/language/statements/class/subclass/builtin-objects/Error/message-property-assignment.js b/js/src/tests/test262/language/statements/class/subclass/builtin-objects/Error/message-property-assignment.js new file mode 100644 index 0000000000..afa9b7e924 --- /dev/null +++ b/js/src/tests/test262/language/statements/class/subclass/builtin-objects/Error/message-property-assignment.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: 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'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/class/subclass/builtin-objects/Error/regular-subclassing.js b/js/src/tests/test262/language/statements/class/subclass/builtin-objects/Error/regular-subclassing.js new file mode 100644 index 0000000000..d34c85cb3c --- /dev/null +++ b/js/src/tests/test262/language/statements/class/subclass/builtin-objects/Error/regular-subclassing.js @@ -0,0 +1,24 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +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'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/class/subclass/builtin-objects/Error/shell.js b/js/src/tests/test262/language/statements/class/subclass/builtin-objects/Error/shell.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/language/statements/class/subclass/builtin-objects/Error/shell.js diff --git a/js/src/tests/test262/language/statements/class/subclass/builtin-objects/Error/super-must-be-called.js b/js/src/tests/test262/language/statements/class/subclass/builtin-objects/Error/super-must-be-called.js new file mode 100644 index 0000000000..8d7dcae53e --- /dev/null +++ b/js/src/tests/test262/language/statements/class/subclass/builtin-objects/Error/super-must-be-called.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: 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'); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/class/subclass/builtin-objects/Function/browser.js b/js/src/tests/test262/language/statements/class/subclass/builtin-objects/Function/browser.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/language/statements/class/subclass/builtin-objects/Function/browser.js diff --git a/js/src/tests/test262/language/statements/class/subclass/builtin-objects/Function/instance-length.js b/js/src/tests/test262/language/statements/class/subclass/builtin-objects/Function/instance-length.js new file mode 100644 index 0000000000..d14cd344d4 --- /dev/null +++ b/js/src/tests/test262/language/statements/class/subclass/builtin-objects/Function/instance-length.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: 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'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/class/subclass/builtin-objects/Function/instance-name.js b/js/src/tests/test262/language/statements/class/subclass/builtin-objects/Function/instance-name.js new file mode 100644 index 0000000000..6648909da4 --- /dev/null +++ b/js/src/tests/test262/language/statements/class/subclass/builtin-objects/Function/instance-name.js @@ -0,0 +1,41 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +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'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/class/subclass/builtin-objects/Function/regular-subclassing.js b/js/src/tests/test262/language/statements/class/subclass/builtin-objects/Function/regular-subclassing.js new file mode 100644 index 0000000000..d68fb28206 --- /dev/null +++ b/js/src/tests/test262/language/statements/class/subclass/builtin-objects/Function/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.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); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/class/subclass/builtin-objects/Function/shell.js b/js/src/tests/test262/language/statements/class/subclass/builtin-objects/Function/shell.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/language/statements/class/subclass/builtin-objects/Function/shell.js diff --git a/js/src/tests/test262/language/statements/class/subclass/builtin-objects/Function/super-must-be-called.js b/js/src/tests/test262/language/statements/class/subclass/builtin-objects/Function/super-must-be-called.js new file mode 100644 index 0000000000..9d8fc30c0c --- /dev/null +++ b/js/src/tests/test262/language/statements/class/subclass/builtin-objects/Function/super-must-be-called.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: 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); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/class/subclass/builtin-objects/GeneratorFunction/browser.js b/js/src/tests/test262/language/statements/class/subclass/builtin-objects/GeneratorFunction/browser.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/language/statements/class/subclass/builtin-objects/GeneratorFunction/browser.js diff --git a/js/src/tests/test262/language/statements/class/subclass/builtin-objects/GeneratorFunction/instance-length.js b/js/src/tests/test262/language/statements/class/subclass/builtin-objects/GeneratorFunction/instance-length.js new file mode 100644 index 0000000000..f5d17fe131 --- /dev/null +++ b/js/src/tests/test262/language/statements/class/subclass/builtin-objects/GeneratorFunction/instance-length.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.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'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/class/subclass/builtin-objects/GeneratorFunction/instance-name.js b/js/src/tests/test262/language/statements/class/subclass/builtin-objects/GeneratorFunction/instance-name.js new file mode 100644 index 0000000000..69be80c2e4 --- /dev/null +++ b/js/src/tests/test262/language/statements/class/subclass/builtin-objects/GeneratorFunction/instance-name.js @@ -0,0 +1,48 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +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'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/class/subclass/builtin-objects/GeneratorFunction/instance-prototype.js b/js/src/tests/test262/language/statements/class/subclass/builtin-objects/GeneratorFunction/instance-prototype.js new file mode 100644 index 0000000000..3b4029adcd --- /dev/null +++ b/js/src/tests/test262/language/statements/class/subclass/builtin-objects/GeneratorFunction/instance-prototype.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: 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'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/class/subclass/builtin-objects/GeneratorFunction/regular-subclassing.js b/js/src/tests/test262/language/statements/class/subclass/builtin-objects/GeneratorFunction/regular-subclassing.js new file mode 100644 index 0000000000..55a8c2ded5 --- /dev/null +++ b/js/src/tests/test262/language/statements/class/subclass/builtin-objects/GeneratorFunction/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: 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); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/class/subclass/builtin-objects/GeneratorFunction/shell.js b/js/src/tests/test262/language/statements/class/subclass/builtin-objects/GeneratorFunction/shell.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/language/statements/class/subclass/builtin-objects/GeneratorFunction/shell.js diff --git a/js/src/tests/test262/language/statements/class/subclass/builtin-objects/GeneratorFunction/super-must-be-called.js b/js/src/tests/test262/language/statements/class/subclass/builtin-objects/GeneratorFunction/super-must-be-called.js new file mode 100644 index 0000000000..6d3aa6004d --- /dev/null +++ b/js/src/tests/test262/language/statements/class/subclass/builtin-objects/GeneratorFunction/super-must-be-called.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: 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); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/class/subclass/builtin-objects/Map/browser.js b/js/src/tests/test262/language/statements/class/subclass/builtin-objects/Map/browser.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/language/statements/class/subclass/builtin-objects/Map/browser.js diff --git a/js/src/tests/test262/language/statements/class/subclass/builtin-objects/Map/regular-subclassing.js b/js/src/tests/test262/language/statements/class/subclass/builtin-objects/Map/regular-subclassing.js new file mode 100644 index 0000000000..755b2b1faa --- /dev/null +++ b/js/src/tests/test262/language/statements/class/subclass/builtin-objects/Map/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.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); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/class/subclass/builtin-objects/Map/shell.js b/js/src/tests/test262/language/statements/class/subclass/builtin-objects/Map/shell.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/language/statements/class/subclass/builtin-objects/Map/shell.js diff --git a/js/src/tests/test262/language/statements/class/subclass/builtin-objects/Map/super-must-be-called.js b/js/src/tests/test262/language/statements/class/subclass/builtin-objects/Map/super-must-be-called.js new file mode 100644 index 0000000000..23d3e8dbf8 --- /dev/null +++ b/js/src/tests/test262/language/statements/class/subclass/builtin-objects/Map/super-must-be-called.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: 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(); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/class/subclass/builtin-objects/NativeError/EvalError-message.js b/js/src/tests/test262/language/statements/class/subclass/builtin-objects/NativeError/EvalError-message.js new file mode 100644 index 0000000000..6d911069bf --- /dev/null +++ b/js/src/tests/test262/language/statements/class/subclass/builtin-objects/NativeError/EvalError-message.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: 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'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/class/subclass/builtin-objects/NativeError/EvalError-name.js b/js/src/tests/test262/language/statements/class/subclass/builtin-objects/NativeError/EvalError-name.js new file mode 100644 index 0000000000..9f4c87eeb5 --- /dev/null +++ b/js/src/tests/test262/language/statements/class/subclass/builtin-objects/NativeError/EvalError-name.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.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'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/class/subclass/builtin-objects/NativeError/EvalError-super.js b/js/src/tests/test262/language/statements/class/subclass/builtin-objects/NativeError/EvalError-super.js new file mode 100644 index 0000000000..3e7055bcc0 --- /dev/null +++ b/js/src/tests/test262/language/statements/class/subclass/builtin-objects/NativeError/EvalError-super.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: 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(); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/class/subclass/builtin-objects/NativeError/RangeError-message.js b/js/src/tests/test262/language/statements/class/subclass/builtin-objects/NativeError/RangeError-message.js new file mode 100644 index 0000000000..28931bfcd5 --- /dev/null +++ b/js/src/tests/test262/language/statements/class/subclass/builtin-objects/NativeError/RangeError-message.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: 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'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/class/subclass/builtin-objects/NativeError/RangeError-name.js b/js/src/tests/test262/language/statements/class/subclass/builtin-objects/NativeError/RangeError-name.js new file mode 100644 index 0000000000..49a05b2ab0 --- /dev/null +++ b/js/src/tests/test262/language/statements/class/subclass/builtin-objects/NativeError/RangeError-name.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.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'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/class/subclass/builtin-objects/NativeError/RangeError-super.js b/js/src/tests/test262/language/statements/class/subclass/builtin-objects/NativeError/RangeError-super.js new file mode 100644 index 0000000000..af5a17d16e --- /dev/null +++ b/js/src/tests/test262/language/statements/class/subclass/builtin-objects/NativeError/RangeError-super.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: 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(); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/class/subclass/builtin-objects/NativeError/ReferenceError-message.js b/js/src/tests/test262/language/statements/class/subclass/builtin-objects/NativeError/ReferenceError-message.js new file mode 100644 index 0000000000..cb5626c984 --- /dev/null +++ b/js/src/tests/test262/language/statements/class/subclass/builtin-objects/NativeError/ReferenceError-message.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: 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'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/class/subclass/builtin-objects/NativeError/ReferenceError-name.js b/js/src/tests/test262/language/statements/class/subclass/builtin-objects/NativeError/ReferenceError-name.js new file mode 100644 index 0000000000..8898f2e7b5 --- /dev/null +++ b/js/src/tests/test262/language/statements/class/subclass/builtin-objects/NativeError/ReferenceError-name.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.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'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/class/subclass/builtin-objects/NativeError/ReferenceError-super.js b/js/src/tests/test262/language/statements/class/subclass/builtin-objects/NativeError/ReferenceError-super.js new file mode 100644 index 0000000000..b8517e4e25 --- /dev/null +++ b/js/src/tests/test262/language/statements/class/subclass/builtin-objects/NativeError/ReferenceError-super.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: 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(); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/class/subclass/builtin-objects/NativeError/SyntaxError-message.js b/js/src/tests/test262/language/statements/class/subclass/builtin-objects/NativeError/SyntaxError-message.js new file mode 100644 index 0000000000..c5460959d6 --- /dev/null +++ b/js/src/tests/test262/language/statements/class/subclass/builtin-objects/NativeError/SyntaxError-message.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: 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'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/class/subclass/builtin-objects/NativeError/SyntaxError-name.js b/js/src/tests/test262/language/statements/class/subclass/builtin-objects/NativeError/SyntaxError-name.js new file mode 100644 index 0000000000..19719c503c --- /dev/null +++ b/js/src/tests/test262/language/statements/class/subclass/builtin-objects/NativeError/SyntaxError-name.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.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'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/class/subclass/builtin-objects/NativeError/SyntaxError-super.js b/js/src/tests/test262/language/statements/class/subclass/builtin-objects/NativeError/SyntaxError-super.js new file mode 100644 index 0000000000..00c4865cab --- /dev/null +++ b/js/src/tests/test262/language/statements/class/subclass/builtin-objects/NativeError/SyntaxError-super.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: 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(); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/class/subclass/builtin-objects/NativeError/TypeError-message.js b/js/src/tests/test262/language/statements/class/subclass/builtin-objects/NativeError/TypeError-message.js new file mode 100644 index 0000000000..855e3ad1a4 --- /dev/null +++ b/js/src/tests/test262/language/statements/class/subclass/builtin-objects/NativeError/TypeError-message.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: 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'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/class/subclass/builtin-objects/NativeError/TypeError-name.js b/js/src/tests/test262/language/statements/class/subclass/builtin-objects/NativeError/TypeError-name.js new file mode 100644 index 0000000000..ca1cb0995a --- /dev/null +++ b/js/src/tests/test262/language/statements/class/subclass/builtin-objects/NativeError/TypeError-name.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.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'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/class/subclass/builtin-objects/NativeError/TypeError-super.js b/js/src/tests/test262/language/statements/class/subclass/builtin-objects/NativeError/TypeError-super.js new file mode 100644 index 0000000000..80fcbf935a --- /dev/null +++ b/js/src/tests/test262/language/statements/class/subclass/builtin-objects/NativeError/TypeError-super.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: 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(); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/class/subclass/builtin-objects/NativeError/URIError-message.js b/js/src/tests/test262/language/statements/class/subclass/builtin-objects/NativeError/URIError-message.js new file mode 100644 index 0000000000..1131b75185 --- /dev/null +++ b/js/src/tests/test262/language/statements/class/subclass/builtin-objects/NativeError/URIError-message.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: 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'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/class/subclass/builtin-objects/NativeError/URIError-name.js b/js/src/tests/test262/language/statements/class/subclass/builtin-objects/NativeError/URIError-name.js new file mode 100644 index 0000000000..83d8d8f5e8 --- /dev/null +++ b/js/src/tests/test262/language/statements/class/subclass/builtin-objects/NativeError/URIError-name.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.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'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/class/subclass/builtin-objects/NativeError/URIError-super.js b/js/src/tests/test262/language/statements/class/subclass/builtin-objects/NativeError/URIError-super.js new file mode 100644 index 0000000000..3714a11749 --- /dev/null +++ b/js/src/tests/test262/language/statements/class/subclass/builtin-objects/NativeError/URIError-super.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: 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(); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/class/subclass/builtin-objects/NativeError/browser.js b/js/src/tests/test262/language/statements/class/subclass/builtin-objects/NativeError/browser.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/language/statements/class/subclass/builtin-objects/NativeError/browser.js diff --git a/js/src/tests/test262/language/statements/class/subclass/builtin-objects/NativeError/shell.js b/js/src/tests/test262/language/statements/class/subclass/builtin-objects/NativeError/shell.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/language/statements/class/subclass/builtin-objects/NativeError/shell.js diff --git a/js/src/tests/test262/language/statements/class/subclass/builtin-objects/Number/browser.js b/js/src/tests/test262/language/statements/class/subclass/builtin-objects/Number/browser.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/language/statements/class/subclass/builtin-objects/Number/browser.js diff --git a/js/src/tests/test262/language/statements/class/subclass/builtin-objects/Number/regular-subclassing.js b/js/src/tests/test262/language/statements/class/subclass/builtin-objects/Number/regular-subclassing.js new file mode 100644 index 0000000000..f5764f046f --- /dev/null +++ b/js/src/tests/test262/language/statements/class/subclass/builtin-objects/Number/regular-subclassing.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: 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'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/class/subclass/builtin-objects/Number/shell.js b/js/src/tests/test262/language/statements/class/subclass/builtin-objects/Number/shell.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/language/statements/class/subclass/builtin-objects/Number/shell.js diff --git a/js/src/tests/test262/language/statements/class/subclass/builtin-objects/Number/super-must-be-called.js b/js/src/tests/test262/language/statements/class/subclass/builtin-objects/Number/super-must-be-called.js new file mode 100644 index 0000000000..fb37ca829c --- /dev/null +++ b/js/src/tests/test262/language/statements/class/subclass/builtin-objects/Number/super-must-be-called.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: 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(); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/class/subclass/builtin-objects/Object/browser.js b/js/src/tests/test262/language/statements/class/subclass/builtin-objects/Object/browser.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/language/statements/class/subclass/builtin-objects/Object/browser.js diff --git a/js/src/tests/test262/language/statements/class/subclass/builtin-objects/Object/constructor-return-undefined-throws.js b/js/src/tests/test262/language/statements/class/subclass/builtin-objects/Object/constructor-return-undefined-throws.js new file mode 100644 index 0000000000..ddf4ec4795 --- /dev/null +++ b/js/src/tests/test262/language/statements/class/subclass/builtin-objects/Object/constructor-return-undefined-throws.js @@ -0,0 +1,47 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +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(); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/class/subclass/builtin-objects/Object/constructor-returns-non-object.js b/js/src/tests/test262/language/statements/class/subclass/builtin-objects/Object/constructor-returns-non-object.js new file mode 100644 index 0000000000..6f266cc1e7 --- /dev/null +++ b/js/src/tests/test262/language/statements/class/subclass/builtin-objects/Object/constructor-returns-non-object.js @@ -0,0 +1,42 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +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(); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/class/subclass/builtin-objects/Object/regular-subclassing.js b/js/src/tests/test262/language/statements/class/subclass/builtin-objects/Object/regular-subclassing.js new file mode 100644 index 0000000000..59b6afd6a3 --- /dev/null +++ b/js/src/tests/test262/language/statements/class/subclass/builtin-objects/Object/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.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' +); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/class/subclass/builtin-objects/Object/replacing-prototype.js b/js/src/tests/test262/language/statements/class/subclass/builtin-objects/Object/replacing-prototype.js new file mode 100644 index 0000000000..dd6e7d5635 --- /dev/null +++ b/js/src/tests/test262/language/statements/class/subclass/builtin-objects/Object/replacing-prototype.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.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'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/class/subclass/builtin-objects/Object/shell.js b/js/src/tests/test262/language/statements/class/subclass/builtin-objects/Object/shell.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/language/statements/class/subclass/builtin-objects/Object/shell.js diff --git a/js/src/tests/test262/language/statements/class/subclass/builtin-objects/Promise/browser.js b/js/src/tests/test262/language/statements/class/subclass/builtin-objects/Promise/browser.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/language/statements/class/subclass/builtin-objects/Promise/browser.js diff --git a/js/src/tests/test262/language/statements/class/subclass/builtin-objects/Promise/regular-subclassing.js b/js/src/tests/test262/language/statements/class/subclass/builtin-objects/Promise/regular-subclassing.js new file mode 100644 index 0000000000..397e452cf0 --- /dev/null +++ b/js/src/tests/test262/language/statements/class/subclass/builtin-objects/Promise/regular-subclassing.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.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 executorArguments; + +var prom1 = new Prom(function() { + calledExecutor = true; + executorArguments = arguments; +}); + +assert(calledExecutor); +assert.sameValue(executorArguments.length, 2); +assert.sameValue(typeof executorArguments[0], "function"); +assert.sameValue(typeof executorArguments[1], "function"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/class/subclass/builtin-objects/Promise/shell.js b/js/src/tests/test262/language/statements/class/subclass/builtin-objects/Promise/shell.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/language/statements/class/subclass/builtin-objects/Promise/shell.js diff --git a/js/src/tests/test262/language/statements/class/subclass/builtin-objects/Promise/super-must-be-called.js b/js/src/tests/test262/language/statements/class/subclass/builtin-objects/Promise/super-must-be-called.js new file mode 100644 index 0000000000..8ed2fb3f63 --- /dev/null +++ b/js/src/tests/test262/language/statements/class/subclass/builtin-objects/Promise/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: 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() {}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/class/subclass/builtin-objects/Proxy/browser.js b/js/src/tests/test262/language/statements/class/subclass/builtin-objects/Proxy/browser.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/language/statements/class/subclass/builtin-objects/Proxy/browser.js diff --git a/js/src/tests/test262/language/statements/class/subclass/builtin-objects/Proxy/no-prototype-throws.js b/js/src/tests/test262/language/statements/class/subclass/builtin-objects/Proxy/no-prototype-throws.js new file mode 100644 index 0000000000..c61848395c --- /dev/null +++ b/js/src/tests/test262/language/statements/class/subclass/builtin-objects/Proxy/no-prototype-throws.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: 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 {} +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/class/subclass/builtin-objects/Proxy/shell.js b/js/src/tests/test262/language/statements/class/subclass/builtin-objects/Proxy/shell.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/language/statements/class/subclass/builtin-objects/Proxy/shell.js diff --git a/js/src/tests/test262/language/statements/class/subclass/builtin-objects/RegExp/browser.js b/js/src/tests/test262/language/statements/class/subclass/builtin-objects/RegExp/browser.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/language/statements/class/subclass/builtin-objects/RegExp/browser.js diff --git a/js/src/tests/test262/language/statements/class/subclass/builtin-objects/RegExp/lastIndex.js b/js/src/tests/test262/language/statements/class/subclass/builtin-objects/RegExp/lastIndex.js new file mode 100644 index 0000000000..bf0726227b --- /dev/null +++ b/js/src/tests/test262/language/statements/class/subclass/builtin-objects/RegExp/lastIndex.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: 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'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/class/subclass/builtin-objects/RegExp/regular-subclassing.js b/js/src/tests/test262/language/statements/class/subclass/builtin-objects/RegExp/regular-subclassing.js new file mode 100644 index 0000000000..3dab8a3ee6 --- /dev/null +++ b/js/src/tests/test262/language/statements/class/subclass/builtin-objects/RegExp/regular-subclassing.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: 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); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/class/subclass/builtin-objects/RegExp/shell.js b/js/src/tests/test262/language/statements/class/subclass/builtin-objects/RegExp/shell.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/language/statements/class/subclass/builtin-objects/RegExp/shell.js diff --git a/js/src/tests/test262/language/statements/class/subclass/builtin-objects/RegExp/super-must-be-called.js b/js/src/tests/test262/language/statements/class/subclass/builtin-objects/RegExp/super-must-be-called.js new file mode 100644 index 0000000000..8d617a15ee --- /dev/null +++ b/js/src/tests/test262/language/statements/class/subclass/builtin-objects/RegExp/super-must-be-called.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: 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(); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/class/subclass/builtin-objects/Set/browser.js b/js/src/tests/test262/language/statements/class/subclass/builtin-objects/Set/browser.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/language/statements/class/subclass/builtin-objects/Set/browser.js diff --git a/js/src/tests/test262/language/statements/class/subclass/builtin-objects/Set/regular-subclassing.js b/js/src/tests/test262/language/statements/class/subclass/builtin-objects/Set/regular-subclassing.js new file mode 100644 index 0000000000..43a92d8a69 --- /dev/null +++ b/js/src/tests/test262/language/statements/class/subclass/builtin-objects/Set/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.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); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/class/subclass/builtin-objects/Set/shell.js b/js/src/tests/test262/language/statements/class/subclass/builtin-objects/Set/shell.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/language/statements/class/subclass/builtin-objects/Set/shell.js diff --git a/js/src/tests/test262/language/statements/class/subclass/builtin-objects/Set/super-must-be-called.js b/js/src/tests/test262/language/statements/class/subclass/builtin-objects/Set/super-must-be-called.js new file mode 100644 index 0000000000..1b5e23cd08 --- /dev/null +++ b/js/src/tests/test262/language/statements/class/subclass/builtin-objects/Set/super-must-be-called.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: 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(); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/class/subclass/builtin-objects/String/browser.js b/js/src/tests/test262/language/statements/class/subclass/builtin-objects/String/browser.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/language/statements/class/subclass/builtin-objects/String/browser.js diff --git a/js/src/tests/test262/language/statements/class/subclass/builtin-objects/String/length.js b/js/src/tests/test262/language/statements/class/subclass/builtin-objects/String/length.js new file mode 100644 index 0000000000..0d1f33ef7f --- /dev/null +++ b/js/src/tests/test262/language/statements/class/subclass/builtin-objects/String/length.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.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'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/class/subclass/builtin-objects/String/regular-subclassing.js b/js/src/tests/test262/language/statements/class/subclass/builtin-objects/String/regular-subclassing.js new file mode 100644 index 0000000000..b5c2ac34be --- /dev/null +++ b/js/src/tests/test262/language/statements/class/subclass/builtin-objects/String/regular-subclassing.js @@ -0,0 +1,24 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +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'); + + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/class/subclass/builtin-objects/String/shell.js b/js/src/tests/test262/language/statements/class/subclass/builtin-objects/String/shell.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/language/statements/class/subclass/builtin-objects/String/shell.js diff --git a/js/src/tests/test262/language/statements/class/subclass/builtin-objects/String/super-must-be-called.js b/js/src/tests/test262/language/statements/class/subclass/builtin-objects/String/super-must-be-called.js new file mode 100644 index 0000000000..0c247e62db --- /dev/null +++ b/js/src/tests/test262/language/statements/class/subclass/builtin-objects/String/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: 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(); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/class/subclass/builtin-objects/Symbol/browser.js b/js/src/tests/test262/language/statements/class/subclass/builtin-objects/Symbol/browser.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/language/statements/class/subclass/builtin-objects/Symbol/browser.js diff --git a/js/src/tests/test262/language/statements/class/subclass/builtin-objects/Symbol/new-symbol-with-super-throws.js b/js/src/tests/test262/language/statements/class/subclass/builtin-objects/Symbol/new-symbol-with-super-throws.js new file mode 100644 index 0000000000..70cdae8717 --- /dev/null +++ b/js/src/tests/test262/language/statements/class/subclass/builtin-objects/Symbol/new-symbol-with-super-throws.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: 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. +features: [Symbol] +---*/ + +class S1 extends Symbol {} + +assert.throws(TypeError, function() { + new S1(); +}); + +class S2 extends Symbol { + constructor() { + super(); + } +} + +assert.throws(TypeError, function() { + new S2(); +}); + + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/class/subclass/builtin-objects/Symbol/shell.js b/js/src/tests/test262/language/statements/class/subclass/builtin-objects/Symbol/shell.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/language/statements/class/subclass/builtin-objects/Symbol/shell.js diff --git a/js/src/tests/test262/language/statements/class/subclass/builtin-objects/Symbol/symbol-valid-as-extends-value.js b/js/src/tests/test262/language/statements/class/subclass/builtin-objects/Symbol/symbol-valid-as-extends-value.js new file mode 100644 index 0000000000..2ba5f953e2 --- /dev/null +++ b/js/src/tests/test262/language/statements/class/subclass/builtin-objects/Symbol/symbol-valid-as-extends-value.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. +/*--- +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. + ... +features: [Symbol] +---*/ + +class S extends Symbol {} + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/class/subclass/builtin-objects/TypedArray/browser.js b/js/src/tests/test262/language/statements/class/subclass/builtin-objects/TypedArray/browser.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/language/statements/class/subclass/builtin-objects/TypedArray/browser.js diff --git a/js/src/tests/test262/language/statements/class/subclass/builtin-objects/TypedArray/regular-subclassing.js b/js/src/tests/test262/language/statements/class/subclass/builtin-objects/TypedArray/regular-subclassing.js new file mode 100644 index 0000000000..abc83cdf31 --- /dev/null +++ b/js/src/tests/test262/language/statements/class/subclass/builtin-objects/TypedArray/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: 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); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/class/subclass/builtin-objects/TypedArray/shell.js b/js/src/tests/test262/language/statements/class/subclass/builtin-objects/TypedArray/shell.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/language/statements/class/subclass/builtin-objects/TypedArray/shell.js diff --git a/js/src/tests/test262/language/statements/class/subclass/builtin-objects/TypedArray/super-must-be-called.js b/js/src/tests/test262/language/statements/class/subclass/builtin-objects/TypedArray/super-must-be-called.js new file mode 100644 index 0000000000..5a8ae56122 --- /dev/null +++ b/js/src/tests/test262/language/statements/class/subclass/builtin-objects/TypedArray/super-must-be-called.js @@ -0,0 +1,47 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +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(); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/class/subclass/builtin-objects/WeakMap/browser.js b/js/src/tests/test262/language/statements/class/subclass/builtin-objects/WeakMap/browser.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/language/statements/class/subclass/builtin-objects/WeakMap/browser.js diff --git a/js/src/tests/test262/language/statements/class/subclass/builtin-objects/WeakMap/regular-subclassing.js b/js/src/tests/test262/language/statements/class/subclass/builtin-objects/WeakMap/regular-subclassing.js new file mode 100644 index 0000000000..04e2258258 --- /dev/null +++ b/js/src/tests/test262/language/statements/class/subclass/builtin-objects/WeakMap/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: 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. +features: [WeakMap] +---*/ + +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); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/class/subclass/builtin-objects/WeakMap/shell.js b/js/src/tests/test262/language/statements/class/subclass/builtin-objects/WeakMap/shell.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/language/statements/class/subclass/builtin-objects/WeakMap/shell.js diff --git a/js/src/tests/test262/language/statements/class/subclass/builtin-objects/WeakMap/super-must-be-called.js b/js/src/tests/test262/language/statements/class/subclass/builtin-objects/WeakMap/super-must-be-called.js new file mode 100644 index 0000000000..ae4c4acf2c --- /dev/null +++ b/js/src/tests/test262/language/statements/class/subclass/builtin-objects/WeakMap/super-must-be-called.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: 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. +features: [WeakMap] +---*/ + +class M1 extends WeakMap { + constructor() {} +} + +assert.throws(ReferenceError, function() { + new M1(); +}); + +class M2 extends WeakMap { + constructor() { + super(); + } +} + +new M2(); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/class/subclass/builtin-objects/WeakSet/browser.js b/js/src/tests/test262/language/statements/class/subclass/builtin-objects/WeakSet/browser.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/language/statements/class/subclass/builtin-objects/WeakSet/browser.js diff --git a/js/src/tests/test262/language/statements/class/subclass/builtin-objects/WeakSet/regular-subclassing.js b/js/src/tests/test262/language/statements/class/subclass/builtin-objects/WeakSet/regular-subclassing.js new file mode 100644 index 0000000000..9f8aa73318 --- /dev/null +++ b/js/src/tests/test262/language/statements/class/subclass/builtin-objects/WeakSet/regular-subclassing.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: 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. +features: [WeakSet] +---*/ + +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); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/class/subclass/builtin-objects/WeakSet/shell.js b/js/src/tests/test262/language/statements/class/subclass/builtin-objects/WeakSet/shell.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/language/statements/class/subclass/builtin-objects/WeakSet/shell.js diff --git a/js/src/tests/test262/language/statements/class/subclass/builtin-objects/WeakSet/super-must-be-called.js b/js/src/tests/test262/language/statements/class/subclass/builtin-objects/WeakSet/super-must-be-called.js new file mode 100644 index 0000000000..473bbf7c5e --- /dev/null +++ b/js/src/tests/test262/language/statements/class/subclass/builtin-objects/WeakSet/super-must-be-called.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: 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. +features: [WeakSet] +---*/ + +class WS1 extends WeakSet { + constructor() {} +} + +assert.throws(ReferenceError, function() { + new WS1(); +}); + +class WS2 extends WeakSet { + constructor() { + super(); + } +} + +new WS2(); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/class/subclass/builtin-objects/browser.js b/js/src/tests/test262/language/statements/class/subclass/builtin-objects/browser.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/language/statements/class/subclass/builtin-objects/browser.js diff --git a/js/src/tests/test262/language/statements/class/subclass/builtin-objects/shell.js b/js/src/tests/test262/language/statements/class/subclass/builtin-objects/shell.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/language/statements/class/subclass/builtin-objects/shell.js |