Merge pull request #468 from bocoup/subclassing

Subclassing built-in objects
This commit is contained in:
Gorkem Yakin 2016-01-14 11:48:57 -08:00
commit 4d418a9fe7
70 changed files with 2058 additions and 0 deletions

View File

@ -0,0 +1,26 @@
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
es6id: 22.1.1
description: >
Constructor calling super() with 2+ arguments creates an Array object
info: >
22.1.1 The Array Constructor
The Array constructor is designed to be subclassable. It may be used as the
value of an extends clause of a class definition. Subclass constructors that
intend to inherit the exotic Array behaviour must include a super call to the
Array constructor to initialize subclass instances that are exotic Array
objects.
includes: [compareArray.js]
---*/
class Sub extends Array {
constructor(a, b) {
super(a, b);
}
}
var sub = new Sub(42, 'foo');
assert(compareArray(sub, [42, 'foo']));

View File

@ -0,0 +1,25 @@
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
es6id: 22.1.1
description: >
Constructor calling super() with a single argument creates an Array object
info: >
22.1.1 The Array Constructor
The Array constructor is designed to be subclassable. It may be used as the
value of an extends clause of a class definition. Subclass constructors that
intend to inherit the exotic Array behaviour must include a super call to the
Array constructor to initialize subclass instances that are exotic Array
objects.
---*/
class Sub extends Array {
constructor(a) {
super(a);
}
}
var sub = new Sub(42);
assert.sameValue(sub.length, 42);

View File

@ -0,0 +1,37 @@
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
es6id: 22.1.4.1
description: >
Instances has the own property length
info: >
22.1.4.1 length
The length property of an Array instance is a data property whose value is
always numerically greater than the name of every configurable own property
whose name is an array index.
The length property initially has the attributes { [[Writable]]: true,
[[Enumerable]]: false, [[Configurable]]: false }.
includes: [propertyHelper.js]
---*/
class Ar extends Array {}
var arr = new Ar('foo', 'bar');
assert.sameValue(arr[0], 'foo');
assert.sameValue(arr[1], 'bar');
var arrDesc = Object.getOwnPropertyDescriptor(arr, 'length');
assert.sameValue(arrDesc.writable, true);
assert.sameValue(arrDesc.enumerable, false);
assert.sameValue(arrDesc.configurable, false);
assert.sameValue(arr[1], 'bar');
arr.length = 1;
assert.sameValue(arr[0], 'foo');
assert.sameValue(arr[1], undefined);

View File

@ -0,0 +1,33 @@
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
es6id: 22.1.1
description: Subclassing Array
info: >
22.1.1 The Array Constructor
The Array constructor is designed to be subclassable. It may be used as the
value of an extends clause of a class definition. (...)
includes: [compareArray.js]
---*/
class Sub extends Array {}
var a1 = new Sub(42, 'foo');
assert.sameValue(a1.length, 2);
assert.sameValue(a1[0], 42);
assert.sameValue(a1[1], 'foo');
a1.push(true);
assert.sameValue(a1.length, 3, 'Array#push updates the length property');
assert.sameValue(a1[0], 42);
assert.sameValue(a1[1], 'foo');
assert.sameValue(a1[2], true, 'Adds new item');
var a2 = new Sub(7);
assert.sameValue(a2.length, 7);
var a3 = new Sub();
assert(compareArray(a3, []));
assert.sameValue(a3.length, 0);

View File

@ -0,0 +1,32 @@
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
es6id: 22.1.1
description: Super need to be called to initialize internals
info: >
22.1.1 The Array Constructor
...
The Array constructor is designed to be subclassable. It may be used as the
value of an extends clause of a class definition. Subclass constructors that
intend to inherit the exotic Array behaviour must include a super call to the
Array constructor to initialize subclass instances that are exotic Array
objects.
---*/
class A extends Array {
constructor() {}
}
assert.throws(ReferenceError, function() {
new A();
});
class A2 extends Array {
constructor() {
super();
}
}
new A2();

View File

@ -0,0 +1,31 @@
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
es6id: 24.1.2
description: Subclassing the ArrayBuffer object
info: >
24.1.2 The ArrayBuffer Constructor
...
The ArrayBuffer constructor is designed to be subclassable. It may be used as
the value of an extends clause of a class definition. Subclass constructors
that intend to inherit the specified ArrayBuffer behaviour must include a
super call to the ArrayBuffer constructor to create and initialize subclass
instances with the internal state necessary to support the
ArrayBuffer.prototype built-in methods.
---*/
class AB extends ArrayBuffer {}
var ab = new AB(4);
var sliced = ab.slice(0, 1);
assert(sliced instanceof AB);
assert(sliced instanceof ArrayBuffer);
assert.notSameValue(ab, sliced);
assert.throws(RangeError, function() {
new AB();
});

View File

@ -0,0 +1,33 @@
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
es6id: 24.1.2
description: Super need to be called to initialize internals
info: >
24.1.2 The ArrayBuffer Constructor
...
The ArrayBuffer constructor is designed to be subclassable. It may be used as
the value of an extends clause of a class definition. Subclass constructors
that intend to inherit the specified ArrayBuffer behaviour must include a
super call to the ArrayBuffer constructor to create and initialize subclass
instances with the internal state necessary to support the
ArrayBuffer.prototype built-in methods.
---*/
class AB1 extends ArrayBuffer {
constructor() {}
}
assert.throws(ReferenceError, function() {
new AB1(1);
});
class AB2 extends ArrayBuffer {
constructor(length) {
super(length);
}
}
new AB2(1);

View File

@ -0,0 +1,23 @@
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
es6id: 19.3.1
description: Subclassing Function
info: >
19.3.1 The Boolean Constructor
The Boolean constructor is designed to be subclassable. It may be used as the
value of an extends clause of a class definition.
...
---*/
class Bln extends Boolean {}
var b1 = new Bln(1);
assert.notSameValue(b1, true, 'b1 is an Boolean object');
assert.sameValue(b1.valueOf(), true);
var b2 = new Bln(0);
assert.notSameValue(b2, false, 'bln is an Boolean object');
assert.sameValue(b2.valueOf(), false);

View File

@ -0,0 +1,31 @@
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
es6id: 19.3.1
description: Super need to be called to initialize Boolean internals
info: >
19.3.1 The Boolean Constructor
...
Subclass constructors that intend to inherit the specified Boolean behaviour
must include a super call to the Boolean constructor to create and initialize
the subclass instance with a [[BooleanData]] internal slot.
---*/
class Bln extends Boolean {
constructor() {}
}
// Boolean internals are not initialized
assert.throws(ReferenceError, function() {
new Bln(1);
});
class Bln2 extends Boolean {
constructor() {
super();
}
}
var b = new Bln2(1);
assert(b instanceof Boolean);

View File

@ -0,0 +1,28 @@
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
es6id: 24.2.2
description: Subclassing the DataView object
info: >
24.2.2 The DataView Constructor
...
The DataView constructor is designed to be subclassable. It may be used as the
value of an extends clause of a class definition. Subclass constructors that
intend to inherit the specified DataView behaviour must include a super call
to the DataView constructor to create and initialize subclass instances with
the internal state necessary to support the DataView.prototype built-in
methods.
---*/
class DV extends DataView {}
var buffer = new ArrayBuffer(1);
var dv = new DV(buffer);
assert.sameValue(dv.buffer, buffer);
assert.throws(TypeError, function() {
new DV();
});

View File

@ -0,0 +1,35 @@
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
es6id: 24.2.2
description: Super need to be called to initialize internals
info: >
24.2.2 The DataView Constructor
...
The DataView constructor is designed to be subclassable. It may be used as the
value of an extends clause of a class definition. Subclass constructors that
intend to inherit the specified DataView behaviour must include a super call
to the DataView constructor to create and initialize subclass instances with
the internal state necessary to support the DataView.prototype built-in
methods.
---*/
class DV1 extends DataView {
constructor() {}
}
var buffer = new ArrayBuffer(1);
assert.throws(ReferenceError, function() {
new DV1(buffer);
});
class DV2 extends DataView {
constructor(length) {
super(length);
}
}
new DV2(buffer);

View File

@ -0,0 +1,37 @@
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
es6id: 20.3.2
description: Subclassing the String object
info: >
20.3.2 The Date Constructor
...
The Date constructor is a single function whose behaviour is overloaded based
upon the number and types of its arguments.
The Date constructor is designed to be subclassable. It may be used as the
value of an extends clause of a class definition. Subclass constructors that
intend to inherit the specified Date behaviour must include a super call to
the Date constructor to create and initialize the subclass instance with a
[[DateValue]] internal slot.
---*/
class D extends Date {}
var d1 = new D(1859, '10', 24);
assert.sameValue(d1.getUTCFullYear(), 1859);
assert.sameValue(d1.getUTCMonth(), 10);
assert.sameValue(d1.getUTCDate(), 24);
var d2 = new D(-3474558000000);
assert.sameValue(d2.getUTCFullYear(), 1859);
assert.sameValue(d2.getUTCMonth(), 10);
assert.sameValue(d2.getUTCDate(), 24);
var d3 = new D();
var d4 = new Date();
assert.sameValue(d3.getUTCFullYear(), d4.getUTCFullYear());
assert.sameValue(d3.getUTCMonth(), d4.getUTCMonth());
assert.sameValue(d3.getUTCDate(), d4.getUTCDate());

View File

@ -0,0 +1,35 @@
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
es6id: 20.3.2
description: Super need to be called to initialize internals
info: >
20.3.2 The Date Constructor
...
The Date constructor is a single function whose behaviour is overloaded based
upon the number and types of its arguments.
The Date constructor is designed to be subclassable. It may be used as the
value of an extends clause of a class definition. Subclass constructors that
intend to inherit the specified Date behaviour must include a super call to
the Date constructor to create and initialize the subclass instance with a
[[DateValue]] internal slot.
---*/
class D extends Date {
constructor() {}
}
assert.throws(ReferenceError, function() {
new D();
});
class D2 extends Date {
constructor() {
super();
}
}
new D2();

View File

@ -0,0 +1,36 @@
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
es6id: 19.5.1.1
description: >
A new instance has the message property if created with a parameter
info: >
19.5.1.1 Error ( message )
...
4. If message is not undefined, then
a. Let msg be ToString(message).
b. ReturnIfAbrupt(msg).
c. Let msgDesc be the PropertyDescriptor{[[Value]]: msg, [[Writable]]: true,
[[Enumerable]]: false, [[Configurable]]: true}.
d. Let status be DefinePropertyOrThrow(O, "message", msgDesc).
...
includes: [propertyHelper.js]
---*/
class Err extends Error {}
Err.prototype.message = 'custom-error';
var err1 = new Err('foo 42');
assert.sameValue(err1.message, 'foo 42');
assert(err1.hasOwnProperty('message'));
verifyWritable(err1, 'message');
verifyNotEnumerable(err1, 'message');
verifyConfigurable(err1, 'message');
var err2 = new Err();
assert.sameValue(err2.hasOwnProperty('message'), false);
assert.sameValue(err2.message, 'custom-error');

View File

@ -0,0 +1,22 @@
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
es6id: 19.5.1
description: Subclassing the Error object
info: >
19.5.1 The Error Constructor
...
The Error constructor is designed to be subclassable. It may be used as the
alue of an extends clause of a class definition. Subclass constructors that
intend to inherit the specified Error behaviour must include a super call to
the Error constructor to create and initialize subclass instances with a
[[ErrorData]] internal slot.
---*/
class CustomError extends Error {}
var err = new CustomError('foo 42');
assert.sameValue(err.message, 'foo 42');
assert.sameValue(err.name, 'Error');

View File

@ -0,0 +1,23 @@
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
es6id: 19.5.1
description: Super need to be called to initialize internals
info: >
19.5.1 The Error Constructor
...
The Error constructor is designed to be subclassable. It may be used as the
alue of an extends clause of a class definition. Subclass constructors that
intend to inherit the specified Error behaviour must include a super call to
the Error constructor to create and initialize subclass instances with a
[[ErrorData]] internal slot.
---*/
class CustomError extends Error {
constructor() {}
}
assert.throws(ReferenceError, function() {
new CustomError('foo');
});

View File

@ -0,0 +1,27 @@
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
es6id: 19.2.4.1
description: Subclassed Function instances has length and name properties
info: >
19.2.4.1 length
The value of the length property is an integer that indicates the typical
number of arguments expected by the function. However, the language permits
the function to be invoked with some other number of arguments. The behaviour
of a function when invoked on a number of arguments other than the number
specified by its length property depends on the function. This property has
the attributes { [[Writable]]: false, [[Enumerable]]: false,
[[Configurable]]: true }.
includes: [propertyHelper.js]
---*/
class Fn extends Function {}
var fn = new Fn('a', 'b', 'return a + b');
assert.sameValue(fn.length, 2);
verifyNotEnumerable(fn, 'length');
verifyNotWritable(fn, 'length');
verifyConfigurable(fn, 'length');

View File

@ -0,0 +1,39 @@
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
es6id: 19.2.4.2
description: Subclassed Function instances has length and name properties
info: >
19.2.4.2 name
The value of the name property is an String that is descriptive of the
function. The name has no semantic significance but is typically a variable or
property name that is used to refer to the function at its point of definition
in ECMAScript code. This property has the attributes { [[Writable]]: false,
[[Enumerable]]: false, [[Configurable]]: true }.
Anonymous functions objects that do not have a contextual name associated with
them by this specification do not have a name own property but inherit the
name property of %FunctionPrototype%.
19.2.1.1.1 RuntimeSemantics: CreateDynamicFunction(constructor, newTarget,
kind, args)
...
29. Perform SetFunctionName(F, "anonymous").
...
includes: [propertyHelper.js]
---*/
class Fn extends Function {}
var fn = new Fn('a', 'b', 'return a + b');
assert.sameValue(
fn.name, 'anonymous',
'Dynamic Functions are called anonymous'
);
verifyNotEnumerable(fn, 'name');
verifyNotWritable(fn, 'name');
verifyConfigurable(fn, 'name');

View File

@ -0,0 +1,20 @@
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
es6id: 19.2.1
description: Subclassing Function
info: >
19.2.1 The Function Constructor
...
The Function constructor is designed to be subclassable. It may be used as the
value of an extends clause of a class definition.
...
---*/
class Fn extends Function {}
var fn = new Fn('a', 'return a * 2');
assert.sameValue(fn(42), 84);

View File

@ -0,0 +1,35 @@
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
es6id: 19.2.1
description: >
super must be called to initialize Function internal slots
info: >
19.2.1 The Function Constructor
...
The Function constructor is designed to be subclassable. It may be used as the
value of an extends clause of a class definition. Subclass constructors that
intend to inherit the specified Function behaviour must include a super call
to the Function constructor to create and initialize a subclass instances with
the internal slots necessary for built-in function behaviour.
...
---*/
class Fn extends Function {
constructor() {}
}
assert.throws(ReferenceError, function() {
new Fn();
});
class Fn2 extends Function {
constructor() {
super();
}
}
var fn = new Fn2();
assert(fn instanceof Function);

View File

@ -0,0 +1,31 @@
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
es6id: 25.2.4.1
description: >
Subclassed GeneratorFunction instances `length` property
info: >
25.2.4.1 length
The value of the length property is an integer that indicates the typical
number of arguments expected by the GeneratorFunction. However, the language
permits the function to be invoked with some other number of arguments. The
behaviour of a GeneratorFunction when invoked on a number of arguments other
than the number specified by its length property depends on the function.
This property has the attributes { [[Writable]]: false, [[Enumerable]]: false,
[[Configurable]]: true }.
includes: [propertyHelper.js]
---*/
var GeneratorFunction = Object.getPrototypeOf(function* () {}).constructor;
class GFn extends GeneratorFunction {}
var gfn = new GFn('a', 'b', 'return a + b');
assert.sameValue(gfn.length, 2);
verifyNotEnumerable(gfn, 'length');
verifyNotWritable(gfn, 'length');
verifyConfigurable(gfn, 'length');

View File

@ -0,0 +1,46 @@
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
es6id: 25.2.4.2
description: Subclassed GeneratorFunction instances `name` property
info: >
25.2.4.2 name
The specification for the name property of Function instances given in
19.2.4.2 also applies to GeneratorFunction instances.
19.2.4.2 name
The value of the name property is an String that is descriptive of the
function. The name has no semantic significance but is typically a variable or
property name that is used to refer to the function at its point of definition
in ECMAScript code. This property has the attributes { [[Writable]]: false,
[[Enumerable]]: false, [[Configurable]]: true }.
Anonymous functions objects that do not have a contextual name associated with
them by this specification do not have a name own property but inherit the
name property of %FunctionPrototype%.
19.2.1.1.1 RuntimeSemantics: CreateDynamicFunction(constructor, newTarget,
kind, args)
...
29. Perform SetFunctionName(F, "anonymous").
...
includes: [propertyHelper.js]
---*/
var GeneratorFunction = Object.getPrototypeOf(function* () {}).constructor;
class GFn extends GeneratorFunction {}
var gfn = new GFn('a', 'b', 'return a + b');
assert.sameValue(
gfn.name, 'anonymous',
'Dynamic Functions are called anonymous'
);
verifyNotEnumerable(gfn, 'name');
verifyNotWritable(gfn, 'name');
verifyConfigurable(gfn, 'name');

View File

@ -0,0 +1,38 @@
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
es6id: 25.2.4.3
description: >
Subclassed GeneratorFunction instances `prototype` property
info: >
25.2.4.3 prototype
Whenever a GeneratorFunction instance is created another ordinary object is
also created and is the initial value of the generator functions 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');

View File

@ -0,0 +1,29 @@
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
es6id: 25.2.1
description: Subclassing GeneratorFunction
info: >
25.2.1 The GeneratorFunction Constructor
...
GeneratorFunction is designed to be subclassable. It may be used as the value
of an extends clause of a class definition. Subclass constructors that intend
to inherit the specified GeneratorFunction behaviour must include a super call
to the GeneratorFunction constructor to create and initialize subclass
instances with the internal slots necessary for built-in GeneratorFunction
behaviour.
...
---*/
var GeneratorFunction = Object.getPrototypeOf(function* () {}).constructor;
class Gfn extends GeneratorFunction {}
var gfn = new Gfn('a', 'yield a; yield a * 2;');
var iter = gfn(42);
assert.sameValue(iter.next().value, 42);
assert.sameValue(iter.next().value, 84);

View File

@ -0,0 +1,38 @@
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
es6id: 25.2.1
description: >
super must be called to initialize GeneratorFunction internal slots
info: >
25.2.1 The GeneratorFunction Constructor
...
GeneratorFunction is designed to be subclassable. It may be used as the value
of an extends clause of a class definition. Subclass constructors that intend
to inherit the specified GeneratorFunction behaviour must include a super call
to the GeneratorFunction constructor to create and initialize subclass
instances with the internal slots necessary for built-in GeneratorFunction
behaviour.
...
---*/
var GeneratorFunction = Object.getPrototypeOf(function* () {}).constructor;
class GFn1 extends GeneratorFunction {
constructor() {}
}
assert.throws(ReferenceError, function() {
new GFn1();
});
class GFn2 extends GeneratorFunction {
constructor() {
super();
}
}
var fn = new GFn2();
assert(fn instanceof GeneratorFunction);

View File

@ -0,0 +1,26 @@
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
es6id: 23.1.1
description: Subclassing the Map object
info: >
23.1.1 The Map Constructor
...
The Map constructor is designed to be subclassable. It may be used as the
value in an extends clause of a class definition. Subclass constructors that
intend to inherit the specified Map behaviour must include a super call to the
Map constructor to create and initialize the subclass instance with the
internal state necessary to support the Map.prototype built-in methods.
---*/
class M extends Map {}
var map = new M([{ 'foo': 'bar' }]);
assert.sameValue(map.size, 1);
map.set('bar', 'baz');
assert.sameValue(map.size, 2);

View File

@ -0,0 +1,32 @@
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
es6id: 23.1.1
description: Super need to be called to initialize internals
info: >
23.1.1 The Map Constructor
...
The Map constructor is designed to be subclassable. It may be used as the
value in an extends clause of a class definition. Subclass constructors that
intend to inherit the specified Map behaviour must include a super call to the
Map constructor to create and initialize the subclass instance with the
internal state necessary to support the Map.prototype built-in methods.
---*/
class M1 extends Map {
constructor() {}
}
assert.throws(ReferenceError, function() {
new M1();
});
class M2 extends Map {
constructor() {
super();
}
}
new M2();

View File

@ -0,0 +1,35 @@
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
es6id: 19.5.6.1.1
description: >
A new instance has the message property if created with a parameter
info: >
19.5.6.1.1 NativeError ( message )
...
4. If message is not undefined, then
a. Let msg be ToString(message).
b. Let msgDesc be the PropertyDescriptor{[[Value]]: msg, [[Writable]]: true,
[[Enumerable]]: false, [[Configurable]]: true}.
c. Let status be DefinePropertyOrThrow(O, "message", msgDesc).
...
includes: [propertyHelper.js]
---*/
class Err extends EvalError {}
Err.prototype.message = 'custom-eval-error';
var err1 = new Err('foo 42');
assert.sameValue(err1.message, 'foo 42');
assert(err1.hasOwnProperty('message'));
verifyWritable(err1, 'message');
verifyNotEnumerable(err1, 'message');
verifyConfigurable(err1, 'message');
var err2 = new Err();
assert.sameValue(err2.hasOwnProperty('message'), false);
assert.sameValue(err2.message, 'custom-eval-error');

View File

@ -0,0 +1,18 @@
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
es6id: 19.5.6.1.1
description: >
The name property on a new instance
info: >
19.5.6.3.3 NativeError.prototype.name
The initial value of the name property of the prototype for a given
NativeError constructor is a string consisting of the name of the constructor
(the name used instead of NativeError).
---*/
class Err extends EvalError {}
var err1 = new Err();
assert.sameValue(err1.name, 'EvalError');

View File

@ -0,0 +1,23 @@
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
es6id: 19.5.6.1
description: Super need to be called to initialize internals
info: >
19.5.6.1 NativeError Constructors
...
Each NativeError constructor is designed to be subclassable. It may be used as
the value of an extends clause of a class definition. Subclass constructors
that intend to inherit the specified NativeError behaviour must include a
super call to the NativeError constructor to create and initialize subclass
instances with a [[ErrorData]] internal slot.
---*/
class CustomError extends EvalError {
constructor() {}
}
assert.throws(ReferenceError, function() {
new CustomError();
});

View File

@ -0,0 +1,35 @@
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
es6id: 19.5.6.1.1
description: >
A new instance has the message property if created with a parameter
info: >
19.5.6.1.1 NativeError ( message )
...
4. If message is not undefined, then
a. Let msg be ToString(message).
b. Let msgDesc be the PropertyDescriptor{[[Value]]: msg, [[Writable]]: true,
[[Enumerable]]: false, [[Configurable]]: true}.
c. Let status be DefinePropertyOrThrow(O, "message", msgDesc).
...
includes: [propertyHelper.js]
---*/
class Err extends RangeError {}
Err.prototype.message = 'custom-range-error';
var err1 = new Err('foo 42');
assert.sameValue(err1.message, 'foo 42');
assert(err1.hasOwnProperty('message'));
verifyWritable(err1, 'message');
verifyNotEnumerable(err1, 'message');
verifyConfigurable(err1, 'message');
var err2 = new Err();
assert.sameValue(err2.hasOwnProperty('message'), false);
assert.sameValue(err2.message, 'custom-range-error');

View File

@ -0,0 +1,18 @@
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
es6id: 19.5.6.1.1
description: >
The name property on a new instance
info: >
19.5.6.3.3 NativeError.prototype.name
The initial value of the name property of the prototype for a given
NativeError constructor is a string consisting of the name of the constructor
(the name used instead of NativeError).
---*/
class Err extends RangeError {}
var err1 = new Err();
assert.sameValue(err1.name, 'RangeError');

View File

@ -0,0 +1,23 @@
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
es6id: 19.5.6.1
description: Super need to be called to initialize internals
info: >
19.5.6.1 NativeError Constructors
...
Each NativeError constructor is designed to be subclassable. It may be used as
the value of an extends clause of a class definition. Subclass constructors
that intend to inherit the specified NativeError behaviour must include a
super call to the NativeError constructor to create and initialize subclass
instances with a [[ErrorData]] internal slot.
---*/
class CustomError extends RangeError {
constructor() {}
}
assert.throws(ReferenceError, function() {
new CustomError();
});

View File

@ -0,0 +1,35 @@
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
es6id: 19.5.6.1.1
description: >
A new instance has the message property if created with a parameter
info: >
19.5.6.1.1 NativeError ( message )
...
4. If message is not undefined, then
a. Let msg be ToString(message).
b. Let msgDesc be the PropertyDescriptor{[[Value]]: msg, [[Writable]]: true,
[[Enumerable]]: false, [[Configurable]]: true}.
c. Let status be DefinePropertyOrThrow(O, "message", msgDesc).
...
includes: [propertyHelper.js]
---*/
class Err extends ReferenceError {}
Err.prototype.message = 'custom-reference-error';
var err1 = new Err('foo 42');
assert.sameValue(err1.message, 'foo 42');
assert(err1.hasOwnProperty('message'));
verifyWritable(err1, 'message');
verifyNotEnumerable(err1, 'message');
verifyConfigurable(err1, 'message');
var err2 = new Err();
assert.sameValue(err2.hasOwnProperty('message'), false);
assert.sameValue(err2.message, 'custom-reference-error');

View File

@ -0,0 +1,18 @@
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
es6id: 19.5.6.1.1
description: >
The name property on a new instance
info: >
19.5.6.3.3 NativeError.prototype.name
The initial value of the name property of the prototype for a given
NativeError constructor is a string consisting of the name of the constructor
(the name used instead of NativeError).
---*/
class Err extends ReferenceError {}
var err1 = new Err();
assert.sameValue(err1.name, 'ReferenceError');

View File

@ -0,0 +1,23 @@
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
es6id: 19.5.6.1
description: Super need to be called to initialize internals
info: >
19.5.6.1 NativeError Constructors
...
Each NativeError constructor is designed to be subclassable. It may be used as
the value of an extends clause of a class definition. Subclass constructors
that intend to inherit the specified NativeError behaviour must include a
super call to the NativeError constructor to create and initialize subclass
instances with a [[ErrorData]] internal slot.
---*/
class CustomError extends ReferenceError {
constructor() {}
}
assert.throws(ReferenceError, function() {
new CustomError();
});

View File

@ -0,0 +1,35 @@
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
es6id: 19.5.6.1.1
description: >
A new instance has the message property if created with a parameter
info: >
19.5.6.1.1 NativeError ( message )
...
4. If message is not undefined, then
a. Let msg be ToString(message).
b. Let msgDesc be the PropertyDescriptor{[[Value]]: msg, [[Writable]]: true,
[[Enumerable]]: false, [[Configurable]]: true}.
c. Let status be DefinePropertyOrThrow(O, "message", msgDesc).
...
includes: [propertyHelper.js]
---*/
class Err extends SyntaxError {}
Err.prototype.message = 'custom-syntax-error';
var err1 = new Err('foo 42');
assert.sameValue(err1.message, 'foo 42');
assert(err1.hasOwnProperty('message'));
verifyWritable(err1, 'message');
verifyNotEnumerable(err1, 'message');
verifyConfigurable(err1, 'message');
var err2 = new Err();
assert.sameValue(err2.hasOwnProperty('message'), false);
assert.sameValue(err2.message, 'custom-syntax-error');

View File

@ -0,0 +1,18 @@
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
es6id: 19.5.6.1.1
description: >
The name property on a new instance
info: >
19.5.6.3.3 NativeError.prototype.name
The initial value of the name property of the prototype for a given
NativeError constructor is a string consisting of the name of the constructor
(the name used instead of NativeError).
---*/
class Err extends SyntaxError {}
var err1 = new Err();
assert.sameValue(err1.name, 'SyntaxError');

View File

@ -0,0 +1,23 @@
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
es6id: 19.5.6.1
description: Super need to be called to initialize internals
info: >
19.5.6.1 NativeError Constructors
...
Each NativeError constructor is designed to be subclassable. It may be used as
the value of an extends clause of a class definition. Subclass constructors
that intend to inherit the specified NativeError behaviour must include a
super call to the NativeError constructor to create and initialize subclass
instances with a [[ErrorData]] internal slot.
---*/
class CustomError extends SyntaxError {
constructor() {}
}
assert.throws(ReferenceError, function() {
new CustomError();
});

View File

@ -0,0 +1,35 @@
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
es6id: 19.5.6.1.1
description: >
A new instance has the message property if created with a parameter
info: >
19.5.6.1.1 NativeError ( message )
...
4. If message is not undefined, then
a. Let msg be ToString(message).
b. Let msgDesc be the PropertyDescriptor{[[Value]]: msg, [[Writable]]: true,
[[Enumerable]]: false, [[Configurable]]: true}.
c. Let status be DefinePropertyOrThrow(O, "message", msgDesc).
...
includes: [propertyHelper.js]
---*/
class Err extends TypeError {}
Err.prototype.message = 'custom-type-error';
var err1 = new Err('foo 42');
assert.sameValue(err1.message, 'foo 42');
assert(err1.hasOwnProperty('message'));
verifyWritable(err1, 'message');
verifyNotEnumerable(err1, 'message');
verifyConfigurable(err1, 'message');
var err2 = new Err();
assert.sameValue(err2.hasOwnProperty('message'), false);
assert.sameValue(err2.message, 'custom-type-error');

View File

@ -0,0 +1,18 @@
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
es6id: 19.5.6.1.1
description: >
The name property on a new instance
info: >
19.5.6.3.3 NativeError.prototype.name
The initial value of the name property of the prototype for a given
NativeError constructor is a string consisting of the name of the constructor
(the name used instead of NativeError).
---*/
class Err extends TypeError {}
var err1 = new Err();
assert.sameValue(err1.name, 'TypeError');

View File

@ -0,0 +1,23 @@
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
es6id: 19.5.6.1
description: Super need to be called to initialize internals
info: >
19.5.6.1 NativeError Constructors
...
Each NativeError constructor is designed to be subclassable. It may be used as
the value of an extends clause of a class definition. Subclass constructors
that intend to inherit the specified NativeError behaviour must include a
super call to the NativeError constructor to create and initialize subclass
instances with a [[ErrorData]] internal slot.
---*/
class CustomError extends TypeError {
constructor() {}
}
assert.throws(ReferenceError, function() {
new CustomError();
});

View File

@ -0,0 +1,35 @@
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
es6id: 19.5.6.1.1
description: >
A new instance has the message property if created with a parameter
info: >
19.5.6.1.1 NativeError ( message )
...
4. If message is not undefined, then
a. Let msg be ToString(message).
b. Let msgDesc be the PropertyDescriptor{[[Value]]: msg, [[Writable]]: true,
[[Enumerable]]: false, [[Configurable]]: true}.
c. Let status be DefinePropertyOrThrow(O, "message", msgDesc).
...
includes: [propertyHelper.js]
---*/
class Err extends URIError {}
Err.prototype.message = 'custom-uri-error';
var err1 = new Err('foo 42');
assert.sameValue(err1.message, 'foo 42');
assert(err1.hasOwnProperty('message'));
verifyWritable(err1, 'message');
verifyNotEnumerable(err1, 'message');
verifyConfigurable(err1, 'message');
var err2 = new Err();
assert.sameValue(err2.hasOwnProperty('message'), false);
assert.sameValue(err2.message, 'custom-uri-error');

View File

@ -0,0 +1,18 @@
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
es6id: 19.5.6.1.1
description: >
The name property on a new instance
info: >
19.5.6.3.3 NativeError.prototype.name
The initial value of the name property of the prototype for a given
NativeError constructor is a string consisting of the name of the constructor
(the name used instead of NativeError).
---*/
class Err extends URIError {}
var err1 = new Err();
assert.sameValue(err1.name, 'URIError');

View File

@ -0,0 +1,23 @@
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
es6id: 19.5.6.1
description: Super need to be called to initialize internals
info: >
19.5.6.1 NativeError Constructors
...
Each NativeError constructor is designed to be subclassable. It may be used as
the value of an extends clause of a class definition. Subclass constructors
that intend to inherit the specified NativeError behaviour must include a
super call to the NativeError constructor to create and initialize subclass
instances with a [[ErrorData]] internal slot.
---*/
class CustomError extends URIError {
constructor() {}
}
assert.throws(ReferenceError, function() {
new CustomError();
});

View File

@ -0,0 +1,23 @@
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
es6id: 20.1.1
description: Subclassing the Number object
info: >
20.1.1 The Number Constructor
...
The Number constructor is designed to be subclassable. It may be used as the
value of an extends clause of a class definition. Subclass constructors that
intend to inherit the specified Number behaviour must include a super call to
the Number constructor to create and initialize the subclass instance with a
[[NumberData]] internal slot.
---*/
class N extends Number {}
var n = new N(42);
assert.sameValue(n.toFixed(2), '42.00');
assert.sameValue(n.toExponential(2), '4.20e+1');

View File

@ -0,0 +1,32 @@
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
es6id: 20.1.1
description: Super need to be called to initialize internals
info: >
20.1.1 The Number Constructor
...
The Number constructor is designed to be subclassable. It may be used as the
value of an extends clause of a class definition. Subclass constructors that
intend to inherit the specified Number behaviour must include a super call to
the Number constructor to create and initialize the subclass instance with a
[[NumberData]] internal slot.
---*/
class N extends Number {
constructor() {}
}
assert.throws(ReferenceError, function() {
new N();
});
class N2 extends Number {
constructor() {
super();
}
}
new N2();

View File

@ -0,0 +1,45 @@
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
es6id: 9.2.2
description: Throws a ReferenceError if constructor result is undefined
info: >
9.2.2 [[Construct]] ( argumentsList, newTarget)
...
11. Let result be OrdinaryCallEvaluateBody(F, argumentsList).
...
13. If result.[[type]] is return, then
a. If Type(result.[[value]]) is Object, return
NormalCompletion(result.[[value]]).
...
c. If result.[[value]] is not undefined, throw a TypeError exception.
...
15. Return envRec.GetThisBinding().
8.1.1.3.4 GetThisBinding ()
...
3. If envRec.[[thisBindingStatus]] is "uninitialized", throw a ReferenceError
exception.
...
---*/
class Obj extends Object {
constructor() {
return undefined;
}
}
class Obj2 extends Object {
constructor() {}
}
assert.throws(ReferenceError, function() {
new Obj();
});
assert.throws(ReferenceError, function() {
new Obj2();
});

View File

@ -0,0 +1,40 @@
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
es6id: 9.2.2
description: The Type of the return value must be an Object
info: >
9.2.2 [[Construct]] ( argumentsList, newTarget)
...
11. Let result be OrdinaryCallEvaluateBody(F, argumentsList).
...
13. If result.[[type]] is return, then
a. If Type(result.[[value]]) is Object, return
NormalCompletion(result.[[value]]).
...
c. If result.[[value]] is not undefined, throw a TypeError exception.
...
6.1.7.2 Object Internal Methods and Internal Slots
...
If any specified use of an internal method of an exotic object is not
supported by an implementation, that usage must throw a TypeError exception
when attempted.
6.1.7.3 Invariants of the Essential Internal Methods
[[Construct]] ( )
- The Type of the return value must be Object.
---*/
class Obj extends Object {
constructor() {
return 42;
}
}
assert.throws(TypeError, function() {
var obj = new Obj();
});

View File

@ -0,0 +1,20 @@
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
es6id: 19.1.1
description: Subclassing Object
info: >
19.1.1 The Object Constructor
The Object constructor is designed to be subclassable. It may be used as the
value of an extends clause of a class definition.
---*/
class Obj extends Object {}
var obj = new Obj();
assert.notSameValue(
Object.getPrototypeOf(obj), Object.prototype,
'returns the class prototype'
);

View File

@ -0,0 +1,21 @@
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
es6id: 19.1.1
description: Subclassing Object replacing a prototype method
info: >
19.1.1 The Object Constructor
The Object constructor is designed to be subclassable. It may be used as the
value of an extends clause of a class definition.
---*/
class Obj extends Object {
valueOf() {
return 42;
}
}
var obj = new Obj();
assert.sameValue(obj.valueOf(), 42, 'Replaces prototype');

View File

@ -0,0 +1,34 @@
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
es6id: 25.4.3
description: Subclassing the Promise object
info: >
25.4.3 The Promise Constructor
...
The Promise constructor is designed to be subclassable. It may be used as the
value in an extends clause of a class definition. Subclass constructors that
intend to inherit the specified Promise behaviour must include a super call
to the Promise constructor to create and initialize the subclass instance with
the internal state necessary to support the Promise and Promise.prototype
built-in methods.
---*/
class Prom extends Promise {}
assert.throws(TypeError, function() {
new Prom();
});
var calledExecutor = false;
var prom1 = new Prom(function(resolve) {
calledExecutor = true;
assert.sameValue(arguments.length, 2);
assert(arguments[0] === Promise.resolve);
assert(arguments[1] === Promise.reject);
});
assert(calledExecutor);

View File

@ -0,0 +1,33 @@
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
es6id: 25.4.3
description: Super need to be called to initialize internals
info: >
25.4.3 The Promise Constructor
...
The Promise constructor is designed to be subclassable. It may be used as the
value in an extends clause of a class definition. Subclass constructors that
intend to inherit the specified Promise behaviour must include a super call
to the Promise constructor to create and initialize the subclass instance with
the internal state necessary to support the Promise and Promise.prototype
built-in methods.
---*/
class Prom1 extends Promise {
constructor() {}
}
assert.throws(ReferenceError, function() {
new Prom1();
});
class Prom2 extends Promise {
constructor(exec) {
super(exec);
}
}
new Prom2(function() {});

View File

@ -0,0 +1,32 @@
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
es6id: 14.5.14
description: The Proxy Object is not subclasseable without a prototype
info: >
14.5.14 Runtime Semantics: ClassDefinitionEvaluation
5. If ClassHeritageopt is not present, then
...
6. Else
...
e. If superclass is null, then
...
f. Else if IsConstructor(superclass) is false, throw a TypeError exception.
g. Else
...
ii. Let protoParent be Get(superclass, "prototype").
iii. ReturnIfAbrupt(protoParent).
iv. If Type(protoParent) is neither Object nor Null, throw a TypeError exception.
26.2.1 The Proxy Constructor
The Proxy constructor is the %Proxy% intrinsic object and the initial value of
the Proxy property of the global object. When called as a constructor it
creates and initializes a new proxy exotic object. Proxy is not intended to be
called as a function and will throw an exception when called in that manner.
---*/
assert.throws(TypeError, function() {
class P extends Proxy {}
});

View File

@ -0,0 +1,26 @@
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
es6id: 21.2.6.1
description: Instances has the own property lastIndex
info: >
21.2.6.1 lastIndex
The value of the lastIndex property specifies the String index at which to
start the next match. It is coerced to an integer when used (see 21.2.5.2.2).
This property shall have the attributes { [[Writable]]: true, [[Enumerable]]:
false, [[Configurable]]: false }.
includes: [propertyHelper.js]
---*/
class RE extends RegExp {}
var re = new RE('39?');
re.exec('TC39');
assert.sameValue(re.lastIndex, 0);
verifyWritable(re, 'lastIndex');
verifyNotEnumerable(re, 'lastIndex');
verifyNotConfigurable(re, 'lastIndex');

View File

@ -0,0 +1,23 @@
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
es6id: 21.2.3
description: Subclassing the RegExp object
info: >
21.2.3 The RegExp Constructor
...
The RegExp constructor is designed to be subclassable. It may be used as the
value of an extends clause of a class definition. Subclass constructors that
intend to inherit the specified RegExp behaviour must include a super call to
the RegExp constructor to create and initialize subclass instances with the
necessary internal slots.
---*/
class RE extends RegExp {}
var re = new RE(39);
assert.sameValue(re.test('TC39'), true);
assert.sameValue(re.test('42'), false);

View File

@ -0,0 +1,32 @@
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
es6id: 21.2.3
description: Super need to be called to initialize internals
info: >
21.2.3 The RegExp Constructor
...
The RegExp constructor is designed to be subclassable. It may be used as the
value of an extends clause of a class definition. Subclass constructors that
intend to inherit the specified RegExp behaviour must include a super call to
the RegExp constructor to create and initialize subclass instances with the
necessary internal slots.
---*/
class RE1 extends RegExp {
constructor() {}
}
assert.throws(ReferenceError, function() {
new RE1();
});
class RE2 extends RegExp {
constructor() {
super();
}
}
new RE2();

View File

@ -0,0 +1,26 @@
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
es6id: 23.2.1
description: Subclassing the Set object
info: >
23.2.1 The Set Constructor
...
The Set constructor is designed to be subclassable. It may be used as the
value in an extends clause of a class definition. Subclass constructors that
intend to inherit the specified Set behaviour must include a super call to the
Set constructor to create and initialize the subclass instance with the
internal state necessary to support the Set.prototype built-in methods.
---*/
class S extends Set {}
var set = new S([{}, {}]);
assert.sameValue(set.size, 2);
set.add({});
assert.sameValue(set.size, 3);

View File

@ -0,0 +1,32 @@
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
es6id: 23.2.1
description: Super need to be called to initialize internals
info: >
23.2.1 The Set Constructor
...
The Set constructor is designed to be subclassable. It may be used as the
value in an extends clause of a class definition. Subclass constructors that
intend to inherit the specified Set behaviour must include a super call to the
Set constructor to create and initialize the subclass instance with the
internal state necessary to support the Set.prototype built-in methods.
---*/
class S1 extends Set {
constructor() {}
}
assert.throws(ReferenceError, function() {
new S1();
});
class S2 extends Set {
constructor() {
super();
}
}
new S2();

View File

@ -0,0 +1,30 @@
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
es6id: 21.1.4
description: Instances has the own property length
info: >
21.1.4 Properties of String Instances
...
String instances have a length property, and a set of enumerable properties
with integer indexed names.
includes: [propertyHelper.js]
---*/
class S extends String {}
var s1 = new S();
assert.sameValue(s1.length, 0);
verifyNotWritable(s1, 'length');
verifyNotEnumerable(s1, 'length');
verifyNotConfigurable(s1, 'length');
var s2 = new S('test262');
assert.sameValue(s2.length, 7);
verifyNotWritable(s2, 'length');
verifyNotEnumerable(s2, 'length');
verifyNotConfigurable(s2, 'length');

View File

@ -0,0 +1,22 @@
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
es6id: 21.1.1
description: Subclassing the String object
info: >
21.1.1 The String Constructor
...
The String constructor is designed to be subclassable. It may be used as the
value of an extends clause of a class definition. Subclass constructors that
intend to inherit the specified String behaviour must include a super call to
the String constructor to create and initialize the subclass instance with a
[[StringData]] internal slot.
---*/
class S extends String {}
var s = new S(' test262 ');
assert.sameValue(s.trim(), 'test262');

View File

@ -0,0 +1,31 @@
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
es6id: 21.1.1
description: Super need to be called to initialize internals
info: >
21.1.1 The String Constructor
...
The String constructor is designed to be subclassable. It may be used as the
value of an extends clause of a class definition. Subclass constructors that
intend to inherit the specified String behaviour must include a super call to
the String constructor to create and initialize the subclass instance with a
[[StringData]] internal slot.
---*/
class S1 extends String {
constructor() {}
}
assert.throws(ReferenceError, function() {
new S1();
});
class S2 extends String {
constructor() {
super();
}
}
new S2();

View File

@ -0,0 +1,35 @@
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
es6id: 19.4.1
description: Symbol subclass called with the new operator throws on super()
info: >
19.4.1 The Symbol Constructor
...
The Symbol constructor is not intended to be used with the new operator or to
be subclassed. It may be used as the value of an extends clause of a class
definition but a super call to the Symbol constructor will cause an exception.
19.4.1.1 Symbol ( [ description ] )
...
1. If NewTarget is not undefined, throw a TypeError exception.
---*/
class S1 extends Symbol {}
assert.throws(TypeError, function() {
new S1();
});
class S2 extends Symbol {
constructor() {
super();
}
}
assert.throws(TypeError, function() {
new S2();
});

View File

@ -0,0 +1,16 @@
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
es6id: 19.4.1
description: Symbol can be used as the value of an extends
info: >
19.4.1 The Symbol Constructor
...
The Symbol constructor is not intended to be used with the new operator or to
be subclassed. It may be used as the value of an extends clause of a class
definition but a super call to the Symbol constructor will cause an exception.
...
---*/
class S extends Symbol {}

View File

@ -0,0 +1,35 @@
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
es6id: 22.2.4
description: Subclassing TypedArrays
info: >
22.2.4 The TypedArray Constructors
...
The TypedArray constructors are designed to be subclassable. They may be used
as the value of an extends clause of a class definition. Subclass constructors
that intend to inherit the specified TypedArray behaviour must include a super
call to the TypedArray constructor to create and initialize the subclass
instance with the internal state necessary to support the
%TypedArray%.prototype built-in methods.
---*/
[
Int8Array,
Uint8Array,
Uint8ClampedArray,
Int16Array,
Uint16Array,
Int32Array,
Uint32Array,
Float32Array,
Float64Array
].forEach(function(Constructor) {
class Typed extends Constructor {}
var arr = new Typed(2);
assert.sameValue(arr.length, 2);
});

View File

@ -0,0 +1,45 @@
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
es6id: 22.2.4
description: Super need to be called to initialize internals
info: >
22.2.4 The TypedArray Constructors
...
The TypedArray constructors are designed to be subclassable. They may be used
as the value of an extends clause of a class definition. Subclass constructors
that intend to inherit the specified TypedArray behaviour must include a super
call to the TypedArray constructor to create and initialize the subclass
instance with the internal state necessary to support the
%TypedArray%.prototype built-in methods.
---*/
[
Int8Array,
Uint8Array,
Uint8ClampedArray,
Int16Array,
Uint16Array,
Int32Array,
Uint32Array,
Float32Array,
Float64Array
].forEach(function(Constructor) {
class Typed extends Constructor {
constructor() {}
}
assert.throws(ReferenceError, function() {
new Typed();
});
class TypedWithSuper extends Constructor {
constructor() {
super();
}
}
new TypedWithSuper();
});

View File

@ -0,0 +1,28 @@
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
es6id: 23.3.1
description: Subclassing the WeakMap object
info: >
23.3.1 The WeakMap Constructor
...
The WeakMap constructor is designed to be subclassable. It may be used as the
value in an extends clause of a class definition. Subclass constructors that
intend to inherit the specified WeakMap behaviour must include a super call to
the WeakMap constructor to create and initialize the subclass instance with
the internal state necessary to support the WeakMap.prototype built-in
methods.
---*/
class WM extends WeakMap {}
var map = new WM();
var obj = {};
assert.sameValue(map.has(obj), false);
map.set(obj, 42);
assert.sameValue(map.has(obj), true);
assert.sameValue(map.get(obj), 42);

View File

@ -0,0 +1,33 @@
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
es6id: 23.3.1
description: Super need to be called to initialize internals
info: >
23.3.1 The WeakMap Constructor
...
The WeakMap constructor is designed to be subclassable. It may be used as the
value in an extends clause of a class definition. Subclass constructors that
intend to inherit the specified WeakMap behaviour must include a super call to
the WeakMap constructor to create and initialize the subclass instance with
the internal state necessary to support the WeakMap.prototype built-in
methods.
---*/
class M1 extends WeakMap {
constructor() {}
}
assert.throws(ReferenceError, function() {
new M1();
});
class M2 extends WeakMap {
constructor() {
super();
}
}
new M2();

View File

@ -0,0 +1,27 @@
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
es6id: 23.4.1
description: Subclassing the WeakSet object
info: >
23.4.1 The WeakSet Constructor
...
The WeakSet constructor is designed to be subclassable. It may be used as the
value in an extends clause of a class definition. Subclass constructors that
intend to inherit the specified WeakSet behaviour must include a super call to
the WeakSet constructor to create and initialize the subclass instance with
the internal state necessary to support the WeakSet.prototype built-in
methods.
---*/
class WS extends WeakSet {}
var set = new WS();
var obj = {};
assert.sameValue(set.has(obj), false);
set.add(obj);
assert.sameValue(set.has(obj), true);

View File

@ -0,0 +1,33 @@
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
es6id: 23.4.1
description: Super need to be called to initialize internals
info: >
23.4.1 The WeakSet Constructor
...
The WeakSet constructor is designed to be subclassable. It may be used as the
value in an extends clause of a class definition. Subclass constructors that
intend to inherit the specified WeakSet behaviour must include a super call to
the WeakSet constructor to create and initialize the subclass instance with
the internal state necessary to support the WeakSet.prototype built-in
methods.
---*/
class WS1 extends WeakSet {
constructor() {}
}
assert.throws(ReferenceError, function() {
new WS1();
});
class WS2 extends WeakSet {
constructor() {
super();
}
}
new WS2();