OLD | NEW |
(Empty) | |
| 1 // Copyright 2014 the V8 project authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef V8_UNSCOPABLES_H_ |
| 6 #define V8_UNSCOPABLES_H_ |
| 7 |
| 8 #include "src/isolate.h" |
| 9 #include "src/objects.h" |
| 10 #include "src/prototype.h" |
| 11 |
| 12 namespace v8 { |
| 13 namespace internal { |
| 14 |
| 15 |
| 16 /** |
| 17 * Lookups a property in an object environment, taking the unscopables into |
| 18 * account. This is used For HasBinding and GetBindingValue spec algorithms for |
| 19 * ObjectEnvironment. |
| 20 */ |
| 21 static PropertyAttributes UnscopableLookup(Isolate* isolate, |
| 22 Handle<JSReceiver> object, |
| 23 Handle<String> name, |
| 24 Handle<JSReceiver>* holder, |
| 25 bool* ok) { |
| 26 Handle<Symbol> unscopables_symbol( |
| 27 isolate->native_context()->unscopables_symbol(), isolate); |
| 28 *ok = true; |
| 29 |
| 30 for (PrototypeIterator iter(isolate, object, |
| 31 PrototypeIterator::START_AT_RECEIVER); |
| 32 !iter.IsAtEnd(); iter.Advance()) { |
| 33 Handle<JSReceiver> object = |
| 34 Handle<JSReceiver>::cast(PrototypeIterator::GetCurrent(iter)); |
| 35 |
| 36 PropertyAttributes name_attrs = |
| 37 JSReceiver::GetOwnPropertyAttributes(object, name); |
| 38 if (name_attrs != ABSENT) { |
| 39 bool has_unscopables = |
| 40 JSReceiver::HasOwnProperty(object, unscopables_symbol); |
| 41 bool blocked = false; |
| 42 if (has_unscopables) { |
| 43 MaybeHandle<Object> maybe_unscopables_object = |
| 44 Object::GetProperty(object, unscopables_symbol); |
| 45 Handle<Object> unscopables_object; |
| 46 if (!maybe_unscopables_object.ToHandle(&unscopables_object)) { |
| 47 ASSERT(isolate->has_pending_exception()); |
| 48 *ok = false; |
| 49 return ABSENT; |
| 50 } |
| 51 if (unscopables_object->IsSpecObject()) { |
| 52 blocked = JSReceiver::HasOwnProperty( |
| 53 Handle<JSReceiver>::cast(unscopables_object), name); |
| 54 } |
| 55 } |
| 56 |
| 57 if (!blocked) { |
| 58 *holder = object; |
| 59 return name_attrs; |
| 60 } |
| 61 } |
| 62 } |
| 63 return ABSENT; |
| 64 } |
| 65 |
| 66 |
| 67 } } // namespace v8::internal |
| 68 |
| 69 #endif // V8_UNSCOPABLES_H_ |
OLD | NEW |