summaryrefslogtreecommitdiff
path: root/deps/v8/test/cctest/compiler/test-run-jsobjects.cc
blob: 338e0e27d3e1bb763743602e5e5f3535e48bf06c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
// 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 "src/factory.h"
#include "src/isolate.h"
#include "src/objects.h"
// FIXME(mstarzinger, marja): This is weird, but required because of the missing
// (disallowed) include: src/factory.h -> src/objects-inl.h
#include "src/objects-inl.h"
// FIXME(mstarzinger, marja): This is weird, but required because of the missing
// (disallowed) include: src/type-feedback-vector.h ->
// src/type-feedback-vector-inl.h
#include "src/type-feedback-vector-inl.h"
#include "test/cctest/compiler/function-tester.h"

namespace v8 {
namespace internal {
namespace compiler {

TEST(ArgumentsMapped) {
  FunctionTester T("(function(a) { return arguments; })");

  Handle<Object> 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<String> l = T.isolate->factory()->length_string();
  Handle<Object> length = Object::GetProperty(arguments, l).ToHandleChecked();
  CHECK_EQ(4, length->Number());
}


TEST(ArgumentsUnmapped) {
  FunctionTester T("(function(a) { 'use strict'; return arguments; })");

  Handle<Object> 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<String> l = T.isolate->factory()->length_string();
  Handle<Object> length = Object::GetProperty(arguments, l).ToHandleChecked();
  CHECK_EQ(4, length->Number());
}


TEST(ArgumentsRest) {
  FunctionTester T("(function(a, ...args) { return args; })");

  Handle<Object> 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<String> l = T.isolate->factory()->length_string();
  Handle<Object> length = Object::GetProperty(arguments, l).ToHandleChecked();
  CHECK_EQ(3, length->Number());
}

}  // namespace compiler
}  // namespace internal
}  // namespace v8