mirror of https://github.com/tc39/test262.git
Add tests for Subclassing the built-in NativeError Objects
This commit is contained in:
parent
390c7a7fdb
commit
67ec7fbf7b
test/language/subclassing/NativeError
EvalError-message.jsEvalError-name.jsEvalError-super.jsRangeError-message.jsRangeError-name.jsRangeError-super.jsReferenceError-message.jsReferenceError-name.jsReferenceError-super.jsSyntaxError-message.jsSyntaxError-name.jsSyntaxError-super.jsTypeError-message.jsTypeError-name.jsTypeError-super.jsURIError-message.jsURIError-name.jsURIError-super.js
|
@ -0,0 +1,35 @@
|
||||||
|
// Copyright (C) 2016 the V8 project authors. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
/*---
|
||||||
|
es6id: 19.5.6.1.1
|
||||||
|
description: >
|
||||||
|
A new instance has the message property if created with a parameter
|
||||||
|
info: >
|
||||||
|
19.5.6.1.1 NativeError ( message )
|
||||||
|
|
||||||
|
...
|
||||||
|
4. If message is not undefined, then
|
||||||
|
a. Let msg be ToString(message).
|
||||||
|
b. Let msgDesc be the PropertyDescriptor{[[Value]]: msg, [[Writable]]: true,
|
||||||
|
[[Enumerable]]: false, [[Configurable]]: true}.
|
||||||
|
c. Let status be DefinePropertyOrThrow(O, "message", msgDesc).
|
||||||
|
...
|
||||||
|
includes: [propertyHelper.js]
|
||||||
|
|
||||||
|
---*/
|
||||||
|
|
||||||
|
class Err extends EvalError {}
|
||||||
|
|
||||||
|
Err.prototype.message = 'custom-eval-error';
|
||||||
|
|
||||||
|
var err1 = new Err('foo 42');
|
||||||
|
assert.sameValue(err1.message, 'foo 42');
|
||||||
|
assert(err1.hasOwnProperty('message'));
|
||||||
|
|
||||||
|
verifyWritable(err1, 'message');
|
||||||
|
verifyNotEnumerable(err1, 'message');
|
||||||
|
verifyConfigurable(err1, 'message');
|
||||||
|
|
||||||
|
var err2 = new Err();
|
||||||
|
assert.sameValue(err2.hasOwnProperty('message'), false);
|
||||||
|
assert.sameValue(err2.message, 'custom-eval-error');
|
|
@ -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');
|
|
@ -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();
|
||||||
|
});
|
|
@ -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');
|
|
@ -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');
|
|
@ -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();
|
||||||
|
});
|
|
@ -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');
|
|
@ -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');
|
|
@ -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();
|
||||||
|
});
|
|
@ -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');
|
|
@ -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');
|
|
@ -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();
|
||||||
|
});
|
|
@ -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');
|
|
@ -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');
|
|
@ -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();
|
||||||
|
});
|
|
@ -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');
|
|
@ -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');
|
|
@ -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();
|
||||||
|
});
|
Loading…
Reference in New Issue