Commit 18cb17c9 authored by arv's avatar arv Committed by Commit bot

ES6: Error functions should extend Error

The /NativeError/ functions should have Error as their [[Prototype]].

http://people.mozilla.org/~jorendorff/es6-draft.html#sec-properties-of-the-nativeerror-constructors

BUG=v8:3998
LOG=N
R=adamk, dslomov@chromium.org
CQ_INCLUDE_TRYBOTS=tryserver.chromium.linux:linux_chromium_rel_ng;tryserver.blink:linux_blink_rel

Review URL: https://codereview.chromium.org/1049323003

Cr-Commit-Position: refs/heads/master@{#27572}
parent 5a93a330
......@@ -1172,10 +1172,11 @@ function SetUpError() {
%FunctionSetPrototype(f, new ErrorPrototype());
} else {
%FunctionSetPrototype(f, new $Error());
%InternalSetPrototype(f, $Error);
}
%FunctionSetInstanceClassName(f, 'Error');
%AddNamedProperty(f.prototype, 'constructor', f, DONT_ENUM);
%AddNamedProperty(f.prototype, "name", name, DONT_ENUM);
%AddNamedProperty(f.prototype, 'name', name, DONT_ENUM);
%SetCode(f, function(m) {
if (%_IsConstructCall()) {
try { captureStackTrace(this, f); } catch (e) { }
......
......@@ -25,10 +25,16 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
function assertPrototypeOf(func, expected) {
assertEquals(expected, Object.getPrototypeOf(func));
}
assertThrows(function() {
Object.getPrototypeOf(undefined);
}, TypeError);
assertThrows(function() {
Object.getPrototypeOf(null);
}, TypeError);
......@@ -37,20 +43,35 @@ assertThrows(function() {
function F(){};
var y = new F();
assertSame(Object.getPrototypeOf(y), F.prototype);
assertSame(Object.getPrototypeOf(F), Function.prototype);
assertPrototypeOf(y, F.prototype);
assertPrototypeOf(F, Function.prototype);
assertSame(Object.getPrototypeOf({x: 5}), Object.prototype);
assertSame(Object.getPrototypeOf({x: 5, __proto__: null}), null);
assertPrototypeOf({x: 5}, Object.prototype);
assertPrototypeOf({x: 5, __proto__: null}, null);
assertSame(Object.getPrototypeOf([1, 2]), Array.prototype);
assertPrototypeOf([1, 2], Array.prototype);
assertSame(Object.getPrototypeOf(1), Number.prototype);
assertSame(Object.getPrototypeOf(true), Boolean.prototype);
assertSame(Object.getPrototypeOf(false), Boolean.prototype);
assertSame(Object.getPrototypeOf('str'), String.prototype);
assertSame(Object.getPrototypeOf(Symbol()), Symbol.prototype);
assertPrototypeOf(1, Number.prototype);
assertPrototypeOf(true, Boolean.prototype);
assertPrototypeOf(false, Boolean.prototype);
assertPrototypeOf('str', String.prototype);
assertPrototypeOf(Symbol(), Symbol.prototype);
var errorFunctions = [
EvalError,
RangeError,
ReferenceError,
SyntaxError,
TypeError,
URIError,
];
for (var f of errorFunctions) {
assertPrototypeOf(f, Error);
assertPrototypeOf(new f(), f.prototype);
}
// Builtin constructors.
......@@ -61,7 +82,6 @@ var functions = [
// DataView,
Date,
Error,
EvalError,
Float32Array,
Float64Array,
Function,
......@@ -72,15 +92,10 @@ var functions = [
Number,
Object,
// Promise,
RangeError,
ReferenceError,
RegExp,
Set,
String,
// Symbol, not constructible
SyntaxError,
TypeError,
URIError,
Uint16Array,
Uint32Array,
Uint8Array,
......@@ -90,12 +105,12 @@ var functions = [
];
for (var f of functions) {
assertSame(Object.getPrototypeOf(f), Function.prototype);
assertSame(Object.getPrototypeOf(new f), f.prototype);
assertPrototypeOf(f, Function.prototype);
assertPrototypeOf(new f(), f.prototype);
}
var p = new Promise(function() {});
assertSame(Object.getPrototypeOf(p), Promise.prototype);
assertPrototypeOf(p, Promise.prototype);
var dv = new DataView(new ArrayBuffer());
assertSame(Object.getPrototypeOf(dv), DataView.prototype);
assertPrototypeOf(dv, DataView.prototype);
......@@ -269,12 +269,6 @@
'built-ins/Object/getOwnPropertyDescriptor/15.2.3.3-4-213': [FAIL],
'built-ins/Object/getOwnPropertyDescriptor/15.2.3.3-4-214': [FAIL],
'built-ins/Object/getOwnPropertyDescriptor/15.2.3.3-4-215': [FAIL],
'built-ins/Object/getPrototypeOf/15.2.3.2-2-12': [FAIL],
'built-ins/Object/getPrototypeOf/15.2.3.2-2-13': [FAIL],
'built-ins/Object/getPrototypeOf/15.2.3.2-2-14': [FAIL],
'built-ins/Object/getPrototypeOf/15.2.3.2-2-15': [FAIL],
'built-ins/Object/getPrototypeOf/15.2.3.2-2-16': [FAIL],
'built-ins/Object/getPrototypeOf/15.2.3.2-2-17': [FAIL],
'built-ins/Object/isExtensible/15.2.3.13-1': [FAIL],
'built-ins/Object/isExtensible/15.2.3.13-1-1': [FAIL],
'built-ins/Object/isExtensible/15.2.3.13-1-2': [FAIL],
......
......@@ -63,6 +63,14 @@
'11.1.5_4-4-d-3': [FAIL],
'11.1.5_4-4-d-4': [FAIL],
# NativeError has Error as its [[Prototype]]
'15.2.3.2-2-12': [FAIL],
'15.2.3.2-2-13': [FAIL],
'15.2.3.2-2-14': [FAIL],
'15.2.3.2-2-15': [FAIL],
'15.2.3.2-2-16': [FAIL],
'15.2.3.2-2-17': [FAIL],
# Function length properties are configurable in ES6
'10.1_L15': [FAIL],
'10.2.2_L15': [FAIL],
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment