OLD | NEW |
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/contexts.h" | 5 #include "src/contexts.h" |
6 | 6 |
7 #include "src/bootstrapper.h" | 7 #include "src/bootstrapper.h" |
8 #include "src/debug/debug.h" | 8 #include "src/debug/debug.h" |
9 #include "src/isolate-inl.h" | 9 #include "src/isolate-inl.h" |
10 | 10 |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
50 result->context_index = i; | 50 result->context_index = i; |
51 result->slot_index = slot_index; | 51 result->slot_index = slot_index; |
52 return true; | 52 return true; |
53 } | 53 } |
54 } | 54 } |
55 return false; | 55 return false; |
56 } | 56 } |
57 | 57 |
58 | 58 |
59 bool Context::is_declaration_context() { | 59 bool Context::is_declaration_context() { |
60 if (IsFunctionContext() || IsNativeContext() || IsScriptContext()) { | 60 if (IsFunctionContext() || IsNativeContext() || IsScriptContext() || |
| 61 IsModuleContext()) { |
61 return true; | 62 return true; |
62 } | 63 } |
63 if (!IsBlockContext()) return false; | 64 if (!IsBlockContext()) return false; |
64 Object* ext = extension(); | 65 Object* ext = extension(); |
65 // If we have the special extension, we immediately know it must be a | 66 // If we have the special extension, we immediately know it must be a |
66 // declaration scope. That's just a small performance shortcut. | 67 // declaration scope. That's just a small performance shortcut. |
67 return ext->IsContextExtension() || | 68 return ext->IsContextExtension() || |
68 ScopeInfo::cast(ext)->is_declaration_scope(); | 69 ScopeInfo::cast(ext)->is_declaration_scope(); |
69 } | 70 } |
70 | 71 |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
116 } | 117 } |
117 HeapObject* object = extension(); | 118 HeapObject* object = extension(); |
118 if (object->IsContextExtension()) { | 119 if (object->IsContextExtension()) { |
119 DCHECK(IsBlockContext() || IsCatchContext() || IsWithContext() || | 120 DCHECK(IsBlockContext() || IsCatchContext() || IsWithContext() || |
120 IsDebugEvaluateContext()); | 121 IsDebugEvaluateContext()); |
121 object = ContextExtension::cast(object)->scope_info(); | 122 object = ContextExtension::cast(object)->scope_info(); |
122 } | 123 } |
123 return ScopeInfo::cast(object); | 124 return ScopeInfo::cast(object); |
124 } | 125 } |
125 | 126 |
| 127 JSModule* Context::module() { |
| 128 Context* current = this; |
| 129 while (!current->IsModuleContext()) { |
| 130 current = current->previous(); |
| 131 } |
| 132 return JSModule::cast(current->extension()); |
| 133 } |
126 | 134 |
127 String* Context::catch_name() { | 135 String* Context::catch_name() { |
128 DCHECK(IsCatchContext()); | 136 DCHECK(IsCatchContext()); |
129 return String::cast(ContextExtension::cast(extension())->extension()); | 137 return String::cast(ContextExtension::cast(extension())->extension()); |
130 } | 138 } |
131 | 139 |
132 | 140 |
133 JSGlobalObject* Context::global_object() { | 141 JSGlobalObject* Context::global_object() { |
134 return JSGlobalObject::cast(native_context()->extension()); | 142 return JSGlobalObject::cast(native_context()->extension()); |
135 } | 143 } |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
182 | 190 |
183 static PropertyAttributes GetAttributesForMode(VariableMode mode) { | 191 static PropertyAttributes GetAttributesForMode(VariableMode mode) { |
184 DCHECK(IsDeclaredVariableMode(mode)); | 192 DCHECK(IsDeclaredVariableMode(mode)); |
185 return mode == CONST ? READ_ONLY : NONE; | 193 return mode == CONST ? READ_ONLY : NONE; |
186 } | 194 } |
187 | 195 |
188 Handle<Object> Context::Lookup(Handle<String> name, ContextLookupFlags flags, | 196 Handle<Object> Context::Lookup(Handle<String> name, ContextLookupFlags flags, |
189 int* index, PropertyAttributes* attributes, | 197 int* index, PropertyAttributes* attributes, |
190 InitializationFlag* init_flag, | 198 InitializationFlag* init_flag, |
191 VariableMode* variable_mode) { | 199 VariableMode* variable_mode) { |
| 200 DCHECK(!IsModuleContext()); |
192 Isolate* isolate = GetIsolate(); | 201 Isolate* isolate = GetIsolate(); |
193 Handle<Context> context(this, isolate); | 202 Handle<Context> context(this, isolate); |
194 | 203 |
195 bool follow_context_chain = (flags & FOLLOW_CONTEXT_CHAIN) != 0; | 204 bool follow_context_chain = (flags & FOLLOW_CONTEXT_CHAIN) != 0; |
196 bool failed_whitelist = false; | 205 bool failed_whitelist = false; |
197 *index = kNotFound; | 206 *index = kNotFound; |
198 *attributes = ABSENT; | 207 *attributes = ABSENT; |
199 *init_flag = kCreatedInitialized; | 208 *init_flag = kCreatedInitialized; |
200 *variable_mode = VAR; | 209 *variable_mode = VAR; |
201 | 210 |
(...skipping 360 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
562 | 571 |
563 int previous_value = errors_thrown()->value(); | 572 int previous_value = errors_thrown()->value(); |
564 set_errors_thrown(Smi::FromInt(previous_value + 1)); | 573 set_errors_thrown(Smi::FromInt(previous_value + 1)); |
565 } | 574 } |
566 | 575 |
567 | 576 |
568 int Context::GetErrorsThrown() { return errors_thrown()->value(); } | 577 int Context::GetErrorsThrown() { return errors_thrown()->value(); } |
569 | 578 |
570 } // namespace internal | 579 } // namespace internal |
571 } // namespace v8 | 580 } // namespace v8 |
OLD | NEW |