// Copyright 2015 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. #include "test/cctest/compiler/function-tester.h" using namespace v8::internal; using namespace v8::internal::compiler; TEST(ArgumentsMapped) { FunctionTester T("(function(a) { return arguments; })"); Handle arguments; T.Call(T.Val(19), T.Val(23), T.Val(42), T.Val(65)).ToHandle(&arguments); CHECK(arguments->IsJSObject() && !arguments->IsJSArray()); CHECK(JSObject::cast(*arguments)->HasSloppyArgumentsElements()); Handle l = T.isolate->factory()->length_string(); Handle length = JSObject::GetProperty(arguments, l).ToHandleChecked(); CHECK_EQ(4, length->Number()); } TEST(ArgumentsUnmapped) { FunctionTester T("(function(a) { 'use strict'; return arguments; })"); Handle arguments; T.Call(T.Val(19), T.Val(23), T.Val(42), T.Val(65)).ToHandle(&arguments); CHECK(arguments->IsJSObject() && !arguments->IsJSArray()); CHECK(!JSObject::cast(*arguments)->HasSloppyArgumentsElements()); Handle l = T.isolate->factory()->length_string(); Handle length = JSObject::GetProperty(arguments, l).ToHandleChecked(); CHECK_EQ(4, length->Number()); } TEST(ArgumentsRest) { FLAG_harmony_rest_parameters = true; FunctionTester T("(function(a, ...args) { return args; })"); Handle arguments; T.Call(T.Val(19), T.Val(23), T.Val(42), T.Val(65)).ToHandle(&arguments); CHECK(arguments->IsJSObject() && arguments->IsJSArray()); CHECK(!JSObject::cast(*arguments)->HasSloppyArgumentsElements()); Handle l = T.isolate->factory()->length_string(); Handle length = JSObject::GetProperty(arguments, l).ToHandleChecked(); CHECK_EQ(3, length->Number()); }