Commit 49a4f2d1 authored by verwaest's avatar verwaest Committed by Commit bot

Turn Array.isArray into a Turbofan stub

The current stub supports everything except JSProxy

BUG=

Review-Url: https://codereview.chromium.org/1924233002
Cr-Commit-Position: refs/heads/master@{#35891}
parent f1a0f054
......@@ -351,6 +351,39 @@ BUILTIN(Illegal) {
BUILTIN(EmptyFunction) { return isolate->heap()->undefined_value(); }
void Builtins::Generate_ArrayIsArray(CodeStubAssembler* assembler) {
typedef compiler::Node Node;
typedef CodeStubAssembler::Label Label;
Node* object = assembler->Parameter(1);
Node* context = assembler->Parameter(4);
Label call_runtime(assembler), return_true(assembler),
return_false(assembler);
assembler->GotoIf(assembler->WordIsSmi(object), &return_false);
Node* instance_type = assembler->LoadInstanceType(object);
assembler->GotoIf(assembler->Word32Equal(
instance_type, assembler->Int32Constant(JS_ARRAY_TYPE)),
&return_true);
// TODO(verwaest): Handle proxies in-place.
assembler->Branch(assembler->Word32Equal(
instance_type, assembler->Int32Constant(JS_PROXY_TYPE)),
&call_runtime, &return_false);
assembler->Bind(&return_true);
assembler->Return(assembler->BooleanConstant(true));
assembler->Bind(&return_false);
assembler->Return(assembler->BooleanConstant(false));
assembler->Bind(&call_runtime);
assembler->Return(
assembler->CallRuntime(Runtime::kArrayIsArray, context, object));
}
void Builtins::Generate_ObjectHasOwnProperty(CodeStubAssembler* assembler) {
typedef compiler::Node Node;
typedef CodeStubAssembler::Label Label;
......@@ -1609,16 +1642,6 @@ BUILTIN(ArrayConcat) {
}
// ES6 22.1.2.2 Array.isArray
BUILTIN(ArrayIsArray) {
HandleScope scope(isolate);
DCHECK_EQ(2, args.length());
Handle<Object> object = args.at<Object>(1);
Maybe<bool> result = Object::IsArray(object);
MAYBE_RETURN(result, isolate->heap()->exception());
return *isolate->factory()->ToBoolean(result.FromJust());
}
namespace {
MUST_USE_RESULT Maybe<bool> FastAssign(Handle<JSReceiver> to,
......
......@@ -60,7 +60,6 @@ inline bool operator&(BuiltinExtraArguments lhs, BuiltinExtraArguments rhs) {
V(EmptyFunction, kNone) \
\
V(ArrayConcat, kNone) \
V(ArrayIsArray, kNone) \
V(ArrayPop, kNone) \
V(ArrayPush, kNone) \
V(ArrayShift, kNone) \
......@@ -313,6 +312,7 @@ inline bool operator&(BuiltinExtraArguments lhs, BuiltinExtraArguments rhs) {
V(MathSqrt, 2) \
V(MathTrunc, 2) \
V(ObjectHasOwnProperty, 2) \
V(ArrayIsArray, 2) \
V(StringPrototypeCharAt, 2) \
V(StringPrototypeCharCodeAt, 2) \
V(AtomicsLoad, 3)
......@@ -628,6 +628,9 @@ class Builtins {
// ES6 section 19.1.3.2 Object.prototype.hasOwnProperty
static void Generate_ObjectHasOwnProperty(CodeStubAssembler* assembler);
// ES6 section 22.1.2.2 Array.isArray
static void Generate_ArrayIsArray(CodeStubAssembler* assembler);
// ES6 section 21.1.3.1 String.prototype.charAt ( pos )
static void Generate_StringPrototypeCharAt(CodeStubAssembler* assembler);
// ES6 section 21.1.3.2 String.prototype.charCodeAt ( pos )
......
......@@ -455,6 +455,15 @@ RUNTIME_FUNCTION(Runtime_HasComplexElements) {
return isolate->heap()->false_value();
}
// ES6 22.1.2.2 Array.isArray
RUNTIME_FUNCTION(Runtime_ArrayIsArray) {
HandleScope shs(isolate);
DCHECK(args.length() == 1);
CONVERT_ARG_HANDLE_CHECKED(Object, object, 0);
Maybe<bool> result = Object::IsArray(object);
MAYBE_RETURN(result, isolate->heap()->exception());
return isolate->heap()->ToBoolean(result.FromJust());
}
RUNTIME_FUNCTION(Runtime_IsArray) {
SealHandleScope shs(isolate);
......@@ -463,7 +472,6 @@ RUNTIME_FUNCTION(Runtime_IsArray) {
return isolate->heap()->ToBoolean(obj->IsJSArray());
}
RUNTIME_FUNCTION(Runtime_HasCachedArrayIndex) {
SealHandleScope shs(isolate);
DCHECK(args.length() == 1);
......
......@@ -47,6 +47,7 @@ namespace internal {
F(GrowArrayElements, 2, 1) \
F(HasComplexElements, 1, 1) \
F(IsArray, 1, 1) \
F(ArrayIsArray, 1, 1) \
F(HasCachedArrayIndex, 1, 1) \
F(GetCachedArrayIndex, 1, 1) \
F(FixedArrayGet, 2, 1) \
......
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