Commit fdc5c134 authored by verwaest's avatar verwaest Committed by Commit bot

Return this in Context::native_context if receiver is a native context.

Checking for native context is faster than checking for global object. Additionally it speeds up the case were it actually is the native context, while not slowing down the alternative case. The bootstrapper only needs to access the native context from the native context, so this avoids the expensive fallback.

BUG=

Review URL: https://codereview.chromium.org/1214903017

Cr-Commit-Position: refs/heads/master@{#29423}
parent b71fe9ee
...@@ -85,22 +85,13 @@ Context* Context::script_context() { ...@@ -85,22 +85,13 @@ Context* Context::script_context() {
Context* Context::native_context() { Context* Context::native_context() {
// Fast case: the global object for this context has been set. In // Fast case: the receiver context is already a native context.
// that case, the global object has a direct pointer to the global if (IsNativeContext()) return this;
// context. // The global object has a direct pointer to the native context. If the
if (global_object()->IsGlobalObject()) { // following DCHECK fails, the native context is probably being accessed
return global_object()->native_context(); // indirectly during bootstrapping. This is unsupported.
} DCHECK(global_object()->IsGlobalObject());
return global_object()->native_context();
// During bootstrapping, the global object might not be set and we
// have to search the context chain to find the native context.
DCHECK(this->GetIsolate()->bootstrapper()->IsActive());
Context* current = this;
while (!current->IsNativeContext()) {
JSFunction* closure = JSFunction::cast(current->closure());
current = Context::cast(closure->context());
}
return current;
} }
......
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