From 67ec7fbf7b139ddaefce2ccbb922e5ea47b138ec Mon Sep 17 00:00:00 2001
From: Leonardo Balter <leonardo.balter@gmail.com>
Date: Thu, 7 Jan 2016 17:23:47 -0500
Subject: [PATCH] Add tests for Subclassing the built-in NativeError Objects

---
 .../NativeError/EvalError-message.js          | 35 +++++++++++++++++++
 .../subclassing/NativeError/EvalError-name.js | 18 ++++++++++
 .../NativeError/EvalError-super.js            | 23 ++++++++++++
 .../NativeError/RangeError-message.js         | 35 +++++++++++++++++++
 .../NativeError/RangeError-name.js            | 18 ++++++++++
 .../NativeError/RangeError-super.js           | 23 ++++++++++++
 .../NativeError/ReferenceError-message.js     | 35 +++++++++++++++++++
 .../NativeError/ReferenceError-name.js        | 18 ++++++++++
 .../NativeError/ReferenceError-super.js       | 23 ++++++++++++
 .../NativeError/SyntaxError-message.js        | 35 +++++++++++++++++++
 .../NativeError/SyntaxError-name.js           | 18 ++++++++++
 .../NativeError/SyntaxError-super.js          | 23 ++++++++++++
 .../NativeError/TypeError-message.js          | 35 +++++++++++++++++++
 .../subclassing/NativeError/TypeError-name.js | 18 ++++++++++
 .../NativeError/TypeError-super.js            | 23 ++++++++++++
 .../NativeError/URIError-message.js           | 35 +++++++++++++++++++
 .../subclassing/NativeError/URIError-name.js  | 18 ++++++++++
 .../subclassing/NativeError/URIError-super.js | 23 ++++++++++++
 18 files changed, 456 insertions(+)
 create mode 100644 test/language/subclassing/NativeError/EvalError-message.js
 create mode 100644 test/language/subclassing/NativeError/EvalError-name.js
 create mode 100644 test/language/subclassing/NativeError/EvalError-super.js
 create mode 100644 test/language/subclassing/NativeError/RangeError-message.js
 create mode 100644 test/language/subclassing/NativeError/RangeError-name.js
 create mode 100644 test/language/subclassing/NativeError/RangeError-super.js
 create mode 100644 test/language/subclassing/NativeError/ReferenceError-message.js
 create mode 100644 test/language/subclassing/NativeError/ReferenceError-name.js
 create mode 100644 test/language/subclassing/NativeError/ReferenceError-super.js
 create mode 100644 test/language/subclassing/NativeError/SyntaxError-message.js
 create mode 100644 test/language/subclassing/NativeError/SyntaxError-name.js
 create mode 100644 test/language/subclassing/NativeError/SyntaxError-super.js
 create mode 100644 test/language/subclassing/NativeError/TypeError-message.js
 create mode 100644 test/language/subclassing/NativeError/TypeError-name.js
 create mode 100644 test/language/subclassing/NativeError/TypeError-super.js
 create mode 100644 test/language/subclassing/NativeError/URIError-message.js
 create mode 100644 test/language/subclassing/NativeError/URIError-name.js
 create mode 100644 test/language/subclassing/NativeError/URIError-super.js

diff --git a/test/language/subclassing/NativeError/EvalError-message.js b/test/language/subclassing/NativeError/EvalError-message.js
new file mode 100644
index 0000000000..475b236b8f
--- /dev/null
+++ b/test/language/subclassing/NativeError/EvalError-message.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');
diff --git a/test/language/subclassing/NativeError/EvalError-name.js b/test/language/subclassing/NativeError/EvalError-name.js
new file mode 100644
index 0000000000..cfd96de075
--- /dev/null
+++ b/test/language/subclassing/NativeError/EvalError-name.js
@@ -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');
diff --git a/test/language/subclassing/NativeError/EvalError-super.js b/test/language/subclassing/NativeError/EvalError-super.js
new file mode 100644
index 0000000000..c55cbf0b16
--- /dev/null
+++ b/test/language/subclassing/NativeError/EvalError-super.js
@@ -0,0 +1,23 @@
+// Copyright (C) 2016 the V8 project authors. All rights reserved.
+// This code is governed by the BSD license found in the LICENSE file.
+/*---
+es6id: 19.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();
+});
diff --git a/test/language/subclassing/NativeError/RangeError-message.js b/test/language/subclassing/NativeError/RangeError-message.js
new file mode 100644
index 0000000000..f3f4150fcf
--- /dev/null
+++ b/test/language/subclassing/NativeError/RangeError-message.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 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');
diff --git a/test/language/subclassing/NativeError/RangeError-name.js b/test/language/subclassing/NativeError/RangeError-name.js
new file mode 100644
index 0000000000..c676057e2b
--- /dev/null
+++ b/test/language/subclassing/NativeError/RangeError-name.js
@@ -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');
diff --git a/test/language/subclassing/NativeError/RangeError-super.js b/test/language/subclassing/NativeError/RangeError-super.js
new file mode 100644
index 0000000000..c02eec530d
--- /dev/null
+++ b/test/language/subclassing/NativeError/RangeError-super.js
@@ -0,0 +1,23 @@
+// Copyright (C) 2016 the V8 project authors. All rights reserved.
+// This code is governed by the BSD license found in the LICENSE file.
+/*---
+es6id: 19.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();
+});
diff --git a/test/language/subclassing/NativeError/ReferenceError-message.js b/test/language/subclassing/NativeError/ReferenceError-message.js
new file mode 100644
index 0000000000..d8ba34f100
--- /dev/null
+++ b/test/language/subclassing/NativeError/ReferenceError-message.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 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');
diff --git a/test/language/subclassing/NativeError/ReferenceError-name.js b/test/language/subclassing/NativeError/ReferenceError-name.js
new file mode 100644
index 0000000000..ca746745ad
--- /dev/null
+++ b/test/language/subclassing/NativeError/ReferenceError-name.js
@@ -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');
diff --git a/test/language/subclassing/NativeError/ReferenceError-super.js b/test/language/subclassing/NativeError/ReferenceError-super.js
new file mode 100644
index 0000000000..7ea1b66d18
--- /dev/null
+++ b/test/language/subclassing/NativeError/ReferenceError-super.js
@@ -0,0 +1,23 @@
+// Copyright (C) 2016 the V8 project authors. All rights reserved.
+// This code is governed by the BSD license found in the LICENSE file.
+/*---
+es6id: 19.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();
+});
diff --git a/test/language/subclassing/NativeError/SyntaxError-message.js b/test/language/subclassing/NativeError/SyntaxError-message.js
new file mode 100644
index 0000000000..4a31b87739
--- /dev/null
+++ b/test/language/subclassing/NativeError/SyntaxError-message.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 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');
diff --git a/test/language/subclassing/NativeError/SyntaxError-name.js b/test/language/subclassing/NativeError/SyntaxError-name.js
new file mode 100644
index 0000000000..658d59e547
--- /dev/null
+++ b/test/language/subclassing/NativeError/SyntaxError-name.js
@@ -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');
diff --git a/test/language/subclassing/NativeError/SyntaxError-super.js b/test/language/subclassing/NativeError/SyntaxError-super.js
new file mode 100644
index 0000000000..903f5337bf
--- /dev/null
+++ b/test/language/subclassing/NativeError/SyntaxError-super.js
@@ -0,0 +1,23 @@
+// Copyright (C) 2016 the V8 project authors. All rights reserved.
+// This code is governed by the BSD license found in the LICENSE file.
+/*---
+es6id: 19.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();
+});
diff --git a/test/language/subclassing/NativeError/TypeError-message.js b/test/language/subclassing/NativeError/TypeError-message.js
new file mode 100644
index 0000000000..a8bdbb3c0a
--- /dev/null
+++ b/test/language/subclassing/NativeError/TypeError-message.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 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');
diff --git a/test/language/subclassing/NativeError/TypeError-name.js b/test/language/subclassing/NativeError/TypeError-name.js
new file mode 100644
index 0000000000..d84b419c98
--- /dev/null
+++ b/test/language/subclassing/NativeError/TypeError-name.js
@@ -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');
diff --git a/test/language/subclassing/NativeError/TypeError-super.js b/test/language/subclassing/NativeError/TypeError-super.js
new file mode 100644
index 0000000000..ee764f80d0
--- /dev/null
+++ b/test/language/subclassing/NativeError/TypeError-super.js
@@ -0,0 +1,23 @@
+// Copyright (C) 2016 the V8 project authors. All rights reserved.
+// This code is governed by the BSD license found in the LICENSE file.
+/*---
+es6id: 19.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();
+});
diff --git a/test/language/subclassing/NativeError/URIError-message.js b/test/language/subclassing/NativeError/URIError-message.js
new file mode 100644
index 0000000000..214e73d387
--- /dev/null
+++ b/test/language/subclassing/NativeError/URIError-message.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 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');
diff --git a/test/language/subclassing/NativeError/URIError-name.js b/test/language/subclassing/NativeError/URIError-name.js
new file mode 100644
index 0000000000..78791e36d7
--- /dev/null
+++ b/test/language/subclassing/NativeError/URIError-name.js
@@ -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');
diff --git a/test/language/subclassing/NativeError/URIError-super.js b/test/language/subclassing/NativeError/URIError-super.js
new file mode 100644
index 0000000000..ab21a7170a
--- /dev/null
+++ b/test/language/subclassing/NativeError/URIError-super.js
@@ -0,0 +1,23 @@
+// Copyright (C) 2016 the V8 project authors. All rights reserved.
+// This code is governed by the BSD license found in the LICENSE file.
+/*---
+es6id: 19.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();
+});
-- 
GitLab