2012-01-25 00:16:07 +00:00
|
|
|
// Copyright 2012 the V8 project authors. All rights reserved.
|
2014-04-29 06:42:26 +00:00
|
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
|
|
// found in the LICENSE file.
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
#ifndef V8_ACCESSORS_H_
|
|
|
|
#define V8_ACCESSORS_H_
|
|
|
|
|
2015-08-11 07:34:10 +00:00
|
|
|
#include "include/v8.h"
|
2014-06-03 08:12:43 +00:00
|
|
|
#include "src/allocation.h"
|
|
|
|
#include "src/globals.h"
|
2015-08-11 07:34:10 +00:00
|
|
|
#include "src/property-details.h"
|
2011-05-06 06:50:20 +00:00
|
|
|
|
2009-05-25 10:05:56 +00:00
|
|
|
namespace v8 {
|
|
|
|
namespace internal {
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2015-08-11 12:00:01 +00:00
|
|
|
// Forward declarations.
|
2016-01-18 15:08:36 +00:00
|
|
|
class AccessorInfo;
|
2017-01-27 13:53:13 +00:00
|
|
|
template <typename T>
|
|
|
|
class Handle;
|
2017-11-14 14:15:00 +00:00
|
|
|
class FieldIndex;
|
2017-11-29 13:18:33 +00:00
|
|
|
class JavaScriptFrame;
|
2015-08-11 12:00:01 +00:00
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
// The list of accessor descriptors. This is a second-order macro
|
|
|
|
// taking a macro to be applied to all accessor descriptor names.
|
2018-09-04 08:53:13 +00:00
|
|
|
// V(accessor_name, AccessorName, GetterSideEffectType, SetterSideEffectType)
|
2018-09-24 09:25:21 +00:00
|
|
|
#define ACCESSOR_INFO_LIST_GENERATOR(V, _) \
|
|
|
|
V(_, arguments_iterator, ArgumentsIterator, kHasNoSideEffect, \
|
|
|
|
kHasSideEffectToReceiver) \
|
|
|
|
V(_, array_length, ArrayLength, kHasNoSideEffect, kHasSideEffectToReceiver) \
|
|
|
|
V(_, bound_function_length, BoundFunctionLength, kHasNoSideEffect, \
|
|
|
|
kHasSideEffectToReceiver) \
|
|
|
|
V(_, bound_function_name, BoundFunctionName, kHasNoSideEffect, \
|
|
|
|
kHasSideEffectToReceiver) \
|
|
|
|
V(_, error_stack, ErrorStack, kHasSideEffectToReceiver, \
|
|
|
|
kHasSideEffectToReceiver) \
|
|
|
|
V(_, function_arguments, FunctionArguments, kHasNoSideEffect, \
|
|
|
|
kHasSideEffectToReceiver) \
|
|
|
|
V(_, function_caller, FunctionCaller, kHasNoSideEffect, \
|
|
|
|
kHasSideEffectToReceiver) \
|
|
|
|
V(_, function_name, FunctionName, kHasNoSideEffect, \
|
|
|
|
kHasSideEffectToReceiver) \
|
|
|
|
V(_, function_length, FunctionLength, kHasNoSideEffect, \
|
|
|
|
kHasSideEffectToReceiver) \
|
|
|
|
V(_, function_prototype, FunctionPrototype, kHasNoSideEffect, \
|
|
|
|
kHasSideEffectToReceiver) \
|
|
|
|
V(_, string_length, StringLength, kHasNoSideEffect, kHasSideEffectToReceiver)
|
2018-03-06 08:43:46 +00:00
|
|
|
|
2016-07-20 13:02:36 +00:00
|
|
|
#define ACCESSOR_SETTER_LIST(V) \
|
|
|
|
V(ArrayLengthSetter) \
|
|
|
|
V(ErrorStackSetter) \
|
2016-10-07 19:37:04 +00:00
|
|
|
V(FunctionPrototypeSetter) \
|
|
|
|
V(ModuleNamespaceEntrySetter) \
|
|
|
|
V(ReconfigureToDataProperty)
|
2016-01-27 13:21:53 +00:00
|
|
|
|
2008-08-27 13:47:52 +00:00
|
|
|
// Accessors contains all predefined proxy accessors.
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
class Accessors : public AllStatic {
|
|
|
|
public:
|
2018-09-24 09:25:21 +00:00
|
|
|
#define ACCESSOR_GETTER_DECLARATION(_, accessor_name, AccessorName, ...) \
|
|
|
|
static void AccessorName##Getter( \
|
|
|
|
v8::Local<v8::Name> name, \
|
2017-10-27 09:06:44 +00:00
|
|
|
const v8::PropertyCallbackInfo<v8::Value>& info);
|
2018-09-24 09:25:21 +00:00
|
|
|
ACCESSOR_INFO_LIST_GENERATOR(ACCESSOR_GETTER_DECLARATION, /* not used */)
|
2017-10-27 09:06:44 +00:00
|
|
|
#undef ACCESSOR_GETTER_DECLARATION
|
2014-04-15 13:25:17 +00:00
|
|
|
|
2017-10-27 09:06:44 +00:00
|
|
|
#define ACCESSOR_SETTER_DECLARATION(accessor_name) \
|
|
|
|
static void accessor_name( \
|
|
|
|
v8::Local<v8::Name> name, v8::Local<v8::Value> value, \
|
|
|
|
const v8::PropertyCallbackInfo<v8::Boolean>& info);
|
2016-01-27 13:21:53 +00:00
|
|
|
ACCESSOR_SETTER_LIST(ACCESSOR_SETTER_DECLARATION)
|
|
|
|
#undef ACCESSOR_SETTER_DECLARATION
|
|
|
|
|
2018-03-19 14:36:52 +00:00
|
|
|
static constexpr int kAccessorInfoCount =
|
|
|
|
#define COUNT_ACCESSOR(...) +1
|
2018-09-24 09:25:21 +00:00
|
|
|
ACCESSOR_INFO_LIST_GENERATOR(COUNT_ACCESSOR, /* not used */);
|
2018-03-19 14:36:52 +00:00
|
|
|
#undef COUNT_ACCESSOR
|
|
|
|
|
|
|
|
static constexpr int kAccessorSetterCount =
|
|
|
|
#define COUNT_ACCESSOR(...) +1
|
|
|
|
ACCESSOR_SETTER_LIST(COUNT_ACCESSOR);
|
|
|
|
#undef COUNT_ACCESSOR
|
|
|
|
|
2016-10-07 19:37:04 +00:00
|
|
|
static void ModuleNamespaceEntryGetter(
|
|
|
|
v8::Local<v8::Name> name,
|
|
|
|
const v8::PropertyCallbackInfo<v8::Value>& info);
|
2017-10-27 09:06:44 +00:00
|
|
|
static Handle<AccessorInfo> MakeModuleNamespaceEntryInfo(Isolate* isolate,
|
|
|
|
Handle<String> name);
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2017-11-29 13:18:33 +00:00
|
|
|
// Accessor function called directly from the runtime system. Returns the
|
|
|
|
// newly materialized arguments object for the given {frame}. Note that for
|
|
|
|
// optimized frames it is possible to specify an {inlined_jsframe_index}.
|
|
|
|
static Handle<JSObject> FunctionGetArguments(JavaScriptFrame* frame,
|
|
|
|
int inlined_jsframe_index);
|
2010-12-07 11:31:57 +00:00
|
|
|
|
2013-09-25 08:19:35 +00:00
|
|
|
// Returns true for properties that are accessors to object fields.
|
2017-11-14 14:15:00 +00:00
|
|
|
// If true, the matching FieldIndex is returned through |field_index|.
|
2018-05-31 14:47:33 +00:00
|
|
|
static bool IsJSObjectFieldAccessor(Isolate* isolate, Handle<Map> map,
|
|
|
|
Handle<Name> name,
|
2017-11-14 14:15:00 +00:00
|
|
|
FieldIndex* field_index);
|
2013-09-25 08:19:35 +00:00
|
|
|
|
2018-04-19 18:08:02 +00:00
|
|
|
static MaybeHandle<Object> ReplaceAccessorWithDataProperty(
|
2018-07-18 16:05:36 +00:00
|
|
|
Handle<Object> receiver, Handle<JSObject> holder, Handle<Name> name,
|
|
|
|
Handle<Object> value);
|
2018-04-19 18:08:02 +00:00
|
|
|
|
2016-10-26 08:59:24 +00:00
|
|
|
// Create an AccessorInfo. The setter is optional (can be nullptr).
|
|
|
|
//
|
|
|
|
// Note that the type of setter is AccessorNameBooleanSetterCallback instead
|
|
|
|
// of v8::AccessorNameSetterCallback. The difference is that the former can
|
|
|
|
// set a (boolean) return value. The setter should roughly follow the same
|
|
|
|
// conventions as many of the internal methods in objects.cc:
|
|
|
|
// - The return value is unset iff there was an exception.
|
|
|
|
// - If the ShouldThrow argument is true, the return value must not be false.
|
|
|
|
typedef void (*AccessorNameBooleanSetterCallback)(
|
|
|
|
Local<v8::Name> property, Local<v8::Value> value,
|
|
|
|
const PropertyCallbackInfo<v8::Boolean>& info);
|
|
|
|
|
2014-04-29 10:59:14 +00:00
|
|
|
static Handle<AccessorInfo> MakeAccessor(
|
2016-10-26 08:59:24 +00:00
|
|
|
Isolate* isolate, Handle<Name> name, AccessorNameGetterCallback getter,
|
2017-10-26 15:18:09 +00:00
|
|
|
AccessorNameBooleanSetterCallback setter);
|
2017-10-27 09:06:44 +00:00
|
|
|
|
|
|
|
private:
|
2018-09-24 09:25:21 +00:00
|
|
|
#define ACCESSOR_INFO_DECLARATION(_, accessor_name, AccessorName, ...) \
|
2017-10-27 09:06:44 +00:00
|
|
|
static Handle<AccessorInfo> Make##AccessorName##Info(Isolate* isolate);
|
2018-09-24 09:25:21 +00:00
|
|
|
ACCESSOR_INFO_LIST_GENERATOR(ACCESSOR_INFO_DECLARATION, /* not used */)
|
2017-10-27 09:06:44 +00:00
|
|
|
#undef ACCESSOR_INFO_DECLARATION
|
|
|
|
|
|
|
|
friend class Heap;
|
2008-07-03 15:10:15 +00:00
|
|
|
};
|
|
|
|
|
2015-09-30 13:46:56 +00:00
|
|
|
} // namespace internal
|
|
|
|
} // namespace v8
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
#endif // V8_ACCESSORS_H_
|