Skip to content

Commit cbdb135

Browse files
camillobruniCommit bot
authored andcommitted
Adding ElementsAccessor::Concat
- Moving parts of ArrayConcat from builtins.cc to the ElementsAccessor - Removing ArrayConcat Runtime Function BUG=v8:4317 LOG=N Review URL: https://codereview.chromium.org/1330483003 Cr-Commit-Position: refs/heads/master@{#30619}
1 parent aef772b commit cbdb135

9 files changed

Lines changed: 923 additions & 860 deletions

File tree

src/array.js

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -522,24 +522,6 @@ function ArrayPush() {
522522
}
523523

524524

525-
// Returns an array containing the array elements of the object followed
526-
// by the array elements of each argument in order. See ECMA-262,
527-
// section 15.4.4.7.
528-
function ArrayConcatJS(arg1) { // length == 1
529-
CHECK_OBJECT_COERCIBLE(this, "Array.prototype.concat");
530-
531-
var array = TO_OBJECT(this);
532-
var arg_count = %_ArgumentsLength();
533-
var arrays = new InternalArray(1 + arg_count);
534-
arrays[0] = array;
535-
for (var i = 0; i < arg_count; i++) {
536-
arrays[i + 1] = %_Arguments(i);
537-
}
538-
539-
return %ArrayConcat(arrays);
540-
}
541-
542-
543525
// For implementing reverse() on large, sparse arrays.
544526
function SparseReverse(array, len) {
545527
var keys = GetSortedArrayKeys(array, %GetArrayKeys(array, len));
@@ -1642,7 +1624,6 @@ utils.InstallFunctions(GlobalArray.prototype, DONT_ENUM, [
16421624
"join", getFunction("join", ArrayJoin),
16431625
"pop", getFunction("pop", ArrayPop),
16441626
"push", getFunction("push", ArrayPush, 1),
1645-
"concat", getFunction("concat", ArrayConcatJS, 1),
16461627
"reverse", getFunction("reverse", ArrayReverse),
16471628
"shift", getFunction("shift", ArrayShift),
16481629
"unshift", getFunction("unshift", ArrayUnshift, 1),
@@ -1666,7 +1647,6 @@ utils.InstallFunctions(GlobalArray.prototype, DONT_ENUM, [
16661647
// exposed to user code.
16671648
// Adding only the functions that are actually used.
16681649
utils.SetUpLockedPrototype(InternalArray, GlobalArray(), [
1669-
"concat", getFunction("concat", ArrayConcatJS),
16701650
"indexOf", getFunction("indexOf", ArrayIndexOf),
16711651
"join", getFunction("join", ArrayJoin),
16721652
"pop", getFunction("pop", ArrayPop),
@@ -1707,7 +1687,6 @@ utils.Export(function(to) {
17071687
});
17081688

17091689
%InstallToContext([
1710-
"array_concat", ArrayConcatJS,
17111690
"array_pop", ArrayPop,
17121691
"array_push", ArrayPush,
17131692
"array_shift", ArrayShift,

src/bootstrapper.cc

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2331,6 +2331,40 @@ bool Genesis::InstallNatives(ContextType context_type) {
23312331
to_primitive->shared()->set_length(1);
23322332
}
23332333

2334+
// Install Array.prototype.concat
2335+
{
2336+
Handle<JSFunction> array_constructor(native_context()->array_function());
2337+
Handle<JSObject> proto(JSObject::cast(array_constructor->prototype()));
2338+
Handle<JSFunction> concat =
2339+
InstallFunction(proto, "concat", JS_OBJECT_TYPE, JSObject::kHeaderSize,
2340+
MaybeHandle<JSObject>(), Builtins::kArrayConcat);
2341+
2342+
// Make sure that Array.prototype.concat appears to be compiled.
2343+
// The code will never be called, but inline caching for call will
2344+
// only work if it appears to be compiled.
2345+
concat->shared()->DontAdaptArguments();
2346+
DCHECK(concat->is_compiled());
2347+
// Set the lengths for the functions to satisfy ECMA-262.
2348+
concat->shared()->set_length(1);
2349+
}
2350+
2351+
// Install InternalArray.prototype.concat
2352+
{
2353+
Handle<JSFunction> array_constructor(
2354+
native_context()->internal_array_function());
2355+
Handle<JSObject> proto(JSObject::cast(array_constructor->prototype()));
2356+
Handle<JSFunction> concat =
2357+
InstallFunction(proto, "concat", JS_OBJECT_TYPE, JSObject::kHeaderSize,
2358+
MaybeHandle<JSObject>(), Builtins::kArrayConcat);
2359+
2360+
// Make sure that InternalArray.prototype.concat appears to be compiled.
2361+
// The code will never be called, but inline caching for call will
2362+
// only work if it appears to be compiled.
2363+
concat->shared()->DontAdaptArguments();
2364+
DCHECK(concat->is_compiled());
2365+
// Set the lengths for the functions to satisfy ECMA-262.
2366+
concat->shared()->set_length(1);
2367+
}
23342368
// Install Function.prototype.call and apply.
23352369
{
23362370
Handle<String> key = factory()->Function_string();

0 commit comments

Comments
 (0)