blob: 6c1765c404ddcd09f2ef7d3f4805afb67624f92c [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.
18class ExecutableAccessorInfo;
19
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
47// Accessors contains all predefined proxy accessors.
48
49class Accessors : public AllStatic {
50 public:
51 // Accessor descriptors.
Ben Murdochb8a8cc12014-11-26 15:28:44 +000052#define ACCESSOR_INFO_DECLARATION(name) \
53 static void name##Getter( \
54 v8::Local<v8::Name> name, \
55 const v8::PropertyCallbackInfo<v8::Value>& info); \
56 static void name##Setter( \
57 v8::Local<v8::Name> name, \
58 v8::Local<v8::Value> value, \
59 const v8::PropertyCallbackInfo<void>& info); \
60 static Handle<AccessorInfo> name##Info( \
61 Isolate* isolate, \
62 PropertyAttributes attributes);
63 ACCESSOR_INFO_LIST(ACCESSOR_INFO_DECLARATION)
64#undef ACCESSOR_INFO_DECLARATION
Steve Blocka7e24c12009-10-30 11:49:00 +000065
66 enum DescriptorId {
Ben Murdochb8a8cc12014-11-26 15:28:44 +000067#define ACCESSOR_INFO_DECLARATION(name) \
68 k##name##Getter, \
69 k##name##Setter,
70 ACCESSOR_INFO_LIST(ACCESSOR_INFO_DECLARATION)
71#undef ACCESSOR_INFO_DECLARATION
Steve Blocka7e24c12009-10-30 11:49:00 +000072 descriptorCount
73 };
74
75 // Accessor functions called directly from the runtime system.
Emily Bernierd0a1eb72015-03-24 16:35:39 -040076 MUST_USE_RESULT static MaybeHandle<Object> FunctionSetPrototype(
77 Handle<JSFunction> object, Handle<Object> value);
Ben Murdochb8a8cc12014-11-26 15:28:44 +000078 static Handle<Object> FunctionGetArguments(Handle<JSFunction> object);
79
80 // Accessor infos.
81 static Handle<AccessorInfo> MakeModuleExport(
82 Handle<String> name, int index, PropertyAttributes attributes);
83
84 // Returns true for properties that are accessors to object fields.
85 // If true, *object_offset contains offset of object field.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000086 static bool IsJSObjectFieldAccessor(Handle<Map> map, Handle<Name> name,
Ben Murdochb8a8cc12014-11-26 15:28:44 +000087 int* object_offset);
88
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000089 // Returns true for properties that are accessors to ArrayBufferView and
90 // derived classes fields. If true, *object_offset contains offset of
91 // object field. The caller still has to check whether the underlying
92 // buffer was neutered.
93 static bool IsJSArrayBufferViewFieldAccessor(Handle<Map> map,
94 Handle<Name> name,
95 int* object_offset);
96
Ben Murdochb8a8cc12014-11-26 15:28:44 +000097 static Handle<AccessorInfo> MakeAccessor(
98 Isolate* isolate,
99 Handle<Name> name,
100 AccessorNameGetterCallback getter,
101 AccessorNameSetterCallback setter,
102 PropertyAttributes attributes);
103
104 static Handle<ExecutableAccessorInfo> CloneAccessor(
105 Isolate* isolate,
106 Handle<ExecutableAccessorInfo> accessor);
Steve Blocka7e24c12009-10-30 11:49:00 +0000107};
108
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000109} // namespace internal
110} // namespace v8
Steve Blocka7e24c12009-10-30 11:49:00 +0000111
112#endif // V8_ACCESSORS_H_