ccb86fc503
Bug: v8:12781 Change-Id: I19de9ab655e3e4b7ad45cde7f9bc659741d856a4 Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3858928 Reviewed-by: Anton Bikineev <bikineev@chromium.org> Commit-Queue: Feng Yu <f3n67u@gmail.com> Cr-Commit-Position: refs/heads/main@{#82786}
63 lines
2.2 KiB
C++
63 lines
2.2 KiB
C++
// Copyright 2022 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 "src/execution/isolate.h"
|
|
#include "src/heap/factory.h"
|
|
#include "src/objects/objects-inl.h"
|
|
#include "test/unittests/compiler/function-tester.h"
|
|
#include "test/unittests/test-utils.h"
|
|
|
|
namespace v8 {
|
|
namespace internal {
|
|
namespace compiler {
|
|
|
|
using RunJSObjectsTest = TestWithContext;
|
|
|
|
TEST_F(RunJSObjectsTest, ArgumentsMapped) {
|
|
FunctionTester T(i_isolate(), "(function(a) { return arguments; })");
|
|
|
|
Handle<Object> arguments =
|
|
T.Call(T.NewNumber(19), T.NewNumber(23), T.NewNumber(42), T.NewNumber(65))
|
|
.ToHandleChecked();
|
|
CHECK(arguments->IsJSObject() && !arguments->IsJSArray());
|
|
CHECK(JSObject::cast(*arguments).HasSloppyArgumentsElements());
|
|
Handle<String> l = T.isolate->factory()->length_string();
|
|
Handle<Object> length =
|
|
Object::GetProperty(T.isolate, arguments, l).ToHandleChecked();
|
|
CHECK_EQ(4, length->Number());
|
|
}
|
|
|
|
TEST_F(RunJSObjectsTest, ArgumentsUnmapped) {
|
|
FunctionTester T(i_isolate(),
|
|
"(function(a) { 'use strict'; return arguments; })");
|
|
|
|
Handle<Object> arguments =
|
|
T.Call(T.NewNumber(19), T.NewNumber(23), T.NewNumber(42), T.NewNumber(65))
|
|
.ToHandleChecked();
|
|
CHECK(arguments->IsJSObject() && !arguments->IsJSArray());
|
|
CHECK(!JSObject::cast(*arguments).HasSloppyArgumentsElements());
|
|
Handle<String> l = T.isolate->factory()->length_string();
|
|
Handle<Object> length =
|
|
Object::GetProperty(T.isolate, arguments, l).ToHandleChecked();
|
|
CHECK_EQ(4, length->Number());
|
|
}
|
|
|
|
TEST_F(RunJSObjectsTest, ArgumentsRest) {
|
|
FunctionTester T(i_isolate(), "(function(a, ...args) { return args; })");
|
|
|
|
Handle<Object> arguments =
|
|
T.Call(T.NewNumber(19), T.NewNumber(23), T.NewNumber(42), T.NewNumber(65))
|
|
.ToHandleChecked();
|
|
CHECK(arguments->IsJSObject() && arguments->IsJSArray());
|
|
CHECK(!JSObject::cast(*arguments).HasSloppyArgumentsElements());
|
|
Handle<String> l = T.isolate->factory()->length_string();
|
|
Handle<Object> length =
|
|
Object::GetProperty(T.isolate, arguments, l).ToHandleChecked();
|
|
CHECK_EQ(3, length->Number());
|
|
}
|
|
|
|
} // namespace compiler
|
|
} // namespace internal
|
|
} // namespace v8
|