diff options
Diffstat (limited to 'deps/v8/src/roots-inl.h')
-rw-r--r-- | deps/v8/src/roots-inl.h | 42 |
1 files changed, 29 insertions, 13 deletions
diff --git a/deps/v8/src/roots-inl.h b/deps/v8/src/roots-inl.h index 0eadb79555..cae3d37a39 100644 --- a/deps/v8/src/roots-inl.h +++ b/deps/v8/src/roots-inl.h @@ -9,13 +9,18 @@ #include "src/feedback-vector.h" #include "src/handles.h" -#include "src/heap/heap-inl.h" +#include "src/isolate.h" #include "src/objects/api-callbacks.h" #include "src/objects/descriptor-array.h" +#include "src/objects/heap-number.h" #include "src/objects/literal-objects.h" #include "src/objects/map.h" +#include "src/objects/oddball.h" +#include "src/objects/property-array.h" +#include "src/objects/property-cell.h" #include "src/objects/scope-info.h" #include "src/objects/slots.h" +#include "src/objects/string.h" namespace v8 { namespace internal { @@ -52,17 +57,24 @@ bool RootsTable::IsRootHandle(Handle<T> handle, RootIndex* index) const { } ReadOnlyRoots::ReadOnlyRoots(Heap* heap) - : roots_table_(heap->isolate()->roots_table()) {} + : roots_table_(Isolate::FromHeap(heap)->roots_table()) {} ReadOnlyRoots::ReadOnlyRoots(Isolate* isolate) : roots_table_(isolate->roots_table()) {} -#define ROOT_ACCESSOR(Type, name, CamelName) \ - Type ReadOnlyRoots::name() const { \ - return Type::cast(Object(roots_table_[RootIndex::k##CamelName])); \ - } \ - Handle<Type> ReadOnlyRoots::name##_handle() const { \ - return Handle<Type>(&roots_table_[RootIndex::k##CamelName]); \ +// We use unchecked_cast below because we trust our read-only roots to +// have the right type, and to avoid the heavy #includes that would be +// required for checked casts. + +#define ROOT_ACCESSOR(Type, name, CamelName) \ + Type ReadOnlyRoots::name() const { \ + DCHECK(CheckType(RootIndex::k##CamelName)); \ + return Type::unchecked_cast( \ + Object(roots_table_[RootIndex::k##CamelName])); \ + } \ + Handle<Type> ReadOnlyRoots::name##_handle() const { \ + DCHECK(CheckType(RootIndex::k##CamelName)); \ + return Handle<Type>(&roots_table_[RootIndex::k##CamelName]); \ } READ_ONLY_ROOT_LIST(ROOT_ACCESSOR) @@ -70,18 +82,22 @@ READ_ONLY_ROOT_LIST(ROOT_ACCESSOR) Map ReadOnlyRoots::MapForFixedTypedArray(ExternalArrayType array_type) { RootIndex root_index = RootsTable::RootIndexForFixedTypedArray(array_type); - return Map::cast(Object(roots_table_[root_index])); + DCHECK(CheckType(root_index)); + return Map::unchecked_cast(Object(roots_table_[root_index])); } Map ReadOnlyRoots::MapForFixedTypedArray(ElementsKind elements_kind) { RootIndex root_index = RootsTable::RootIndexForFixedTypedArray(elements_kind); - return Map::cast(Object(roots_table_[root_index])); + DCHECK(CheckType(root_index)); + return Map::unchecked_cast(Object(roots_table_[root_index])); } -FixedTypedArrayBase ReadOnlyRoots::EmptyFixedTypedArrayForMap(const Map map) { +FixedTypedArrayBase ReadOnlyRoots::EmptyFixedTypedArrayForTypedArray( + ElementsKind elements_kind) { RootIndex root_index = - RootsTable::RootIndexForEmptyFixedTypedArray(map->elements_kind()); - return FixedTypedArrayBase::cast(Object(roots_table_[root_index])); + RootsTable::RootIndexForEmptyFixedTypedArray(elements_kind); + DCHECK(CheckType(root_index)); + return FixedTypedArrayBase::unchecked_cast(Object(roots_table_[root_index])); } } // namespace internal |