Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(90)

Side by Side Diff: src/contexts.cc

Issue 1214903017: Return this in Context::native_context if receiver is a native context. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Update comment Created 5 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2011 the V8 project authors. All rights reserved. 1 // Copyright 2011 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "src/v8.h" 5 #include "src/v8.h"
6 6
7 #include "src/bootstrapper.h" 7 #include "src/bootstrapper.h"
8 #include "src/debug.h" 8 #include "src/debug.h"
9 #include "src/scopeinfo.h" 9 #include "src/scopeinfo.h"
10 10
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
78 Context* Context::script_context() { 78 Context* Context::script_context() {
79 Context* current = this; 79 Context* current = this;
80 while (!current->IsScriptContext()) { 80 while (!current->IsScriptContext()) {
81 current = current->previous(); 81 current = current->previous();
82 } 82 }
83 return current; 83 return current;
84 } 84 }
85 85
86 86
87 Context* Context::native_context() { 87 Context* Context::native_context() {
88 // Fast case: the global object for this context has been set. In 88 // Fast case: the receiver context is already a native context.
89 // that case, the global object has a direct pointer to the global 89 if (IsNativeContext()) return this;
90 // context. 90 // The global object has a direct pointer to the native context. If the
91 if (global_object()->IsGlobalObject()) { 91 // following DCHECK fails, the native context is probably being accessed
92 return global_object()->native_context(); 92 // indirectly during bootstrapping. This is unsupported.
93 } 93 DCHECK(global_object()->IsGlobalObject());
94 94 return global_object()->native_context();
95 // During bootstrapping, the global object might not be set and we
96 // have to search the context chain to find the native context.
97 DCHECK(this->GetIsolate()->bootstrapper()->IsActive());
98 Context* current = this;
99 while (!current->IsNativeContext()) {
100 JSFunction* closure = JSFunction::cast(current->closure());
101 current = Context::cast(closure->context());
102 }
103 return current;
104 } 95 }
105 96
106 97
107 JSObject* Context::global_proxy() { 98 JSObject* Context::global_proxy() {
108 return native_context()->global_proxy_object(); 99 return native_context()->global_proxy_object();
109 } 100 }
110 101
111 102
112 void Context::set_global_proxy(JSObject* object) { 103 void Context::set_global_proxy(JSObject* object) {
113 native_context()->set_global_proxy_object(object); 104 native_context()->set_global_proxy_object(object);
(...skipping 384 matching lines...) Expand 10 before | Expand all | Expand 10 after
498 // During bootstrapping we allow all objects to pass as global 489 // During bootstrapping we allow all objects to pass as global
499 // objects. This is necessary to fix circular dependencies. 490 // objects. This is necessary to fix circular dependencies.
500 return isolate->heap()->gc_state() != Heap::NOT_IN_GC || 491 return isolate->heap()->gc_state() != Heap::NOT_IN_GC ||
501 isolate->bootstrapper()->IsActive() || 492 isolate->bootstrapper()->IsActive() ||
502 object->IsGlobalObject(); 493 object->IsGlobalObject();
503 } 494 }
504 #endif 495 #endif
505 496
506 } // namespace internal 497 } // namespace internal
507 } // namespace v8 498 } // namespace v8
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698