Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1 | // Copyright 2012 the V8 project authors. All rights reserved. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 4 | |
| 5 | #ifndef V8_ACCESSORS_H_ |
| 6 | #define V8_ACCESSORS_H_ |
| 7 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 8 | #include "include/v8.h" |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 9 | #include "src/allocation.h" |
| 10 | #include "src/globals.h" |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 11 | #include "src/handles.h" |
| 12 | #include "src/property-details.h" |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 13 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 14 | namespace v8 { |
| 15 | namespace internal { |
| 16 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 17 | // Forward declarations. |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 18 | class AccessorInfo; |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 19 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 20 | // The list of accessor descriptors. This is a second-order macro |
| 21 | // taking a macro to be applied to all accessor descriptor names. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 22 | #define ACCESSOR_INFO_LIST(V) \ |
| 23 | V(ArgumentsIterator) \ |
| 24 | V(ArrayLength) \ |
Ben Murdoch | c561043 | 2016-08-08 18:44:38 +0100 | [diff] [blame] | 25 | V(BoundFunctionLength) \ |
| 26 | V(BoundFunctionName) \ |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 27 | V(FunctionArguments) \ |
| 28 | V(FunctionCaller) \ |
| 29 | V(FunctionName) \ |
| 30 | V(FunctionLength) \ |
| 31 | V(FunctionPrototype) \ |
| 32 | V(ScriptColumnOffset) \ |
| 33 | V(ScriptCompilationType) \ |
| 34 | V(ScriptContextData) \ |
| 35 | V(ScriptEvalFromScript) \ |
| 36 | V(ScriptEvalFromScriptPosition) \ |
| 37 | V(ScriptEvalFromFunctionName) \ |
| 38 | V(ScriptId) \ |
| 39 | V(ScriptLineEnds) \ |
| 40 | V(ScriptLineOffset) \ |
| 41 | V(ScriptName) \ |
| 42 | V(ScriptSource) \ |
| 43 | V(ScriptType) \ |
| 44 | V(ScriptSourceUrl) \ |
| 45 | V(ScriptSourceMappingUrl) \ |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 46 | V(ScriptIsEmbedderDebugScript) \ |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 47 | V(StringLength) |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 48 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 49 | #define ACCESSOR_SETTER_LIST(V) \ |
| 50 | V(ReconfigureToDataProperty) \ |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 51 | V(ArrayLengthSetter) \ |
| 52 | V(FunctionPrototypeSetter) |
| 53 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 54 | // Accessors contains all predefined proxy accessors. |
| 55 | |
| 56 | class Accessors : public AllStatic { |
| 57 | public: |
| 58 | // Accessor descriptors. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 59 | #define ACCESSOR_INFO_DECLARATION(name) \ |
| 60 | static void name##Getter( \ |
| 61 | v8::Local<v8::Name> name, \ |
| 62 | const v8::PropertyCallbackInfo<v8::Value>& info); \ |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 63 | static Handle<AccessorInfo> name##Info( \ |
| 64 | Isolate* isolate, \ |
| 65 | PropertyAttributes attributes); |
| 66 | ACCESSOR_INFO_LIST(ACCESSOR_INFO_DECLARATION) |
| 67 | #undef ACCESSOR_INFO_DECLARATION |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 68 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 69 | #define ACCESSOR_SETTER_DECLARATION(name) \ |
| 70 | static void name(v8::Local<v8::Name> name, v8::Local<v8::Value> value, \ |
| 71 | const v8::PropertyCallbackInfo<void>& info); |
| 72 | ACCESSOR_SETTER_LIST(ACCESSOR_SETTER_DECLARATION) |
| 73 | #undef ACCESSOR_SETTER_DECLARATION |
| 74 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 75 | enum DescriptorId { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 76 | #define ACCESSOR_INFO_DECLARATION(name) \ |
| 77 | k##name##Getter, \ |
| 78 | k##name##Setter, |
| 79 | ACCESSOR_INFO_LIST(ACCESSOR_INFO_DECLARATION) |
| 80 | #undef ACCESSOR_INFO_DECLARATION |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 81 | descriptorCount |
| 82 | }; |
| 83 | |
| 84 | // Accessor functions called directly from the runtime system. |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 85 | MUST_USE_RESULT static MaybeHandle<Object> FunctionSetPrototype( |
| 86 | Handle<JSFunction> object, Handle<Object> value); |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 87 | static Handle<JSObject> FunctionGetArguments(Handle<JSFunction> object); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 88 | |
| 89 | // Accessor infos. |
| 90 | static Handle<AccessorInfo> MakeModuleExport( |
| 91 | Handle<String> name, int index, PropertyAttributes attributes); |
| 92 | |
| 93 | // Returns true for properties that are accessors to object fields. |
| 94 | // If true, *object_offset contains offset of object field. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 95 | static bool IsJSObjectFieldAccessor(Handle<Map> map, Handle<Name> name, |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 96 | int* object_offset); |
| 97 | |
| 98 | static Handle<AccessorInfo> MakeAccessor( |
| 99 | Isolate* isolate, |
| 100 | Handle<Name> name, |
| 101 | AccessorNameGetterCallback getter, |
| 102 | AccessorNameSetterCallback setter, |
| 103 | PropertyAttributes attributes); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 104 | }; |
| 105 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 106 | } // namespace internal |
| 107 | } // namespace v8 |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 108 | |
| 109 | #endif // V8_ACCESSORS_H_ |