Bug 1658308 - Backout Array.prototype.item and %TypedArray%.prototype.item.

There are too many web compatibility issues. Keeping this on Nightly is not going
to be useful.

Differential Revision: https://phabricator.services.mozilla.com/D92987
This commit is contained in:
Tom Schuster 2020-10-08 19:34:08 +00:00
parent cad53f4804
commit 436fcfbe71
7 changed files with 0 additions and 172 deletions

View File

@ -3760,11 +3760,6 @@ static const JSFunctionSpec array_methods[] = {
JS_SELF_HOSTED_FN("flatMap", "ArrayFlatMap", 1, 0),
JS_SELF_HOSTED_FN("flat", "ArrayFlat", 0, 0),
/* Proposal */
#ifdef NIGHTLY_BUILD
JS_SELF_HOSTED_FN("item", "ArrayItem", 1, 0),
#endif
JS_FS_END};
static const JSFunctionSpec array_static_methods[] = {

View File

@ -1140,32 +1140,3 @@ function FlattenIntoArray(target, source, sourceLen, start, depth, mapperFunctio
// Step 4.
return targetIndex;
}
// https://github.com/tc39/proposal-item-method
// Array.prototype.item ( index )
function ArrayItem(index) {
// Step 1.
var O = ToObject(this);
// Step 2.
var len = ToLength(O.length);
// Step 3.
var relativeIndex = ToInteger(index);
// Steps 4-5.
var k;
if (relativeIndex >= 0) {
k = relativeIndex;
} else {
k = len + relativeIndex;
}
// Step 6.
if (k < 0 || k >= len) {
return undefined;
}
// Step 7.
return O[k];
}

View File

@ -1335,45 +1335,6 @@ function TypedArraySubarray(begin, end) {
return TypedArraySpeciesCreateWithBuffer(obj, buffer, beginByteOffset, newLength);
}
// https://github.com/tc39/proposal-item-method
// %TypedArray%.prototype.item ( index )
function TypedArrayItem(index) {
// Step 1.
var obj = this;
// Step 2.
// This function is not generic.
if (!IsObject(obj) || !IsTypedArray(obj)) {
return callFunction(CallTypedArrayMethodIfWrapped, obj, index,
"TypedArrayItem");
}
GetAttachedArrayBuffer(obj);
// If we got here, `this` is either a typed array or a wrapper for one.
// Step 3.
var len = TypedArrayLength(obj);
// Step 4.
var relativeIndex = ToInteger(index);
// Steps 5-6.
var k;
if (relativeIndex >= 0) {
k = relativeIndex;
} else {
k = len + relativeIndex;
}
// Step 7.
if (k < 0 || k >= len) {
return undefined;
}
// Step 8.
return obj[k];
}
// ES6 draft rev30 (2014/12/24) 22.2.3.30 %TypedArray%.prototype.values()
//
// Uncloned functions with `$` prefix are allocated as extended function

View File

@ -1,41 +0,0 @@
// |reftest| skip-if(!Array.prototype.item)
function basic() {
assertEq([0].item(0), 0);
assertEq([0].item(-1), 0);
assertEq([].item(0), undefined);
assertEq([].item(-1), undefined);
assertEq([].item(1), undefined);
assertEq([0, 1].item(0), 0);
assertEq([0, 1].item(1), 1);
assertEq([0, 1].item(-2), 0);
assertEq([0, 1].item(-1), 1);
assertEq([0, 1].item(2), undefined);
assertEq([0, 1].item(-3), undefined);
assertEq([0, 1].item(-4), undefined);
assertEq([0, 1].item(Infinity), undefined);
assertEq([0, 1].item(-Infinity), undefined);
assertEq([0, 1].item(NaN), 0); // ToInteger(NaN) = 0
}
function obj() {
var o = {length: 0, [0]: "a", item: Array.prototype.item};
assertEq(o.item(0), undefined);
assertEq(o.item(-1), undefined);
o.length = 1;
assertEq(o.item(0), "a");
assertEq(o.item(-1), "a");
assertEq(o.item(1), undefined);
assertEq(o.item(-2), undefined);
}
basic();
obj();
if (typeof reportCompare === "function")
reportCompare(true, true);

View File

@ -1,49 +0,0 @@
// |reftest| skip-if(!Int32Array.prototype.item)
for (var constructor of anyTypedArrayConstructors) {
assertEq(constructor.prototype.item.length, 1);
assertEq(new constructor([0]).item(0), 0);
assertEq(new constructor([0]).item(-1), 0);
assertEq(new constructor([]).item(0), undefined);
assertEq(new constructor([]).item(-1), undefined);
assertEq(new constructor([]).item(1), undefined);
assertEq(new constructor([0, 1]).item(0), 0);
assertEq(new constructor([0, 1]).item(1), 1);
assertEq(new constructor([0, 1]).item(-2), 0);
assertEq(new constructor([0, 1]).item(-1), 1);
assertEq(new constructor([0, 1]).item(2), undefined);
assertEq(new constructor([0, 1]).item(-3), undefined);
assertEq(new constructor([0, 1]).item(-4), undefined);
assertEq(new constructor([0, 1]).item(Infinity), undefined);
assertEq(new constructor([0, 1]).item(-Infinity), undefined);
assertEq(new constructor([0, 1]).item(NaN), 0); // ToInteger(NaN) = 0
// Called from other globals.
if (typeof newGlobal === "function") {
var item = newGlobal()[constructor.name].prototype.item;
assertEq(item.call(new constructor([1, 2, 3]), 2), 3);
}
// Throws if `this` isn't a TypedArray.
var invalidReceivers = [undefined, null, 1, false, "", Symbol(), [], {}, /./,
new Proxy(new constructor(), {})];
invalidReceivers.forEach(invalidReceiver => {
assertThrowsInstanceOf(() => {
constructor.prototype.item.call(invalidReceiver);
}, TypeError, "Assert that item fails if this value is not a TypedArray");
});
// Test that the length getter is never called.
assertEq(Object.defineProperty(new constructor([1, 2, 3]), "length", {
get() {
throw new Error("length accessor called");
}
}).item(1), 2);
}
if (typeof reportCompare === "function")
reportCompare(true, true);

View File

@ -1919,9 +1919,6 @@ bool TypedArrayObject::set(JSContext* cx, unsigned argc, Value* vp) {
JS_SELF_HOSTED_FN("includes", "TypedArrayIncludes", 2, 0),
JS_SELF_HOSTED_FN("toString", "ArrayToString", 0, 0),
JS_SELF_HOSTED_FN("toLocaleString", "TypedArrayToLocaleString", 2, 0),
#ifdef NIGHTLY_BUILD
JS_SELF_HOSTED_FN("item", "TypedArrayItem", 1, 0),
#endif
JS_FS_END};
/* static */ const JSFunctionSpec TypedArrayObject::staticFunctions[] = {

View File

@ -235,9 +235,6 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=933681
"includes", "forEach", "map", "reduce", "reduceRight", "filter", "some", "every", "find",
"findIndex", "copyWithin", "fill", Symbol.iterator, Symbol.unscopables, "entries", "keys",
"values", "constructor", "flat", "flatMap"];
if (isNightlyBuild) {
gPrototypeProperties['Array'].push("item");
}
gConstructorProperties['Array'] =
constructorProps(["isArray", "from", "of", Symbol.species]);
for (var c of typedArrayClasses) {
@ -249,9 +246,6 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=933681
"set", "copyWithin", "find", "findIndex", "forEach","indexOf", "lastIndexOf", "includes",
"reverse", "join", "every", "some", "reduce", "reduceRight", "entries", "keys", "values",
"slice", "map", "filter"];
if (isNightlyBuild) {
gPrototypeProperties['TypedArray'].push("item");
}
// There is no TypedArray constructor, looks like.
is(window.TypedArray, undefined, "If this ever changes, add to this test!");
for (var c of errorObjectClasses) {