| 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 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 return true; | 61 return true; |
| 62 } | 62 } |
| 63 if (!IsBlockContext()) return false; | 63 if (!IsBlockContext()) return false; |
| 64 Object* ext = extension(); | 64 Object* ext = extension(); |
| 65 // If we have the special extension, we immediately know it must be a | 65 // If we have the special extension, we immediately know it must be a |
| 66 // declaration scope. That's just a small performance shortcut. | 66 // declaration scope. That's just a small performance shortcut. |
| 67 return ext->IsSloppyBlockWithEvalContextExtension() | 67 return ext->IsContextExtension() || |
| 68 || ScopeInfo::cast(ext)->is_declaration_scope(); | 68 ScopeInfo::cast(ext)->is_declaration_scope(); |
| 69 } | 69 } |
| 70 | 70 |
| 71 | 71 |
| 72 Context* Context::declaration_context() { | 72 Context* Context::declaration_context() { |
| 73 Context* current = this; | 73 Context* current = this; |
| 74 while (!current->is_declaration_context()) { | 74 while (!current->is_declaration_context()) { |
| 75 current = current->previous(); | 75 current = current->previous(); |
| 76 DCHECK(current->closure() == closure()); | 76 DCHECK(current->closure() == closure()); |
| 77 } | 77 } |
| 78 return current; | 78 return current; |
| 79 } | 79 } |
| 80 | 80 |
| 81 Context* Context::closure_context() { | 81 Context* Context::closure_context() { |
| 82 Context* current = this; | 82 Context* current = this; |
| 83 while (!current->IsFunctionContext() && !current->IsScriptContext() && | 83 while (!current->IsFunctionContext() && !current->IsScriptContext() && |
| 84 !current->IsNativeContext()) { | 84 !current->IsNativeContext()) { |
| 85 current = current->previous(); | 85 current = current->previous(); |
| 86 DCHECK(current->closure() == closure()); | 86 DCHECK(current->closure() == closure()); |
| 87 } | 87 } |
| 88 return current; | 88 return current; |
| 89 } | 89 } |
| 90 | 90 |
| 91 JSObject* Context::extension_object() { | 91 JSObject* Context::extension_object() { |
| 92 DCHECK(IsNativeContext() || IsFunctionContext() || IsBlockContext()); | 92 DCHECK(IsNativeContext() || IsFunctionContext() || IsBlockContext()); |
| 93 HeapObject* object = extension(); | 93 HeapObject* object = extension(); |
| 94 if (object->IsTheHole(GetIsolate())) return nullptr; | 94 if (object->IsTheHole(GetIsolate())) return nullptr; |
| 95 if (IsBlockContext()) { | 95 if (IsBlockContext()) { |
| 96 if (!object->IsSloppyBlockWithEvalContextExtension()) return nullptr; | 96 if (!object->IsContextExtension()) return nullptr; |
| 97 object = SloppyBlockWithEvalContextExtension::cast(object)->extension(); | 97 object = JSObject::cast(ContextExtension::cast(object)->extension()); |
| 98 } | 98 } |
| 99 DCHECK(object->IsJSContextExtensionObject() || | 99 DCHECK(object->IsJSContextExtensionObject() || |
| 100 (IsNativeContext() && object->IsJSGlobalObject())); | 100 (IsNativeContext() && object->IsJSGlobalObject())); |
| 101 return JSObject::cast(object); | 101 return JSObject::cast(object); |
| 102 } | 102 } |
| 103 | 103 |
| 104 | 104 |
| 105 JSReceiver* Context::extension_receiver() { | 105 JSReceiver* Context::extension_receiver() { |
| 106 DCHECK(IsNativeContext() || IsWithContext() || | 106 DCHECK(IsNativeContext() || IsWithContext() || |
| 107 IsFunctionContext() || IsBlockContext()); | 107 IsFunctionContext() || IsBlockContext()); |
| 108 return IsWithContext() ? JSReceiver::cast(extension()) : extension_object(); | 108 return IsWithContext() ? JSReceiver::cast(extension()) : extension_object(); |
| 109 } | 109 } |
| 110 | 110 |
| 111 | 111 |
| 112 ScopeInfo* Context::scope_info() { | 112 ScopeInfo* Context::scope_info() { |
| 113 DCHECK(IsModuleContext() || IsScriptContext() || IsBlockContext()); | 113 DCHECK(IsModuleContext() || IsScriptContext() || IsBlockContext()); |
| 114 HeapObject* object = extension(); | 114 HeapObject* object = extension(); |
| 115 if (object->IsSloppyBlockWithEvalContextExtension()) { | 115 if (object->IsContextExtension()) { |
| 116 DCHECK(IsBlockContext()); | 116 DCHECK(IsBlockContext()); |
| 117 object = SloppyBlockWithEvalContextExtension::cast(object)->scope_info(); | 117 object = ContextExtension::cast(object)->scope_info(); |
| 118 } | 118 } |
| 119 return ScopeInfo::cast(object); | 119 return ScopeInfo::cast(object); |
| 120 } | 120 } |
| 121 | 121 |
| 122 | 122 |
| 123 String* Context::catch_name() { | 123 String* Context::catch_name() { |
| 124 DCHECK(IsCatchContext()); | 124 DCHECK(IsCatchContext()); |
| 125 return String::cast(extension()); | 125 return String::cast(extension()); |
| 126 } | 126 } |
| 127 | 127 |
| (...skipping 427 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 555 | 555 |
| 556 int previous_value = errors_thrown()->value(); | 556 int previous_value = errors_thrown()->value(); |
| 557 set_errors_thrown(Smi::FromInt(previous_value + 1)); | 557 set_errors_thrown(Smi::FromInt(previous_value + 1)); |
| 558 } | 558 } |
| 559 | 559 |
| 560 | 560 |
| 561 int Context::GetErrorsThrown() { return errors_thrown()->value(); } | 561 int Context::GetErrorsThrown() { return errors_thrown()->value(); } |
| 562 | 562 |
| 563 } // namespace internal | 563 } // namespace internal |
| 564 } // namespace v8 | 564 } // namespace v8 |
| OLD | NEW |