678064df168f0c977209d5b259b5926e239c179e
[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 "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   MUST_USE_RESULT static MaybeHandle<Object> FunctionSetPrototype(
70       Handle<JSFunction> object, Handle<Object> value);
71   static Handle<Object> FunctionGetArguments(Handle<JSFunction> object);
72
73   // Accessor infos.
74   static Handle<AccessorInfo> MakeModuleExport(
75       Handle<String> name, int index, PropertyAttributes attributes);
76
77   // Returns true for properties that are accessors to object fields.
78   // If true, *object_offset contains offset of object field.
79   template <class T>
80   static bool IsJSObjectFieldAccessor(typename T::TypeHandle type,
81                                       Handle<Name> name,
82                                       int* object_offset);
83
84   static Handle<AccessorInfo> MakeAccessor(
85       Isolate* isolate,
86       Handle<Name> name,
87       AccessorNameGetterCallback getter,
88       AccessorNameSetterCallback setter,
89       PropertyAttributes attributes);
90
91   static Handle<ExecutableAccessorInfo> CloneAccessor(
92       Isolate* isolate,
93       Handle<ExecutableAccessorInfo> accessor);
94
95
96  private:
97   // Helper functions.
98   static Handle<Object> FlattenNumber(Isolate* isolate, Handle<Object> value);
99 };
100
101 } }  // namespace v8::internal
102
103 #endif  // V8_ACCESSORS_H_