Commit c0282f60 authored by cbruni's avatar cbruni Committed by Commit bot

Add unittests to keep InstanceType lists in sync

STRUCT_LIST and INSTANCE_TYPE_LIST are now forced to have the same order
as the InstanceType enum.

Drive-by-fix 1: Move type check and cast functions closer together in objects-inl.h

Drive-by-fix 2: Remove unused instance types SIGNATURE_INFO_TYPE and  TYPE_SWITCH_INFO_TYPE.

BUG=

Review-Url: https://codereview.chromium.org/2578573002
Cr-Commit-Position: refs/heads/master@{#41804}
parent 99a5aa1b
...@@ -8380,8 +8380,8 @@ class Internals { ...@@ -8380,8 +8380,8 @@ class Internals {
static const int kNodeIsIndependentShift = 3; static const int kNodeIsIndependentShift = 3;
static const int kNodeIsActiveShift = 4; static const int kNodeIsActiveShift = 4;
static const int kJSObjectType = 0xbe; static const int kJSApiObjectType = 0xbb;
static const int kJSApiObjectType = 0xbd; static const int kJSObjectType = 0xbc;
static const int kFirstNonstringType = 0x80; static const int kFirstNonstringType = 0x80;
static const int kOddballType = 0x83; static const int kOddballType = 0x83;
static const int kForeignType = 0x87; static const int kForeignType = 0x87;
......
...@@ -303,8 +303,6 @@ AstType::bitset AstBitsetType::Lub(i::Map* map) { ...@@ -303,8 +303,6 @@ AstType::bitset AstBitsetType::Lub(i::Map* map) {
case PROMISE_REACTION_JOB_INFO_TYPE: case PROMISE_REACTION_JOB_INFO_TYPE:
case FUNCTION_TEMPLATE_INFO_TYPE: case FUNCTION_TEMPLATE_INFO_TYPE:
case OBJECT_TEMPLATE_INFO_TYPE: case OBJECT_TEMPLATE_INFO_TYPE:
case SIGNATURE_INFO_TYPE:
case TYPE_SWITCH_INFO_TYPE:
case ALLOCATION_MEMENTO_TYPE: case ALLOCATION_MEMENTO_TYPE:
case TYPE_FEEDBACK_INFO_TYPE: case TYPE_FEEDBACK_INFO_TYPE:
case ALIASED_ARGUMENTS_ENTRY_TYPE: case ALIASED_ARGUMENTS_ENTRY_TYPE:
......
...@@ -310,8 +310,6 @@ Type::bitset BitsetType::Lub(i::Map* map) { ...@@ -310,8 +310,6 @@ Type::bitset BitsetType::Lub(i::Map* map) {
case INTERCEPTOR_INFO_TYPE: case INTERCEPTOR_INFO_TYPE:
case CALL_HANDLER_INFO_TYPE: case CALL_HANDLER_INFO_TYPE:
case OBJECT_TEMPLATE_INFO_TYPE: case OBJECT_TEMPLATE_INFO_TYPE:
case SIGNATURE_INFO_TYPE:
case TYPE_SWITCH_INFO_TYPE:
case ALLOCATION_MEMENTO_TYPE: case ALLOCATION_MEMENTO_TYPE:
case TYPE_FEEDBACK_INFO_TYPE: case TYPE_FEEDBACK_INFO_TYPE:
case ALIASED_ARGUMENTS_ENTRY_TYPE: case ALIASED_ARGUMENTS_ENTRY_TYPE:
......
This diff is collapsed.
This diff is collapsed.
...@@ -120,6 +120,7 @@ v8_executable("unittests") { ...@@ -120,6 +120,7 @@ v8_executable("unittests") {
"libplatform/task-queue-unittest.cc", "libplatform/task-queue-unittest.cc",
"libplatform/worker-thread-unittest.cc", "libplatform/worker-thread-unittest.cc",
"locked-queue-unittest.cc", "locked-queue-unittest.cc",
"object-unittest.cc",
"register-configuration-unittest.cc", "register-configuration-unittest.cc",
"run-all-unittests.cc", "run-all-unittests.cc",
"source-position-table-unittest.cc", "source-position-table-unittest.cc",
......
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
// found in the LICENSE file. // found in the LICENSE file.
#include <cmath> #include <cmath>
#include <iostream>
#include <limits> #include <limits>
#include "src/objects.h" #include "src/objects.h"
......
// Copyright 2016 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 <cmath>
#include <iostream>
#include <limits>
#include "src/objects-inl.h"
#include "src/objects.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace v8 {
namespace internal {
TEST(Object, InstanceTypeListOrder) {
int current = 0;
int last = -1;
InstanceType current_type = static_cast<InstanceType>(current);
EXPECT_EQ(current_type, InstanceType::FIRST_TYPE);
EXPECT_EQ(current_type, InstanceType::INTERNALIZED_STRING_TYPE);
#define TEST_INSTANCE_TYPE(type) \
current_type = InstanceType::type; \
current = static_cast<int>(current_type); \
if (current > static_cast<int>(LAST_NAME_TYPE)) { \
EXPECT_EQ(last + 1, current); \
} \
EXPECT_LT(last, current) << " INSTANCE_TYPE_LIST is not ordered: " \
<< "last = " << static_cast<InstanceType>(last) \
<< " vs. current = " << current_type; \
last = current;
INSTANCE_TYPE_LIST(TEST_INSTANCE_TYPE)
#undef TEST_INSTANCE_TYPE
}
TEST(Object, StructListOrder) {
int current = static_cast<int>(InstanceType::ACCESSOR_INFO_TYPE);
int last = current - 1;
ASSERT_LT(0, last);
InstanceType current_type = static_cast<InstanceType>(current);
#define TEST_STRUCT(type, class, name) \
current_type = InstanceType::type##_TYPE; \
current = static_cast<int>(current_type); \
EXPECT_EQ(last + 1, current) \
<< " STRUCT_LIST is not ordered: " \
<< " last = " << static_cast<InstanceType>(last) \
<< " vs. current = " << current_type; \
last = current;
STRUCT_LIST(TEST_STRUCT)
#undef TEST_STRUCT
}
} // namespace internal
} // namespace v8
...@@ -118,6 +118,7 @@ ...@@ -118,6 +118,7 @@
'heap/scavenge-job-unittest.cc', 'heap/scavenge-job-unittest.cc',
'heap/slot-set-unittest.cc', 'heap/slot-set-unittest.cc',
'locked-queue-unittest.cc', 'locked-queue-unittest.cc',
'object-unittest.cc',
'register-configuration-unittest.cc', 'register-configuration-unittest.cc',
'run-all-unittests.cc', 'run-all-unittests.cc',
'source-position-table-unittest.cc', 'source-position-table-unittest.cc',
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment