From a9db2c74b5bae2345ac52be404748954a3b5050d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marja=20H=C3=B6ltt=C3=A4?= Date: Mon, 30 Apr 2018 15:27:37 +0200 Subject: [PATCH] [objects.h splitting] Move classes related to api callbacks. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit BUG=v8:5402,v8:7570 Cq-Include-Trybots: luci.chromium.try:linux_chromium_rel_ng Change-Id: I56beb15109a3557ba514e8d17880b1a37a109031 Reviewed-on: https://chromium-review.googlesource.com/1032552 Reviewed-by: Michael Lippautz Reviewed-by: Igor Sheludko Reviewed-by: Jakob Gruber Commit-Queue: Marja Hölttä Cr-Commit-Position: refs/heads/master@{#52908} --- BUILD.gn | 2 + src/accessors.cc | 1 + src/api-arguments-inl.h | 1 + src/api-natives.cc | 1 + src/api.cc | 1 + src/arm/code-stubs-arm.cc | 1 + src/arm64/code-stubs-arm64.cc | 1 + src/bootstrapper.cc | 1 + src/builtins/builtins-error.cc | 1 + src/builtins/builtins-function-gen.cc | 1 + src/builtins/builtins-function.cc | 1 + src/code-stub-assembler.cc | 1 + src/debug/debug-evaluate.cc | 1 + src/heap/factory.cc | 1 + src/heap/factory.h | 1 + src/heap/heap-inl.h | 1 + src/ia32/code-stubs-ia32.cc | 1 + src/ic/ic.cc | 1 + src/keys.cc | 1 + src/log.cc | 1 + src/mips/code-stubs-mips.cc | 1 + src/mips64/code-stubs-mips64.cc | 1 + src/objects-inl.h | 91 ---------- src/objects.cc | 1 + src/objects.h | 193 +--------------------- src/objects/api-callbacks-inl.h | 117 +++++++++++++ src/objects/api-callbacks.h | 210 ++++++++++++++++++++++++ src/objects/map-inl.h | 1 + src/profiler/heap-snapshot-generator.cc | 1 + src/snapshot/deserializer.cc | 1 + src/snapshot/serializer-common.h | 1 + src/x64/code-stubs-x64.cc | 1 + test/cctest/heap/test-alloc.cc | 1 + test/cctest/test-unboxed-doubles.cc | 1 + 34 files changed, 359 insertions(+), 283 deletions(-) create mode 100644 src/objects/api-callbacks-inl.h create mode 100644 src/objects/api-callbacks.h diff --git a/BUILD.gn b/BUILD.gn index 99a4d81c86..7f1331f9cb 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -2012,6 +2012,8 @@ v8_source_set("v8_base") { "src/objects-printer.cc", "src/objects.cc", "src/objects.h", + "src/objects/api-callbacks-inl.h", + "src/objects/api-callbacks.h", "src/objects/arguments-inl.h", "src/objects/arguments.h", "src/objects/bigint.cc", diff --git a/src/accessors.cc b/src/accessors.cc index f0538248db..565c019092 100644 --- a/src/accessors.cc +++ b/src/accessors.cc @@ -12,6 +12,7 @@ #include "src/heap/factory.h" #include "src/isolate-inl.h" #include "src/messages.h" +#include "src/objects/api-callbacks.h" #include "src/property-details.h" #include "src/prototype.h" diff --git a/src/api-arguments-inl.h b/src/api-arguments-inl.h index 1cf9662b94..503cea8dcb 100644 --- a/src/api-arguments-inl.h +++ b/src/api-arguments-inl.h @@ -7,6 +7,7 @@ #include "src/api-arguments.h" +#include "src/objects/api-callbacks.h" #include "src/tracing/trace-event.h" #include "src/vm-state-inl.h" diff --git a/src/api-natives.cc b/src/api-natives.cc index e56da8c976..cdc13c86ba 100644 --- a/src/api-natives.cc +++ b/src/api-natives.cc @@ -8,6 +8,7 @@ #include "src/isolate-inl.h" #include "src/lookup.h" #include "src/messages.h" +#include "src/objects/api-callbacks.h" #include "src/objects/templates.h" namespace v8 { diff --git a/src/api.cc b/src/api.cc index e062484039..1754e09d4f 100644 --- a/src/api.cc +++ b/src/api.cc @@ -49,6 +49,7 @@ #include "src/json-stringifier.h" #include "src/messages.h" #include "src/objects-inl.h" +#include "src/objects/api-callbacks.h" #include "src/objects/templates.h" #include "src/parsing/parser.h" #include "src/parsing/scanner-character-streams.h" diff --git a/src/arm/code-stubs-arm.cc b/src/arm/code-stubs-arm.cc index d1bba45f97..758f0d1b47 100644 --- a/src/arm/code-stubs-arm.cc +++ b/src/arm/code-stubs-arm.cc @@ -17,6 +17,7 @@ #include "src/ic/ic.h" #include "src/ic/stub-cache.h" #include "src/isolate.h" +#include "src/objects/api-callbacks.h" #include "src/objects/regexp-match-info.h" #include "src/regexp/jsregexp.h" #include "src/regexp/regexp-macro-assembler.h" diff --git a/src/arm64/code-stubs-arm64.cc b/src/arm64/code-stubs-arm64.cc index 2a7d556cc4..eab39731df 100644 --- a/src/arm64/code-stubs-arm64.cc +++ b/src/arm64/code-stubs-arm64.cc @@ -16,6 +16,7 @@ #include "src/ic/ic.h" #include "src/ic/stub-cache.h" #include "src/isolate.h" +#include "src/objects/api-callbacks.h" #include "src/objects/regexp-match-info.h" #include "src/regexp/jsregexp.h" #include "src/regexp/regexp-macro-assembler.h" diff --git a/src/bootstrapper.cc b/src/bootstrapper.cc index f93f42ad2c..ddf86df7bf 100644 --- a/src/bootstrapper.cc +++ b/src/bootstrapper.cc @@ -19,6 +19,7 @@ #include "src/extensions/trigger-failure-extension.h" #include "src/heap/heap.h" #include "src/isolate-inl.h" +#include "src/objects/api-callbacks.h" #include "src/objects/js-regexp.h" #include "src/objects/templates.h" #include "src/snapshot/natives.h" diff --git a/src/builtins/builtins-error.cc b/src/builtins/builtins-error.cc index a80409794c..4e5276484f 100644 --- a/src/builtins/builtins-error.cc +++ b/src/builtins/builtins-error.cc @@ -9,6 +9,7 @@ #include "src/counters.h" #include "src/messages.h" #include "src/objects-inl.h" +#include "src/objects/api-callbacks.h" #include "src/property-descriptor.h" #include "src/string-builder.h" diff --git a/src/builtins/builtins-function-gen.cc b/src/builtins/builtins-function-gen.cc index 05b0fb9fcd..d53f89418c 100644 --- a/src/builtins/builtins-function-gen.cc +++ b/src/builtins/builtins-function-gen.cc @@ -6,6 +6,7 @@ #include "src/builtins/builtins.h" #include "src/code-stub-assembler.h" #include "src/frame-constants.h" +#include "src/objects/api-callbacks.h" #include "src/objects/descriptor-array.h" namespace v8 { diff --git a/src/builtins/builtins-function.cc b/src/builtins/builtins-function.cc index cc6d237af6..df1dc19d82 100644 --- a/src/builtins/builtins-function.cc +++ b/src/builtins/builtins-function.cc @@ -10,6 +10,7 @@ #include "src/counters.h" #include "src/lookup.h" #include "src/objects-inl.h" +#include "src/objects/api-callbacks.h" #include "src/string-builder.h" namespace v8 { diff --git a/src/code-stub-assembler.cc b/src/code-stub-assembler.cc index 2c018f5f7e..88f079efe4 100644 --- a/src/code-stub-assembler.cc +++ b/src/code-stub-assembler.cc @@ -7,6 +7,7 @@ #include "src/code-factory.h" #include "src/frames-inl.h" #include "src/frames.h" +#include "src/objects/api-callbacks.h" namespace v8 { namespace internal { diff --git a/src/debug/debug-evaluate.cc b/src/debug/debug-evaluate.cc index 3ec4184025..d68a4cde90 100644 --- a/src/debug/debug-evaluate.cc +++ b/src/debug/debug-evaluate.cc @@ -16,6 +16,7 @@ #include "src/interpreter/bytecode-array-iterator.h" #include "src/interpreter/bytecodes.h" #include "src/isolate-inl.h" +#include "src/objects/api-callbacks.h" #include "src/snapshot/snapshot.h" namespace v8 { diff --git a/src/heap/factory.cc b/src/heap/factory.cc index 414e0fab96..40785a9bef 100644 --- a/src/heap/factory.cc +++ b/src/heap/factory.cc @@ -15,6 +15,7 @@ #include "src/interpreter/interpreter.h" #include "src/isolate-inl.h" #include "src/macro-assembler.h" +#include "src/objects/api-callbacks.h" #include "src/objects/bigint.h" #include "src/objects/debug-objects-inl.h" #include "src/objects/frame-array-inl.h" diff --git a/src/heap/factory.h b/src/heap/factory.h index f1e9b54550..9d1f2c95c8 100644 --- a/src/heap/factory.h +++ b/src/heap/factory.h @@ -27,6 +27,7 @@ class BreakPoint; class BreakPointInfo; class CallableTask; class CallbackTask; +class CallHandlerInfo; class ConstantElementsPair; class CoverageInfo; class DebugInfo; diff --git a/src/heap/heap-inl.h b/src/heap/heap-inl.h index 4460785044..1603ba96c3 100644 --- a/src/heap/heap-inl.h +++ b/src/heap/heap-inl.h @@ -23,6 +23,7 @@ #include "src/log.h" #include "src/msan.h" #include "src/objects-inl.h" +#include "src/objects/api-callbacks-inl.h" #include "src/objects/descriptor-array.h" #include "src/objects/literal-objects.h" #include "src/objects/scope-info.h" diff --git a/src/ia32/code-stubs-ia32.cc b/src/ia32/code-stubs-ia32.cc index 9602c5a0fb..4d3f942eb2 100644 --- a/src/ia32/code-stubs-ia32.cc +++ b/src/ia32/code-stubs-ia32.cc @@ -15,6 +15,7 @@ #include "src/ic/ic.h" #include "src/ic/stub-cache.h" #include "src/isolate.h" +#include "src/objects/api-callbacks.h" #include "src/regexp/jsregexp.h" #include "src/regexp/regexp-macro-assembler.h" #include "src/runtime/runtime.h" diff --git a/src/ic/ic.cc b/src/ic/ic.cc index 7b992c62e2..7268f62677 100644 --- a/src/ic/ic.cc +++ b/src/ic/ic.cc @@ -20,6 +20,7 @@ #include "src/ic/stub-cache.h" #include "src/isolate-inl.h" #include "src/macro-assembler.h" +#include "src/objects/api-callbacks.h" #include "src/prototype.h" #include "src/runtime-profiler.h" #include "src/runtime/runtime-utils.h" diff --git a/src/keys.cc b/src/keys.cc index 873e87b602..22fcc62be9 100644 --- a/src/keys.cc +++ b/src/keys.cc @@ -10,6 +10,7 @@ #include "src/identity-map.h" #include "src/isolate-inl.h" #include "src/objects-inl.h" +#include "src/objects/api-callbacks.h" #include "src/property-descriptor.h" #include "src/prototype.h" diff --git a/src/log.cc b/src/log.cc index 3c130e831d..7ec4627e47 100644 --- a/src/log.cc +++ b/src/log.cc @@ -22,6 +22,7 @@ #include "src/libsampler/sampler.h" #include "src/log-inl.h" #include "src/macro-assembler.h" +#include "src/objects/api-callbacks.h" #include "src/perf-jit.h" #include "src/profiler/profiler-listener.h" #include "src/profiler/tick-sample.h" diff --git a/src/mips/code-stubs-mips.cc b/src/mips/code-stubs-mips.cc index 525968cd43..93ca3d3513 100644 --- a/src/mips/code-stubs-mips.cc +++ b/src/mips/code-stubs-mips.cc @@ -14,6 +14,7 @@ #include "src/ic/ic.h" #include "src/ic/stub-cache.h" #include "src/isolate.h" +#include "src/objects/api-callbacks.h" #include "src/regexp/jsregexp.h" #include "src/regexp/regexp-macro-assembler.h" #include "src/runtime/runtime.h" diff --git a/src/mips64/code-stubs-mips64.cc b/src/mips64/code-stubs-mips64.cc index 85effa58ee..a24a6650f1 100644 --- a/src/mips64/code-stubs-mips64.cc +++ b/src/mips64/code-stubs-mips64.cc @@ -13,6 +13,7 @@ #include "src/ic/ic.h" #include "src/ic/stub-cache.h" #include "src/isolate.h" +#include "src/objects/api-callbacks.h" #include "src/regexp/jsregexp.h" #include "src/regexp/regexp-macro-assembler.h" #include "src/runtime/runtime.h" diff --git a/src/objects-inl.h b/src/objects-inl.h index db3f9e55b2..56d6673435 100644 --- a/src/objects-inl.h +++ b/src/objects-inl.h @@ -81,7 +81,6 @@ TYPE_CHECKER(BigInt, BIGINT_TYPE) TYPE_CHECKER(BoilerplateDescription, BOILERPLATE_DESCRIPTION_TYPE) TYPE_CHECKER(BreakPoint, TUPLE2_TYPE) TYPE_CHECKER(BreakPointInfo, TUPLE2_TYPE) -TYPE_CHECKER(CallHandlerInfo, CALL_HANDLER_INFO_TYPE) TYPE_CHECKER(Cell, CELL_TYPE) TYPE_CHECKER(ConstantElementsPair, TUPLE2_TYPE) TYPE_CHECKER(CoverageInfo, FIXED_ARRAY_TYPE) @@ -564,15 +563,12 @@ bool Object::IsMinusZero() const { // ------------------------------------ // Cast operations -CAST_ACCESSOR(AccessCheckInfo) -CAST_ACCESSOR(AccessorInfo) CAST_ACCESSOR(AccessorPair) CAST_ACCESSOR(AllocationMemento) CAST_ACCESSOR(AllocationSite) CAST_ACCESSOR(AsyncGeneratorRequest) CAST_ACCESSOR(BigInt) CAST_ACCESSOR(BoilerplateDescription) -CAST_ACCESSOR(CallHandlerInfo) CAST_ACCESSOR(Cell) CAST_ACCESSOR(ConstantElementsPair) CAST_ACCESSOR(ContextExtension) @@ -582,7 +578,6 @@ CAST_ACCESSOR(FeedbackCell) CAST_ACCESSOR(Foreign) CAST_ACCESSOR(GlobalDictionary) CAST_ACCESSOR(HeapObject) -CAST_ACCESSOR(InterceptorInfo) CAST_ACCESSOR(JSAsyncFromSyncIterator) CAST_ACCESSOR(JSAsyncGeneratorObject) CAST_ACCESSOR(JSBoundFunction) @@ -2294,33 +2289,6 @@ ACCESSORS(JSGlobalObject, global_proxy, JSObject, kGlobalProxyOffset) ACCESSORS(JSGlobalProxy, native_context, Object, kNativeContextOffset) -ACCESSORS(AccessorInfo, name, Name, kNameOffset) -SMI_ACCESSORS(AccessorInfo, flags, kFlagsOffset) -ACCESSORS(AccessorInfo, expected_receiver_type, Object, - kExpectedReceiverTypeOffset) - -ACCESSORS_CHECKED2(AccessorInfo, getter, Object, kGetterOffset, true, - Foreign::IsNormalized(value)) -ACCESSORS_CHECKED2(AccessorInfo, setter, Object, kSetterOffset, true, - Foreign::IsNormalized(value)); -ACCESSORS(AccessorInfo, js_getter, Object, kJsGetterOffset) -ACCESSORS(AccessorInfo, data, Object, kDataOffset) - -bool AccessorInfo::has_getter() { - bool result = getter() != Smi::kZero; - DCHECK_EQ(result, - getter() != Smi::kZero && - Foreign::cast(getter())->foreign_address() != kNullAddress); - return result; -} - -bool AccessorInfo::has_setter() { - bool result = setter() != Smi::kZero; - DCHECK_EQ(result, - setter() != Smi::kZero && - Foreign::cast(setter())->foreign_address() != kNullAddress); - return result; -} ACCESSORS(AsyncGeneratorRequest, next, Object, kNextOffset) SMI_ACCESSORS(AsyncGeneratorRequest, resume_mode, kResumeModeOffset) @@ -2371,38 +2339,6 @@ ACCESSORS(TemplateObjectDescription, cooked_strings, FixedArray, ACCESSORS(AccessorPair, getter, Object, kGetterOffset) ACCESSORS(AccessorPair, setter, Object, kSetterOffset) -ACCESSORS(AccessCheckInfo, callback, Object, kCallbackOffset) -ACCESSORS(AccessCheckInfo, named_interceptor, Object, kNamedInterceptorOffset) -ACCESSORS(AccessCheckInfo, indexed_interceptor, Object, - kIndexedInterceptorOffset) -ACCESSORS(AccessCheckInfo, data, Object, kDataOffset) - -ACCESSORS(InterceptorInfo, getter, Object, kGetterOffset) -ACCESSORS(InterceptorInfo, setter, Object, kSetterOffset) -ACCESSORS(InterceptorInfo, query, Object, kQueryOffset) -ACCESSORS(InterceptorInfo, descriptor, Object, kDescriptorOffset) -ACCESSORS(InterceptorInfo, deleter, Object, kDeleterOffset) -ACCESSORS(InterceptorInfo, enumerator, Object, kEnumeratorOffset) -ACCESSORS(InterceptorInfo, definer, Object, kDefinerOffset) -ACCESSORS(InterceptorInfo, data, Object, kDataOffset) -SMI_ACCESSORS(InterceptorInfo, flags, kFlagsOffset) -BOOL_ACCESSORS(InterceptorInfo, flags, can_intercept_symbols, - kCanInterceptSymbolsBit) -BOOL_ACCESSORS(InterceptorInfo, flags, all_can_read, kAllCanReadBit) -BOOL_ACCESSORS(InterceptorInfo, flags, non_masking, kNonMasking) -BOOL_ACCESSORS(InterceptorInfo, flags, is_named, kNamed) -BOOL_ACCESSORS(InterceptorInfo, flags, has_no_side_effect, kHasNoSideEffect) - -ACCESSORS(CallHandlerInfo, callback, Object, kCallbackOffset) -ACCESSORS(CallHandlerInfo, js_callback, Object, kJsCallbackOffset) -ACCESSORS(CallHandlerInfo, data, Object, kDataOffset) - -bool CallHandlerInfo::IsSideEffectFreeCallHandlerInfo() const { - DCHECK(map() == GetHeap()->side_effect_call_handler_info_map() || - map() == GetHeap()->side_effect_free_call_handler_info_map()); - return map() == GetHeap()->side_effect_free_call_handler_info_map(); -} - ACCESSORS(AllocationSite, transition_info_or_boilerplate, Object, kTransitionInfoOrBoilerplateOffset) @@ -3085,33 +3021,6 @@ inline int JSGlobalProxy::SizeWithEmbedderFields(int embedder_field_count) { return kSize + embedder_field_count * kPointerSize; } -BIT_FIELD_ACCESSORS(AccessorInfo, flags, all_can_read, - AccessorInfo::AllCanReadBit) -BIT_FIELD_ACCESSORS(AccessorInfo, flags, all_can_write, - AccessorInfo::AllCanWriteBit) -BIT_FIELD_ACCESSORS(AccessorInfo, flags, is_special_data_property, - AccessorInfo::IsSpecialDataPropertyBit) -BIT_FIELD_ACCESSORS(AccessorInfo, flags, replace_on_access, - AccessorInfo::ReplaceOnAccessBit) -BIT_FIELD_ACCESSORS(AccessorInfo, flags, is_sloppy, AccessorInfo::IsSloppyBit) -BIT_FIELD_ACCESSORS(AccessorInfo, flags, has_no_side_effect, - AccessorInfo::HasNoSideEffectBit) -BIT_FIELD_ACCESSORS(AccessorInfo, flags, initial_property_attributes, - AccessorInfo::InitialAttributesBits) - -bool AccessorInfo::IsCompatibleReceiver(Object* receiver) { - if (!HasExpectedReceiverType()) return true; - if (!receiver->IsJSObject()) return false; - return FunctionTemplateInfo::cast(expected_receiver_type()) - ->IsTemplateFor(JSObject::cast(receiver)->map()); -} - - -bool AccessorInfo::HasExpectedReceiverType() { - return expected_receiver_type()->IsFunctionTemplateInfo(); -} - - Object* AccessorPair::get(AccessorComponent component) { return component == ACCESSOR_GETTER ? getter() : setter(); } diff --git a/src/objects.cc b/src/objects.cc index d71933f799..d475bf9701 100644 --- a/src/objects.cc +++ b/src/objects.cc @@ -53,6 +53,7 @@ #include "src/map-updater.h" #include "src/messages.h" #include "src/objects-body-descriptors-inl.h" +#include "src/objects/api-callbacks.h" #include "src/objects/bigint.h" #include "src/objects/code-inl.h" #include "src/objects/compilation-cache-inl.h" diff --git a/src/objects.h b/src/objects.h index 2f6154e850..234cfbf9e1 100644 --- a/src/objects.h +++ b/src/objects.h @@ -953,6 +953,7 @@ bool ComparisonResultToBool(Operation op, ComparisonResult result); class AbstractCode; class AccessorPair; +class AccessCheckInfo; class AllocationSite; class ByteArray; class Cell; @@ -4445,100 +4446,6 @@ class Foreign: public HeapObject { DISALLOW_IMPLICIT_CONSTRUCTORS(Foreign); }; -// An accessor must have a getter, but can have no setter. -// -// When setting a property, V8 searches accessors in prototypes. -// If an accessor was found and it does not have a setter, -// the request is ignored. -// -// If the accessor in the prototype has the READ_ONLY property attribute, then -// a new value is added to the derived object when the property is set. -// This shadows the accessor in the prototype. -class AccessorInfo: public Struct { - public: - DECL_ACCESSORS(name, Name) - DECL_INT_ACCESSORS(flags) - DECL_ACCESSORS(expected_receiver_type, Object) - // This directly points at a foreign C function to be used from the runtime. - DECL_ACCESSORS(getter, Object) - inline bool has_getter(); - DECL_ACCESSORS(setter, Object) - inline bool has_setter(); - // This either points at the same as above, or a trampoline in case we are - // running with the simulator. Use these entries from generated code. - DECL_ACCESSORS(js_getter, Object) - DECL_ACCESSORS(data, Object) - - static Address redirect(Isolate* isolate, Address address, - AccessorComponent component); - Address redirected_getter() const; - - // Dispatched behavior. - DECL_PRINTER(AccessorInfo) - - DECL_BOOLEAN_ACCESSORS(all_can_read) - DECL_BOOLEAN_ACCESSORS(all_can_write) - DECL_BOOLEAN_ACCESSORS(is_special_data_property) - DECL_BOOLEAN_ACCESSORS(replace_on_access) - DECL_BOOLEAN_ACCESSORS(is_sloppy) - DECL_BOOLEAN_ACCESSORS(has_no_side_effect) - - // The property attributes used when an API object template is instantiated - // for the first time. Changing of this value afterwards does not affect - // the actual attributes of a property. - inline PropertyAttributes initial_property_attributes() const; - inline void set_initial_property_attributes(PropertyAttributes attributes); - - // Checks whether the given receiver is compatible with this accessor. - static bool IsCompatibleReceiverMap(Isolate* isolate, - Handle info, - Handle map); - inline bool IsCompatibleReceiver(Object* receiver); - - DECL_CAST(AccessorInfo) - - // Dispatched behavior. - DECL_VERIFIER(AccessorInfo) - - // Append all descriptors to the array that are not already there. - // Return number added. - static int AppendUnique(Handle descriptors, - Handle array, - int valid_descriptors); - -// Layout description. -#define ACCESSOR_INFO_FIELDS(V) \ - V(kNameOffset, kPointerSize) \ - V(kFlagsOffset, kPointerSize) \ - V(kExpectedReceiverTypeOffset, kPointerSize) \ - V(kSetterOffset, kPointerSize) \ - V(kGetterOffset, kPointerSize) \ - V(kJsGetterOffset, kPointerSize) \ - V(kDataOffset, kPointerSize) \ - V(kSize, 0) - - DEFINE_FIELD_OFFSET_CONSTANTS(HeapObject::kHeaderSize, ACCESSOR_INFO_FIELDS) -#undef ACCESSOR_INFO_FIELDS - - private: - inline bool HasExpectedReceiverType(); - -// Bit positions in |flags|. -#define ACCESSOR_INFO_FLAGS_BIT_FIELDS(V, _) \ - V(AllCanReadBit, bool, 1, _) \ - V(AllCanWriteBit, bool, 1, _) \ - V(IsSpecialDataPropertyBit, bool, 1, _) \ - V(IsSloppyBit, bool, 1, _) \ - V(ReplaceOnAccessBit, bool, 1, _) \ - V(HasNoSideEffectBit, bool, 1, _) \ - V(InitialAttributesBits, PropertyAttributes, 3, _) - - DEFINE_BIT_FIELDS(ACCESSOR_INFO_FLAGS_BIT_FIELDS) -#undef ACCESSOR_INFO_FLAGS_BIT_FIELDS - - DISALLOW_IMPLICIT_CONSTRUCTORS(AccessorInfo); -}; - // Support for JavaScript accessors: A pair of a getter and a setter. Each // accessor can either be // * a JavaScript function or proxy: a real accessor @@ -4588,104 +4495,6 @@ class AccessorPair: public Struct { DISALLOW_IMPLICIT_CONSTRUCTORS(AccessorPair); }; - -class AccessCheckInfo: public Struct { - public: - DECL_ACCESSORS(callback, Object) - DECL_ACCESSORS(named_interceptor, Object) - DECL_ACCESSORS(indexed_interceptor, Object) - DECL_ACCESSORS(data, Object) - - DECL_CAST(AccessCheckInfo) - - // Dispatched behavior. - DECL_PRINTER(AccessCheckInfo) - DECL_VERIFIER(AccessCheckInfo) - - static AccessCheckInfo* Get(Isolate* isolate, Handle receiver); - - static const int kCallbackOffset = HeapObject::kHeaderSize; - static const int kNamedInterceptorOffset = kCallbackOffset + kPointerSize; - static const int kIndexedInterceptorOffset = - kNamedInterceptorOffset + kPointerSize; - static const int kDataOffset = kIndexedInterceptorOffset + kPointerSize; - static const int kSize = kDataOffset + kPointerSize; - - private: - DISALLOW_IMPLICIT_CONSTRUCTORS(AccessCheckInfo); -}; - - -class InterceptorInfo: public Struct { - public: - DECL_ACCESSORS(getter, Object) - DECL_ACCESSORS(setter, Object) - DECL_ACCESSORS(query, Object) - DECL_ACCESSORS(descriptor, Object) - DECL_ACCESSORS(deleter, Object) - DECL_ACCESSORS(enumerator, Object) - DECL_ACCESSORS(definer, Object) - DECL_ACCESSORS(data, Object) - DECL_BOOLEAN_ACCESSORS(can_intercept_symbols) - DECL_BOOLEAN_ACCESSORS(all_can_read) - DECL_BOOLEAN_ACCESSORS(non_masking) - DECL_BOOLEAN_ACCESSORS(is_named) - DECL_BOOLEAN_ACCESSORS(has_no_side_effect) - - inline int flags() const; - inline void set_flags(int flags); - - DECL_CAST(InterceptorInfo) - - // Dispatched behavior. - DECL_PRINTER(InterceptorInfo) - DECL_VERIFIER(InterceptorInfo) - - static const int kGetterOffset = HeapObject::kHeaderSize; - static const int kSetterOffset = kGetterOffset + kPointerSize; - static const int kQueryOffset = kSetterOffset + kPointerSize; - static const int kDescriptorOffset = kQueryOffset + kPointerSize; - static const int kDeleterOffset = kDescriptorOffset + kPointerSize; - static const int kEnumeratorOffset = kDeleterOffset + kPointerSize; - static const int kDefinerOffset = kEnumeratorOffset + kPointerSize; - static const int kDataOffset = kDefinerOffset + kPointerSize; - static const int kFlagsOffset = kDataOffset + kPointerSize; - static const int kSize = kFlagsOffset + kPointerSize; - - static const int kCanInterceptSymbolsBit = 0; - static const int kAllCanReadBit = 1; - static const int kNonMasking = 2; - static const int kNamed = 3; - static const int kHasNoSideEffect = 4; - - private: - DISALLOW_IMPLICIT_CONSTRUCTORS(InterceptorInfo); -}; - -class CallHandlerInfo : public Tuple3 { - public: - DECL_ACCESSORS(callback, Object) - DECL_ACCESSORS(js_callback, Object) - DECL_ACCESSORS(data, Object) - - DECL_CAST(CallHandlerInfo) - - inline bool IsSideEffectFreeCallHandlerInfo() const; - - // Dispatched behavior. - DECL_PRINTER(CallHandlerInfo) - DECL_VERIFIER(CallHandlerInfo) - - Address redirected_callback() const; - - static const int kCallbackOffset = kValue1Offset; - static const int kJsCallbackOffset = kValue2Offset; - static const int kDataOffset = kValue3Offset; - - private: - DISALLOW_IMPLICIT_CONSTRUCTORS(CallHandlerInfo); -}; - class StackFrameInfo : public Struct { public: DECL_INT_ACCESSORS(line_number) diff --git a/src/objects/api-callbacks-inl.h b/src/objects/api-callbacks-inl.h new file mode 100644 index 0000000000..ee8265f4ba --- /dev/null +++ b/src/objects/api-callbacks-inl.h @@ -0,0 +1,117 @@ +// Copyright 2018 the V8 project authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef V8_OBJECTS_API_CALLBACKS_INL_H_ +#define V8_OBJECTS_API_CALLBACKS_INL_H_ + +#include "src/objects/api-callbacks.h" + +#include "src/heap/heap-inl.h" +#include "src/objects/name.h" +#include "src/objects/templates.h" + +// Has to be the last include (doesn't have include guards): +#include "src/objects/object-macros.h" + +namespace v8 { +namespace internal { + +CAST_ACCESSOR(AccessorInfo) +CAST_ACCESSOR(AccessCheckInfo) +CAST_ACCESSOR(InterceptorInfo) +CAST_ACCESSOR(CallHandlerInfo) + +TYPE_CHECKER(CallHandlerInfo, CALL_HANDLER_INFO_TYPE) + +ACCESSORS(AccessorInfo, name, Name, kNameOffset) +SMI_ACCESSORS(AccessorInfo, flags, kFlagsOffset) +ACCESSORS(AccessorInfo, expected_receiver_type, Object, + kExpectedReceiverTypeOffset) + +ACCESSORS_CHECKED2(AccessorInfo, getter, Object, kGetterOffset, true, + Foreign::IsNormalized(value)) +ACCESSORS_CHECKED2(AccessorInfo, setter, Object, kSetterOffset, true, + Foreign::IsNormalized(value)); +ACCESSORS(AccessorInfo, js_getter, Object, kJsGetterOffset) +ACCESSORS(AccessorInfo, data, Object, kDataOffset) + +bool AccessorInfo::has_getter() { + bool result = getter() != Smi::kZero; + DCHECK_EQ(result, + getter() != Smi::kZero && + Foreign::cast(getter())->foreign_address() != kNullAddress); + return result; +} + +bool AccessorInfo::has_setter() { + bool result = setter() != Smi::kZero; + DCHECK_EQ(result, + setter() != Smi::kZero && + Foreign::cast(setter())->foreign_address() != kNullAddress); + return result; +} + +BIT_FIELD_ACCESSORS(AccessorInfo, flags, all_can_read, + AccessorInfo::AllCanReadBit) +BIT_FIELD_ACCESSORS(AccessorInfo, flags, all_can_write, + AccessorInfo::AllCanWriteBit) +BIT_FIELD_ACCESSORS(AccessorInfo, flags, is_special_data_property, + AccessorInfo::IsSpecialDataPropertyBit) +BIT_FIELD_ACCESSORS(AccessorInfo, flags, replace_on_access, + AccessorInfo::ReplaceOnAccessBit) +BIT_FIELD_ACCESSORS(AccessorInfo, flags, is_sloppy, AccessorInfo::IsSloppyBit) +BIT_FIELD_ACCESSORS(AccessorInfo, flags, has_no_side_effect, + AccessorInfo::HasNoSideEffectBit) +BIT_FIELD_ACCESSORS(AccessorInfo, flags, initial_property_attributes, + AccessorInfo::InitialAttributesBits) + +bool AccessorInfo::IsCompatibleReceiver(Object* receiver) { + if (!HasExpectedReceiverType()) return true; + if (!receiver->IsJSObject()) return false; + return FunctionTemplateInfo::cast(expected_receiver_type()) + ->IsTemplateFor(JSObject::cast(receiver)->map()); +} + +bool AccessorInfo::HasExpectedReceiverType() { + return expected_receiver_type()->IsFunctionTemplateInfo(); +} + +ACCESSORS(AccessCheckInfo, callback, Object, kCallbackOffset) +ACCESSORS(AccessCheckInfo, named_interceptor, Object, kNamedInterceptorOffset) +ACCESSORS(AccessCheckInfo, indexed_interceptor, Object, + kIndexedInterceptorOffset) +ACCESSORS(AccessCheckInfo, data, Object, kDataOffset) + +ACCESSORS(InterceptorInfo, getter, Object, kGetterOffset) +ACCESSORS(InterceptorInfo, setter, Object, kSetterOffset) +ACCESSORS(InterceptorInfo, query, Object, kQueryOffset) +ACCESSORS(InterceptorInfo, descriptor, Object, kDescriptorOffset) +ACCESSORS(InterceptorInfo, deleter, Object, kDeleterOffset) +ACCESSORS(InterceptorInfo, enumerator, Object, kEnumeratorOffset) +ACCESSORS(InterceptorInfo, definer, Object, kDefinerOffset) +ACCESSORS(InterceptorInfo, data, Object, kDataOffset) +SMI_ACCESSORS(InterceptorInfo, flags, kFlagsOffset) +BOOL_ACCESSORS(InterceptorInfo, flags, can_intercept_symbols, + kCanInterceptSymbolsBit) +BOOL_ACCESSORS(InterceptorInfo, flags, all_can_read, kAllCanReadBit) +BOOL_ACCESSORS(InterceptorInfo, flags, non_masking, kNonMasking) +BOOL_ACCESSORS(InterceptorInfo, flags, is_named, kNamed) +BOOL_ACCESSORS(InterceptorInfo, flags, has_no_side_effect, kHasNoSideEffect) + +ACCESSORS(CallHandlerInfo, callback, Object, kCallbackOffset) +ACCESSORS(CallHandlerInfo, js_callback, Object, kJsCallbackOffset) +ACCESSORS(CallHandlerInfo, data, Object, kDataOffset) + +bool CallHandlerInfo::IsSideEffectFreeCallHandlerInfo() const { + DCHECK(map() == GetHeap()->side_effect_call_handler_info_map() || + map() == GetHeap()->side_effect_free_call_handler_info_map()); + return map() == GetHeap()->side_effect_free_call_handler_info_map(); +} + +} // namespace internal +} // namespace v8 + +#include "src/objects/object-macros-undef.h" + +#endif // V8_OBJECTS_API_CALLBACKS_INL_H_ diff --git a/src/objects/api-callbacks.h b/src/objects/api-callbacks.h new file mode 100644 index 0000000000..49dfb1cf96 --- /dev/null +++ b/src/objects/api-callbacks.h @@ -0,0 +1,210 @@ +// Copyright 2018 the V8 project authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef V8_OBJECTS_API_CALLBACKS_H_ +#define V8_OBJECTS_API_CALLBACKS_H_ + +#include "src/objects.h" + +// Has to be the last include (doesn't have include guards): +#include "src/objects/object-macros.h" + +namespace v8 { +namespace internal { + +// An accessor must have a getter, but can have no setter. +// +// When setting a property, V8 searches accessors in prototypes. +// If an accessor was found and it does not have a setter, +// the request is ignored. +// +// If the accessor in the prototype has the READ_ONLY property attribute, then +// a new value is added to the derived object when the property is set. +// This shadows the accessor in the prototype. +class AccessorInfo : public Struct { + public: + DECL_ACCESSORS(name, Name) + DECL_INT_ACCESSORS(flags) + DECL_ACCESSORS(expected_receiver_type, Object) + // This directly points at a foreign C function to be used from the runtime. + DECL_ACCESSORS(getter, Object) + inline bool has_getter(); + DECL_ACCESSORS(setter, Object) + inline bool has_setter(); + // This either points at the same as above, or a trampoline in case we are + // running with the simulator. Use these entries from generated code. + DECL_ACCESSORS(js_getter, Object) + DECL_ACCESSORS(data, Object) + + static Address redirect(Isolate* isolate, Address address, + AccessorComponent component); + Address redirected_getter() const; + + // Dispatched behavior. + DECL_PRINTER(AccessorInfo) + + DECL_BOOLEAN_ACCESSORS(all_can_read) + DECL_BOOLEAN_ACCESSORS(all_can_write) + DECL_BOOLEAN_ACCESSORS(is_special_data_property) + DECL_BOOLEAN_ACCESSORS(replace_on_access) + DECL_BOOLEAN_ACCESSORS(is_sloppy) + DECL_BOOLEAN_ACCESSORS(has_no_side_effect) + + // The property attributes used when an API object template is instantiated + // for the first time. Changing of this value afterwards does not affect + // the actual attributes of a property. + inline PropertyAttributes initial_property_attributes() const; + inline void set_initial_property_attributes(PropertyAttributes attributes); + + // Checks whether the given receiver is compatible with this accessor. + static bool IsCompatibleReceiverMap(Isolate* isolate, + Handle info, + Handle map); + inline bool IsCompatibleReceiver(Object* receiver); + + DECL_CAST(AccessorInfo) + + // Dispatched behavior. + DECL_VERIFIER(AccessorInfo) + + // Append all descriptors to the array that are not already there. + // Return number added. + static int AppendUnique(Handle descriptors, Handle array, + int valid_descriptors); + +// Layout description. +#define ACCESSOR_INFO_FIELDS(V) \ + V(kNameOffset, kPointerSize) \ + V(kFlagsOffset, kPointerSize) \ + V(kExpectedReceiverTypeOffset, kPointerSize) \ + V(kSetterOffset, kPointerSize) \ + V(kGetterOffset, kPointerSize) \ + V(kJsGetterOffset, kPointerSize) \ + V(kDataOffset, kPointerSize) \ + V(kSize, 0) + + DEFINE_FIELD_OFFSET_CONSTANTS(HeapObject::kHeaderSize, ACCESSOR_INFO_FIELDS) +#undef ACCESSOR_INFO_FIELDS + + private: + inline bool HasExpectedReceiverType(); + +// Bit positions in |flags|. +#define ACCESSOR_INFO_FLAGS_BIT_FIELDS(V, _) \ + V(AllCanReadBit, bool, 1, _) \ + V(AllCanWriteBit, bool, 1, _) \ + V(IsSpecialDataPropertyBit, bool, 1, _) \ + V(IsSloppyBit, bool, 1, _) \ + V(ReplaceOnAccessBit, bool, 1, _) \ + V(HasNoSideEffectBit, bool, 1, _) \ + V(InitialAttributesBits, PropertyAttributes, 3, _) + + DEFINE_BIT_FIELDS(ACCESSOR_INFO_FLAGS_BIT_FIELDS) +#undef ACCESSOR_INFO_FLAGS_BIT_FIELDS + + DISALLOW_IMPLICIT_CONSTRUCTORS(AccessorInfo); +}; + +class AccessCheckInfo : public Struct { + public: + DECL_ACCESSORS(callback, Object) + DECL_ACCESSORS(named_interceptor, Object) + DECL_ACCESSORS(indexed_interceptor, Object) + DECL_ACCESSORS(data, Object) + + DECL_CAST(AccessCheckInfo) + + // Dispatched behavior. + DECL_PRINTER(AccessCheckInfo) + DECL_VERIFIER(AccessCheckInfo) + + static AccessCheckInfo* Get(Isolate* isolate, Handle receiver); + + static const int kCallbackOffset = HeapObject::kHeaderSize; + static const int kNamedInterceptorOffset = kCallbackOffset + kPointerSize; + static const int kIndexedInterceptorOffset = + kNamedInterceptorOffset + kPointerSize; + static const int kDataOffset = kIndexedInterceptorOffset + kPointerSize; + static const int kSize = kDataOffset + kPointerSize; + + private: + DISALLOW_IMPLICIT_CONSTRUCTORS(AccessCheckInfo); +}; + +class InterceptorInfo : public Struct { + public: + DECL_ACCESSORS(getter, Object) + DECL_ACCESSORS(setter, Object) + DECL_ACCESSORS(query, Object) + DECL_ACCESSORS(descriptor, Object) + DECL_ACCESSORS(deleter, Object) + DECL_ACCESSORS(enumerator, Object) + DECL_ACCESSORS(definer, Object) + DECL_ACCESSORS(data, Object) + DECL_BOOLEAN_ACCESSORS(can_intercept_symbols) + DECL_BOOLEAN_ACCESSORS(all_can_read) + DECL_BOOLEAN_ACCESSORS(non_masking) + DECL_BOOLEAN_ACCESSORS(is_named) + DECL_BOOLEAN_ACCESSORS(has_no_side_effect) + + inline int flags() const; + inline void set_flags(int flags); + + DECL_CAST(InterceptorInfo) + + // Dispatched behavior. + DECL_PRINTER(InterceptorInfo) + DECL_VERIFIER(InterceptorInfo) + + static const int kGetterOffset = HeapObject::kHeaderSize; + static const int kSetterOffset = kGetterOffset + kPointerSize; + static const int kQueryOffset = kSetterOffset + kPointerSize; + static const int kDescriptorOffset = kQueryOffset + kPointerSize; + static const int kDeleterOffset = kDescriptorOffset + kPointerSize; + static const int kEnumeratorOffset = kDeleterOffset + kPointerSize; + static const int kDefinerOffset = kEnumeratorOffset + kPointerSize; + static const int kDataOffset = kDefinerOffset + kPointerSize; + static const int kFlagsOffset = kDataOffset + kPointerSize; + static const int kSize = kFlagsOffset + kPointerSize; + + static const int kCanInterceptSymbolsBit = 0; + static const int kAllCanReadBit = 1; + static const int kNonMasking = 2; + static const int kNamed = 3; + static const int kHasNoSideEffect = 4; + + private: + DISALLOW_IMPLICIT_CONSTRUCTORS(InterceptorInfo); +}; + +class CallHandlerInfo : public Tuple3 { + public: + DECL_ACCESSORS(callback, Object) + DECL_ACCESSORS(js_callback, Object) + DECL_ACCESSORS(data, Object) + + DECL_CAST(CallHandlerInfo) + + inline bool IsSideEffectFreeCallHandlerInfo() const; + + // Dispatched behavior. + DECL_PRINTER(CallHandlerInfo) + DECL_VERIFIER(CallHandlerInfo) + + Address redirected_callback() const; + + static const int kCallbackOffset = kValue1Offset; + static const int kJsCallbackOffset = kValue2Offset; + static const int kDataOffset = kValue3Offset; + + private: + DISALLOW_IMPLICIT_CONSTRUCTORS(CallHandlerInfo); +}; + +} // namespace internal +} // namespace v8 + +#include "src/objects/object-macros-undef.h" + +#endif // V8_OBJECTS_API_CALLBACKS_H_ diff --git a/src/objects/map-inl.h b/src/objects/map-inl.h index 212f76b9a6..696dea91ea 100644 --- a/src/objects/map-inl.h +++ b/src/objects/map-inl.h @@ -9,6 +9,7 @@ #include "src/field-type.h" #include "src/objects-inl.h" +#include "src/objects/api-callbacks-inl.h" #include "src/objects/descriptor-array.h" #include "src/objects/shared-function-info.h" #include "src/objects/templates-inl.h" diff --git a/src/profiler/heap-snapshot-generator.cc b/src/profiler/heap-snapshot-generator.cc index 3062413963..cd53b2af5e 100644 --- a/src/profiler/heap-snapshot-generator.cc +++ b/src/profiler/heap-snapshot-generator.cc @@ -14,6 +14,7 @@ #include "src/layout-descriptor.h" #include "src/objects-body-descriptors.h" #include "src/objects-inl.h" +#include "src/objects/api-callbacks.h" #include "src/profiler/allocation-tracker.h" #include "src/profiler/heap-profiler.h" #include "src/profiler/heap-snapshot-generator-inl.h" diff --git a/src/snapshot/deserializer.cc b/src/snapshot/deserializer.cc index 56ea3b83a3..7e42e71e75 100644 --- a/src/snapshot/deserializer.cc +++ b/src/snapshot/deserializer.cc @@ -6,6 +6,7 @@ #include "src/assembler-inl.h" #include "src/isolate.h" +#include "src/objects/api-callbacks.h" #include "src/objects/hash-table.h" #include "src/objects/maybe-object.h" #include "src/objects/string.h" diff --git a/src/snapshot/serializer-common.h b/src/snapshot/serializer-common.h index 8663e32471..3e9abef597 100644 --- a/src/snapshot/serializer-common.h +++ b/src/snapshot/serializer-common.h @@ -15,6 +15,7 @@ namespace v8 { namespace internal { +class CallHandlerInfo; class Isolate; class ExternalReferenceEncoder { diff --git a/src/x64/code-stubs-x64.cc b/src/x64/code-stubs-x64.cc index f42fbfe4f7..04e937a870 100644 --- a/src/x64/code-stubs-x64.cc +++ b/src/x64/code-stubs-x64.cc @@ -16,6 +16,7 @@ #include "src/ic/stub-cache.h" #include "src/isolate.h" #include "src/objects-inl.h" +#include "src/objects/api-callbacks.h" #include "src/objects/regexp-match-info.h" #include "src/regexp/jsregexp.h" #include "src/regexp/regexp-macro-assembler.h" diff --git a/test/cctest/heap/test-alloc.cc b/test/cctest/heap/test-alloc.cc index 7d85db6e7f..e4c0018dbc 100644 --- a/test/cctest/heap/test-alloc.cc +++ b/test/cctest/heap/test-alloc.cc @@ -31,6 +31,7 @@ #include "src/accessors.h" #include "src/api.h" #include "src/objects-inl.h" +#include "src/objects/api-callbacks.h" #include "src/property.h" #include "test/cctest/heap/heap-tester.h" #include "test/cctest/heap/heap-utils.h" diff --git a/test/cctest/test-unboxed-doubles.cc b/test/cctest/test-unboxed-doubles.cc index 6b7b60150e..97623bc3ef 100644 --- a/test/cctest/test-unboxed-doubles.cc +++ b/test/cctest/test-unboxed-doubles.cc @@ -20,6 +20,7 @@ #include "src/layout-descriptor.h" #include "src/macro-assembler.h" #include "src/objects-inl.h" +#include "src/objects/api-callbacks.h" #include "src/property.h" #include "test/cctest/cctest.h" #include "test/cctest/heap/heap-utils.h"