Reviewers: Jakob,
Message:
ptal
Description:
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=
Please review this at
https://codereview.chromium.org/1214903017/
Base URL:
https://chromium.googlesource.com/v8/v8.git@master
Affected files (+3, -13 lines):
M src/contexts.cc
Index: src/contexts.cc
diff --git a/src/contexts.cc b/src/contexts.cc
index
61b83c2c4e546b7a37d25007ee0ea26d1de6ef4f..d434cf3a6d0bd6d0dbc1590d44f8d178767f58bc
100644
--- a/src/contexts.cc
+++ b/src/contexts.cc
@@ -85,22 +85,12 @@ Context* Context::script_context() {
Context* Context::native_context() {
+ if (IsNativeContext()) return this;
// Fast case: the global object for this context has been set. In
// that case, the global object has a direct pointer to the global
// context.
- if (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;
+ DCHECK(global_object()->IsGlobalObject());
+ return global_object()->native_context();
}