v8/test/unittests/parser/ast-value-unittest.cc
Adam Klein 317cf32131 [ast] Move AstValue implementation into Literal
This eliminates the AstValue class, effectively moving its
implementation into the Literal AstNode. This should cause
no difference in behavior, but it does signal some shifts
in the underlying system. Biggest changes include:

  - Reduction in AST memory usage
  - No duplicate HeapNumbers in Ignition constant pools
  - Non-String values are allocated either at constant pool
    creation time (or at boilerplate creation time for literals),
    rather than at AstValueFactory::Internalize() time.

There are a variety of test-only/debug-only changes due to these
switches as well.

Bug: v8:6984
Change-Id: I5f178040ce2796d4e7370c24d1063419e1c843a1
Reviewed-on: https://chromium-review.googlesource.com/731111
Commit-Queue: Adam Klein <adamk@chromium.org>
Reviewed-by: Ross McIlroy <rmcilroy@chromium.org>
Reviewed-by: Marja Hölttä <marja@chromium.org>
Cr-Commit-Position: refs/heads/master@{#49013}
2017-10-27 20:21:29 +00:00

52 lines
1.8 KiB
C++

// Copyright 2017 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/ast/ast-value-factory.h"
#include "src/ast/ast.h"
#include "src/heap/heap-inl.h"
#include "src/isolate-inl.h"
#include "src/zone/zone.h"
#include "test/unittests/test-utils.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace v8 {
namespace internal {
class AstValueTest : public TestWithIsolateAndZone {
protected:
AstValueTest()
: ast_value_factory_(zone(), i_isolate()->ast_string_constants(),
i_isolate()->heap()->HashSeed()),
ast_node_factory_(&ast_value_factory_, zone()) {}
Literal* NewBigInt(const char* str) {
return ast_node_factory_.NewBigIntLiteral(AstBigInt(str),
kNoSourcePosition);
}
AstValueFactory ast_value_factory_;
AstNodeFactory ast_node_factory_;
};
TEST_F(AstValueTest, BigIntToBooleanIsTrue) {
EXPECT_FALSE(NewBigInt("0")->ToBooleanIsTrue());
EXPECT_FALSE(NewBigInt("0b0")->ToBooleanIsTrue());
EXPECT_FALSE(NewBigInt("0o0")->ToBooleanIsTrue());
EXPECT_FALSE(NewBigInt("0x0")->ToBooleanIsTrue());
EXPECT_FALSE(NewBigInt("0b000")->ToBooleanIsTrue());
EXPECT_FALSE(NewBigInt("0o00000")->ToBooleanIsTrue());
EXPECT_FALSE(NewBigInt("0x000000000")->ToBooleanIsTrue());
EXPECT_TRUE(NewBigInt("3")->ToBooleanIsTrue());
EXPECT_TRUE(NewBigInt("0b1")->ToBooleanIsTrue());
EXPECT_TRUE(NewBigInt("0o6")->ToBooleanIsTrue());
EXPECT_TRUE(NewBigInt("0xa")->ToBooleanIsTrue());
EXPECT_TRUE(NewBigInt("0b0000001")->ToBooleanIsTrue());
EXPECT_TRUE(NewBigInt("0o00005000")->ToBooleanIsTrue());
EXPECT_TRUE(NewBigInt("0x0000d00c0")->ToBooleanIsTrue());
}
} // namespace internal
} // namespace v8