Commit 611add52 authored by littledan's avatar littledan Committed by Commit bot

Minor library function fixes for TypedArray spec compliance

- Make separate iterator functions for TypedArrays which do a type check
  (and in the future should check for detached TypedArrays)
- Share the toString method with Arrays

BUG=v8:4785
R=adamk
LOG=Y

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

Cr-Commit-Position: refs/heads/master@{#34698}
parent 5f5c48da
...@@ -109,6 +109,24 @@ function ArrayKeys() { ...@@ -109,6 +109,24 @@ function ArrayKeys() {
return CreateArrayIterator(this, ITERATOR_KIND_KEYS); return CreateArrayIterator(this, ITERATOR_KIND_KEYS);
} }
// TODO(littledan): Check for detached TypedArray in these three methods
function TypedArrayEntries() {
if (!IS_TYPEDARRAY(this)) throw MakeTypeError(kNotTypedArray);
return %_Call(ArrayEntries, this);
}
function TypedArrayValues() {
if (!IS_TYPEDARRAY(this)) throw MakeTypeError(kNotTypedArray);
return %_Call(ArrayValues, this);
}
function TypedArrayKeys() {
if (!IS_TYPEDARRAY(this)) throw MakeTypeError(kNotTypedArray);
return %_Call(ArrayKeys, this);
}
%FunctionSetPrototype(ArrayIterator, {__proto__: IteratorPrototype}); %FunctionSetPrototype(ArrayIterator, {__proto__: IteratorPrototype});
%FunctionSetInstanceClassName(ArrayIterator, 'Array Iterator'); %FunctionSetInstanceClassName(ArrayIterator, 'Array Iterator');
...@@ -133,12 +151,13 @@ utils.SetFunctionName(ArrayValues, 'values'); ...@@ -133,12 +151,13 @@ utils.SetFunctionName(ArrayValues, 'values');
%AddNamedProperty(GlobalArray.prototype, iteratorSymbol, ArrayValues, %AddNamedProperty(GlobalArray.prototype, iteratorSymbol, ArrayValues,
DONT_ENUM); DONT_ENUM);
utils.InstallFunctions(GlobalTypedArray.prototype, DONT_ENUM, [
'entries', TypedArrayEntries,
'keys', TypedArrayKeys,
'values', TypedArrayValues
]);
%AddNamedProperty(GlobalTypedArray.prototype, %AddNamedProperty(GlobalTypedArray.prototype,
'entries', ArrayEntries, DONT_ENUM); iteratorSymbol, TypedArrayValues, DONT_ENUM);
%AddNamedProperty(GlobalTypedArray.prototype, 'values', ArrayValues, DONT_ENUM);
%AddNamedProperty(GlobalTypedArray.prototype, 'keys', ArrayKeys, DONT_ENUM);
%AddNamedProperty(GlobalTypedArray.prototype,
iteratorSymbol, ArrayValues, DONT_ENUM);
// ------------------------------------------------------------------- // -------------------------------------------------------------------
// Exports // Exports
......
...@@ -12,7 +12,8 @@ ...@@ -12,7 +12,8 @@
// Imports // Imports
var AddIndexedProperty; var AddIndexedProperty;
var ArrayToString; // array.js has to come before typedarray.js for this to work
var ArrayToString = utils.ImportNow("ArrayToString");
var ArrayValues; var ArrayValues;
var GetIterator; var GetIterator;
var GetMethod; var GetMethod;
...@@ -71,7 +72,6 @@ TYPED_ARRAYS(DECLARE_GLOBALS) ...@@ -71,7 +72,6 @@ TYPED_ARRAYS(DECLARE_GLOBALS)
utils.Import(function(from) { utils.Import(function(from) {
AddIndexedProperty = from.AddIndexedProperty; AddIndexedProperty = from.AddIndexedProperty;
ArrayToString = from.ArrayToString;
ArrayValues = from.ArrayValues; ArrayValues = from.ArrayValues;
GetIterator = from.GetIterator; GetIterator = from.GetIterator;
GetMethod = from.GetMethod; GetMethod = from.GetMethod;
...@@ -675,12 +675,6 @@ function TypedArrayToLocaleString() { ...@@ -675,12 +675,6 @@ function TypedArrayToLocaleString() {
} }
// ES6 section 22.2.3.28
function TypedArrayToString() {
return %_Call(ArrayToString, this);
}
// ES6 section 22.2.3.14 // ES6 section 22.2.3.14
function TypedArrayJoin(separator) { function TypedArrayJoin(separator) {
if (!IS_TYPEDARRAY(this)) throw MakeTypeError(kNotTypedArray); if (!IS_TYPEDARRAY(this)) throw MakeTypeError(kNotTypedArray);
...@@ -873,10 +867,12 @@ utils.InstallFunctions(TypedArray.prototype, DONT_ENUM, [ ...@@ -873,10 +867,12 @@ utils.InstallFunctions(TypedArray.prototype, DONT_ENUM, [
"slice", TypedArraySlice, "slice", TypedArraySlice,
"some", TypedArraySome, "some", TypedArraySome,
"sort", TypedArraySort, "sort", TypedArraySort,
"toString", TypedArrayToString,
"toLocaleString", TypedArrayToLocaleString "toLocaleString", TypedArrayToLocaleString
]); ]);
%AddNamedProperty(TypedArray.prototype, "toString", ArrayToString,
DONT_ENUM);
macro SETUP_TYPED_ARRAY(ARRAY_ID, NAME, ELEMENT_SIZE) macro SETUP_TYPED_ARRAY(ARRAY_ID, NAME, ELEMENT_SIZE)
%SetCode(GlobalNAME, NAMEConstructor); %SetCode(GlobalNAME, NAMEConstructor);
......
...@@ -21,10 +21,10 @@ assertFalse(TypedArrayPrototype.propertyIsEnumerable('values')); ...@@ -21,10 +21,10 @@ assertFalse(TypedArrayPrototype.propertyIsEnumerable('values'));
assertFalse(TypedArrayPrototype.propertyIsEnumerable('keys')); assertFalse(TypedArrayPrototype.propertyIsEnumerable('keys'));
assertFalse(TypedArrayPrototype.propertyIsEnumerable(Symbol.iterator)); assertFalse(TypedArrayPrototype.propertyIsEnumerable(Symbol.iterator));
assertEquals(Array.prototype.entries, TypedArrayPrototype.entries); assertFalse(Array.prototype.entries === TypedArrayPrototype.entries);
assertEquals(Array.prototype[Symbol.iterator], TypedArrayPrototype.values); assertFalse(Array.prototype[Symbol.iterator] === TypedArrayPrototype.values);
assertEquals(Array.prototype.keys, TypedArrayPrototype.keys); assertFalse(Array.prototype.keys === TypedArrayPrototype.keys);
assertEquals(Array.prototype[Symbol.iterator], TypedArrayPrototype[Symbol.iterator]); assertFalse(Array.prototype[Symbol.iterator] === TypedArrayPrototype[Symbol.iterator]);
function TestTypedArrayValues(constructor) { function TestTypedArrayValues(constructor) {
......
...@@ -239,12 +239,6 @@ ...@@ -239,12 +239,6 @@
# https://bugs.chromium.org/p/v8/issues/detail?id=4784 # https://bugs.chromium.org/p/v8/issues/detail?id=4784
'built-ins/TypedArrays/buffer-arg-defined-negative-length': [FAIL], 'built-ins/TypedArrays/buffer-arg-defined-negative-length': [FAIL],
# https://bugs.chromium.org/p/v8/issues/detail?id=4785
'built-ins/TypedArray/prototype/entries/invoked-as-method': [FAIL],
'built-ins/TypedArray/prototype/keys/invoked-as-method': [FAIL],
'built-ins/TypedArray/prototype/values/invoked-as-method': [FAIL],
'built-ins/TypedArray/prototype/toString': [FAIL],
######################## NEEDS INVESTIGATION ########################### ######################## NEEDS INVESTIGATION ###########################
# These test failures are specific to the intl402 suite and need investigation # These test failures are specific to the intl402 suite and need investigation
......
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