accessors.h 3.57 KB
Newer Older
1
// Copyright 2012 the V8 project authors. All rights reserved.
2 3
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
4 5 6 7

#ifndef V8_ACCESSORS_H_
#define V8_ACCESSORS_H_

8 9
#include "src/allocation.h"
#include "src/globals.h"
10

11 12
namespace v8 {
namespace internal {
13 14 15

// The list of accessor descriptors. This is a second-order macro
// 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 25
  V(ScriptCompilationType)          \
  V(ScriptContextData)              \
26 27
  V(ScriptEvalFromScript)           \
  V(ScriptEvalFromScriptPosition)   \
28
  V(ScriptEvalFromFunctionName)     \
29
  V(ScriptId)                       \
30
  V(ScriptLineEnds)                 \
31 32 33
  V(ScriptLineOffset)               \
  V(ScriptName)                     \
  V(ScriptSource)                   \
34
  V(ScriptType)                     \
35 36
  V(ScriptSourceUrl)                \
  V(ScriptSourceMappingUrl)         \
37
  V(StringLength)
38

39
// Accessors contains all predefined proxy accessors.
40 41 42 43

class Accessors : public AllStatic {
 public:
  // Accessor descriptors.
44 45 46 47 48 49 50 51 52 53 54 55 56 57
#define ACCESSOR_INFO_DECLARATION(name)                   \
  static void name##Getter(                               \
      v8::Local<v8::String> name,                         \
      const v8::PropertyCallbackInfo<v8::Value>& info);   \
  static void name##Setter(                               \
      v8::Local<v8::String> name,                         \
      v8::Local<v8::Value> value,                         \
      const v8::PropertyCallbackInfo<void>& info);   \
  static Handle<AccessorInfo> name##Info(                 \
      Isolate* isolate,                                   \
      PropertyAttributes attributes);
  ACCESSOR_INFO_LIST(ACCESSOR_INFO_DECLARATION)
#undef ACCESSOR_INFO_DECLARATION

58
  enum DescriptorId {
59 60 61 62 63
#define ACCESSOR_INFO_DECLARATION(name) \
    k##name##Getter, \
    k##name##Setter,
  ACCESSOR_INFO_LIST(ACCESSOR_INFO_DECLARATION)
#undef ACCESSOR_INFO_DECLARATION
64 65 66 67
    descriptorCount
  };

  // Accessor functions called directly from the runtime system.
68 69 70 71
  static Handle<Object> FunctionSetPrototype(Handle<JSFunction> object,
                                             Handle<Object> value);
  static Handle<Object> FunctionGetPrototype(Handle<JSFunction> object);
  static Handle<Object> FunctionGetArguments(Handle<JSFunction> object);
72

73 74 75 76
  // Accessor infos.
  static Handle<AccessorInfo> MakeModuleExport(
      Handle<String> name, int index, PropertyAttributes attributes);

77 78
  // Returns true for properties that are accessors to object fields.
  // If true, *object_offset contains offset of object field.
79 80 81 82
  template <class T>
  static bool IsJSObjectFieldAccessor(typename T::TypeHandle type,
                                      Handle<String> name,
                                      int* object_offset);
83

84 85 86 87 88 89
  static Handle<AccessorInfo> MakeAccessor(
      Isolate* isolate,
      Handle<String> name,
      AccessorGetterCallback getter,
      AccessorSetterCallback setter,
      PropertyAttributes attributes);
90

91 92 93 94 95
  static Handle<ExecutableAccessorInfo> CloneAccessor(
      Isolate* isolate,
      Handle<ExecutableAccessorInfo> accessor);


96
 private:
97
  // Helper functions.
98
  static Handle<Object> FlattenNumber(Isolate* isolate, Handle<Object> value);
99 100 101 102 103
};

} }  // namespace v8::internal

#endif  // V8_ACCESSORS_H_