Commit 1e03479c authored by mvstanton's avatar mvstanton Committed by Commit bot

[builtins] Array.prototype.filter implemented as a TurboFan code stub.

BUG=

Review-Url: https://codereview.chromium.org/2680153005
Cr-Commit-Position: refs/heads/master@{#43965}
parent ed93e7c2
......@@ -3678,6 +3678,7 @@ void Genesis::InitializeGlobal_enable_fast_array_builtins() {
factory->NewStringFromAsciiChecked("prototype"),
LookupIterator::OWN_SKIP_INTERCEPTOR);
Handle<Object> array_prototype = Object::GetProperty(&it2).ToHandleChecked();
LookupIterator it3(array_prototype,
factory->NewStringFromAsciiChecked("forEach"),
LookupIterator::OWN_SKIP_INTERCEPTOR);
......@@ -3708,6 +3709,19 @@ void Genesis::InitializeGlobal_enable_fast_array_builtins() {
Handle<JSFunction>::cast(some_function)
->shared()
->set_code(isolate->builtins()->builtin(Builtins::kArraySome));
if (FLAG_experimental_array_builtins) {
LookupIterator it6(array_prototype,
factory->NewStringFromAsciiChecked("filter"),
LookupIterator::OWN_SKIP_INTERCEPTOR);
Handle<Object> filter_function =
Object::GetProperty(&it6).ToHandleChecked();
Handle<JSFunction>::cast(filter_function)
->set_code(isolate->builtins()->builtin(Builtins::kArrayFilter));
Handle<JSFunction>::cast(filter_function)
->shared()
->set_code(isolate->builtins()->builtin(Builtins::kArrayFilter));
}
}
void Genesis::InitializeGlobal_harmony_sharedarraybuffer() {
......
This diff is collapsed.
......@@ -293,6 +293,9 @@ class Isolate;
/* ES6 #sec-array.prototype.some */ \
TFJ(ArraySomeLoopContinuation, 6) \
TFJ(ArraySome, 2, kCallbackFn, kThisArg) \
/* ES6 #sec-array.prototype.filter */ \
TFJ(ArrayFilterLoopContinuation, 6) \
TFJ(ArrayFilter, 2, kCallbackFn, kThisArg) \
/* ES6 #sec-array.prototype.entries */ \
TFJ(ArrayPrototypeEntries, 0) \
/* ES6 #sec-array.prototype.keys */ \
......
......@@ -488,6 +488,12 @@ Callable CodeFactory::ArrayPush(Isolate* isolate) {
return Callable(isolate->builtins()->ArrayPush(), BuiltinDescriptor(isolate));
}
// static
Callable CodeFactory::ArrayFilterLoopContinuation(Isolate* isolate) {
return Callable(isolate->builtins()->ArrayFilterLoopContinuation(),
IteratingArrayBuiltinLoopContinuationDescriptor(isolate));
}
// static
Callable CodeFactory::ArrayForEachLoopContinuation(Isolate* isolate) {
return Callable(isolate->builtins()->ArrayForEachLoopContinuation(),
......
......@@ -181,6 +181,7 @@ class V8_EXPORT_PRIVATE CodeFactory final {
static Callable ArrayConstructor(Isolate* isolate);
static Callable ArrayPush(Isolate* isolate);
static Callable ArrayFilterLoopContinuation(Isolate* isolate);
static Callable ArrayForEachLoopContinuation(Isolate* isolate);
static Callable ArraySomeLoopContinuation(Isolate* isolate);
static Callable ArrayEveryLoopContinuation(Isolate* isolate);
......
......@@ -8080,6 +8080,16 @@ Node* CodeStubAssembler::AllocateJSArrayIterator(Node* array, Node* array_map,
return iterator;
}
Node* CodeStubAssembler::ArraySpeciesCreate(Node* context, Node* originalArray,
Node* len) {
// TODO(mvstanton): Install a fast path as well, which avoids the runtime
// call.
Node* constructor =
CallRuntime(Runtime::kArraySpeciesConstructor, context, originalArray);
return ConstructJS(CodeFactory::Construct(isolate()), context, constructor,
len);
}
Node* CodeStubAssembler::IsDetachedBuffer(Node* buffer) {
CSA_ASSERT(this, HasInstanceType(buffer, JS_ARRAY_BUFFER_TYPE));
......
......@@ -586,6 +586,9 @@ class V8_EXPORT_PRIVATE CodeStubAssembler : public compiler::CodeAssembler {
Node* AllocateJSArrayIterator(Node* array, Node* array_map, Node* map);
// Perform ArraySpeciesCreate (ES6 #sec-arrayspeciescreate).
Node* ArraySpeciesCreate(Node* context, Node* originalArray, Node* len);
void FillFixedArrayWithValue(ElementsKind kind, Node* array, Node* from_index,
Node* to_index,
Heap::RootListIndex value_root_index,
......
......@@ -770,6 +770,8 @@ DEFINE_BOOL(builtins_in_stack_traces, false,
// builtins.cc
DEFINE_BOOL(enable_fast_array_builtins, false, "use optimized builtins")
DEFINE_BOOL(experimental_array_builtins, false,
"Experimental versions of array builtins")
DEFINE_BOOL(allow_unsafe_function_constructor, false,
"allow invoking the function constructor without security checks")
......
// 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.
new BenchmarkSuite('Filter', [1000], [
new Benchmark('SmiFilter', false, false, 0,
Filter, SmiFilterSetup, ()=>{}),
new Benchmark('DoubleFilter', false, false, 0,
Filter, DoubleFilterSetup, ()=>{}),
new Benchmark('FastFilter', false, false, 0,
Filter, FastFilterSetup, ()=>{}),
new Benchmark('HoleySmiFilter', false, false, 0,
Filter, HoleySmiFilterSetup, ()=>{}),
new Benchmark('HoleyDoubleFilter', false, false, 0,
Filter, HoleyDoubleFilterSetup, ()=>{}),
new Benchmark('HoleyFastFilter', false, false, 0,
Filter, HoleyFastFilterSetup, ()=>{}),
new Benchmark('ObjectFilter', false, false, 0,
GenericFilter, ObjectFilterSetup, ()=>{}),
]);
var array;
var func;
var this_arg;
var result;
var array_size = 100;
function Filter() {
result = array.filter(func, this_arg);
}
function GenericFilter() {
result = Array.prototype.filter.call(array, func, this_arg);
}
function SmiFilterSetup() {
array = new Array();
for (var i = 0; i < array_size; i++) array[i] = i;
func = (value, index, object) => { return value % 2 === 0; };
}
function HoleySmiFilterSetup() {
array = new Array(array_size);
for (var i = 0; i < array_size; i++) {
if (i % 2 === 0) array[i] = i;
}
func = (value, index, object) => { return value % 2 === 0; };
}
function DoubleFilterSetup() {
array = new Array();
for (var i = 0; i < array_size; i++) array[i] = (i + 0.5);
func = (value, index, object) => { return Math.floor(value) % 2 === 0; };
}
function HoleyDoubleFilterSetup() {
array = new Array(array_size);
for (var i = 0; i < array_size; i++) {
if (i != 3) {
array[i] = (i + 0.5);
}
}
func = (value, index, object) => { return Math.floor(value) % 2 === 0; };
}
function FastFilterSetup() {
array = new Array();
for (var i = 0; i < array_size; i++) array[i] = 'value ' + i;
func = (value, index, object) => { return index % 2 === 0; };
}
function HoleyFastFilterSetup() {
array = new Array(array_size);
for (var i = 0; i < array_size; i++) {
if (i % 2 != 0) {
array[i] = 'value ' + i;
}
}
func = (value, index, object) => { return index % 2 === 0; };
}
function ObjectFilterSetup() {
array = { length: array_size };
for (var i = 0; i < array_size; i++) {
array[i] = i;
}
func = (value, index, object) => { return index % 2 === 0; };
}
// Copyright 2014 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.
load('../base.js');
load('filter.js');
var success = true;
function PrintResult(name, result) {
print(name + '-Array(Score): ' + result);
}
function PrintStep(name) {
print('Completed ' + name + '-Array...');
}
function PrintError(name, error) {
PrintResult(name, error);
success = false;
}
BenchmarkSuite.config.doWarmup = undefined;
BenchmarkSuite.config.doDeterministic = undefined;
BenchmarkSuite.RunSuites({ NotifyResult: PrintResult,
NotifyError: PrintError,
NotifyStep: PrintStep });
......@@ -327,6 +327,18 @@
"test_flags": ["sort"]
}
]
},
{
"name": "Arrays",
"path": ["Arrays"],
"main": "run.js",
"resources": [
"filter.js"
],
"results_regexp": "^Arrays\\-%s\\(Scope\\): (.+)$",
"tests": [
{"name": "Filter"}
]
}
]
}
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