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 /** |
| 75 * Lookups a property in an object environment, taking the unscopables into |
| 76 * account. This is used For HasBinding spec algorithms for ObjectEnvironment. |
| 77 */ |
| 78 static Maybe<PropertyAttributes> UnscopableLookup(LookupIterator* it) { |
| 79 Isolate* isolate = it->isolate(); |
| 80 |
| 81 Maybe<PropertyAttributes> attrs = JSReceiver::GetPropertyAttributes(it); |
| 82 DCHECK(attrs.has_value || isolate->has_pending_exception()); |
| 83 if (!attrs.has_value || attrs.value == ABSENT) return attrs; |
| 84 |
| 85 Handle<Symbol> unscopables_symbol( |
| 86 isolate->native_context()->unscopables_symbol(), isolate); |
| 87 Handle<Object> receiver = it->GetReceiver(); |
| 88 Handle<Object> unscopables; |
| 89 MaybeHandle<Object> maybe_unscopables = |
| 90 Object::GetProperty(receiver, unscopables_symbol); |
| 91 if (!maybe_unscopables.ToHandle(&unscopables)) { |
| 92 return Maybe<PropertyAttributes>(); |
| 93 } |
| 94 if (!unscopables->IsSpecObject()) return attrs; |
| 95 Maybe<bool> blacklist = JSReceiver::HasProperty( |
| 96 Handle<JSReceiver>::cast(unscopables), it->name()); |
| 97 if (!blacklist.has_value) { |
| 98 DCHECK(isolate->has_pending_exception()); |
| 99 return Maybe<PropertyAttributes>(); |
| 100 } |
| 101 if (blacklist.value) return maybe(ABSENT); |
| 102 return attrs; |
| 103 } |
| 104 |
| 105 |
74 Handle<Object> Context::Lookup(Handle<String> name, | 106 Handle<Object> Context::Lookup(Handle<String> name, |
75 ContextLookupFlags flags, | 107 ContextLookupFlags flags, |
76 int* index, | 108 int* index, |
77 PropertyAttributes* attributes, | 109 PropertyAttributes* attributes, |
78 BindingFlags* binding_flags) { | 110 BindingFlags* binding_flags) { |
79 Isolate* isolate = GetIsolate(); | 111 Isolate* isolate = GetIsolate(); |
80 Handle<Context> context(this, isolate); | 112 Handle<Context> context(this, isolate); |
81 | 113 |
82 bool follow_context_chain = (flags & FOLLOW_CONTEXT_CHAIN) != 0; | 114 bool follow_context_chain = (flags & FOLLOW_CONTEXT_CHAIN) != 0; |
83 *index = -1; | 115 *index = -1; |
(...skipping 19 matching lines...) Expand all Loading... |
103 (context->IsFunctionContext() && context->has_extension())) { | 135 (context->IsFunctionContext() && context->has_extension())) { |
104 Handle<JSReceiver> object( | 136 Handle<JSReceiver> object( |
105 JSReceiver::cast(context->extension()), isolate); | 137 JSReceiver::cast(context->extension()), isolate); |
106 // Context extension objects needs to behave as if they have no | 138 // Context extension objects needs to behave as if they have no |
107 // prototype. So even if we want to follow prototype chains, we need | 139 // prototype. So even if we want to follow prototype chains, we need |
108 // to only do a local lookup for context extension objects. | 140 // to only do a local lookup for context extension objects. |
109 Maybe<PropertyAttributes> maybe; | 141 Maybe<PropertyAttributes> maybe; |
110 if ((flags & FOLLOW_PROTOTYPE_CHAIN) == 0 || | 142 if ((flags & FOLLOW_PROTOTYPE_CHAIN) == 0 || |
111 object->IsJSContextExtensionObject()) { | 143 object->IsJSContextExtensionObject()) { |
112 maybe = JSReceiver::GetOwnPropertyAttributes(object, name); | 144 maybe = JSReceiver::GetOwnPropertyAttributes(object, name); |
| 145 } else if (FLAG_harmony_unscopables && context->IsWithContext()) { |
| 146 LookupIterator it(object, name); |
| 147 maybe = UnscopableLookup(&it); |
113 } else { | 148 } else { |
114 maybe = JSReceiver::GetPropertyAttributes(object, name); | 149 maybe = JSReceiver::GetPropertyAttributes(object, name); |
115 } | 150 } |
| 151 |
116 if (!maybe.has_value) return Handle<Object>(); | 152 if (!maybe.has_value) return Handle<Object>(); |
117 DCHECK(!isolate->has_pending_exception()); | 153 DCHECK(!isolate->has_pending_exception()); |
118 *attributes = maybe.value; | 154 *attributes = maybe.value; |
119 | 155 |
120 if (maybe.value != ABSENT) { | 156 if (maybe.value != ABSENT) { |
121 if (FLAG_trace_contexts) { | 157 if (FLAG_trace_contexts) { |
122 PrintF("=> found property in context object %p\n", | 158 PrintF("=> found property in context object %p\n", |
123 reinterpret_cast<void*>(*object)); | 159 reinterpret_cast<void*>(*object)); |
124 } | 160 } |
125 return object; | 161 return object; |
(...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
373 bool Context::IsBootstrappingOrGlobalObject(Isolate* isolate, Object* object) { | 409 bool Context::IsBootstrappingOrGlobalObject(Isolate* isolate, Object* object) { |
374 // During bootstrapping we allow all objects to pass as global | 410 // During bootstrapping we allow all objects to pass as global |
375 // objects. This is necessary to fix circular dependencies. | 411 // objects. This is necessary to fix circular dependencies. |
376 return isolate->heap()->gc_state() != Heap::NOT_IN_GC || | 412 return isolate->heap()->gc_state() != Heap::NOT_IN_GC || |
377 isolate->bootstrapper()->IsActive() || | 413 isolate->bootstrapper()->IsActive() || |
378 object->IsGlobalObject(); | 414 object->IsGlobalObject(); |
379 } | 415 } |
380 #endif | 416 #endif |
381 | 417 |
382 } } // namespace v8::internal | 418 } } // namespace v8::internal |
OLD | NEW |