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 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
94 if (object->IsTheHole(GetIsolate())) return nullptr; | 94 if (object->IsTheHole(GetIsolate())) return nullptr; |
95 if (IsBlockContext()) { | 95 if (IsBlockContext()) { |
96 if (!object->IsContextExtension()) return nullptr; | 96 if (!object->IsContextExtension()) return nullptr; |
97 object = JSObject::cast(ContextExtension::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 | |
105 JSReceiver* Context::extension_receiver() { | 104 JSReceiver* Context::extension_receiver() { |
106 DCHECK(IsNativeContext() || IsWithContext() || | 105 DCHECK(IsNativeContext() || IsWithContext() || |
107 IsFunctionContext() || IsBlockContext()); | 106 IsFunctionContext() || IsBlockContext()); |
108 return IsWithContext() ? JSReceiver::cast(extension()) : extension_object(); | 107 return IsWithContext() ? JSReceiver::cast( |
| 108 ContextExtension::cast(extension())->extension()) |
| 109 : extension_object(); |
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 IsCatchContext()); | 114 IsCatchContext() || IsWithContext() || IsDebugEvaluateContext()); |
115 HeapObject* object = extension(); | 115 HeapObject* object = extension(); |
116 if (object->IsContextExtension()) { | 116 if (object->IsContextExtension()) { |
117 DCHECK(IsBlockContext() || IsCatchContext()); | 117 DCHECK(IsBlockContext() || IsCatchContext() || IsWithContext() || |
| 118 IsDebugEvaluateContext()); |
118 object = ContextExtension::cast(object)->scope_info(); | 119 object = ContextExtension::cast(object)->scope_info(); |
119 } | 120 } |
120 return ScopeInfo::cast(object); | 121 return ScopeInfo::cast(object); |
121 } | 122 } |
122 | 123 |
123 | 124 |
124 String* Context::catch_name() { | 125 String* Context::catch_name() { |
125 DCHECK(IsCatchContext()); | 126 DCHECK(IsCatchContext()); |
126 return String::cast(ContextExtension::cast(extension())->extension()); | 127 return String::cast(ContextExtension::cast(extension())->extension()); |
127 } | 128 } |
(...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
333 PrintF("=> found in catch context\n"); | 334 PrintF("=> found in catch context\n"); |
334 } | 335 } |
335 *index = Context::THROWN_OBJECT_INDEX; | 336 *index = Context::THROWN_OBJECT_INDEX; |
336 *attributes = NONE; | 337 *attributes = NONE; |
337 *init_flag = kCreatedInitialized; | 338 *init_flag = kCreatedInitialized; |
338 *variable_mode = VAR; | 339 *variable_mode = VAR; |
339 return context; | 340 return context; |
340 } | 341 } |
341 } else if (context->IsDebugEvaluateContext()) { | 342 } else if (context->IsDebugEvaluateContext()) { |
342 // Check materialized locals. | 343 // Check materialized locals. |
343 Object* obj = context->get(EXTENSION_INDEX); | 344 Object* ext = context->get(EXTENSION_INDEX); |
344 if (obj->IsJSReceiver()) { | 345 if (ext->IsContextExtension()) { |
345 Handle<JSReceiver> extension(JSReceiver::cast(obj)); | 346 Object* obj = ContextExtension::cast(ext)->extension(); |
346 LookupIterator it(extension, name, extension); | 347 if (obj->IsJSReceiver()) { |
347 Maybe<bool> found = JSReceiver::HasProperty(&it); | 348 Handle<JSReceiver> extension(JSReceiver::cast(obj)); |
348 if (found.FromMaybe(false)) { | 349 LookupIterator it(extension, name, extension); |
349 *attributes = NONE; | 350 Maybe<bool> found = JSReceiver::HasProperty(&it); |
350 return extension; | 351 if (found.FromMaybe(false)) { |
| 352 *attributes = NONE; |
| 353 return extension; |
| 354 } |
351 } | 355 } |
352 } | 356 } |
353 // Check the original context, but do not follow its context chain. | 357 // Check the original context, but do not follow its context chain. |
354 obj = context->get(WRAPPED_CONTEXT_INDEX); | 358 Object* obj = context->get(WRAPPED_CONTEXT_INDEX); |
355 if (obj->IsContext()) { | 359 if (obj->IsContext()) { |
356 Handle<Object> result = | 360 Handle<Object> result = |
357 Context::cast(obj)->Lookup(name, DONT_FOLLOW_CHAINS, index, | 361 Context::cast(obj)->Lookup(name, DONT_FOLLOW_CHAINS, index, |
358 attributes, init_flag, variable_mode); | 362 attributes, init_flag, variable_mode); |
359 if (!result.is_null()) return result; | 363 if (!result.is_null()) return result; |
360 } | 364 } |
361 // Check whitelist. Names that do not pass whitelist shall only resolve | 365 // Check whitelist. Names that do not pass whitelist shall only resolve |
362 // to with, script or native contexts up the context chain. | 366 // to with, script or native contexts up the context chain. |
363 obj = context->get(WHITE_LIST_INDEX); | 367 obj = context->get(WHITE_LIST_INDEX); |
364 if (obj->IsStringSet()) { | 368 if (obj->IsStringSet()) { |
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
556 | 560 |
557 int previous_value = errors_thrown()->value(); | 561 int previous_value = errors_thrown()->value(); |
558 set_errors_thrown(Smi::FromInt(previous_value + 1)); | 562 set_errors_thrown(Smi::FromInt(previous_value + 1)); |
559 } | 563 } |
560 | 564 |
561 | 565 |
562 int Context::GetErrorsThrown() { return errors_thrown()->value(); } | 566 int Context::GetErrorsThrown() { return errors_thrown()->value(); } |
563 | 567 |
564 } // namespace internal | 568 } // namespace internal |
565 } // namespace v8 | 569 } // namespace v8 |
OLD | NEW |