V8 API Reference, 7.2.502.16 (for Deno 0.2.4)
api-arguments.h
1 // Copyright 2016 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_API_ARGUMENTS_H_
6 #define V8_API_ARGUMENTS_H_
7 
8 #include "src/api.h"
9 #include "src/debug/debug.h"
10 #include "src/isolate.h"
11 #include "src/objects/slots.h"
12 #include "src/visitors.h"
13 
14 namespace v8 {
15 namespace internal {
16 
17 // Custom arguments replicate a small segment of stack that can be
18 // accessed through an Arguments object the same way the actual stack
19 // can.
21  protected:
22  explicit inline CustomArgumentsBase(Isolate* isolate);
23 };
24 
25 template <typename T>
26 class CustomArguments : public CustomArgumentsBase {
27  public:
28  static const int kReturnValueOffset = T::kReturnValueIndex;
29 
30  ~CustomArguments() override;
31 
32  inline void IterateInstance(RootVisitor* v) override {
33  v->VisitRootPointers(Root::kRelocatable, nullptr, slot_at(0),
34  slot_at(T::kArgsLength));
35  }
36 
37  protected:
38  explicit inline CustomArguments(Isolate* isolate)
39  : CustomArgumentsBase(isolate) {}
40 
41  template <typename V>
42  Handle<V> GetReturnValue(Isolate* isolate);
43 
44  inline Isolate* isolate() {
45  return reinterpret_cast<Isolate*>(*slot_at(T::kIsolateIndex));
46  }
47 
48  inline ObjectSlot slot_at(int index) {
49  // This allows index == T::kArgsLength so "one past the end" slots
50  // can be retrieved for iterating purposes.
51  DCHECK(index >= 0 && index <= T::kArgsLength);
52  return ObjectSlot(values_ + index);
53  }
54  Address values_[T::kArgsLength];
55 };
56 
57 // Note: Calling args.Call() sets the return value on args. For multiple
58 // Call()'s, a new args should be used every time.
60  : public CustomArguments<PropertyCallbackInfo<Value> > {
61  public:
63  typedef CustomArguments<T> Super;
64  static const int kArgsLength = T::kArgsLength;
65  static const int kThisIndex = T::kThisIndex;
66  static const int kHolderIndex = T::kHolderIndex;
67  static const int kDataIndex = T::kDataIndex;
68  static const int kReturnValueDefaultValueIndex =
69  T::kReturnValueDefaultValueIndex;
70  static const int kIsolateIndex = T::kIsolateIndex;
71  static const int kShouldThrowOnErrorIndex = T::kShouldThrowOnErrorIndex;
72 
73  PropertyCallbackArguments(Isolate* isolate, Object* data, Object* self,
74  JSObject* holder, ShouldThrow should_throw);
75 
76  // -------------------------------------------------------------------------
77  // Accessor Callbacks
78  // Also used for AccessorSetterCallback.
79  inline Handle<Object> CallAccessorSetter(Handle<AccessorInfo> info,
80  Handle<Name> name,
81  Handle<Object> value);
82  // Also used for AccessorGetterCallback, AccessorNameGetterCallback.
83  inline Handle<Object> CallAccessorGetter(Handle<AccessorInfo> info,
84  Handle<Name> name);
85 
86  // -------------------------------------------------------------------------
87  // Named Interceptor Callbacks
88  inline Handle<Object> CallNamedQuery(Handle<InterceptorInfo> interceptor,
89  Handle<Name> name);
90  inline Handle<Object> CallNamedGetter(Handle<InterceptorInfo> interceptor,
91  Handle<Name> name);
92  inline Handle<Object> CallNamedSetter(Handle<InterceptorInfo> interceptor,
93  Handle<Name> name,
94  Handle<Object> value);
95  inline Handle<Object> CallNamedDefiner(Handle<InterceptorInfo> interceptor,
96  Handle<Name> name,
97  const v8::PropertyDescriptor& desc);
98  inline Handle<Object> CallNamedDeleter(Handle<InterceptorInfo> interceptor,
99  Handle<Name> name);
100  inline Handle<Object> CallNamedDescriptor(Handle<InterceptorInfo> interceptor,
101  Handle<Name> name);
102  inline Handle<JSObject> CallNamedEnumerator(
103  Handle<InterceptorInfo> interceptor);
104 
105  // -------------------------------------------------------------------------
106  // Indexed Interceptor Callbacks
107  inline Handle<Object> CallIndexedQuery(Handle<InterceptorInfo> interceptor,
108  uint32_t index);
109  inline Handle<Object> CallIndexedGetter(Handle<InterceptorInfo> interceptor,
110  uint32_t index);
111  inline Handle<Object> CallIndexedSetter(Handle<InterceptorInfo> interceptor,
112  uint32_t index, Handle<Object> value);
113  inline Handle<Object> CallIndexedDefiner(Handle<InterceptorInfo> interceptor,
114  uint32_t index,
115  const v8::PropertyDescriptor& desc);
116  inline Handle<Object> CallIndexedDeleter(Handle<InterceptorInfo> interceptor,
117  uint32_t index);
118  inline Handle<Object> CallIndexedDescriptor(
119  Handle<InterceptorInfo> interceptor, uint32_t index);
120  inline Handle<JSObject> CallIndexedEnumerator(
121  Handle<InterceptorInfo> interceptor);
122 
123  private:
124  /*
125  * The following Call functions wrap the calling of all callbacks to handle
126  * calling either the old or the new style callbacks depending on which one
127  * has been registered.
128  * For old callbacks which return an empty handle, the ReturnValue is checked
129  * and used if it's been set to anything inside the callback.
130  * New style callbacks always use the return value.
131  */
132  inline Handle<JSObject> CallPropertyEnumerator(
133  Handle<InterceptorInfo> interceptor);
134 
135  inline Handle<Object> BasicCallIndexedGetterCallback(
137  inline Handle<Object> BasicCallNamedGetterCallback(
139  Handle<Object> info, Handle<Object> receiver = Handle<Object>());
140 
141  inline JSObject* holder();
142  inline Object* receiver();
143 
144  // Don't copy PropertyCallbackArguments, because they would both have the
145  // same prev_ pointer.
146  DISALLOW_COPY_AND_ASSIGN(PropertyCallbackArguments);
147 };
148 
150  : public CustomArguments<FunctionCallbackInfo<Value> > {
151  public:
153  typedef CustomArguments<T> Super;
154  static const int kArgsLength = T::kArgsLength;
155  static const int kHolderIndex = T::kHolderIndex;
156  static const int kDataIndex = T::kDataIndex;
157  static const int kReturnValueDefaultValueIndex =
158  T::kReturnValueDefaultValueIndex;
159  static const int kIsolateIndex = T::kIsolateIndex;
160  static const int kNewTargetIndex = T::kNewTargetIndex;
161 
163  internal::HeapObject* callee,
164  internal::Object* holder,
165  internal::HeapObject* new_target,
166  internal::Address* argv, int argc);
167 
168  /*
169  * The following Call function wraps the calling of all callbacks to handle
170  * calling either the old or the new style callbacks depending on which one
171  * has been registered.
172  * For old callbacks which return an empty handle, the ReturnValue is checked
173  * and used if it's been set to anything inside the callback.
174  * New style callbacks always use the return value.
175  */
176  inline Handle<Object> Call(CallHandlerInfo* handler);
177 
178  private:
179  inline JSObject* holder();
180 
181  internal::Address* argv_;
182  int argc_;
183 };
184 
185 } // namespace internal
186 } // namespace v8
187 
188 #endif // V8_API_ARGUMENTS_H_
Definition: libplatform.h:13
void(* IndexedPropertyGetterCallback)(uint32_t index, const PropertyCallbackInfo< Value > &info)
Definition: v8.h:5550
void(* GenericNamedPropertyGetterCallback)(Local< Name > property, const PropertyCallbackInfo< Value > &info)
Definition: v8.h:5416