Commit ca9d499f authored by dehrenberg's avatar dehrenberg Committed by Commit bot

Make one copy for all TypedArray methods

This is the first step of converting TypedArrays to the proper
proto chain. There is one copy for each of the Harmony TypedArray
methods, rather than a version for each TypedArray type. This
form prevents accidentally baking in knowledge about a particular
array type into the method definition.

R=adamk@chromium.org, arv@chromium.org, caitpotter88@gmail.com, dslomov@chromium.org, jochen@chromium.org
BUG=v8:4085
LOG=Y

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

Cr-Commit-Position: refs/heads/master@{#28325}
parent 53930ea3
...@@ -10,18 +10,18 @@ ...@@ -10,18 +10,18 @@
macro TYPED_ARRAYS(FUNCTION) macro TYPED_ARRAYS(FUNCTION)
// arrayIds below should be synchronized with Runtime_TypedArrayInitialize. // arrayIds below should be synchronized with Runtime_TypedArrayInitialize.
FUNCTION(1, Uint8Array, 1) FUNCTION(Uint8Array)
FUNCTION(2, Int8Array, 1) FUNCTION(Int8Array)
FUNCTION(3, Uint16Array, 2) FUNCTION(Uint16Array)
FUNCTION(4, Int16Array, 2) FUNCTION(Int16Array)
FUNCTION(5, Uint32Array, 4) FUNCTION(Uint32Array)
FUNCTION(6, Int32Array, 4) FUNCTION(Int32Array)
FUNCTION(7, Float32Array, 4) FUNCTION(Float32Array)
FUNCTION(8, Float64Array, 8) FUNCTION(Float64Array)
FUNCTION(9, Uint8ClampedArray, 1) FUNCTION(Uint8ClampedArray)
endmacro endmacro
macro DECLARE_GLOBALS(INDEX, NAME, SIZE) macro DECLARE_GLOBALS(NAME)
var GlobalNAME = global.NAME; var GlobalNAME = global.NAME;
endmacro endmacro
...@@ -29,10 +29,8 @@ TYPED_ARRAYS(DECLARE_GLOBALS) ...@@ -29,10 +29,8 @@ TYPED_ARRAYS(DECLARE_GLOBALS)
// ------------------------------------------------------------------- // -------------------------------------------------------------------
macro TYPED_ARRAY_HARMONY_ADDITIONS(ARRAY_ID, NAME, ELEMENT_SIZE)
// ES6 draft 05-05-15, section 22.2.3.7 // ES6 draft 05-05-15, section 22.2.3.7
function NAMEEvery(f /* thisArg */) { // length == 1 function TypedArrayEvery(f /* thisArg */) { // length == 1
if (!%IsTypedArray(this)) { if (!%IsTypedArray(this)) {
throw MakeTypeError('not_typed_array', []); throw MakeTypeError('not_typed_array', []);
} }
...@@ -66,7 +64,7 @@ function NAMEEvery(f /* thisArg */) { // length == 1 ...@@ -66,7 +64,7 @@ function NAMEEvery(f /* thisArg */) { // length == 1
} }
// ES6 draft 08-24-14, section 22.2.3.12 // ES6 draft 08-24-14, section 22.2.3.12
function NAMEForEach(f /* thisArg */) { // length == 1 function TypedArrayForEach(f /* thisArg */) { // length == 1
if (!%IsTypedArray(this)) throw MakeTypeError(kNotTypedArray); if (!%IsTypedArray(this)) throw MakeTypeError(kNotTypedArray);
if (!IS_SPEC_FUNCTION(f)) throw MakeTypeError(kCalledNonCallable, f); if (!IS_SPEC_FUNCTION(f)) throw MakeTypeError(kCalledNonCallable, f);
...@@ -95,7 +93,7 @@ function NAMEForEach(f /* thisArg */) { // length == 1 ...@@ -95,7 +93,7 @@ function NAMEForEach(f /* thisArg */) { // length == 1
} }
// ES6 draft 08-24-14, section 22.2.2.2 // ES6 draft 08-24-14, section 22.2.2.2
function NAMEOf() { // length == 0 function TypedArrayOf() { // length == 0
var length = %_ArgumentsLength(); var length = %_ArgumentsLength();
var array = new this(length); var array = new this(length);
for (var i = 0; i < length; i++) { for (var i = 0; i < length; i++) {
...@@ -104,21 +102,16 @@ function NAMEOf() { // length == 0 ...@@ -104,21 +102,16 @@ function NAMEOf() { // length == 0
return array; return array;
} }
endmacro macro EXTEND_TYPED_ARRAY(NAME)
TYPED_ARRAYS(TYPED_ARRAY_HARMONY_ADDITIONS)
macro EXTEND_TYPED_ARRAY(ARRAY_ID, NAME, ELEMENT_SIZE)
// Set up non-enumerable functions on the object. // Set up non-enumerable functions on the object.
$installFunctions(GlobalNAME, DONT_ENUM | DONT_DELETE | READ_ONLY, [ $installFunctions(GlobalNAME, DONT_ENUM | DONT_DELETE | READ_ONLY, [
"of", NAMEOf "of", TypedArrayOf
]); ]);
// Set up non-enumerable functions on the prototype object. // Set up non-enumerable functions on the prototype object.
$installFunctions(GlobalNAME.prototype, DONT_ENUM, [ $installFunctions(GlobalNAME.prototype, DONT_ENUM, [
"every", NAMEEvery, "every", TypedArrayEvery,
"forEach", NAMEForEach "forEach", TypedArrayForEach
]); ]);
endmacro endmacro
......
// Copyright 2015 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Flags: --harmony-arrays
// Test that the methods for different TypedArray types have the same
// identity.
// TODO(dehrenberg): Test that the TypedArray proto hierarchy is set
// up properly.
// TODO(dehrenberg): subarray is currently left out because that still
// uses per-type methods. When that's fixed, stop leaving it out.
var typedArrayConstructors = [
Uint8Array,
Int8Array,
Uint16Array,
Int16Array,
Uint32Array,
Int32Array,
Uint8ClampedArray,
Float32Array,
Float64Array];
function functionProperties(object) {
return Object.getOwnPropertyNames(object).filter(function(name) {
return typeof Object.getOwnPropertyDescriptor(object, name).value
== "function"
&& name != 'constructor' && name != 'subarray';
});
}
var typedArrayMethods = functionProperties(Uint8Array.prototype);
var typedArrayClassMethods = functionProperties(Uint8Array);
for (var constructor of typedArrayConstructors) {
for (var method of typedArrayMethods) {
assertEquals(constructor.prototype[method],
Uint8Array.prototype[method], method);
}
for (var classMethod of typedArrayClassMethods) {
assertEquals(constructor[method], Uint8Array[method], classMethod);
}
}
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