blob: 3fe550c25a4559021a9fa886cb52ee31a4576c57 [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) \
25 V(FunctionArguments) \
26 V(FunctionCaller) \
27 V(FunctionName) \
28 V(FunctionLength) \
29 V(FunctionPrototype) \
30 V(ScriptColumnOffset) \
31 V(ScriptCompilationType) \
32 V(ScriptContextData) \
33 V(ScriptEvalFromScript) \
34 V(ScriptEvalFromScriptPosition) \
35 V(ScriptEvalFromFunctionName) \
36 V(ScriptId) \
37 V(ScriptLineEnds) \
38 V(ScriptLineOffset) \
39 V(ScriptName) \
40 V(ScriptSource) \
41 V(ScriptType) \
42 V(ScriptSourceUrl) \
43 V(ScriptSourceMappingUrl) \
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000044 V(ScriptIsEmbedderDebugScript) \
Ben Murdochb8a8cc12014-11-26 15:28:44 +000045 V(StringLength)
Steve Blocka7e24c12009-10-30 11:49:00 +000046
Ben Murdoch097c5b22016-05-18 11:27:45 +010047#define ACCESSOR_SETTER_LIST(V) \
48 V(ReconfigureToDataProperty) \
49 V(ObservedReconfigureToDataProperty) \
50 V(ArrayLengthSetter) \
51 V(FunctionPrototypeSetter)
52
Steve Blocka7e24c12009-10-30 11:49:00 +000053// Accessors contains all predefined proxy accessors.
54
55class Accessors : public AllStatic {
56 public:
57 // Accessor descriptors.
Ben Murdochb8a8cc12014-11-26 15:28:44 +000058#define ACCESSOR_INFO_DECLARATION(name) \
59 static void name##Getter( \
60 v8::Local<v8::Name> name, \
61 const v8::PropertyCallbackInfo<v8::Value>& info); \
Ben Murdochb8a8cc12014-11-26 15:28:44 +000062 static Handle<AccessorInfo> name##Info( \
63 Isolate* isolate, \
64 PropertyAttributes attributes);
65 ACCESSOR_INFO_LIST(ACCESSOR_INFO_DECLARATION)
66#undef ACCESSOR_INFO_DECLARATION
Steve Blocka7e24c12009-10-30 11:49:00 +000067
Ben Murdoch097c5b22016-05-18 11:27:45 +010068#define ACCESSOR_SETTER_DECLARATION(name) \
69 static void name(v8::Local<v8::Name> name, v8::Local<v8::Value> value, \
70 const v8::PropertyCallbackInfo<void>& info);
71 ACCESSOR_SETTER_LIST(ACCESSOR_SETTER_DECLARATION)
72#undef ACCESSOR_SETTER_DECLARATION
73
Steve Blocka7e24c12009-10-30 11:49:00 +000074 enum DescriptorId {
Ben Murdochb8a8cc12014-11-26 15:28:44 +000075#define ACCESSOR_INFO_DECLARATION(name) \
76 k##name##Getter, \
77 k##name##Setter,
78 ACCESSOR_INFO_LIST(ACCESSOR_INFO_DECLARATION)
79#undef ACCESSOR_INFO_DECLARATION
Steve Blocka7e24c12009-10-30 11:49:00 +000080 descriptorCount
81 };
82
83 // Accessor functions called directly from the runtime system.
Emily Bernierd0a1eb72015-03-24 16:35:39 -040084 MUST_USE_RESULT static MaybeHandle<Object> FunctionSetPrototype(
85 Handle<JSFunction> object, Handle<Object> value);
Ben Murdoch097c5b22016-05-18 11:27:45 +010086 static Handle<JSObject> FunctionGetArguments(Handle<JSFunction> object);
Ben Murdochb8a8cc12014-11-26 15:28:44 +000087
88 // Accessor infos.
89 static Handle<AccessorInfo> MakeModuleExport(
90 Handle<String> name, int index, PropertyAttributes attributes);
91
92 // Returns true for properties that are accessors to object fields.
93 // If true, *object_offset contains offset of object field.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000094 static bool IsJSObjectFieldAccessor(Handle<Map> map, Handle<Name> name,
Ben Murdochb8a8cc12014-11-26 15:28:44 +000095 int* object_offset);
96
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000097 // Returns true for properties that are accessors to ArrayBufferView and
98 // derived classes fields. If true, *object_offset contains offset of
99 // object field. The caller still has to check whether the underlying
100 // buffer was neutered.
101 static bool IsJSArrayBufferViewFieldAccessor(Handle<Map> map,
102 Handle<Name> name,
103 int* object_offset);
104
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000105 static Handle<AccessorInfo> MakeAccessor(
106 Isolate* isolate,
107 Handle<Name> name,
108 AccessorNameGetterCallback getter,
109 AccessorNameSetterCallback setter,
110 PropertyAttributes attributes);
Steve Blocka7e24c12009-10-30 11:49:00 +0000111};
112
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000113} // namespace internal
114} // namespace v8
Steve Blocka7e24c12009-10-30 11:49:00 +0000115
116#endif // V8_ACCESSORS_H_