Commit 4fbe8408 authored by Pan, Tao's avatar Pan, Tao Committed by V8 LUCI CQ

[cleanup] Unify getting native context of JSFunction object

There are two kinds of method to get native context of JSFunction
object, directly calling to native_context() and calling
context().native_context(). Replace all context().native_context()
with native_context().

Change-Id: Ia7a7e64648446002717d38fafecd2420f622325e
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3541468Reviewed-by: 's avatarTobias Tebbi <tebbi@chromium.org>
Reviewed-by: 's avatarJakob Linke <jgruber@chromium.org>
Reviewed-by: 's avatarJakob Kummerow <jkummerow@chromium.org>
Commit-Queue: Tao Pan <tao.pan@intel.com>
Cr-Commit-Position: refs/heads/main@{#79663}
parent 21cfbf04
......@@ -386,7 +386,7 @@ bool IsSimpleInstantiation(Isolate* isolate, ObjectTemplateInfo info,
if (fun.shared().function_data(kAcquireLoad) != info.constructor())
return false;
if (info.immutable_proto()) return false;
return fun.context().native_context() == isolate->raw_native_context();
return fun.native_context() == isolate->raw_native_context();
}
MaybeHandle<JSObject> InstantiateObject(Isolate* isolate,
......
......@@ -900,8 +900,7 @@ void InsertCodeIntoOptimizedCodeCache(
Isolate* isolate = function->GetIsolate();
Handle<CodeT> code = ToCodeT(compilation_info->code(), isolate);
Handle<SharedFunctionInfo> shared(function->shared(), isolate);
Handle<NativeContext> native_context(function->context().native_context(),
isolate);
Handle<NativeContext> native_context(function->native_context(), isolate);
if (compilation_info->osr_offset().IsNone()) {
Handle<FeedbackVector> vector =
handle(function->feedback_vector(), isolate);
......
......@@ -178,7 +178,7 @@ Code Deoptimizer::FindDeoptimizingCode(Address addr) {
if (function_.IsHeapObject()) {
// Search all deoptimizing code in the native context of the function.
Isolate* isolate = isolate_;
NativeContext native_context = function_.context().native_context();
NativeContext native_context = function_.native_context();
Object element = native_context.DeoptimizedCodeListHead();
while (!element.IsUndefined(isolate)) {
Code code = FromCodeT(CodeT::cast(element));
......@@ -445,14 +445,14 @@ void Deoptimizer::DeoptimizeFunction(JSFunction function, Code code) {
if (!code.deopt_already_counted()) {
code.set_deopt_already_counted(true);
}
DeoptimizeMarkedCodeForContext(function.context().native_context());
DeoptimizeMarkedCodeForContext(function.native_context());
// TODO(mythria): Ideally EvictMarkCode should compact the cache without
// having to explicitly call this. We don't do this currently because
// compacting causes GC and DeoptimizeMarkedCodeForContext uses raw
// pointers. Update DeoptimizeMarkedCodeForContext to use handles and remove
// this call from here.
OSROptimizedCodeCache::Compact(
Handle<NativeContext>(function.context().native_context(), isolate));
Handle<NativeContext>(function.native_context(), isolate));
}
}
......
......@@ -1608,7 +1608,7 @@ Handle<Object> FrameSummary::JavaScriptFrameSummary::script() const {
}
Handle<Context> FrameSummary::JavaScriptFrameSummary::native_context() const {
return handle(function_->context().native_context(), isolate());
return handle(function_->native_context(), isolate());
}
Handle<StackFrameInfo>
......
......@@ -157,7 +157,7 @@ bool HaveCachedOSRCodeForCurrentBytecodeOffset(UnoptimizedFrame* frame,
const int bytecode_offset = frame->GetBytecodeOffset();
if (V8_UNLIKELY(function.shared().osr_code_cache_state() != kNotCached)) {
OSROptimizedCodeCache cache =
function.context().native_context().GetOSROptimizedCodeCache();
function.native_context().GetOSROptimizedCodeCache();
interpreter::BytecodeArrayIterator iterator(
handle(bytecode, frame->isolate()));
for (int jump_offset : cache.GetBytecodeOffsetsFromSFI(function.shared())) {
......
......@@ -2240,8 +2240,7 @@ DEFINE_ERROR(WasmExceptionError, wasm_exception_error)
Handle<JSObject> Factory::NewFunctionPrototype(Handle<JSFunction> function) {
// Make sure to use globals from the function's context, since the function
// can be from a different context.
Handle<NativeContext> native_context(function->context().native_context(),
isolate());
Handle<NativeContext> native_context(function->native_context(), isolate());
Handle<Map> new_map;
if (V8_UNLIKELY(IsAsyncGeneratorFunction(function->shared().kind()))) {
new_map = handle(native_context->async_generator_object_prototype_map(),
......
......@@ -25,10 +25,10 @@ template CallOptimization::CallOptimization(LocalIsolate* isolate,
Context CallOptimization::GetAccessorContext(Map holder_map) const {
if (is_constant_call()) {
return constant_function_->context().native_context();
return constant_function_->native_context();
}
JSFunction constructor = JSFunction::cast(holder_map.GetConstructor());
return constructor.context().native_context();
return constructor.native_context();
}
bool CallOptimization::IsCrossContextLazyAccessorPair(Context native_context,
......
......@@ -646,8 +646,7 @@ void SetInstancePrototype(Isolate* isolate, Handle<JSFunction> function,
// If the function is used as the global Array function, cache the
// updated initial maps (and transitioned versions) in the native context.
Handle<Context> native_context(function->context().native_context(),
isolate);
Handle<Context> native_context(function->native_context(), isolate);
Handle<Object> array_function(
native_context->get(Context::ARRAY_FUNCTION_INDEX), isolate);
if (array_function->IsJSFunction() &&
......@@ -696,8 +695,7 @@ void JSFunction::SetPrototype(Handle<JSFunction> function,
JSObject::MigrateToMap(isolate, function, new_map);
FunctionKind kind = function->shared().kind();
Handle<Context> native_context(function->context().native_context(),
isolate);
Handle<Context> native_context(function->native_context(), isolate);
construct_prototype = Handle<JSReceiver>(
IsGeneratorFunction(kind)
......
......@@ -601,7 +601,7 @@ MaybeHandle<NativeContext> JSReceiver::GetCreationContext() {
}
return function.has_context()
? Handle<NativeContext>(function.context().native_context(),
? Handle<NativeContext>(function.native_context(),
receiver.GetIsolate())
: MaybeHandle<NativeContext>();
}
......@@ -629,7 +629,7 @@ MaybeHandle<NativeContext> JSReceiver::GetFunctionRealm(
}
if (current.IsJSFunction()) {
JSFunction function = JSFunction::cast(current);
return handle(function.context().native_context(), isolate);
return handle(function.native_context(), isolate);
}
if (current.IsJSBoundFunction()) {
JSBoundFunction function = JSBoundFunction::cast(current);
......@@ -4688,7 +4688,7 @@ void JSObject::OptimizeAsPrototype(Handle<JSObject> object,
if (maybe_constructor.IsJSFunction()) {
JSFunction constructor = JSFunction::cast(maybe_constructor);
if (!constructor.shared().IsApiFunction()) {
Context context = constructor.context().native_context();
Context context = constructor.native_context();
JSFunction object_function = context.object_function();
new_map->SetConstructor(object_function);
}
......
......@@ -1875,8 +1875,7 @@ Handle<Map> Map::TransitionToDataProperty(Isolate* isolate, Handle<Map> map,
!JSFunction::cast(*maybe_constructor).shared().native()) {
Handle<JSFunction> constructor =
Handle<JSFunction>::cast(maybe_constructor);
DCHECK_NE(*constructor,
constructor->context().native_context().object_function());
DCHECK_NE(*constructor, constructor->native_context().object_function());
Handle<Map> initial_map(constructor->initial_map(), isolate);
result = Map::Normalize(isolate, initial_map, CLEAR_INOBJECT_PROPERTIES,
reason);
......
......@@ -791,7 +791,7 @@ bool InstanceBuilder::ExecuteStartFunction() {
// v8::Context::Enter() and must happen in addition to the function call
// sequence doing the compiled version of "isolate->set_context(...)".
HandleScopeImplementer* hsi = isolate_->handle_scope_implementer();
hsi->EnterContext(start_function_->context().native_context());
hsi->EnterContext(start_function_->native_context());
// Call the JS function.
Handle<Object> undefined = isolate_->factory()->undefined_value();
......
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