Index: src/unscopables.h |
diff --git a/src/unscopables.h b/src/unscopables.h |
new file mode 100644 |
index 0000000000000000000000000000000000000000..092a83fa7699a1e3f37264224f04bb3305c7730b |
--- /dev/null |
+++ b/src/unscopables.h |
@@ -0,0 +1,79 @@ |
+// 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 { |
+ |
+#define RETURN_ON_NO_VALUE_TYPE(isolate, type, name, __value__, return_type) \ |
+ type name; \ |
+ do { \ |
+ Maybe<type> __maybe__ = __value__; \ |
+ if (!__maybe__.has_value) { \ |
+ ASSERT((isolate)->has_pending_exception()); \ |
+ return Maybe<return_type>(); \ |
+ } \ |
+ name = __maybe__.value; \ |
+ } while (false) |
Toon Verwaest
2014/07/29 15:12:39
Can you please move these macros next to the other
arv (Not doing code reviews)
2014/07/30 15:39:38
It feels kind of wrong to assume that all usages o
|
+ |
+#define RETURN_ON_NO_VALUE(isolate, type, name, __value__) \ |
+ RETURN_ON_NO_VALUE_TYPE(isolate, type, name, __value__, type) |
+ |
+static Maybe<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 = it->GetHolder<JSReceiver>(); |
+ RETURN_ON_NO_VALUE(isolate, bool, has_own, |
+ JSReceiver::HasOwnProperty(object, unscopables_symbol)); |
+ if (!has_own) return Maybe<bool>(false); |
+ |
+ Handle<Object> unscopables; |
+ MaybeHandle<Object> maybe_unscopables = |
+ Object::GetProperty(object, unscopables_symbol); |
+ if (!maybe_unscopables.ToHandle(&unscopables)) { |
+ return Maybe<bool>(); |
+ } |
+ if (!unscopables->IsSpecObject()) return Maybe<bool>(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 Maybe<PropertyAttributes> UnscopableLookup(LookupIterator* it) { |
+ Isolate* isolate = it->isolate(); |
+ while (true) { |
+ RETURN_ON_NO_VALUE(isolate, PropertyAttributes, attrs, |
+ JSReceiver::GetPropertyAttributes(it)); |
+ if (attrs == ABSENT) break; |
+ RETURN_ON_NO_VALUE_TYPE(isolate, bool, blocked, BlockedByUnscopables(it), |
+ PropertyAttributes); |
+ if (!blocked) return Maybe<PropertyAttributes>(attrs); |
+ it->Next(); |
+ } |
+ |
+ return Maybe<PropertyAttributes>(ABSENT); |
+} |
+ |
+ |
+#undef RETURN_ON_NO_VALUE |
+#undef RETURN_ON_NO_VALUE_TYPE |
+} |
+} // namespace v8::internal |
+ |
+#endif // V8_UNSCOPABLES_H_ |