Commit d4a314f9 authored by arv's avatar arv Committed by Commit bot

[es6] Object.getPrototypeOf should work with values

This reverts commit 992751d0.

The final spec for Object.getPrototypeOf calls ToObject on the
parameter, which means that it should only throw for null and
undefined. For other non object values the prototype of the wrapper
should be used.

Difference from last time: Updated .status and will disable Blink
side tests as needed.

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

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

Cr-Commit-Position: refs/heads/master@{#27558}
parent 729b85ae
......@@ -979,12 +979,9 @@ function DefineOwnProperty(obj, p, desc, should_throw) {
}
// ES5 section 15.2.3.2.
// ES6 section 19.1.2.9
function ObjectGetPrototypeOf(obj) {
if (!IS_SPEC_OBJECT(obj)) {
throw MakeTypeError("called_on_non_object", ["Object.getPrototypeOf"]);
}
return %_GetPrototype(obj);
return %_GetPrototype(TO_OBJECT_INLINE(obj));
}
// ES6 section 19.1.2.19.
......
......@@ -25,43 +25,77 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
assertThrows(function() {
Object.getPrototypeOf(undefined);
}, TypeError);
function TryGetPrototypeOfNonObject(x) {
var caught = 0;
try {
Object.getPrototypeOf(x);
} catch (e) {
caught = e;
}
assertThrows(function() {
Object.getPrototypeOf(null);
}, TypeError);
assertTrue(caught instanceof TypeError);
};
function GetPrototypeOfObject(x) {
assertDoesNotThrow(Object.getPrototypeOf(x));
assertNotNull(Object.getPrototypeOf(x));
assertEquals(Object.getPrototypeOf(x), x.__proto__);
}
function F(){};
var y = new F();
// Non object
var x = 10;
assertSame(Object.getPrototypeOf(y), F.prototype);
assertSame(Object.getPrototypeOf(F), Function.prototype);
// Object
var y = new F();
assertSame(Object.getPrototypeOf({x: 5}), Object.prototype);
assertSame(Object.getPrototypeOf({x: 5, __proto__: null}), null);
assertSame(Object.getPrototypeOf([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);
// Builtin constructors.
var functions = [
Array,
ArrayBuffer,
Boolean,
// DataView,
Date,
Error,
EvalError,
Float32Array,
Float64Array,
Function,
Int16Array,
Int32Array,
Int8Array,
Map,
Number,
Object,
// Promise,
RangeError,
ReferenceError,
RegExp,
Set,
String,
// Symbol, not constructible
SyntaxError,
TypeError,
URIError,
Uint16Array,
Uint32Array,
Uint8Array,
Uint8ClampedArray,
WeakMap,
WeakSet,
];
for (var f of functions) {
assertSame(Object.getPrototypeOf(f), Function.prototype);
assertSame(Object.getPrototypeOf(new f), f.prototype);
}
// Make sure that TypeError exceptions are thrown when non-objects are passed
// as argument
TryGetPrototypeOfNonObject(0);
TryGetPrototypeOfNonObject(null);
TryGetPrototypeOfNonObject('Testing');
TryGetPrototypeOfNonObject(x);
var p = new Promise(function() {});
assertSame(Object.getPrototypeOf(p), Promise.prototype);
// Make sure the real objects have this method and that it returns the
// actual prototype object. Also test for Functions and RegExp.
GetPrototypeOfObject(this);
GetPrototypeOfObject(y);
GetPrototypeOfObject({x:5});
GetPrototypeOfObject(F);
GetPrototypeOfObject(RegExp);
var dv = new DataView(new ArrayBuffer());
assertSame(Object.getPrototypeOf(dv), DataView.prototype);
......@@ -64,15 +64,9 @@ var valuesWithoutNull = coercibleValues.concat(undefined);
function TestSetPrototypeOfCoercibleValues() {
for (var i = 0; i < coercibleValues.length; i++) {
var value = coercibleValues[i];
assertThrows(function() {
Object.getPrototypeOf(value);
}, TypeError);
var proto = Object.getPrototypeOf(value);
assertEquals(Object.setPrototypeOf(value, {}), value);
assertThrows(function() {
Object.getPrototypeOf(value);
}, TypeError);
assertSame(proto, Object.getPrototypeOf(value));
}
}
TestSetPrototypeOfCoercibleValues();
......
......@@ -272,9 +272,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-1': [FAIL],
'built-ins/Object/getPrototypeOf/15.2.3.2-1-3': [FAIL],
'built-ins/Object/getPrototypeOf/15.2.3.2-1-4': [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],
......
# Copyright 2011 the V8 project authors. All rights reserved.
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are
......@@ -189,6 +190,11 @@
'S15.9.5.8_A3_T2': [FAIL],
'S15.9.5.9_A3_T2': [FAIL],
# Object.getPrototypeOf wraps primitive values in ES6.
'15.2.3.2-1': [FAIL],
'15.2.3.2-1-3': [FAIL],
'15.2.3.2-1-4': [FAIL],
######################## NEEDS INVESTIGATION ###########################
# These test failures are specific to the intl402 suite and need investigation
......
......@@ -43,8 +43,8 @@ PASS Array.__proto__ is Object.__proto__
PASS Date.__proto__ is Object.__proto__
PASS Number.__proto__ is Object.__proto__
PASS String.__proto__ is Object.__proto__
PASS Object.getPrototypeOf('') threw exception TypeError: Object.getPrototypeOf called on non-object.
PASS Object.getPrototypeOf(0) threw exception TypeError: Object.getPrototypeOf called on non-object.
PASS Object.getPrototypeOf('') is String.prototype
PASS Object.getPrototypeOf(0) is Number.prototype
PASS Object.getPrototypeOf([]) is Array.prototype
PASS Object.getPrototypeOf({}) is Object.prototype
PASS Object.getPrototypeOf(new Date) is Date.prototype
......
......@@ -43,8 +43,8 @@ shouldBe("Date.__proto__", "Object.__proto__");
shouldBe("Number.__proto__", "Object.__proto__");
shouldBe("String.__proto__", "Object.__proto__");
shouldThrow("Object.getPrototypeOf('')");
shouldThrow("Object.getPrototypeOf(0)");
shouldBe("Object.getPrototypeOf('')", "String.prototype");
shouldBe("Object.getPrototypeOf(0)", "Number.prototype");
shouldBe("Object.getPrototypeOf([])", "Array.prototype");
shouldBe("Object.getPrototypeOf({})", "Object.prototype");
shouldBe("Object.getPrototypeOf(new Date)", "Date.prototype");
......
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