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. |
| 18 | class ExecutableAccessorInfo; |
| 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) \ |
| 25 | V(FunctionArguments) \ |
| 26 | V(FunctionCaller) \ |
| 27 | V(FunctionName) \ |
| 28 | V(FunctionLength) \ |
| 29 | V(FunctionPrototype) \ |
| 30 | V(ScriptColumnOffset) \ |
| 31 | V(ScriptCompilationType) \ |
| 32 | V(ScriptContextData) \ |
| 33 | V(ScriptEvalFromScript) \ |
| 34 | V(ScriptEvalFromScriptPosition) \ |
| 35 | V(ScriptEvalFromFunctionName) \ |
| 36 | V(ScriptId) \ |
| 37 | V(ScriptLineEnds) \ |
| 38 | V(ScriptLineOffset) \ |
| 39 | V(ScriptName) \ |
| 40 | V(ScriptSource) \ |
| 41 | V(ScriptType) \ |
| 42 | V(ScriptSourceUrl) \ |
| 43 | V(ScriptSourceMappingUrl) \ |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame^] | 44 | V(ScriptIsEmbedderDebugScript) \ |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 45 | V(StringLength) |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 46 | |
| 47 | // Accessors contains all predefined proxy accessors. |
| 48 | |
| 49 | class Accessors : public AllStatic { |
| 50 | public: |
| 51 | // Accessor descriptors. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 52 | #define ACCESSOR_INFO_DECLARATION(name) \ |
| 53 | static void name##Getter( \ |
| 54 | v8::Local<v8::Name> name, \ |
| 55 | const v8::PropertyCallbackInfo<v8::Value>& info); \ |
| 56 | static void name##Setter( \ |
| 57 | v8::Local<v8::Name> name, \ |
| 58 | v8::Local<v8::Value> value, \ |
| 59 | const v8::PropertyCallbackInfo<void>& info); \ |
| 60 | static Handle<AccessorInfo> name##Info( \ |
| 61 | Isolate* isolate, \ |
| 62 | PropertyAttributes attributes); |
| 63 | ACCESSOR_INFO_LIST(ACCESSOR_INFO_DECLARATION) |
| 64 | #undef ACCESSOR_INFO_DECLARATION |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 65 | |
| 66 | enum DescriptorId { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 67 | #define ACCESSOR_INFO_DECLARATION(name) \ |
| 68 | k##name##Getter, \ |
| 69 | k##name##Setter, |
| 70 | ACCESSOR_INFO_LIST(ACCESSOR_INFO_DECLARATION) |
| 71 | #undef ACCESSOR_INFO_DECLARATION |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 72 | descriptorCount |
| 73 | }; |
| 74 | |
| 75 | // Accessor functions called directly from the runtime system. |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 76 | MUST_USE_RESULT static MaybeHandle<Object> FunctionSetPrototype( |
| 77 | Handle<JSFunction> object, Handle<Object> value); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 78 | static Handle<Object> FunctionGetArguments(Handle<JSFunction> object); |
| 79 | |
| 80 | // Accessor infos. |
| 81 | static Handle<AccessorInfo> MakeModuleExport( |
| 82 | Handle<String> name, int index, PropertyAttributes attributes); |
| 83 | |
| 84 | // Returns true for properties that are accessors to object fields. |
| 85 | // If true, *object_offset contains offset of object field. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame^] | 86 | static bool IsJSObjectFieldAccessor(Handle<Map> map, Handle<Name> name, |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 87 | int* object_offset); |
| 88 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame^] | 89 | // Returns true for properties that are accessors to ArrayBufferView and |
| 90 | // derived classes fields. If true, *object_offset contains offset of |
| 91 | // object field. The caller still has to check whether the underlying |
| 92 | // buffer was neutered. |
| 93 | static bool IsJSArrayBufferViewFieldAccessor(Handle<Map> map, |
| 94 | Handle<Name> name, |
| 95 | int* object_offset); |
| 96 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 97 | static Handle<AccessorInfo> MakeAccessor( |
| 98 | Isolate* isolate, |
| 99 | Handle<Name> name, |
| 100 | AccessorNameGetterCallback getter, |
| 101 | AccessorNameSetterCallback setter, |
| 102 | PropertyAttributes attributes); |
| 103 | |
| 104 | static Handle<ExecutableAccessorInfo> CloneAccessor( |
| 105 | Isolate* isolate, |
| 106 | Handle<ExecutableAccessorInfo> accessor); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 107 | }; |
| 108 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame^] | 109 | } // namespace internal |
| 110 | } // namespace v8 |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 111 | |
| 112 | #endif // V8_ACCESSORS_H_ |