Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(180)

Side by Side Diff: src/unscopables.h

Issue 384963002: ES6 Unscopables (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Changed tests to test multiple object types Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(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 * A helper class for doing the property lookup for unscopables. This is used
18 * For HasBinding and GetBindingValue spec algorithms for ObjectEnvironment.
19 */
20 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.
21 public:
22 UnscopableLookup(Isolate* isolate, Handle<String> name,
23 Handle<JSReceiver> object)
24 : isolate_(isolate),
25 name_(name),
26 object_(object),
27 property_attrs_(ABSENT),
28 has_error_(false) {
29 Lookup();
30 }
31
32 bool Found() const { return property_attrs_ != ABSENT; }
33
34 bool HasError() const { return has_error_; }
35
36 Handle<JSReceiver> GetHolder() const {
37 ASSERT(Found());
38 return object_;
39 }
40
41 PropertyAttributes GetPropertyAttributes() const { return property_attrs_; }
42
43 private:
44 void Lookup() {
45 Handle<Symbol> unscopables_symbol(
46 isolate_->native_context()->unscopables_symbol(), isolate_);
47
48 for (PrototypeIterator iter(isolate_, object_,
49 PrototypeIterator::START_AT_RECEIVER);
50 !iter.IsAtEnd(); iter.Advance()) {
51 Handle<JSReceiver> object =
52 Handle<JSReceiver>::cast(PrototypeIterator::GetCurrent(iter));
53
54 PropertyAttributes name_attrs =
55 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.
56
57 if (name_attrs != ABSENT) {
58 PropertyAttributes unscopables_attrs =
59 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.
60 PropertyAttributes blocked_attrs = ABSENT;
61 if (unscopables_attrs != ABSENT) {
62 MaybeHandle<Object> maybe_unscopables_object =
63 Object::GetProperty(object, unscopables_symbol);
64 Handle<Object> unscopables_object;
65 if (!maybe_unscopables_object.ToHandle(&unscopables_object)) {
66 ASSERT(isolate_->has_pending_exception());
67 has_error_ = true;
68 return;
69 }
70
71 if (unscopables_object->IsSpecObject()) {
72 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.
73 Handle<JSReceiver>::cast(unscopables_object), name_);
74 }
75 }
76
77 if (blocked_attrs == ABSENT) {
78 object_ = object;
79 property_attrs_ = name_attrs;
80 return;
81 }
82 }
83 }
84 }
85
86 Isolate* isolate_;
87 Handle<Name> name_;
88 Handle<JSReceiver> object_;
89 PropertyAttributes property_attrs_;
90 bool has_error_;
91
92 DISALLOW_COPY_AND_ASSIGN(UnscopableLookup);
93 };
94
95
96 } // namespace internal
97
98 } // namespace v8
99
100 #endif // V8_UNSCOPABLES_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698