| 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 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 103 | 104 |
| 104 | 105 |
| 105 JSReceiver* Context::extension_receiver() { | 106 JSReceiver* Context::extension_receiver() { |
| 106 DCHECK(IsNativeContext() || IsWithContext() || | 107 DCHECK(IsNativeContext() || IsWithContext() || |
| 107 IsFunctionContext() || IsBlockContext()); | 108 IsFunctionContext() || IsBlockContext()); |
| 108 return IsWithContext() ? JSReceiver::cast(extension()) : extension_object(); | 109 return IsWithContext() ? JSReceiver::cast(extension()) : extension_object(); |
| 109 } | 110 } |
| 110 | 111 |
| 111 | 112 |
| 112 ScopeInfo* Context::scope_info() { | 113 ScopeInfo* Context::scope_info() { |
| 113 DCHECK(IsModuleContext() || IsScriptContext() || IsBlockContext()); | 114 DCHECK(IsScriptContext() || IsBlockContext()); |
| 114 HeapObject* object = extension(); | 115 HeapObject* object = extension(); |
| 115 if (object->IsContextExtension()) { | 116 if (object->IsContextExtension()) { |
| 116 DCHECK(IsBlockContext()); | 117 DCHECK(IsBlockContext()); |
| 117 object = ContextExtension::cast(object)->scope_info(); | 118 object = ContextExtension::cast(object)->scope_info(); |
| 118 } | 119 } |
| 119 return ScopeInfo::cast(object); | 120 return ScopeInfo::cast(object); |
| 120 } | 121 } |
| 121 | 122 |
| 123 JSModule* Context::module() { |
| 124 Context* current = this; |
| 125 while (!current->IsModuleContext()) { |
| 126 current = current->previous(); |
| 127 } |
| 128 return JSModule::cast(current->extension()); |
| 129 } |
| 122 | 130 |
| 123 String* Context::catch_name() { | 131 String* Context::catch_name() { |
| 124 DCHECK(IsCatchContext()); | 132 DCHECK(IsCatchContext()); |
| 125 return String::cast(extension()); | 133 return String::cast(extension()); |
| 126 } | 134 } |
| 127 | 135 |
| 128 | 136 |
| 129 JSGlobalObject* Context::global_object() { | 137 JSGlobalObject* Context::global_object() { |
| 130 return JSGlobalObject::cast(native_context()->extension()); | 138 return JSGlobalObject::cast(native_context()->extension()); |
| 131 } | 139 } |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 178 | 186 |
| 179 static PropertyAttributes GetAttributesForMode(VariableMode mode) { | 187 static PropertyAttributes GetAttributesForMode(VariableMode mode) { |
| 180 DCHECK(IsDeclaredVariableMode(mode)); | 188 DCHECK(IsDeclaredVariableMode(mode)); |
| 181 return mode == CONST ? READ_ONLY : NONE; | 189 return mode == CONST ? READ_ONLY : NONE; |
| 182 } | 190 } |
| 183 | 191 |
| 184 Handle<Object> Context::Lookup(Handle<String> name, ContextLookupFlags flags, | 192 Handle<Object> Context::Lookup(Handle<String> name, ContextLookupFlags flags, |
| 185 int* index, PropertyAttributes* attributes, | 193 int* index, PropertyAttributes* attributes, |
| 186 InitializationFlag* init_flag, | 194 InitializationFlag* init_flag, |
| 187 VariableMode* variable_mode) { | 195 VariableMode* variable_mode) { |
| 196 DCHECK(!IsModuleContext()); |
| 188 Isolate* isolate = GetIsolate(); | 197 Isolate* isolate = GetIsolate(); |
| 189 Handle<Context> context(this, isolate); | 198 Handle<Context> context(this, isolate); |
| 190 | 199 |
| 191 bool follow_context_chain = (flags & FOLLOW_CONTEXT_CHAIN) != 0; | 200 bool follow_context_chain = (flags & FOLLOW_CONTEXT_CHAIN) != 0; |
| 192 bool failed_whitelist = false; | 201 bool failed_whitelist = false; |
| 193 *index = kNotFound; | 202 *index = kNotFound; |
| 194 *attributes = ABSENT; | 203 *attributes = ABSENT; |
| 195 *init_flag = kCreatedInitialized; | 204 *init_flag = kCreatedInitialized; |
| 196 *variable_mode = VAR; | 205 *variable_mode = VAR; |
| 197 | 206 |
| (...skipping 357 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 555 | 564 |
| 556 int previous_value = errors_thrown()->value(); | 565 int previous_value = errors_thrown()->value(); |
| 557 set_errors_thrown(Smi::FromInt(previous_value + 1)); | 566 set_errors_thrown(Smi::FromInt(previous_value + 1)); |
| 558 } | 567 } |
| 559 | 568 |
| 560 | 569 |
| 561 int Context::GetErrorsThrown() { return errors_thrown()->value(); } | 570 int Context::GetErrorsThrown() { return errors_thrown()->value(); } |
| 562 | 571 |
| 563 } // namespace internal | 572 } // namespace internal |
| 564 } // namespace v8 | 573 } // namespace v8 |
| OLD | NEW |