blob: 7863c5a3d7f3988a027b6a9abc4e70cb4259ed96 [file] [log] [blame]
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001// Copyright 2012 the V8 project authors. All rights reserved.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
Steve Blocka7e24c12009-10-30 11:49:00 +00004
5#ifndef V8_ACCESSORS_H_
6#define V8_ACCESSORS_H_
7
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00008#include "include/v8.h"
Ben Murdochb8a8cc12014-11-26 15:28:44 +00009#include "src/allocation.h"
10#include "src/globals.h"
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000011#include "src/handles.h"
12#include "src/property-details.h"
Ben Murdoch257744e2011-11-30 15:57:28 +000013
Steve Blocka7e24c12009-10-30 11:49:00 +000014namespace v8 {
15namespace internal {
16
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000017// Forward declarations.
Ben Murdoch097c5b22016-05-18 11:27:45 +010018class AccessorInfo;
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000019
Steve Blocka7e24c12009-10-30 11:49:00 +000020// The list of accessor descriptors. This is a second-order macro
21// taking a macro to be applied to all accessor descriptor names.
Ben Murdochb8a8cc12014-11-26 15:28:44 +000022#define ACCESSOR_INFO_LIST(V) \
23 V(ArgumentsIterator) \
24 V(ArrayLength) \
Ben Murdochc5610432016-08-08 18:44:38 +010025 V(BoundFunctionLength) \
26 V(BoundFunctionName) \
Ben Murdochb8a8cc12014-11-26 15:28:44 +000027 V(FunctionArguments) \
28 V(FunctionCaller) \
29 V(FunctionName) \
30 V(FunctionLength) \
31 V(FunctionPrototype) \
32 V(ScriptColumnOffset) \
33 V(ScriptCompilationType) \
34 V(ScriptContextData) \
35 V(ScriptEvalFromScript) \
36 V(ScriptEvalFromScriptPosition) \
37 V(ScriptEvalFromFunctionName) \
38 V(ScriptId) \
39 V(ScriptLineEnds) \
40 V(ScriptLineOffset) \
41 V(ScriptName) \
42 V(ScriptSource) \
43 V(ScriptType) \
44 V(ScriptSourceUrl) \
45 V(ScriptSourceMappingUrl) \
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000046 V(ScriptIsEmbedderDebugScript) \
Ben Murdochb8a8cc12014-11-26 15:28:44 +000047 V(StringLength)
Steve Blocka7e24c12009-10-30 11:49:00 +000048
Ben Murdoch097c5b22016-05-18 11:27:45 +010049#define ACCESSOR_SETTER_LIST(V) \
50 V(ReconfigureToDataProperty) \
Ben Murdoch097c5b22016-05-18 11:27:45 +010051 V(ArrayLengthSetter) \
52 V(FunctionPrototypeSetter)
53
Steve Blocka7e24c12009-10-30 11:49:00 +000054// Accessors contains all predefined proxy accessors.
55
56class Accessors : public AllStatic {
57 public:
58 // Accessor descriptors.
Ben Murdochb8a8cc12014-11-26 15:28:44 +000059#define ACCESSOR_INFO_DECLARATION(name) \
60 static void name##Getter( \
61 v8::Local<v8::Name> name, \
62 const v8::PropertyCallbackInfo<v8::Value>& info); \
Ben Murdochb8a8cc12014-11-26 15:28:44 +000063 static Handle<AccessorInfo> name##Info( \
64 Isolate* isolate, \
65 PropertyAttributes attributes);
66 ACCESSOR_INFO_LIST(ACCESSOR_INFO_DECLARATION)
67#undef ACCESSOR_INFO_DECLARATION
Steve Blocka7e24c12009-10-30 11:49:00 +000068
Ben Murdoch097c5b22016-05-18 11:27:45 +010069#define ACCESSOR_SETTER_DECLARATION(name) \
70 static void name(v8::Local<v8::Name> name, v8::Local<v8::Value> value, \
71 const v8::PropertyCallbackInfo<void>& info);
72 ACCESSOR_SETTER_LIST(ACCESSOR_SETTER_DECLARATION)
73#undef ACCESSOR_SETTER_DECLARATION
74
Steve Blocka7e24c12009-10-30 11:49:00 +000075 enum DescriptorId {
Ben Murdochb8a8cc12014-11-26 15:28:44 +000076#define ACCESSOR_INFO_DECLARATION(name) \
77 k##name##Getter, \
78 k##name##Setter,
79 ACCESSOR_INFO_LIST(ACCESSOR_INFO_DECLARATION)
80#undef ACCESSOR_INFO_DECLARATION
Steve Blocka7e24c12009-10-30 11:49:00 +000081 descriptorCount
82 };
83
84 // Accessor functions called directly from the runtime system.
Emily Bernierd0a1eb72015-03-24 16:35:39 -040085 MUST_USE_RESULT static MaybeHandle<Object> FunctionSetPrototype(
86 Handle<JSFunction> object, Handle<Object> value);
Ben Murdoch097c5b22016-05-18 11:27:45 +010087 static Handle<JSObject> FunctionGetArguments(Handle<JSFunction> object);
Ben Murdochb8a8cc12014-11-26 15:28:44 +000088
89 // Accessor infos.
90 static Handle<AccessorInfo> MakeModuleExport(
91 Handle<String> name, int index, PropertyAttributes attributes);
92
93 // Returns true for properties that are accessors to object fields.
94 // If true, *object_offset contains offset of object field.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000095 static bool IsJSObjectFieldAccessor(Handle<Map> map, Handle<Name> name,
Ben Murdochb8a8cc12014-11-26 15:28:44 +000096 int* object_offset);
97
98 static Handle<AccessorInfo> MakeAccessor(
99 Isolate* isolate,
100 Handle<Name> name,
101 AccessorNameGetterCallback getter,
102 AccessorNameSetterCallback setter,
103 PropertyAttributes attributes);
Steve Blocka7e24c12009-10-30 11:49:00 +0000104};
105
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000106} // namespace internal
107} // namespace v8
Steve Blocka7e24c12009-10-30 11:49:00 +0000108
109#endif // V8_ACCESSORS_H_