Add fast-path check to ecma_builtin_array_prototype_slice (#3480)

Fixes #3459

JerryScript-DCO-1.0-Signed-off-by: Peter Marki marpeter@inf.u-szeged.hu
This commit is contained in:
Peter Marki
2020-01-06 10:30:10 +01:00
committed by Robert Fancsik
parent dc15944ebd
commit 300570381f
2 changed files with 24 additions and 1 deletions
@@ -827,6 +827,7 @@ ecma_builtin_array_prototype_object_slice (ecma_value_t arg1, /**< start */
JERRY_ASSERT (start <= len && end <= len);
bool use_fast_path = ecma_op_object_is_fast_array (obj_p);
#if ENABLED (JERRY_ES2015)
ecma_value_t new_array = ecma_op_array_species_create (obj_p, 0);
@@ -834,6 +835,7 @@ ecma_builtin_array_prototype_object_slice (ecma_value_t arg1, /**< start */
{
return new_array;
}
use_fast_path &= ecma_op_object_is_fast_array (ecma_get_object_from_value (new_array));
#else /* !ENABLED (JERRY_ES2015) */
ecma_value_t new_array = ecma_op_create_array_object (NULL, 0, false);
JERRY_ASSERT (!ECMA_IS_VALUE_ERROR (new_array));
@@ -844,7 +846,7 @@ ecma_builtin_array_prototype_object_slice (ecma_value_t arg1, /**< start */
/* 9. */
uint32_t n = 0;
if (ecma_op_object_is_fast_array (obj_p))
if (use_fast_path)
{
ecma_extended_object_t *ext_from_obj_p = (ecma_extended_object_t *) obj_p;
@@ -0,0 +1,21 @@
// Copyright JS Foundation and other contributors, http://js.foundation
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
class MyOtherArray {}
class MyNonArray extends Array {
static [Symbol.species] () {}
}
(() => MyNonArray)().prototype.slice.call(new MyNonArray((0) === 1))