diff --git a/include/v8.h b/include/v8.h index ffb3b5f4d3..6b1f310f0b 100644 --- a/include/v8.h +++ b/include/v8.h @@ -8473,6 +8473,22 @@ class V8_EXPORT Isolate { kDateTimeFormatDateTimeStyle = 87, kBreakIteratorTypeWord = 88, kBreakIteratorTypeLine = 89, + kInvalidatedArrayBufferDetachingProtector = 90, + kInvalidatedArrayConstructorProtector = 91, + kInvalidatedArrayIteratorLookupChainProtector = 92, + kInvalidatedArraySpeciesLookupChainProtector = 93, + kInvalidatedIsConcatSpreadableLookupChainProtector = 94, + kInvalidatedMapIteratorLookupChainProtector = 95, + kInvalidatedNoElementsProtector = 96, + kInvalidatedPromiseHookProtector = 97, + kInvalidatedPromiseResolveLookupChainProtector = 98, + kInvalidatedPromiseSpeciesLookupChainProtector = 99, + kInvalidatedPromiseThenLookupChainProtector = 100, + kInvalidatedRegExpSpeciesLookupChainProtector = 101, + kInvalidatedSetIteratorLookupChainProtector = 102, + kInvalidatedStringIteratorLookupChainProtector = 103, + kInvalidatedStringLengthOverflowLookupChainProtector = 104, + kInvalidatedTypedArraySpeciesLookupChainProtector = 105, // If you add new values here, you'll also need to update Chromium's: // web_feature.mojom, use_counter_callback.cc, and enums.xml. V8 changes to diff --git a/src/execution/protectors.cc b/src/execution/protectors.cc index c8ba05a8f9..28b7b89acc 100644 --- a/src/execution/protectors.cc +++ b/src/execution/protectors.cc @@ -17,6 +17,7 @@ namespace v8 { namespace internal { namespace { + void TraceProtectorInvalidation(const char* protector_name) { DCHECK(FLAG_trace_protector_invalidation); static constexpr char kInvalidateProtectorTracingCategory[] = @@ -26,11 +27,23 @@ void TraceProtectorInvalidation(const char* protector_name) { DCHECK(FLAG_trace_protector_invalidation); // TODO(jgruber): Remove the PrintF once tracing can output to stdout. - i::PrintF("Invalidating protector cell %s", protector_name); + i::PrintF("Invalidating protector cell %s\n", protector_name); TRACE_EVENT_INSTANT1("v8", kInvalidateProtectorTracingCategory, TRACE_EVENT_SCOPE_THREAD, kInvalidateProtectorTracingArg, protector_name); } + +// Static asserts to ensure we have a use counter for every protector. If this +// fails, add the use counter in V8 and chromium. Note: IsDefined is not +// strictly needed but clarifies the intent of the static assert. +constexpr bool IsDefined(v8::Isolate::UseCounterFeature) { return true; } +#define V(Name, ...) \ + STATIC_ASSERT(IsDefined(v8::Isolate::kInvalidated##Name##Protector)); + +DECLARED_PROTECTORS_ON_ISOLATE(V) +DECLARED_PROTECTORS_ON_NATIVE_CONTEXT(V) +#undef V + } // namespace #define INVALIDATE_PROTECTOR_ON_NATIVE_CONTEXT_DEFINITION(name, cell) \ @@ -58,6 +71,7 @@ DECLARED_PROTECTORS_ON_NATIVE_CONTEXT( if (FLAG_trace_protector_invalidation) { \ TraceProtectorInvalidation(#name); \ } \ + isolate->CountUsage(v8::Isolate::kInvalidated##name##Protector); \ PropertyCell::SetValueWithInvalidation( \ isolate, #cell, isolate->factory()->cell(), \ handle(Smi::FromInt(kProtectorInvalid), isolate)); \ diff --git a/src/execution/protectors.h b/src/execution/protectors.h index 4601f16cf0..1c92fce13f 100644 --- a/src/execution/protectors.h +++ b/src/execution/protectors.h @@ -16,7 +16,7 @@ class Protectors : public AllStatic { static const int kProtectorInvalid = 0; #define DECLARED_PROTECTORS_ON_NATIVE_CONTEXT(V) \ - V(RegExpSpeciesLookupChainProtector, regexp_species_protector) + V(RegExpSpeciesLookupChain, regexp_species_protector) #define DECLARED_PROTECTORS_ON_ISOLATE(V) \ V(ArrayBufferDetaching, ArrayBufferDetachingProtector, \ diff --git a/src/objects/lookup.cc b/src/objects/lookup.cc index 3671e3ce9f..d7001e04af 100644 --- a/src/objects/lookup.cc +++ b/src/objects/lookup.cc @@ -205,8 +205,7 @@ void LookupIterator::InternalUpdateProtector(Isolate* isolate, if (!Protectors::IsArraySpeciesLookupChainIntact(isolate) && !Protectors::IsPromiseSpeciesLookupChainIntact(isolate) && - !Protectors::IsRegExpSpeciesLookupChainProtectorIntact( - native_context) && + !Protectors::IsRegExpSpeciesLookupChainIntact(native_context) && !Protectors::IsTypedArraySpeciesLookupChainIntact(isolate)) { return; } @@ -222,12 +221,10 @@ void LookupIterator::InternalUpdateProtector(Isolate* isolate, Protectors::InvalidatePromiseSpeciesLookupChain(isolate); return; } else if (receiver->IsJSRegExp(isolate)) { - if (!Protectors::IsRegExpSpeciesLookupChainProtectorIntact( - native_context)) { + if (!Protectors::IsRegExpSpeciesLookupChainIntact(native_context)) { return; } - Protectors::InvalidateRegExpSpeciesLookupChainProtector(isolate, - native_context); + Protectors::InvalidateRegExpSpeciesLookupChain(isolate, native_context); return; } else if (receiver->IsJSTypedArray(isolate)) { if (!Protectors::IsTypedArraySpeciesLookupChainIntact(isolate)) return; @@ -253,12 +250,10 @@ void LookupIterator::InternalUpdateProtector(Isolate* isolate, Protectors::InvalidatePromiseSpeciesLookupChain(isolate); } else if (isolate->IsInAnyContext(*receiver, Context::REGEXP_PROTOTYPE_INDEX)) { - if (!Protectors::IsRegExpSpeciesLookupChainProtectorIntact( - native_context)) { + if (!Protectors::IsRegExpSpeciesLookupChainIntact(native_context)) { return; } - Protectors::InvalidateRegExpSpeciesLookupChainProtector(isolate, - native_context); + Protectors::InvalidateRegExpSpeciesLookupChain(isolate, native_context); } else if (isolate->IsInAnyContext( receiver->map(isolate).prototype(isolate), Context::TYPED_ARRAY_PROTOTYPE_INDEX)) { @@ -301,8 +296,7 @@ void LookupIterator::InternalUpdateProtector(Isolate* isolate, if (!Protectors::IsArraySpeciesLookupChainIntact(isolate) && !Protectors::IsPromiseSpeciesLookupChainIntact(isolate) && - !Protectors::IsRegExpSpeciesLookupChainProtectorIntact( - native_context) && + !Protectors::IsRegExpSpeciesLookupChainIntact(native_context) && !Protectors::IsTypedArraySpeciesLookupChainIntact(isolate)) { return; } @@ -319,12 +313,10 @@ void LookupIterator::InternalUpdateProtector(Isolate* isolate, Protectors::InvalidatePromiseSpeciesLookupChain(isolate); } else if (isolate->IsInAnyContext(*receiver, Context::REGEXP_FUNCTION_INDEX)) { - if (!Protectors::IsRegExpSpeciesLookupChainProtectorIntact( - native_context)) { + if (!Protectors::IsRegExpSpeciesLookupChainIntact(native_context)) { return; } - Protectors::InvalidateRegExpSpeciesLookupChainProtector(isolate, - native_context); + Protectors::InvalidateRegExpSpeciesLookupChain(isolate, native_context); } else if (IsTypedArrayFunctionInAnyContext(isolate, *receiver)) { if (!Protectors::IsTypedArraySpeciesLookupChainIntact(isolate)) return; Protectors::InvalidateTypedArraySpeciesLookupChain(isolate); diff --git a/src/regexp/regexp-utils.cc b/src/regexp/regexp-utils.cc index 73c2015dd9..db21f62a52 100644 --- a/src/regexp/regexp-utils.cc +++ b/src/regexp/regexp-utils.cc @@ -185,7 +185,7 @@ bool RegExpUtils::IsUnmodifiedRegExp(Isolate* isolate, Handle obj) { // property. Similar spots in CSA would use BranchIfFastRegExp_Strict in this // case. - if (!Protectors::IsRegExpSpeciesLookupChainProtectorIntact( + if (!Protectors::IsRegExpSpeciesLookupChainIntact( recv.GetCreationContext())) { return false; }