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, rossberg@chromium.org
>
> Committed: https://crrev.com/
ea463a916bbe5994b0d2d04e8075058b373b2e2c
> Cr-Commit-Position: refs/heads/master@{#27354}
TBR=adamk@chromium.org,rossberg@chromium.org,arv@chromium.org
NOPRESUBMIT=true
NOTREECHECKS=true
NOTRY=true
BUG=v8:3964
Review URL: https://codereview.chromium.org/
1033623002
Cr-Commit-Position: refs/heads/master@{#27389}
}
-// 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.
// (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);
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();
'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.
-
# 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
'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
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
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");