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 "src/allocation.h" 9 #include "src/globals.h" 10 11 namespace v8 { 12 namespace internal { 13 14 // The list of accessor descriptors. This is a second-order macro 15 // taking a macro to be applied to all accessor descriptor names. 16 #define ACCESSOR_INFO_LIST(V) \ 17 V(ArgumentsIterator) \ 18 V(ArrayLength) \ 19 V(FunctionArguments) \ 20 V(FunctionCaller) \ 21 V(FunctionName) \ 22 V(FunctionLength) \ 23 V(FunctionPrototype) \ 24 V(ScriptColumnOffset) \ 25 V(ScriptCompilationType) \ 26 V(ScriptContextData) \ 27 V(ScriptEvalFromScript) \ 28 V(ScriptEvalFromScriptPosition) \ 29 V(ScriptEvalFromFunctionName) \ 30 V(ScriptId) \ 31 V(ScriptLineEnds) \ 32 V(ScriptLineOffset) \ 33 V(ScriptName) \ 34 V(ScriptSource) \ 35 V(ScriptType) \ 36 V(ScriptSourceUrl) \ 37 V(ScriptSourceMappingUrl) \ 38 V(StringLength) 39 40 // Accessors contains all predefined proxy accessors. 41 42 class Accessors : public AllStatic { 43 public: 44 // Accessor descriptors. 45 #define ACCESSOR_INFO_DECLARATION(name) \ 46 static void name##Getter( \ 47 v8::Local<v8::Name> name, \ 48 const v8::PropertyCallbackInfo<v8::Value>& info); \ 49 static void name##Setter( \ 50 v8::Local<v8::Name> name, \ 51 v8::Local<v8::Value> value, \ 52 const v8::PropertyCallbackInfo<void>& info); \ 53 static Handle<AccessorInfo> name##Info( \ 54 Isolate* isolate, \ 55 PropertyAttributes attributes); 56 ACCESSOR_INFO_LIST(ACCESSOR_INFO_DECLARATION) 57 #undef ACCESSOR_INFO_DECLARATION 58 59 enum DescriptorId { 60 #define ACCESSOR_INFO_DECLARATION(name) \ 61 k##name##Getter, \ 62 k##name##Setter, 63 ACCESSOR_INFO_LIST(ACCESSOR_INFO_DECLARATION) 64 #undef ACCESSOR_INFO_DECLARATION 65 descriptorCount 66 }; 67 68 // Accessor functions called directly from the runtime system. 69 static Handle<Object> FunctionSetPrototype(Handle<JSFunction> object, 70 Handle<Object> value); 71 static Handle<Object> FunctionGetPrototype(Handle<JSFunction> object); 72 static Handle<Object> FunctionGetArguments(Handle<JSFunction> object); 73 74 // Accessor infos. 75 static Handle<AccessorInfo> MakeModuleExport( 76 Handle<String> name, int index, PropertyAttributes attributes); 77 78 // Returns true for properties that are accessors to object fields. 79 // If true, *object_offset contains offset of object field. 80 template <class T> 81 static bool IsJSObjectFieldAccessor(typename T::TypeHandle type, 82 Handle<Name> name, 83 int* object_offset); 84 85 static Handle<AccessorInfo> MakeAccessor( 86 Isolate* isolate, 87 Handle<Name> name, 88 AccessorNameGetterCallback getter, 89 AccessorNameSetterCallback setter, 90 PropertyAttributes attributes); 91 92 static Handle<ExecutableAccessorInfo> CloneAccessor( 93 Isolate* isolate, 94 Handle<ExecutableAccessorInfo> accessor); 95 96 97 private: 98 // Helper functions. 99 static Handle<Object> FlattenNumber(Isolate* isolate, Handle<Object> value); 100 }; 101 102 } } // namespace v8::internal 103 104 #endif // V8_ACCESSORS_H_ 105