Add tests for Subclassing the built-in NativeError Objects

This commit is contained in:
Leonardo Balter 2016-01-07 17:23:47 -05:00
parent 390c7a7fdb
commit 67ec7fbf7b
18 changed files with 456 additions and 0 deletions

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();
});