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() { ...@@ -1172,10 +1172,11 @@ function SetUpError() {
%FunctionSetPrototype(f, new ErrorPrototype()); %FunctionSetPrototype(f, new ErrorPrototype());
} else { } else {
%FunctionSetPrototype(f, new $Error()); %FunctionSetPrototype(f, new $Error());
%InternalSetPrototype(f, $Error);
} }
%FunctionSetInstanceClassName(f, 'Error'); %FunctionSetInstanceClassName(f, 'Error');
%AddNamedProperty(f.prototype, 'constructor', f, DONT_ENUM); %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) { %SetCode(f, function(m) {
if (%_IsConstructCall()) { if (%_IsConstructCall()) {
try { captureStackTrace(this, f); } catch (e) { } try { captureStackTrace(this, f); } catch (e) { }
......
...@@ -25,10 +25,16 @@ ...@@ -25,10 +25,16 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
function assertPrototypeOf(func, expected) {
assertEquals(expected, Object.getPrototypeOf(func));
}
assertThrows(function() { assertThrows(function() {
Object.getPrototypeOf(undefined); Object.getPrototypeOf(undefined);
}, TypeError); }, TypeError);
assertThrows(function() { assertThrows(function() {
Object.getPrototypeOf(null); Object.getPrototypeOf(null);
}, TypeError); }, TypeError);
...@@ -37,20 +43,35 @@ assertThrows(function() { ...@@ -37,20 +43,35 @@ assertThrows(function() {
function F(){}; function F(){};
var y = new F(); var y = new F();
assertSame(Object.getPrototypeOf(y), F.prototype); assertPrototypeOf(y, F.prototype);
assertSame(Object.getPrototypeOf(F), Function.prototype); assertPrototypeOf(F, Function.prototype);
assertSame(Object.getPrototypeOf({x: 5}), Object.prototype); assertPrototypeOf({x: 5}, Object.prototype);
assertSame(Object.getPrototypeOf({x: 5, __proto__: null}), null); assertPrototypeOf({x: 5, __proto__: null}, null);
assertSame(Object.getPrototypeOf([1, 2]), Array.prototype); assertPrototypeOf([1, 2], Array.prototype);
assertSame(Object.getPrototypeOf(1), Number.prototype); assertPrototypeOf(1, Number.prototype);
assertSame(Object.getPrototypeOf(true), Boolean.prototype); assertPrototypeOf(true, Boolean.prototype);
assertSame(Object.getPrototypeOf(false), Boolean.prototype); assertPrototypeOf(false, Boolean.prototype);
assertSame(Object.getPrototypeOf('str'), String.prototype); assertPrototypeOf('str', String.prototype);
assertSame(Object.getPrototypeOf(Symbol()), Symbol.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. // Builtin constructors.
...@@ -61,7 +82,6 @@ var functions = [ ...@@ -61,7 +82,6 @@ var functions = [
// DataView, // DataView,
Date, Date,
Error, Error,
EvalError,
Float32Array, Float32Array,
Float64Array, Float64Array,
Function, Function,
...@@ -72,15 +92,10 @@ var functions = [ ...@@ -72,15 +92,10 @@ var functions = [
Number, Number,
Object, Object,
// Promise, // Promise,
RangeError,
ReferenceError,
RegExp, RegExp,
Set, Set,
String, String,
// Symbol, not constructible // Symbol, not constructible
SyntaxError,
TypeError,
URIError,
Uint16Array, Uint16Array,
Uint32Array, Uint32Array,
Uint8Array, Uint8Array,
...@@ -90,12 +105,12 @@ var functions = [ ...@@ -90,12 +105,12 @@ var functions = [
]; ];
for (var f of functions) { for (var f of functions) {
assertSame(Object.getPrototypeOf(f), Function.prototype); assertPrototypeOf(f, Function.prototype);
assertSame(Object.getPrototypeOf(new f), f.prototype); assertPrototypeOf(new f(), f.prototype);
} }
var p = new Promise(function() {}); var p = new Promise(function() {});
assertSame(Object.getPrototypeOf(p), Promise.prototype); assertPrototypeOf(p, Promise.prototype);
var dv = new DataView(new ArrayBuffer()); var dv = new DataView(new ArrayBuffer());
assertSame(Object.getPrototypeOf(dv), DataView.prototype); assertPrototypeOf(dv, DataView.prototype);
...@@ -269,12 +269,6 @@ ...@@ -269,12 +269,6 @@
'built-ins/Object/getOwnPropertyDescriptor/15.2.3.3-4-213': [FAIL], '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-214': [FAIL],
'built-ins/Object/getOwnPropertyDescriptor/15.2.3.3-4-215': [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': [FAIL],
'built-ins/Object/isExtensible/15.2.3.13-1-1': [FAIL], 'built-ins/Object/isExtensible/15.2.3.13-1-1': [FAIL],
'built-ins/Object/isExtensible/15.2.3.13-1-2': [FAIL], 'built-ins/Object/isExtensible/15.2.3.13-1-2': [FAIL],
......
...@@ -63,6 +63,14 @@ ...@@ -63,6 +63,14 @@
'11.1.5_4-4-d-3': [FAIL], '11.1.5_4-4-d-3': [FAIL],
'11.1.5_4-4-d-4': [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 # Function length properties are configurable in ES6
'10.1_L15': [FAIL], '10.1_L15': [FAIL],
'10.2.2_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