Chromium Code Reviews| Index: src/unscopables.h |
| diff --git a/src/unscopables.h b/src/unscopables.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..f96d0212a5fe9ae7087350e25ded26c968903e16 |
| --- /dev/null |
| +++ b/src/unscopables.h |
| @@ -0,0 +1,61 @@ |
| +// Copyright 2014 the V8 project authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#ifndef V8_UNSCOPABLES_H_ |
| +#define V8_UNSCOPABLES_H_ |
| + |
| +#include "src/isolate.h" |
| +#include "src/lookup.h" |
| +#include "src/objects.h" |
| +#include "src/prototype.h" |
| + |
| +namespace v8 { |
| +namespace internal { |
| + |
| + |
| +static bool BlockedByUnscopables(LookupIterator* it) { |
| + Isolate* isolate = it->isolate(); |
| + Handle<Symbol> unscopables_symbol( |
| + isolate->native_context()->unscopables_symbol(), isolate); |
| + |
| + // TODO(arv): This should be GetNonHiddenHolder |
| + Handle<JSReceiver> object; |
| + if (it->state() == LookupIterator::JSPROXY) { |
|
arv (Not doing code reviews)
2014/07/23 23:10:40
Toon, this is a bit ugly. I was considering adding
|
| + object = it->GetJSProxy(); |
| + } else { |
| + object = it->GetHolder(); |
| + } |
| + |
| + if (!JSReceiver::HasOwnProperty(object, unscopables_symbol)) return false; |
| + Handle<Object> unscopables; |
| + MaybeHandle<Object> maybe_unscopables = |
| + Object::GetProperty(object, unscopables_symbol); |
| + if (!maybe_unscopables.ToHandle(&unscopables)) return false; |
| + if (!unscopables->IsSpecObject()) return false; |
| + return JSReceiver::HasOwnProperty(Handle<JSReceiver>::cast(unscopables), |
| + it->name()); |
| +} |
| + |
| + |
| +/** |
| + * Lookups a property in an object environment, taking the unscopables into |
| + * account. This is used For HasBinding and GetBindingValue spec algorithms for |
| + * ObjectEnvironment. |
| + */ |
| +static PropertyAttributes UnscopableLookup(LookupIterator* it) { |
| + PropertyAttributes attrs; |
| + while ((attrs = JSReceiver::GetPropertyAttributes(it)) != ABSENT) { |
| + if (!BlockedByUnscopables(it)) { |
| + return attrs; |
| + } |
| + it->Next(); |
| + } |
| + |
| + return ABSENT; |
| +} |
| +} |
| + |
| +} // namespace v8::internal |
| + |
| +#endif // V8_UNSCOPABLES_H_ |