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 3 // found in the LICENSE file. 4 5 #ifndef V8_ACCESSORS_H_ 6 #define V8_ACCESSORS_H_ 7 8 #include "include/v8.h" 9 #include "src/allocation.h" 10 #include "src/globals.h" 11 #include "src/handles.h" 12 #include "src/property-details.h" 13 14 namespace v8 { 15 namespace internal { 16 17 // Forward declarations. 18 class ExecutableAccessorInfo; 19 20 // The list of accessor descriptors. This is a second-order macro 21 // taking a macro to be applied to all accessor descriptor names. 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) \ 44 V(ScriptIsEmbedderDebugScript) \ 45 V(StringLength) 46 47 // Accessors contains all predefined proxy accessors. 48 49 class Accessors : public AllStatic { 50 public: 51 // Accessor descriptors. 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 65 66 enum DescriptorId { 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 72 descriptorCount 73 }; 74 75 // Accessor functions called directly from the runtime system. 76 MUST_USE_RESULT static MaybeHandle<Object> FunctionSetPrototype( 77 Handle<JSFunction> object, Handle<Object> value); 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. 86 static bool IsJSObjectFieldAccessor(Handle<Map> map, Handle<Name> name, 87 int* object_offset); 88 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 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); 107 }; 108 109 } // namespace internal 110 } // namespace v8 111 112 #endif // V8_ACCESSORS_H_ 113