• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 AccessorInfo;
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(BoundFunctionLength)          \
26   V(BoundFunctionName)            \
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)       \
46   V(ScriptIsEmbedderDebugScript)  \
47   V(StringLength)
48 
49 #define ACCESSOR_SETTER_LIST(V)        \
50   V(ReconfigureToDataProperty)         \
51   V(ArrayLengthSetter)                 \
52   V(FunctionPrototypeSetter)
53 
54 // Accessors contains all predefined proxy accessors.
55 
56 class Accessors : public AllStatic {
57  public:
58   // Accessor descriptors.
59 #define ACCESSOR_INFO_DECLARATION(name)                   \
60   static void name##Getter(                               \
61       v8::Local<v8::Name> name,                           \
62       const v8::PropertyCallbackInfo<v8::Value>& info);   \
63   static Handle<AccessorInfo> name##Info(                 \
64       Isolate* isolate,                                   \
65       PropertyAttributes attributes);
66   ACCESSOR_INFO_LIST(ACCESSOR_INFO_DECLARATION)
67 #undef ACCESSOR_INFO_DECLARATION
68 
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 
75   enum DescriptorId {
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
81     descriptorCount
82   };
83 
84   // Accessor functions called directly from the runtime system.
85   MUST_USE_RESULT static MaybeHandle<Object> FunctionSetPrototype(
86       Handle<JSFunction> object, Handle<Object> value);
87   static Handle<JSObject> FunctionGetArguments(Handle<JSFunction> object);
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.
95   static bool IsJSObjectFieldAccessor(Handle<Map> map, Handle<Name> name,
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);
104 };
105 
106 }  // namespace internal
107 }  // namespace v8
108 
109 #endif  // V8_ACCESSORS_H_
110