Commit dee82c85 authored by Camillo Bruni's avatar Camillo Bruni Committed by V8 LUCI CQ

[runtime] Mark more Context getters const

- Add Context extension slot verification
- Fix ScriptContextTable printing
- Make Context::scope_info() inlinable

Bug: chromium:1244145
Change-Id: Ide71866885f3f92de6561dfef6911ee52c6094f9
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3211578
Commit-Queue: Camillo Bruni <cbruni@chromium.org>
Reviewed-by: 's avatarVictor Gomes <victorgomes@chromium.org>
Cr-Commit-Position: refs/heads/main@{#77286}
parent 18c37d32
......@@ -603,6 +603,7 @@ void FixedDoubleArray::FixedDoubleArrayVerify(Isolate* isolate) {
}
void Context::ContextVerify(Isolate* isolate) {
if (has_extension()) VerifyExtensionSlot(extension());
TorqueGeneratedClassVerifiers::ContextVerify(*this, isolate);
for (int i = 0; i < length(); i++) {
VerifyObjectField(isolate, OffsetOfElementAt(i));
......
......@@ -123,9 +123,11 @@ void HeapObject::HeapObjectPrint(std::ostream& os) {
case MODULE_CONTEXT_TYPE:
case SCRIPT_CONTEXT_TYPE:
case WITH_CONTEXT_TYPE:
case SCRIPT_CONTEXT_TABLE_TYPE:
Context::cast(*this).ContextPrint(os);
break;
case SCRIPT_CONTEXT_TABLE_TYPE:
FixedArray::cast(*this).FixedArrayPrint(os);
break;
case NATIVE_CONTEXT_TYPE:
NativeContext::cast(*this).NativeContextPrint(os);
break;
......
......@@ -113,9 +113,9 @@ void Context::set_scope_info(ScopeInfo scope_info, WriteBarrierMode mode) {
set(SCOPE_INFO_INDEX, scope_info, mode);
}
Object Context::unchecked_previous() { return get(PREVIOUS_INDEX); }
Object Context::unchecked_previous() const { return get(PREVIOUS_INDEX); }
Context Context::previous() {
Context Context::previous() const {
Object result = get(PREVIOUS_INDEX);
DCHECK(IsBootstrappingOrValidParentContext(result, *this));
return Context::unchecked_cast(result);
......@@ -124,19 +124,28 @@ void Context::set_previous(Context context, WriteBarrierMode mode) {
set(PREVIOUS_INDEX, context, mode);
}
Object Context::next_context_link() { return get(Context::NEXT_CONTEXT_LINK); }
ScopeInfo Context::scope_info() const {
return ScopeInfo::cast(get(SCOPE_INFO_INDEX));
}
Object Context::next_context_link() const {
return get(Context::NEXT_CONTEXT_LINK);
}
bool Context::has_extension() {
bool Context::has_extension() const {
return scope_info().HasContextExtensionSlot() && !extension().IsUndefined();
}
HeapObject Context::extension() {
HeapObject Context::extension() const {
DCHECK(scope_info().HasContextExtensionSlot());
return HeapObject::cast(get(EXTENSION_INDEX));
}
void Context::set_extension(HeapObject object, WriteBarrierMode mode) {
DCHECK(scope_info().HasContextExtensionSlot());
#ifdef VERIFY_HEAP
VerifyExtensionSlot(object);
#endif
set(EXTENSION_INDEX, object, mode);
}
......
......@@ -65,7 +65,7 @@ bool ScriptContextTable::Lookup(Isolate* isolate, ScriptContextTable table,
return false;
}
bool Context::is_declaration_context() {
bool Context::is_declaration_context() const {
if (IsFunctionContext() || IsNativeContext() || IsScriptContext() ||
IsModuleContext()) {
return true;
......@@ -77,7 +77,7 @@ bool Context::is_declaration_context() {
return scope_info().is_declaration_scope();
}
Context Context::declaration_context() {
Context Context::declaration_context() const {
Context current = *this;
while (!current.is_declaration_context()) {
current = current.previous();
......@@ -85,7 +85,7 @@ Context Context::declaration_context() {
return current;
}
Context Context::closure_context() {
Context Context::closure_context() const {
Context current = *this;
while (!current.IsFunctionContext() && !current.IsScriptContext() &&
!current.IsModuleContext() && !current.IsNativeContext() &&
......@@ -95,7 +95,7 @@ Context Context::closure_context() {
return current;
}
JSObject Context::extension_object() {
JSObject Context::extension_object() const {
DCHECK(IsNativeContext() || IsFunctionContext() || IsBlockContext() ||
IsEvalContext() || IsCatchContext());
HeapObject object = extension();
......@@ -105,17 +105,13 @@ JSObject Context::extension_object() {
return JSObject::cast(object);
}
JSReceiver Context::extension_receiver() {
JSReceiver Context::extension_receiver() const {
DCHECK(IsNativeContext() || IsWithContext() || IsEvalContext() ||
IsFunctionContext() || IsBlockContext());
return IsWithContext() ? JSReceiver::cast(extension()) : extension_object();
}
ScopeInfo Context::scope_info() {
return ScopeInfo::cast(get(SCOPE_INFO_INDEX));
}
SourceTextModule Context::module() {
SourceTextModule Context::module() const {
Context current = *this;
while (!current.IsModuleContext()) {
current = current.previous();
......@@ -123,11 +119,11 @@ SourceTextModule Context::module() {
return SourceTextModule::cast(current.extension());
}
JSGlobalObject Context::global_object() {
JSGlobalObject Context::global_object() const {
return JSGlobalObject::cast(native_context().extension());
}
Context Context::script_context() {
Context Context::script_context() const {
Context current = *this;
while (!current.IsScriptContext()) {
current = current.previous();
......@@ -135,7 +131,7 @@ Context Context::script_context() {
return current;
}
JSGlobalProxy Context::global_proxy() {
JSGlobalProxy Context::global_proxy() const {
return native_context().global_proxy_object();
}
......@@ -446,6 +442,23 @@ int Context::IntrinsicIndexForName(const unsigned char* unsigned_string,
#undef COMPARE_NAME
#ifdef VERIFY_HEAP
void Context::VerifyExtensionSlot(HeapObject extension) {
CHECK(scope_info().HasContextExtensionSlot());
if (extension.IsUndefined()) return;
if (IsModuleContext()) {
extension.IsSourceTextModule();
} else if (IsDebugEvaluateContext() || IsWithContext()) {
extension.IsJSReceiver();
} else if (IsNativeContext()) {
extension.IsJSGlobalObject();
} else if ((IsBlockContext() && scope_info().is_declaration_scope()) ||
IsFunctionContext()) {
extension.IsJSContextExtensionObject();
}
}
#endif // VERIFY_HEAP
#ifdef DEBUG
bool Context::IsBootstrappingOrValidParentContext(Object object,
......
......@@ -542,39 +542,39 @@ class Context : public TorqueGeneratedContext<Context, HeapObject> {
inline void set_scope_info(ScopeInfo scope_info,
WriteBarrierMode mode = UPDATE_WRITE_BARRIER);
inline Object unchecked_previous();
inline Context previous();
inline Object unchecked_previous() const;
inline Context previous() const;
inline Object next_context_link();
inline Object next_context_link() const;
inline bool has_extension();
inline HeapObject extension();
inline bool has_extension() const;
inline HeapObject extension() const;
inline void set_extension(HeapObject object,
WriteBarrierMode mode = UPDATE_WRITE_BARRIER);
JSObject extension_object();
JSReceiver extension_receiver();
V8_EXPORT_PRIVATE ScopeInfo scope_info();
JSObject extension_object() const;
JSReceiver extension_receiver() const;
V8_EXPORT_PRIVATE inline ScopeInfo scope_info() const;
// Find the module context (assuming there is one) and return the associated
// module object.
SourceTextModule module();
SourceTextModule module() const;
// Get the context where var declarations will be hoisted to, which
// may be the context itself.
Context declaration_context();
bool is_declaration_context();
Context declaration_context() const;
bool is_declaration_context() const;
// Get the next closure's context on the context chain.
Context closure_context();
Context closure_context() const;
// Returns a JSGlobalProxy object or null.
V8_EXPORT_PRIVATE JSGlobalProxy global_proxy();
V8_EXPORT_PRIVATE JSGlobalProxy global_proxy() const;
// Get the JSGlobalObject object.
V8_EXPORT_PRIVATE JSGlobalObject global_object();
V8_EXPORT_PRIVATE JSGlobalObject global_object() const;
// Get the script context by traversing the context chain.
Context script_context();
Context script_context() const;
// Compute the native context.
inline NativeContext native_context() const;
......@@ -652,6 +652,10 @@ class Context : public TorqueGeneratedContext<Context, HeapObject> {
class BodyDescriptor;
#ifdef VERIFY_HEAP
void VerifyExtensionSlot(HeapObject extension);
#endif
private:
#ifdef DEBUG
// Bootstrapping-aware type checks.
......
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