OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef V8_OBJECTS_H_ | 5 #ifndef V8_OBJECTS_H_ |
6 #define V8_OBJECTS_H_ | 6 #define V8_OBJECTS_H_ |
7 | 7 |
8 #include "src/allocation.h" | 8 #include "src/allocation.h" |
9 #include "src/assert-scope.h" | 9 #include "src/assert-scope.h" |
10 #include "src/builtins.h" | 10 #include "src/builtins.h" |
(...skipping 2207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2218 Handle<Name> name, | 2218 Handle<Name> name, |
2219 AccessorComponent component); | 2219 AccessorComponent component); |
2220 | 2220 |
2221 // Defines an AccessorPair property on the given object. | 2221 // Defines an AccessorPair property on the given object. |
2222 // TODO(mstarzinger): Rename to SetAccessor() and return empty handle on | 2222 // TODO(mstarzinger): Rename to SetAccessor() and return empty handle on |
2223 // exception instead of letting callers check for scheduled exception. | 2223 // exception instead of letting callers check for scheduled exception. |
2224 static void DefineAccessor(Handle<JSObject> object, | 2224 static void DefineAccessor(Handle<JSObject> object, |
2225 Handle<Name> name, | 2225 Handle<Name> name, |
2226 Handle<Object> getter, | 2226 Handle<Object> getter, |
2227 Handle<Object> setter, | 2227 Handle<Object> setter, |
2228 PropertyAttributes attributes, | 2228 PropertyAttributes attributes); |
2229 v8::AccessControl access_control = v8::DEFAULT); | |
2230 | 2229 |
2231 // Defines an AccessorInfo property on the given object. | 2230 // Defines an AccessorInfo property on the given object. |
2232 MUST_USE_RESULT static MaybeHandle<Object> SetAccessor( | 2231 MUST_USE_RESULT static MaybeHandle<Object> SetAccessor( |
2233 Handle<JSObject> object, | 2232 Handle<JSObject> object, |
2234 Handle<AccessorInfo> info); | 2233 Handle<AccessorInfo> info); |
2235 | 2234 |
2236 MUST_USE_RESULT static MaybeHandle<Object> GetPropertyWithInterceptor( | 2235 MUST_USE_RESULT static MaybeHandle<Object> GetPropertyWithInterceptor( |
2237 Handle<JSObject> object, | 2236 Handle<JSObject> object, |
2238 Handle<Object> receiver, | 2237 Handle<Object> receiver, |
2239 Handle<Name> name); | 2238 Handle<Name> name); |
(...skipping 574 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2814 Handle<Object> structure, | 2813 Handle<Object> structure, |
2815 PropertyAttributes attributes); | 2814 PropertyAttributes attributes); |
2816 static void SetPropertyCallback(Handle<JSObject> object, | 2815 static void SetPropertyCallback(Handle<JSObject> object, |
2817 Handle<Name> name, | 2816 Handle<Name> name, |
2818 Handle<Object> structure, | 2817 Handle<Object> structure, |
2819 PropertyAttributes attributes); | 2818 PropertyAttributes attributes); |
2820 static void DefineElementAccessor(Handle<JSObject> object, | 2819 static void DefineElementAccessor(Handle<JSObject> object, |
2821 uint32_t index, | 2820 uint32_t index, |
2822 Handle<Object> getter, | 2821 Handle<Object> getter, |
2823 Handle<Object> setter, | 2822 Handle<Object> setter, |
2824 PropertyAttributes attributes, | 2823 PropertyAttributes attributes); |
2825 v8::AccessControl access_control); | |
2826 static Handle<AccessorPair> CreateAccessorPairFor(Handle<JSObject> object, | 2824 static Handle<AccessorPair> CreateAccessorPairFor(Handle<JSObject> object, |
2827 Handle<Name> name); | 2825 Handle<Name> name); |
2828 static void DefinePropertyAccessor(Handle<JSObject> object, | 2826 static void DefinePropertyAccessor(Handle<JSObject> object, |
2829 Handle<Name> name, | 2827 Handle<Name> name, |
2830 Handle<Object> getter, | 2828 Handle<Object> getter, |
2831 Handle<Object> setter, | 2829 Handle<Object> setter, |
2832 PropertyAttributes attributes, | 2830 PropertyAttributes attributes); |
2833 v8::AccessControl access_control); | |
2834 | 2831 |
2835 // Try to define a single accessor paying attention to map transitions. | 2832 // Try to define a single accessor paying attention to map transitions. |
2836 // Returns false if this was not possible and we have to use the slow case. | 2833 // Returns false if this was not possible and we have to use the slow case. |
2837 static bool DefineFastAccessor(Handle<JSObject> object, | 2834 static bool DefineFastAccessor(Handle<JSObject> object, |
2838 Handle<Name> name, | 2835 Handle<Name> name, |
2839 AccessorComponent component, | 2836 AccessorComponent component, |
2840 Handle<Object> accessor, | 2837 Handle<Object> accessor, |
2841 PropertyAttributes attributes); | 2838 PropertyAttributes attributes); |
2842 | 2839 |
2843 | 2840 |
(...skipping 7881 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
10725 DISALLOW_IMPLICIT_CONSTRUCTORS(ExecutableAccessorInfo); | 10722 DISALLOW_IMPLICIT_CONSTRUCTORS(ExecutableAccessorInfo); |
10726 }; | 10723 }; |
10727 | 10724 |
10728 | 10725 |
10729 // Support for JavaScript accessors: A pair of a getter and a setter. Each | 10726 // Support for JavaScript accessors: A pair of a getter and a setter. Each |
10730 // accessor can either be | 10727 // accessor can either be |
10731 // * a pointer to a JavaScript function or proxy: a real accessor | 10728 // * a pointer to a JavaScript function or proxy: a real accessor |
10732 // * undefined: considered an accessor by the spec, too, strangely enough | 10729 // * undefined: considered an accessor by the spec, too, strangely enough |
10733 // * the hole: an accessor which has not been set | 10730 // * the hole: an accessor which has not been set |
10734 // * a pointer to a map: a transition used to ensure map sharing | 10731 // * a pointer to a map: a transition used to ensure map sharing |
10735 // access_flags provides the ability to override access checks on access check | |
10736 // failure. | |
10737 class AccessorPair: public Struct { | 10732 class AccessorPair: public Struct { |
10738 public: | 10733 public: |
10739 DECL_ACCESSORS(getter, Object) | 10734 DECL_ACCESSORS(getter, Object) |
10740 DECL_ACCESSORS(setter, Object) | 10735 DECL_ACCESSORS(setter, Object) |
10741 DECL_ACCESSORS(access_flags, Smi) | |
10742 | |
10743 inline void set_access_flags(v8::AccessControl access_control); | |
10744 inline bool all_can_read(); | |
10745 inline bool all_can_write(); | |
10746 | 10736 |
10747 static inline AccessorPair* cast(Object* obj); | 10737 static inline AccessorPair* cast(Object* obj); |
10748 | 10738 |
10749 static Handle<AccessorPair> Copy(Handle<AccessorPair> pair); | 10739 static Handle<AccessorPair> Copy(Handle<AccessorPair> pair); |
10750 | 10740 |
10751 Object* get(AccessorComponent component) { | 10741 Object* get(AccessorComponent component) { |
10752 return component == ACCESSOR_GETTER ? getter() : setter(); | 10742 return component == ACCESSOR_GETTER ? getter() : setter(); |
10753 } | 10743 } |
10754 | 10744 |
10755 void set(AccessorComponent component, Object* value) { | 10745 void set(AccessorComponent component, Object* value) { |
(...skipping 16 matching lines...) Expand all Loading... |
10772 bool ContainsAccessor() { | 10762 bool ContainsAccessor() { |
10773 return IsJSAccessor(getter()) || IsJSAccessor(setter()); | 10763 return IsJSAccessor(getter()) || IsJSAccessor(setter()); |
10774 } | 10764 } |
10775 | 10765 |
10776 // Dispatched behavior. | 10766 // Dispatched behavior. |
10777 DECLARE_PRINTER(AccessorPair) | 10767 DECLARE_PRINTER(AccessorPair) |
10778 DECLARE_VERIFIER(AccessorPair) | 10768 DECLARE_VERIFIER(AccessorPair) |
10779 | 10769 |
10780 static const int kGetterOffset = HeapObject::kHeaderSize; | 10770 static const int kGetterOffset = HeapObject::kHeaderSize; |
10781 static const int kSetterOffset = kGetterOffset + kPointerSize; | 10771 static const int kSetterOffset = kGetterOffset + kPointerSize; |
10782 static const int kAccessFlagsOffset = kSetterOffset + kPointerSize; | 10772 static const int kSize = kSetterOffset + kPointerSize; |
10783 static const int kSize = kAccessFlagsOffset + kPointerSize; | |
10784 | 10773 |
10785 private: | 10774 private: |
10786 static const int kAllCanReadBit = 0; | |
10787 static const int kAllCanWriteBit = 1; | |
10788 | |
10789 // Strangely enough, in addition to functions and harmony proxies, the spec | 10775 // Strangely enough, in addition to functions and harmony proxies, the spec |
10790 // requires us to consider undefined as a kind of accessor, too: | 10776 // requires us to consider undefined as a kind of accessor, too: |
10791 // var obj = {}; | 10777 // var obj = {}; |
10792 // Object.defineProperty(obj, "foo", {get: undefined}); | 10778 // Object.defineProperty(obj, "foo", {get: undefined}); |
10793 // assertTrue("foo" in obj); | 10779 // assertTrue("foo" in obj); |
10794 bool IsJSAccessor(Object* obj) { | 10780 bool IsJSAccessor(Object* obj) { |
10795 return obj->IsSpecFunction() || obj->IsUndefined(); | 10781 return obj->IsSpecFunction() || obj->IsUndefined(); |
10796 } | 10782 } |
10797 | 10783 |
10798 DISALLOW_IMPLICIT_CONSTRUCTORS(AccessorPair); | 10784 DISALLOW_IMPLICIT_CONSTRUCTORS(AccessorPair); |
(...skipping 450 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
11249 } else { | 11235 } else { |
11250 value &= ~(1 << bit_position); | 11236 value &= ~(1 << bit_position); |
11251 } | 11237 } |
11252 return value; | 11238 return value; |
11253 } | 11239 } |
11254 }; | 11240 }; |
11255 | 11241 |
11256 } } // namespace v8::internal | 11242 } } // namespace v8::internal |
11257 | 11243 |
11258 #endif // V8_OBJECTS_H_ | 11244 #endif // V8_OBJECTS_H_ |
OLD | NEW |