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