Chromium Code Reviews| Index: src/unscopables.h |
| diff --git a/src/unscopables.h b/src/unscopables.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..d28b572db2ca2659f9dad89c42118571ff40bec7 |
| --- /dev/null |
| +++ b/src/unscopables.h |
| @@ -0,0 +1,100 @@ |
| +// 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/objects.h" |
| +#include "src/prototype.h" |
| + |
| +namespace v8 { |
| +namespace internal { |
| + |
| + |
| +/** |
| + * A helper class for doing the property lookup for unscopables. This is used |
| + * For HasBinding and GetBindingValue spec algorithms for ObjectEnvironment. |
| + */ |
| +class UnscopableLookup { |
|
rossberg
2014/07/17 15:12:13
Hm, this class seems overkill to me. It should be
arv (Not doing code reviews)
2014/07/17 23:34:36
Done.
|
| + public: |
| + UnscopableLookup(Isolate* isolate, Handle<String> name, |
| + Handle<JSReceiver> object) |
| + : isolate_(isolate), |
| + name_(name), |
| + object_(object), |
| + property_attrs_(ABSENT), |
| + has_error_(false) { |
| + Lookup(); |
| + } |
| + |
| + bool Found() const { return property_attrs_ != ABSENT; } |
| + |
| + bool HasError() const { return has_error_; } |
| + |
| + Handle<JSReceiver> GetHolder() const { |
| + ASSERT(Found()); |
| + return object_; |
| + } |
| + |
| + PropertyAttributes GetPropertyAttributes() const { return property_attrs_; } |
| + |
| + private: |
| + void Lookup() { |
| + Handle<Symbol> unscopables_symbol( |
| + isolate_->native_context()->unscopables_symbol(), isolate_); |
| + |
| + for (PrototypeIterator iter(isolate_, object_, |
| + PrototypeIterator::START_AT_RECEIVER); |
| + !iter.IsAtEnd(); iter.Advance()) { |
| + Handle<JSReceiver> object = |
| + Handle<JSReceiver>::cast(PrototypeIterator::GetCurrent(iter)); |
| + |
| + PropertyAttributes name_attrs = |
| + JSReceiver::GetOwnPropertyAttributes(object, name_); |
|
rossberg
2014/07/17 15:12:13
Shouldn't this call HasOwnProperty?
arv (Not doing code reviews)
2014/07/17 23:34:36
The caller needs the PropertyAttributes.
|
| + |
| + if (name_attrs != ABSENT) { |
| + PropertyAttributes unscopables_attrs = |
| + JSReceiver::GetOwnPropertyAttributes(object, unscopables_symbol); |
|
rossberg
2014/07/17 15:12:13
Same here?
arv (Not doing code reviews)
2014/07/17 23:34:36
This one can be changed though.
|
| + PropertyAttributes blocked_attrs = ABSENT; |
| + if (unscopables_attrs != ABSENT) { |
| + MaybeHandle<Object> maybe_unscopables_object = |
| + Object::GetProperty(object, unscopables_symbol); |
| + Handle<Object> unscopables_object; |
| + if (!maybe_unscopables_object.ToHandle(&unscopables_object)) { |
| + ASSERT(isolate_->has_pending_exception()); |
| + has_error_ = true; |
| + return; |
| + } |
| + |
| + if (unscopables_object->IsSpecObject()) { |
| + blocked_attrs = JSReceiver::GetOwnPropertyAttributes( |
|
rossberg
2014/07/17 15:12:13
And here?
arv (Not doing code reviews)
2014/07/17 23:34:36
This can also be changed.
|
| + Handle<JSReceiver>::cast(unscopables_object), name_); |
| + } |
| + } |
| + |
| + if (blocked_attrs == ABSENT) { |
| + object_ = object; |
| + property_attrs_ = name_attrs; |
| + return; |
| + } |
| + } |
| + } |
| + } |
| + |
| + Isolate* isolate_; |
| + Handle<Name> name_; |
| + Handle<JSReceiver> object_; |
| + PropertyAttributes property_attrs_; |
| + bool has_error_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(UnscopableLookup); |
| +}; |
| + |
| + |
| +} // namespace internal |
| + |
| +} // namespace v8 |
| + |
| +#endif // V8_UNSCOPABLES_H_ |