diff options
Diffstat (limited to 'js/src/tests/test262/language/statements/class/subclass/builtin-objects/Error')
5 files changed, 87 insertions, 0 deletions
diff --git a/js/src/tests/test262/language/statements/class/subclass/builtin-objects/Error/browser.js b/js/src/tests/test262/language/statements/class/subclass/builtin-objects/Error/browser.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/language/statements/class/subclass/builtin-objects/Error/browser.js diff --git a/js/src/tests/test262/language/statements/class/subclass/builtin-objects/Error/message-property-assignment.js b/js/src/tests/test262/language/statements/class/subclass/builtin-objects/Error/message-property-assignment.js new file mode 100644 index 0000000000..afa9b7e924 --- /dev/null +++ b/js/src/tests/test262/language/statements/class/subclass/builtin-objects/Error/message-property-assignment.js @@ -0,0 +1,38 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 19.5.1.1 +description: > + A new instance has the message property if created with a parameter +info: | + 19.5.1.1 Error ( message ) + + ... + 4. If message is not undefined, then + a. Let msg be ToString(message). + b. ReturnIfAbrupt(msg). + c. Let msgDesc be the PropertyDescriptor{[[Value]]: msg, [[Writable]]: true, + [[Enumerable]]: false, [[Configurable]]: true}. + d. Let status be DefinePropertyOrThrow(O, "message", msgDesc). + ... +includes: [propertyHelper.js] + +---*/ + +class Err extends Error {} + +Err.prototype.message = 'custom-error'; + +var err1 = new Err('foo 42'); +assert.sameValue(err1.message, 'foo 42'); +assert(err1.hasOwnProperty('message')); + +verifyWritable(err1, 'message'); +verifyNotEnumerable(err1, 'message'); +verifyConfigurable(err1, 'message'); + +var err2 = new Err(); +assert.sameValue(err2.hasOwnProperty('message'), false); +assert.sameValue(err2.message, 'custom-error'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/class/subclass/builtin-objects/Error/regular-subclassing.js b/js/src/tests/test262/language/statements/class/subclass/builtin-objects/Error/regular-subclassing.js new file mode 100644 index 0000000000..d34c85cb3c --- /dev/null +++ b/js/src/tests/test262/language/statements/class/subclass/builtin-objects/Error/regular-subclassing.js @@ -0,0 +1,24 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 19.5.1 +description: Subclassing the Error object +info: | + 19.5.1 The Error Constructor + + ... + The Error constructor is designed to be subclassable. It may be used as the + alue of an extends clause of a class definition. Subclass constructors that + intend to inherit the specified Error behaviour must include a super call to + the Error constructor to create and initialize subclass instances with a + [[ErrorData]] internal slot. +---*/ + +class CustomError extends Error {} + +var err = new CustomError('foo 42'); + +assert.sameValue(err.message, 'foo 42'); +assert.sameValue(err.name, 'Error'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/statements/class/subclass/builtin-objects/Error/shell.js b/js/src/tests/test262/language/statements/class/subclass/builtin-objects/Error/shell.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/language/statements/class/subclass/builtin-objects/Error/shell.js diff --git a/js/src/tests/test262/language/statements/class/subclass/builtin-objects/Error/super-must-be-called.js b/js/src/tests/test262/language/statements/class/subclass/builtin-objects/Error/super-must-be-called.js new file mode 100644 index 0000000000..8d7dcae53e --- /dev/null +++ b/js/src/tests/test262/language/statements/class/subclass/builtin-objects/Error/super-must-be-called.js @@ -0,0 +1,25 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 19.5.1 +description: Super need to be called to initialize internals +info: | + 19.5.1 The Error Constructor + + ... + The Error constructor is designed to be subclassable. It may be used as the + alue of an extends clause of a class definition. Subclass constructors that + intend to inherit the specified Error behaviour must include a super call to + the Error constructor to create and initialize subclass instances with a + [[ErrorData]] internal slot. +---*/ + +class CustomError extends Error { + constructor() {} +} + +assert.throws(ReferenceError, function() { + new CustomError('foo'); +}); + +reportCompare(0, 0); |