Commit d53bffb2 authored by Tobias Tebbi's avatar Tobias Tebbi Committed by Commit Bot

[builtins] Enable %TypedArray%.prototype.{some,every,reduce,reduceRight,map}...

[builtins] Enable %TypedArray%.prototype.{some,every,reduce,reduceRight,map} CSA builtins by default

R=danno@chromium.org

Change-Id: I3365642b2682c09d745b7bcc9f983179604e7c3a
Reviewed-on: https://chromium-review.googlesource.com/509549
Commit-Queue: Tobias Tebbi <tebbi@chromium.org>
Reviewed-by: 's avatarDaniel Clifford <danno@chromium.org>
Reviewed-by: 's avatarBenedikt Meurer <bmeurer@chromium.org>
Cr-Commit-Position: refs/heads/master@{#45423}
parent 17a2c6e8
......@@ -178,7 +178,6 @@ class Genesis BASE_EMBEDDED {
void InstallOneBuiltinFunction(Handle<Object> prototype, const char* method,
Builtins::Name name);
void InitializeGlobal_experimental_fast_array_builtins();
Handle<JSFunction> InstallArrayBuffer(Handle<JSObject> target,
const char* name,
......@@ -2780,6 +2779,8 @@ void Genesis::InitializeGlobal(Handle<JSGlobalObject> global_object,
// TODO(caitp): alphasort accessors/methods
SimpleInstallFunction(prototype, "copyWithin",
Builtins::kTypedArrayPrototypeCopyWithin, 2, false);
SimpleInstallFunction(prototype, "every",
Builtins::kTypedArrayPrototypeEvery, 1, false);
SimpleInstallFunction(prototype, "fill",
Builtins::kTypedArrayPrototypeFill, 1, false);
SimpleInstallFunction(prototype, "includes",
......@@ -2788,10 +2789,18 @@ void Genesis::InitializeGlobal(Handle<JSGlobalObject> global_object,
Builtins::kTypedArrayPrototypeIndexOf, 1, false);
SimpleInstallFunction(prototype, "lastIndexOf",
Builtins::kTypedArrayPrototypeLastIndexOf, 1, false);
SimpleInstallFunction(prototype, "map", Builtins::kTypedArrayPrototypeMap,
1, false);
SimpleInstallFunction(prototype, "reverse",
Builtins::kTypedArrayPrototypeReverse, 0, false);
SimpleInstallFunction(prototype, "reduce",
Builtins::kTypedArrayPrototypeReduce, 1, false);
SimpleInstallFunction(prototype, "reduceRight",
Builtins::kTypedArrayPrototypeReduceRight, 1, false);
SimpleInstallFunction(prototype, "slice",
Builtins::kTypedArrayPrototypeSlice, 2, false);
SimpleInstallFunction(prototype, "some", Builtins::kTypedArrayPrototypeSome,
1, false);
}
{ // -- T y p e d A r r a y s
......@@ -3245,8 +3254,6 @@ void Genesis::InitializeExperimentalGlobal() {
HARMONY_STAGED(FEATURE_INITIALIZE_GLOBAL)
HARMONY_SHIPPING(FEATURE_INITIALIZE_GLOBAL)
#undef FEATURE_INITIALIZE_GLOBAL
InitializeGlobal_experimental_fast_array_builtins();
}
bool Bootstrapper::CompileBuiltin(Isolate* isolate, int index) {
......@@ -3885,25 +3892,6 @@ void Genesis::InstallOneBuiltinFunction(Handle<Object> prototype,
Builtins::GetBuiltinParameterCount(builtin_name));
}
void Genesis::InitializeGlobal_experimental_fast_array_builtins() {
if (!FLAG_experimental_fast_array_builtins) return;
{
Handle<Object> typed_array_prototype(
native_context()->typed_array_prototype(), isolate());
// Insert experimental fast TypedArray builtins here.
InstallOneBuiltinFunction(typed_array_prototype, "every",
Builtins::kTypedArrayPrototypeEvery);
InstallOneBuiltinFunction(typed_array_prototype, "some",
Builtins::kTypedArrayPrototypeSome);
InstallOneBuiltinFunction(typed_array_prototype, "reduce",
Builtins::kTypedArrayPrototypeReduce);
InstallOneBuiltinFunction(typed_array_prototype, "reduceRight",
Builtins::kTypedArrayPrototypeReduceRight);
InstallOneBuiltinFunction(typed_array_prototype, "map",
Builtins::kTypedArrayPrototypeMap);
}
}
void Genesis::InitializeGlobal_harmony_sharedarraybuffer() {
if (!FLAG_harmony_sharedarraybuffer) return;
......
......@@ -8982,7 +8982,7 @@ Node* CodeStubAssembler::TypedArraySpeciesCreateByLength(Node* context,
// TODO(tebbi): Install a fast path as well, which avoids the runtime
// call.
return CallRuntime(Runtime::kTypedArraySpeciesCreateByLength, context,
UndefinedConstant(), originalArray, len);
originalArray, len);
}
Node* CodeStubAssembler::IsDetachedBuffer(Node* buffer) {
......
......@@ -802,8 +802,6 @@ DEFINE_BOOL(builtins_in_stack_traces, false,
"show built-in functions in stack traces")
// builtins.cc
DEFINE_BOOL(experimental_fast_array_builtins, false,
"use experimental array builtins")
DEFINE_BOOL(allow_unsafe_function_constructor, false,
"allow invoking the function constructor without security checks")
......
......@@ -366,28 +366,6 @@ function TypedArrayGetToStringTag() {
return name;
}
function InnerTypedArrayEvery(f, receiver, array, length) {
if (!IS_CALLABLE(f)) throw %make_type_error(kCalledNonCallable, f);
for (var i = 0; i < length; i++) {
if (i in array) {
var element = array[i];
if (!%_Call(f, receiver, element, i, array)) return false;
}
}
return true;
}
// ES6 draft 05-05-15, section 22.2.3.7
function TypedArrayEvery(f, receiver) {
ValidateTypedArray(this, "%TypedArray%.prototype.every");
var length = %_TypedArrayGetLength(this);
return InnerTypedArrayEvery(f, receiver, this, length);
}
%FunctionSetLength(TypedArrayEvery, 1);
function InnerTypedArrayForEach(f, receiver, array, length) {
if (!IS_CALLABLE(f)) throw %make_type_error(kCalledNonCallable, f);
......@@ -490,44 +468,6 @@ function TypedArraySort(comparefn) {
}
// ES6 draft 07-15-13, section 22.2.3.18
function TypedArrayMap(f, thisArg) {
ValidateTypedArray(this, "%TypedArray%.prototype.map");
var length = %_TypedArrayGetLength(this);
var result = TypedArraySpeciesCreate(this, length);
if (!IS_CALLABLE(f)) throw %make_type_error(kCalledNonCallable, f);
for (var i = 0; i < length; i++) {
var element = this[i];
result[i] = %_Call(f, thisArg, element, i, this);
}
return result;
}
%FunctionSetLength(TypedArrayMap, 1);
function InnerTypedArraySome(f, receiver, array, length) {
if (!IS_CALLABLE(f)) throw %make_type_error(kCalledNonCallable, f);
for (var i = 0; i < length; i++) {
if (i in array) {
var element = array[i];
if (%_Call(f, receiver, element, i, array)) return true;
}
}
return false;
}
// ES6 draft 05-05-15, section 22.2.3.24
function TypedArraySome(f, receiver) {
ValidateTypedArray(this, "%TypedArray%.prototype.some");
var length = %_TypedArrayGetLength(this);
return InnerTypedArraySome(f, receiver, this, length);
}
%FunctionSetLength(TypedArraySome, 1);
// ES6 section 22.2.3.27
function TypedArrayToLocaleString() {
ValidateTypedArray(this, "%TypedArray%.prototype.toLocaleString");
......@@ -547,78 +487,6 @@ function TypedArrayJoin(separator) {
return InnerArrayJoin(separator, this, length);
}
function InnerTypedArrayReduce(
callback, current, array, length, argumentsLength) {
if (!IS_CALLABLE(callback)) {
throw %make_type_error(kCalledNonCallable, callback);
}
var i = 0;
find_initial: if (argumentsLength < 2) {
for (; i < length; i++) {
if (i in array) {
current = array[i++];
break find_initial;
}
}
throw %make_type_error(kReduceNoInitial);
}
for (; i < length; i++) {
if (i in array) {
var element = array[i];
current = callback(current, element, i, array);
}
}
return current;
}
// ES6 draft 07-15-13, section 22.2.3.19
function TypedArrayReduce(callback, current) {
ValidateTypedArray(this, "%TypedArray%.prototype.reduce");
var length = %_TypedArrayGetLength(this);
return InnerTypedArrayReduce(
callback, current, this, length, arguments.length);
}
%FunctionSetLength(TypedArrayReduce, 1);
function InnerArrayReduceRight(callback, current, array, length,
argumentsLength) {
if (!IS_CALLABLE(callback)) {
throw %make_type_error(kCalledNonCallable, callback);
}
var i = length - 1;
find_initial: if (argumentsLength < 2) {
for (; i >= 0; i--) {
if (i in array) {
current = array[i--];
break find_initial;
}
}
throw %make_type_error(kReduceNoInitial);
}
for (; i >= 0; i--) {
if (i in array) {
var element = array[i];
current = callback(current, element, i, array);
}
}
return current;
}
// ES6 draft 07-15-13, section 22.2.3.19
function TypedArrayReduceRight(callback, current) {
ValidateTypedArray(this, "%TypedArray%.prototype.reduceRight");
var length = %_TypedArrayGetLength(this);
return InnerArrayReduceRight(callback, current, this, length,
arguments.length);
}
%FunctionSetLength(TypedArrayReduceRight, 1);
// ES6 draft 08-24-14, section 22.2.2.2
function TypedArrayOf() {
......@@ -695,16 +563,11 @@ utils.InstallGetter(GlobalTypedArray.prototype, toStringTagSymbol,
utils.InstallFunctions(GlobalTypedArray.prototype, DONT_ENUM, [
"subarray", TypedArraySubArray,
"set", TypedArraySet,
"every", TypedArrayEvery,
"filter", TypedArrayFilter,
"find", TypedArrayFind,
"findIndex", TypedArrayFindIndex,
"join", TypedArrayJoin,
"forEach", TypedArrayForEach,
"map", TypedArrayMap,
"reduce", TypedArrayReduce,
"reduceRight", TypedArrayReduceRight,
"some", TypedArraySome,
"sort", TypedArraySort,
"toLocaleString", TypedArrayToLocaleString
]);
......
......@@ -284,8 +284,8 @@ RUNTIME_FUNCTION(Runtime_IsSharedInteger32TypedArray) {
RUNTIME_FUNCTION(Runtime_TypedArraySpeciesCreateByLength) {
HandleScope scope(isolate);
DCHECK(args.length() == 2);
Handle<JSTypedArray> exemplar = args.at<JSTypedArray>(1);
Handle<Object> length = args.at(2);
Handle<JSTypedArray> exemplar = args.at<JSTypedArray>(0);
Handle<Object> length = args.at(1);
int argc = 1;
ScopedVector<Handle<Object>> argv(argc);
argv[0] = length;
......
// Copyright 2017 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: --allow-natives-syntax
var typedArrayConstructors = [
Uint8Array,
Int8Array,
Uint16Array,
Int16Array,
Uint32Array,
Int32Array,
Uint8ClampedArray,
Float32Array,
Float64Array];
function TestTypedArrayMap(constructor) {
assertEquals(1, constructor.prototype.map.length);
var target;
class EscapingArray extends constructor {
constructor(...args) {
super(...args);
target = this;
}
}
class DetachingArray extends constructor {
static get [Symbol.species]() {
return EscapingArray;
}
}
assertThrows(function(){
new DetachingArray(5).map(function(v,i,a){
print(i);
if (i == 1) {
%ArrayBufferNeuter(target.buffer);
}
})
}, TypeError);
}
for (i = 0; i < typedArrayConstructors.length; i++) {
TestTypedArrayMap(typedArrayConstructors[i]);
}
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