Skip to content
This repository has been archived by the owner on Apr 3, 2020. It is now read-only.

Commit

Permalink
Revert of [es6] Object.getPrototypeOf should work with values (patchset
Browse files Browse the repository at this point in the history
#3 id:40001 of https://codereview.chromium.org/1014813003/)

Reason for revert:
Layout test failures. Please update layout test expectations before landing this, in order to not block the roll.

Original issue's description:
> [es6] Object.getPrototypeOf should work with values
>
> 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.
>
> BUG=v8:3964
> LOG=N
> R=adamk, [email protected]
>
> Committed: https://crrev.com/ea463a916bbe5994b0d2d04e8075058b373b2e2c
> Cr-Commit-Position: refs/heads/master@{#27354}

[email protected],[email protected],[email protected]
NOPRESUBMIT=true
NOTREECHECKS=true
NOTRY=true
BUG=v8:3964

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

Cr-Commit-Position: refs/heads/master@{#27389}
  • Loading branch information
hashseed authored and Commit bot committed Mar 24, 2015
1 parent cff4fb9 commit 992751d
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 85 deletions.
7 changes: 5 additions & 2 deletions src/v8natives.js
Original file line number Diff line number Diff line change
Expand Up @@ -976,9 +976,12 @@ function DefineOwnProperty(obj, p, desc, should_throw) {
}


// ES6 section 19.1.2.9
// ES5 section 15.2.3.2.
function ObjectGetPrototypeOf(obj) {
return %_GetPrototype(TO_OBJECT_INLINE(obj));
if (!IS_SPEC_OBJECT(obj)) {
throw MakeTypeError("called_on_non_object", ["Object.getPrototypeOf"]);
}
return %_GetPrototype(obj);
}

// ES6 section 19.1.2.19.
Expand Down
98 changes: 32 additions & 66 deletions test/mjsunit/get-prototype-of.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,77 +25,43 @@
// (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);

assertThrows(function() {
Object.getPrototypeOf(null);
}, TypeError);
function TryGetPrototypeOfNonObject(x) {
var caught = 0;
try {
Object.getPrototypeOf(x);
} catch (e) {
caught = e;
}

assertTrue(caught instanceof TypeError);
};

function F(){};
var y = new F();

assertSame(Object.getPrototypeOf(y), F.prototype);
assertSame(Object.getPrototypeOf(F), Function.prototype);

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);
function GetPrototypeOfObject(x) {
assertDoesNotThrow(Object.getPrototypeOf(x));
assertNotNull(Object.getPrototypeOf(x));
assertEquals(Object.getPrototypeOf(x), x.__proto__);
}

function F(){};

// 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,
];
// Non object
var x = 10;

for (var f of functions) {
assertSame(Object.getPrototypeOf(f), Function.prototype);
assertSame(Object.getPrototypeOf(new f), f.prototype);
}
// Object
var y = new F();

var p = new Promise(function() {});
assertSame(Object.getPrototypeOf(p), Promise.prototype);
// Make sure that TypeError exceptions are thrown when non-objects are passed
// as argument
TryGetPrototypeOfNonObject(0);
TryGetPrototypeOfNonObject(null);
TryGetPrototypeOfNonObject('Testing');
TryGetPrototypeOfNonObject(x);

var dv = new DataView(new ArrayBuffer());
assertSame(Object.getPrototypeOf(dv), DataView.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);
10 changes: 8 additions & 2 deletions test/mjsunit/harmony/set-prototype-of.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,15 @@ var valuesWithoutNull = coercibleValues.concat(undefined);
function TestSetPrototypeOfCoercibleValues() {
for (var i = 0; i < coercibleValues.length; i++) {
var value = coercibleValues[i];
var proto = Object.getPrototypeOf(value);
assertThrows(function() {
Object.getPrototypeOf(value);
}, TypeError);

assertEquals(Object.setPrototypeOf(value, {}), value);
assertSame(proto, Object.getPrototypeOf(value));

assertThrows(function() {
Object.getPrototypeOf(value);
}, TypeError);
}
}
TestSetPrototypeOfCoercibleValues();
Expand Down
5 changes: 0 additions & 5 deletions test/test262-es6/test262-es6.status
Original file line number Diff line number Diff line change
Expand Up @@ -301,11 +301,6 @@
'intl402/ch13/13.3/13.3.2_L15': [FAIL],
'intl402/ch13/13.3/13.3.3_L15': [FAIL],

# Object.getPrototypeOf wraps primitive values in ES6.
'ch15/15.2/15.2.3/15.2.3.2/15.2.3.2-1-3': [FAIL],
'ch15/15.2/15.2.3/15.2.3.2/15.2.3.2-1-4': [FAIL],
'ch15/15.2/15.2.3/15.2.3.2/15.2.3.2-1': [FAIL],

############################ SKIPPED TESTS #############################

# These tests take a looong time to run in debug mode.
Expand Down
6 changes: 0 additions & 6 deletions test/test262/test262.status
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

# 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
Expand Down Expand Up @@ -190,11 +189,6 @@
'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
Expand Down
4 changes: 2 additions & 2 deletions test/webkit/prototypes-expected.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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('') is String.prototype
PASS Object.getPrototypeOf(0) is Number.prototype
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 Array.prototype
PASS Object.getPrototypeOf({}) is Object.prototype
PASS Object.getPrototypeOf(new Date) is Date.prototype
Expand Down
4 changes: 2 additions & 2 deletions test/webkit/prototypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ shouldBe("Date.__proto__", "Object.__proto__");
shouldBe("Number.__proto__", "Object.__proto__");
shouldBe("String.__proto__", "Object.__proto__");

shouldBe("Object.getPrototypeOf('')", "String.prototype");
shouldBe("Object.getPrototypeOf(0)", "Number.prototype");
shouldThrow("Object.getPrototypeOf('')");
shouldThrow("Object.getPrototypeOf(0)");
shouldBe("Object.getPrototypeOf([])", "Array.prototype");
shouldBe("Object.getPrototypeOf({})", "Object.prototype");
shouldBe("Object.getPrototypeOf(new Date)", "Date.prototype");
Expand Down

0 comments on commit 992751d

Please sign in to comment.