Upstream version 5.34.104.0
[platform/framework/web/crosswalk.git] / src / v8 / src / accessors.h
1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are
4 // met:
5 //
6 //     * Redistributions of source code must retain the above copyright
7 //       notice, this list of conditions and the following disclaimer.
8 //     * Redistributions in binary form must reproduce the above
9 //       copyright notice, this list of conditions and the following
10 //       disclaimer in the documentation and/or other materials provided
11 //       with the distribution.
12 //     * Neither the name of Google Inc. nor the names of its
13 //       contributors may be used to endorse or promote products derived
14 //       from this software without specific prior written permission.
15 //
16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27
28 #ifndef V8_ACCESSORS_H_
29 #define V8_ACCESSORS_H_
30
31 #include "allocation.h"
32 #include "v8globals.h"
33
34 namespace v8 {
35 namespace internal {
36
37 // The list of accessor descriptors. This is a second-order macro
38 // taking a macro to be applied to all accessor descriptor names.
39 #define ACCESSOR_DESCRIPTOR_LIST(V) \
40   V(FunctionPrototype)              \
41   V(FunctionLength)                 \
42   V(FunctionName)                   \
43   V(FunctionArguments)              \
44   V(FunctionCaller)                 \
45   V(ArrayLength)                    \
46   V(StringLength)                   \
47   V(ScriptSource)                   \
48   V(ScriptName)                     \
49   V(ScriptId)                       \
50   V(ScriptLineOffset)               \
51   V(ScriptColumnOffset)             \
52   V(ScriptData)                     \
53   V(ScriptType)                     \
54   V(ScriptCompilationType)          \
55   V(ScriptLineEnds)                 \
56   V(ScriptContextData)              \
57   V(ScriptEvalFromScript)           \
58   V(ScriptEvalFromScriptPosition)   \
59   V(ScriptEvalFromFunctionName)
60
61 // Accessors contains all predefined proxy accessors.
62
63 class Accessors : public AllStatic {
64  public:
65   // Accessor descriptors.
66 #define ACCESSOR_DESCRIPTOR_DECLARATION(name) \
67   static const AccessorDescriptor name;
68   ACCESSOR_DESCRIPTOR_LIST(ACCESSOR_DESCRIPTOR_DECLARATION)
69 #undef ACCESSOR_DESCRIPTOR_DECLARATION
70
71   enum DescriptorId {
72 #define ACCESSOR_DESCRIPTOR_DECLARATION(name) \
73     k##name,
74   ACCESSOR_DESCRIPTOR_LIST(ACCESSOR_DESCRIPTOR_DECLARATION)
75 #undef ACCESSOR_DESCRIPTOR_DECLARATION
76     descriptorCount
77   };
78
79   // Accessor functions called directly from the runtime system.
80   static Handle<Object> FunctionSetPrototype(Handle<JSFunction> object,
81                                              Handle<Object> value);
82   static Handle<Object> FunctionGetPrototype(Handle<JSFunction> object);
83   static Handle<Object> FunctionGetArguments(Handle<JSFunction> object);
84
85   // Accessor infos.
86   static Handle<AccessorInfo> MakeModuleExport(
87       Handle<String> name, int index, PropertyAttributes attributes);
88
89   // Returns true for properties that are accessors to object fields.
90   // If true, *object_offset contains offset of object field.
91   template <class T>
92   static bool IsJSObjectFieldAccessor(typename T::TypeHandle type,
93                                       Handle<String> name,
94                                       int* object_offset);
95
96
97  private:
98   // Accessor functions only used through the descriptor.
99   static MaybeObject* FunctionSetPrototype(Isolate* isolate,
100                                            JSObject* object,
101                                            Object*,
102                                            void*);
103   static MaybeObject* FunctionGetPrototype(Isolate* isolate,
104                                            Object* object,
105                                            void*);
106   static MaybeObject* FunctionGetLength(Isolate* isolate,
107                                         Object* object,
108                                         void*);
109   static MaybeObject* FunctionGetName(Isolate* isolate, Object* object, void*);
110   static MaybeObject* FunctionGetArguments(Isolate* isolate,
111                                            Object* object,
112                                            void*);
113   static MaybeObject* FunctionGetCaller(Isolate* isolate,
114                                         Object* object,
115                                         void*);
116   static MaybeObject* ArraySetLength(Isolate* isolate,
117                                      JSObject* object,
118                                      Object*,
119                                      void*);
120   static MaybeObject* ArrayGetLength(Isolate* isolate, Object* object, void*);
121   static MaybeObject* StringGetLength(Isolate* isolate, Object* object, void*);
122   static MaybeObject* ScriptGetName(Isolate* isolate, Object* object, void*);
123   static MaybeObject* ScriptGetId(Isolate* isolate, Object* object, void*);
124   static MaybeObject* ScriptGetSource(Isolate* isolate, Object* object, void*);
125   static MaybeObject* ScriptGetLineOffset(Isolate* isolate,
126                                           Object* object,
127                                           void*);
128   static MaybeObject* ScriptGetColumnOffset(Isolate* isolate,
129                                             Object* object,
130                                             void*);
131   static MaybeObject* ScriptGetData(Isolate* isolate, Object* object, void*);
132   static MaybeObject* ScriptGetType(Isolate* isolate, Object* object, void*);
133   static MaybeObject* ScriptGetCompilationType(Isolate* isolate,
134                                                Object* object,
135                                                void*);
136   static MaybeObject* ScriptGetLineEnds(Isolate* isolate,
137                                         Object* object,
138                                         void*);
139   static MaybeObject* ScriptGetContextData(Isolate* isolate,
140                                            Object* object,
141                                            void*);
142   static MaybeObject* ScriptGetEvalFromScript(Isolate* isolate,
143                                               Object* object,
144                                               void*);
145   static MaybeObject* ScriptGetEvalFromScriptPosition(Isolate* isolate,
146                                                       Object* object,
147                                                       void*);
148   static MaybeObject* ScriptGetEvalFromFunctionName(Isolate* isolate,
149                                                     Object* object,
150                                                     void*);
151
152   // Helper functions.
153   static Handle<Object> FlattenNumber(Isolate* isolate, Handle<Object> value);
154   static MaybeObject* IllegalSetter(Isolate* isolate,
155                                     JSObject*,
156                                     Object*,
157                                     void*);
158   static Object* IllegalGetAccessor(Isolate* isolate, Object* object, void*);
159   static MaybeObject* ReadOnlySetAccessor(Isolate* isolate,
160                                           JSObject*,
161                                           Object* value,
162                                           void*);
163 };
164
165 } }  // namespace v8::internal
166
167 #endif  // V8_ACCESSORS_H_