accessors.h 3.92 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
#include "include/v8.h"
9 10
#include "src/allocation.h"
#include "src/globals.h"
11 12
#include "src/handles.h"
#include "src/property-details.h"
13

14 15
namespace v8 {
namespace internal {
16

17 18 19
// Forward declarations.
class ExecutableAccessorInfo;

20 21
// The list of accessor descriptors. This is a second-order macro
// taking a macro to be applied to all accessor descriptor names.
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
#define ACCESSOR_INFO_LIST(V)     \
  V(ArgumentsIterator)            \
  V(ArrayLength)                  \
  V(FunctionArguments)            \
  V(FunctionCaller)               \
  V(FunctionName)                 \
  V(FunctionLength)               \
  V(FunctionPrototype)            \
  V(ScriptColumnOffset)           \
  V(ScriptCompilationType)        \
  V(ScriptContextData)            \
  V(ScriptEvalFromScript)         \
  V(ScriptEvalFromScriptPosition) \
  V(ScriptEvalFromFunctionName)   \
  V(ScriptId)                     \
  V(ScriptLineEnds)               \
  V(ScriptLineOffset)             \
  V(ScriptName)                   \
  V(ScriptSource)                 \
  V(ScriptType)                   \
  V(ScriptSourceUrl)              \
  V(ScriptSourceMappingUrl)       \
44
  V(ScriptIsEmbedderDebugScript)  \
45
  V(StringLength)
46

47
// Accessors contains all predefined proxy accessors.
48 49 50 51

class Accessors : public AllStatic {
 public:
  // Accessor descriptors.
52 53
#define ACCESSOR_INFO_DECLARATION(name)                   \
  static void name##Getter(                               \
54
      v8::Local<v8::Name> name,                           \
55 56
      const v8::PropertyCallbackInfo<v8::Value>& info);   \
  static void name##Setter(                               \
57
      v8::Local<v8::Name> name,                           \
58 59 60 61 62 63 64 65
      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

66
  enum DescriptorId {
67 68 69 70 71
#define ACCESSOR_INFO_DECLARATION(name) \
    k##name##Getter, \
    k##name##Setter,
  ACCESSOR_INFO_LIST(ACCESSOR_INFO_DECLARATION)
#undef ACCESSOR_INFO_DECLARATION
72 73 74 75
    descriptorCount
  };

  // Accessor functions called directly from the runtime system.
76 77
  MUST_USE_RESULT static MaybeHandle<Object> FunctionSetPrototype(
      Handle<JSFunction> object, Handle<Object> value);
78
  static Handle<Object> FunctionGetArguments(Handle<JSFunction> object);
79

80 81 82 83
  // Accessor infos.
  static Handle<AccessorInfo> MakeModuleExport(
      Handle<String> name, int index, PropertyAttributes attributes);

84 85
  // Returns true for properties that are accessors to object fields.
  // If true, *object_offset contains offset of object field.
86
  static bool IsJSObjectFieldAccessor(Handle<Map> map, Handle<Name> name,
87
                                      int* object_offset);
88

89 90 91 92 93 94 95 96
  // Returns true for properties that are accessors to ArrayBufferView and
  // derived classes fields. If true, *object_offset contains offset of
  // object field. The caller still has to check whether the underlying
  // buffer was neutered.
  static bool IsJSArrayBufferViewFieldAccessor(Handle<Map> map,
                                               Handle<Name> name,
                                               int* object_offset);

97 98
  static Handle<AccessorInfo> MakeAccessor(
      Isolate* isolate,
99 100 101
      Handle<Name> name,
      AccessorNameGetterCallback getter,
      AccessorNameSetterCallback setter,
102
      PropertyAttributes attributes);
103

104 105 106
  static Handle<ExecutableAccessorInfo> CloneAccessor(
      Isolate* isolate,
      Handle<ExecutableAccessorInfo> accessor);
107 108
};

109 110
}  // namespace internal
}  // namespace v8
111 112

#endif  // V8_ACCESSORS_H_