2015-09-15 09:07:21 +00:00
|
|
|
// 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.
|
|
|
|
|
2019-05-22 07:55:37 +00:00
|
|
|
#include "src/execution/isolate.h"
|
2018-04-09 19:11:22 +00:00
|
|
|
#include "src/heap/factory.h"
|
2019-05-23 08:51:46 +00:00
|
|
|
#include "src/objects/objects-inl.h"
|
2015-09-15 09:07:21 +00:00
|
|
|
#include "test/cctest/compiler/function-tester.h"
|
|
|
|
|
2015-10-30 09:16:26 +00:00
|
|
|
namespace v8 {
|
|
|
|
namespace internal {
|
|
|
|
namespace compiler {
|
2015-09-15 09:07:21 +00:00
|
|
|
|
|
|
|
TEST(ArgumentsMapped) {
|
|
|
|
FunctionTester T("(function(a) { return arguments; })");
|
|
|
|
|
2020-03-03 17:02:42 +00:00
|
|
|
Handle<Object> arguments =
|
|
|
|
T.Call(T.Val(19), T.Val(23), T.Val(42), T.Val(65)).ToHandleChecked();
|
2015-09-15 09:07:21 +00:00
|
|
|
CHECK(arguments->IsJSObject() && !arguments->IsJSArray());
|
|
|
|
CHECK(JSObject::cast(*arguments).HasSloppyArgumentsElements());
|
|
|
|
Handle<String> l = T.isolate->factory()->length_string();
|
2018-07-17 08:49:20 +00:00
|
|
|
Handle<Object> length =
|
|
|
|
Object::GetProperty(T.isolate, arguments, l).ToHandleChecked();
|
2015-09-15 09:07:21 +00:00
|
|
|
CHECK_EQ(4, length->Number());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TEST(ArgumentsUnmapped) {
|
|
|
|
FunctionTester T("(function(a) { 'use strict'; return arguments; })");
|
|
|
|
|
2020-03-03 17:02:42 +00:00
|
|
|
Handle<Object> arguments =
|
|
|
|
T.Call(T.Val(19), T.Val(23), T.Val(42), T.Val(65)).ToHandleChecked();
|
2015-09-15 09:07:21 +00:00
|
|
|
CHECK(arguments->IsJSObject() && !arguments->IsJSArray());
|
|
|
|
CHECK(!JSObject::cast(*arguments).HasSloppyArgumentsElements());
|
|
|
|
Handle<String> l = T.isolate->factory()->length_string();
|
2018-07-17 08:49:20 +00:00
|
|
|
Handle<Object> length =
|
|
|
|
Object::GetProperty(T.isolate, arguments, l).ToHandleChecked();
|
2015-09-15 09:07:21 +00:00
|
|
|
CHECK_EQ(4, length->Number());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TEST(ArgumentsRest) {
|
|
|
|
FunctionTester T("(function(a, ...args) { return args; })");
|
|
|
|
|
2020-03-03 17:02:42 +00:00
|
|
|
Handle<Object> arguments =
|
|
|
|
T.Call(T.Val(19), T.Val(23), T.Val(42), T.Val(65)).ToHandleChecked();
|
2015-09-15 09:07:21 +00:00
|
|
|
CHECK(arguments->IsJSObject() && arguments->IsJSArray());
|
|
|
|
CHECK(!JSObject::cast(*arguments).HasSloppyArgumentsElements());
|
|
|
|
Handle<String> l = T.isolate->factory()->length_string();
|
2018-07-17 08:49:20 +00:00
|
|
|
Handle<Object> length =
|
|
|
|
Object::GetProperty(T.isolate, arguments, l).ToHandleChecked();
|
2015-09-15 09:07:21 +00:00
|
|
|
CHECK_EQ(3, length->Number());
|
|
|
|
}
|
2015-10-30 09:16:26 +00:00
|
|
|
|
|
|
|
} // namespace compiler
|
|
|
|
} // namespace internal
|
|
|
|
} // namespace v8
|