[protectors] Migrate TypedSpeciesArrayLookupChain protector

Migrates TypedSpeciesArrayLookupChain protector to the protectors
static class.

Bug: v8:9463
Change-Id: I6941f664557b463aecd0b57035b2fb741cdfe14d
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1783846
Reviewed-by: Jakob Gruber <jgruber@chromium.org>
Commit-Queue: Joshua Litt <joshualitt@chromium.org>
Cr-Commit-Position: refs/heads/master@{#63611}
This commit is contained in:
Joshua Litt 2019-09-04 07:39:19 -07:00 committed by Commit Bot
parent 098189473a
commit d61dcb846c
6 changed files with 16 additions and 33 deletions

View File

@ -119,13 +119,6 @@ bool Isolate::IsArrayConstructorIntact() {
return array_constructor_cell.value() == Smi::FromInt(kProtectorValid);
}
bool Isolate::IsTypedArraySpeciesLookupChainIntact() {
PropertyCell species_cell =
PropertyCell::cast(root(RootIndex::kTypedArraySpeciesProtector));
return species_cell.value().IsSmi() &&
Smi::ToInt(species_cell.value()) == kProtectorValid;
}
bool Isolate::IsPromiseSpeciesLookupChainIntact() {
PropertyCell species_cell =
PropertyCell::cast(root(RootIndex::kPromiseSpeciesProtector));

View File

@ -3999,16 +3999,6 @@ void Isolate::InvalidateArrayConstructorProtector() {
DCHECK(!IsArrayConstructorIntact());
}
void Isolate::InvalidateTypedArraySpeciesProtector() {
DCHECK(factory()->typed_array_species_protector()->value().IsSmi());
DCHECK(IsTypedArraySpeciesLookupChainIntact());
PropertyCell::SetValueWithInvalidation(
this, "typed_array_species_protector",
factory()->typed_array_species_protector(),
handle(Smi::FromInt(kProtectorInvalid), this));
DCHECK(!IsTypedArraySpeciesLookupChainIntact());
}
void Isolate::InvalidatePromiseSpeciesProtector() {
DCHECK(factory()->promise_species_protector()->value().IsSmi());
DCHECK(IsPromiseSpeciesLookupChainIntact());

View File

@ -1176,8 +1176,6 @@ class Isolate final : private HiddenFactory {
bool IsArrayOrObjectOrStringPrototype(Object object);
inline bool IsTypedArraySpeciesLookupChainIntact();
// Check that the @@species protector is intact, which guards the lookup of
// "constructor" on JSPromise instances, whose [[Prototype]] is the initial
// %PromisePrototype%, and the Symbol.species lookup on the
@ -1263,7 +1261,6 @@ class Isolate final : private HiddenFactory {
void TraceProtectorInvalidation(const char* protector_name);
void InvalidateArrayConstructorProtector();
void InvalidateTypedArraySpeciesProtector();
void InvalidateRegExpSpeciesProtector(Handle<NativeContext> native_context);
void InvalidatePromiseSpeciesProtector();
void InvalidateIsConcatSpreadableProtector();

View File

@ -18,8 +18,10 @@ class Protectors : public AllStatic {
#define DECLARED_PROTECTORS_ON_NATIVE_CONTEXT(V) \
V(RegExpSpeciesLookupChainProtector, regexp_species_protector)
#define DECLARED_PROTECTORS_ON_ISOLATE(V) \
V(ArraySpeciesLookupChain, ArraySpeciesProtector, array_species_protector)
#define DECLARED_PROTECTORS_ON_ISOLATE(V) \
V(ArraySpeciesLookupChain, ArraySpeciesProtector, array_species_protector) \
V(TypedArraySpeciesLookupChain, TypedArraySpeciesProtector, \
typed_array_species_protector)
#define DECLARE_PROTECTOR_ON_NATIVE_CONTEXT(name, unused_cell) \
static inline bool Is##name##Intact(Handle<NativeContext> native_context); \

View File

@ -251,7 +251,7 @@ void LookupIterator::InternalUpdateProtector() {
!isolate_->IsPromiseSpeciesLookupChainIntact() &&
!Protectors::IsRegExpSpeciesLookupChainProtectorIntact(
native_context) &&
!isolate_->IsTypedArraySpeciesLookupChainIntact()) {
!Protectors::IsTypedArraySpeciesLookupChainIntact(isolate_)) {
return;
}
// Setting the constructor property could change an instance's @@species
@ -274,8 +274,8 @@ void LookupIterator::InternalUpdateProtector() {
native_context);
return;
} else if (receiver->IsJSTypedArray(isolate_)) {
if (!isolate_->IsTypedArraySpeciesLookupChainIntact()) return;
isolate_->InvalidateTypedArraySpeciesProtector();
if (!Protectors::IsTypedArraySpeciesLookupChainIntact(isolate_)) return;
Protectors::InvalidateTypedArraySpeciesLookupChain(isolate_);
return;
}
if (receiver->map(isolate_).is_prototype_map()) {
@ -306,8 +306,8 @@ void LookupIterator::InternalUpdateProtector() {
} else if (isolate_->IsInAnyContext(
receiver->map(isolate_).prototype(isolate_),
Context::TYPED_ARRAY_PROTOTYPE_INDEX)) {
if (!isolate_->IsTypedArraySpeciesLookupChainIntact()) return;
isolate_->InvalidateTypedArraySpeciesProtector();
if (!Protectors::IsTypedArraySpeciesLookupChainIntact(isolate_)) return;
Protectors::InvalidateTypedArraySpeciesLookupChain(isolate_);
}
}
} else if (*name_ == roots.next_string()) {
@ -347,7 +347,7 @@ void LookupIterator::InternalUpdateProtector() {
!isolate_->IsPromiseSpeciesLookupChainIntact() &&
!Protectors::IsRegExpSpeciesLookupChainProtectorIntact(
native_context) &&
!isolate_->IsTypedArraySpeciesLookupChainIntact()) {
!Protectors::IsTypedArraySpeciesLookupChainIntact(isolate_)) {
return;
}
// Setting the Symbol.species property of any Array, Promise or TypedArray
@ -370,8 +370,8 @@ void LookupIterator::InternalUpdateProtector() {
Protectors::InvalidateRegExpSpeciesLookupChainProtector(isolate_,
native_context);
} else if (IsTypedArrayFunctionInAnyContext(isolate_, *receiver)) {
if (!isolate_->IsTypedArraySpeciesLookupChainIntact()) return;
isolate_->InvalidateTypedArraySpeciesProtector();
if (!Protectors::IsTypedArraySpeciesLookupChainIntact(isolate_)) return;
Protectors::InvalidateTypedArraySpeciesLookupChain(isolate_);
}
} else if (*name_ == roots.is_concat_spreadable_symbol()) {
if (!isolate_->IsIsConcatSpreadableLookupChainIntact()) return;

View File

@ -7,6 +7,7 @@
#include "src/init/v8.h"
#include "test/cctest/cctest.h"
#include "src/execution/protectors-inl.h"
#include "src/heap/heap.h"
#include "src/objects/objects-inl.h"
#include "src/objects/objects.h"
@ -115,12 +116,12 @@ void TestSpeciesProtector(char* code,
v8::internal::Isolate* i_isolate =
reinterpret_cast<v8::internal::Isolate*>(isolate);
CHECK(i_isolate->IsTypedArraySpeciesLookupChainIntact());
CHECK(Protectors::IsTypedArraySpeciesLookupChainIntact(i_isolate));
CompileRun(code);
if (invalidates_species_protector) {
CHECK(!i_isolate->IsTypedArraySpeciesLookupChainIntact());
CHECK(!Protectors::IsTypedArraySpeciesLookupChainIntact(i_isolate));
} else {
CHECK(i_isolate->IsTypedArraySpeciesLookupChainIntact());
CHECK(Protectors::IsTypedArraySpeciesLookupChainIntact(i_isolate));
}
v8::Local<v8::Value> my_typed_array = CompileRun("MyTypedArray");