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/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 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
64 JSObject* Context::global_proxy() { | 64 JSObject* Context::global_proxy() { |
65 return native_context()->global_proxy_object(); | 65 return native_context()->global_proxy_object(); |
66 } | 66 } |
67 | 67 |
68 | 68 |
69 void Context::set_global_proxy(JSObject* object) { | 69 void Context::set_global_proxy(JSObject* object) { |
70 native_context()->set_global_proxy_object(object); | 70 native_context()->set_global_proxy_object(object); |
71 } | 71 } |
72 | 72 |
73 | 73 |
| 74 static PropertyAttributes GetWithContextAttributes(Isolate* isolate, |
| 75 Handle<String> name, |
| 76 Handle<JSReceiver> object) { |
| 77 Handle<Symbol> unscopables_symbol( |
| 78 isolate->native_context()->unscopables_symbol(), isolate); |
| 79 |
| 80 while (true) { |
| 81 PropertyAttributes name_attrs = |
| 82 JSReceiver::GetOwnPropertyAttributes(object, name); |
| 83 |
| 84 if (name_attrs != ABSENT) { |
| 85 PropertyAttributes unscopables_attrs = |
| 86 JSReceiver::GetOwnPropertyAttributes(object, unscopables_symbol); |
| 87 PropertyAttributes blocked_attrs = ABSENT; |
| 88 if (unscopables_attrs != ABSENT) { |
| 89 Handle<Object> unscopables_object; |
| 90 ASSIGN_RETURN_ON_EXCEPTION_VALUE( |
| 91 isolate, unscopables_object, |
| 92 Object::GetProperty(object, unscopables_symbol), name_attrs); |
| 93 |
| 94 if (unscopables_object->IsSpecObject()) { |
| 95 blocked_attrs = JSReceiver::GetOwnPropertyAttributes( |
| 96 Handle<JSReceiver>::cast(unscopables_object), name); |
| 97 } |
| 98 } |
| 99 |
| 100 if (blocked_attrs == ABSENT) { |
| 101 return name_attrs; |
| 102 } |
| 103 } |
| 104 |
| 105 Object* prototype = object->GetPrototype(); |
| 106 if (prototype->IsNull()) { |
| 107 return ABSENT; |
| 108 } |
| 109 ASSERT(prototype->IsSpecObject()); |
| 110 object = handle(JSReceiver::cast(prototype), isolate); |
| 111 } |
| 112 |
| 113 UNREACHABLE(); |
| 114 return ABSENT; |
| 115 } |
| 116 |
| 117 |
74 Handle<Object> Context::Lookup(Handle<String> name, | 118 Handle<Object> Context::Lookup(Handle<String> name, |
75 ContextLookupFlags flags, | 119 ContextLookupFlags flags, |
76 int* index, | 120 int* index, |
77 PropertyAttributes* attributes, | 121 PropertyAttributes* attributes, |
78 BindingFlags* binding_flags) { | 122 BindingFlags* binding_flags) { |
79 Isolate* isolate = GetIsolate(); | 123 Isolate* isolate = GetIsolate(); |
80 Handle<Context> context(this, isolate); | 124 Handle<Context> context(this, isolate); |
81 | 125 |
82 bool follow_context_chain = (flags & FOLLOW_CONTEXT_CHAIN) != 0; | 126 bool follow_context_chain = (flags & FOLLOW_CONTEXT_CHAIN) != 0; |
83 *index = -1; | 127 *index = -1; |
(...skipping 18 matching lines...) Expand all Loading... |
102 context->IsWithContext() || | 146 context->IsWithContext() || |
103 (context->IsFunctionContext() && context->has_extension())) { | 147 (context->IsFunctionContext() && context->has_extension())) { |
104 Handle<JSReceiver> object( | 148 Handle<JSReceiver> object( |
105 JSReceiver::cast(context->extension()), isolate); | 149 JSReceiver::cast(context->extension()), isolate); |
106 // Context extension objects needs to behave as if they have no | 150 // Context extension objects needs to behave as if they have no |
107 // prototype. So even if we want to follow prototype chains, we need | 151 // prototype. So even if we want to follow prototype chains, we need |
108 // to only do a local lookup for context extension objects. | 152 // to only do a local lookup for context extension objects. |
109 if ((flags & FOLLOW_PROTOTYPE_CHAIN) == 0 || | 153 if ((flags & FOLLOW_PROTOTYPE_CHAIN) == 0 || |
110 object->IsJSContextExtensionObject()) { | 154 object->IsJSContextExtensionObject()) { |
111 *attributes = JSReceiver::GetOwnPropertyAttributes(object, name); | 155 *attributes = JSReceiver::GetOwnPropertyAttributes(object, name); |
| 156 } else if (FLAG_harmony_unscopables && context->IsWithContext()) { |
| 157 *attributes = GetWithContextAttributes(isolate, name, object); |
112 } else { | 158 } else { |
113 *attributes = JSReceiver::GetPropertyAttributes(object, name); | 159 *attributes = JSReceiver::GetPropertyAttributes(object, name); |
114 } | 160 } |
| 161 |
115 if (isolate->has_pending_exception()) return Handle<Object>(); | 162 if (isolate->has_pending_exception()) return Handle<Object>(); |
116 | 163 |
117 if (*attributes != ABSENT) { | 164 if (*attributes != ABSENT) { |
118 if (FLAG_trace_contexts) { | 165 if (FLAG_trace_contexts) { |
119 PrintF("=> found property in context object %p\n", | 166 PrintF("=> found property in context object %p\n", |
120 reinterpret_cast<void*>(*object)); | 167 reinterpret_cast<void*>(*object)); |
121 } | 168 } |
122 return object; | 169 return object; |
123 } | 170 } |
124 } | 171 } |
(...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
367 bool Context::IsBootstrappingOrGlobalObject(Isolate* isolate, Object* object) { | 414 bool Context::IsBootstrappingOrGlobalObject(Isolate* isolate, Object* object) { |
368 // During bootstrapping we allow all objects to pass as global | 415 // During bootstrapping we allow all objects to pass as global |
369 // objects. This is necessary to fix circular dependencies. | 416 // objects. This is necessary to fix circular dependencies. |
370 return isolate->heap()->gc_state() != Heap::NOT_IN_GC || | 417 return isolate->heap()->gc_state() != Heap::NOT_IN_GC || |
371 isolate->bootstrapper()->IsActive() || | 418 isolate->bootstrapper()->IsActive() || |
372 object->IsGlobalObject(); | 419 object->IsGlobalObject(); |
373 } | 420 } |
374 #endif | 421 #endif |
375 | 422 |
376 } } // namespace v8::internal | 423 } } // namespace v8::internal |
OLD | NEW |