[objects.h splitting] Move TemplateInfo + related classes.
BUG=v8:5402,v8:7570 Cq-Include-Trybots: luci.chromium.try:linux_chromium_rel_ng Change-Id: Ia97efa31495b371805eb469be8395aaa19c7628d Reviewed-on: https://chromium-review.googlesource.com/1032431 Reviewed-by: Jakob Gruber <jgruber@chromium.org> Reviewed-by: Georg Neis <neis@chromium.org> Reviewed-by: Andreas Haas <ahaas@chromium.org> Reviewed-by: Michael Lippautz <mlippautz@chromium.org> Commit-Queue: Marja Hölttä <marja@chromium.org> Cr-Commit-Position: refs/heads/master@{#52841}
This commit is contained in:
parent
1961008a03
commit
0a01b62022
2
BUILD.gn
2
BUILD.gn
@ -2071,6 +2071,8 @@ v8_source_set("v8_base") {
|
||||
"src/objects/string.h",
|
||||
"src/objects/template-objects.cc",
|
||||
"src/objects/template-objects.h",
|
||||
"src/objects/templates-inl.h",
|
||||
"src/objects/templates.h",
|
||||
"src/optimized-compilation-info.cc",
|
||||
"src/optimized-compilation-info.h",
|
||||
"src/ostreams.cc",
|
||||
|
@ -8,6 +8,7 @@
|
||||
#include "src/isolate-inl.h"
|
||||
#include "src/lookup.h"
|
||||
#include "src/messages.h"
|
||||
#include "src/objects/templates.h"
|
||||
|
||||
namespace v8 {
|
||||
namespace internal {
|
||||
|
@ -49,6 +49,7 @@
|
||||
#include "src/json-stringifier.h"
|
||||
#include "src/messages.h"
|
||||
#include "src/objects-inl.h"
|
||||
#include "src/objects/templates.h"
|
||||
#include "src/parsing/parser.h"
|
||||
#include "src/parsing/scanner-character-streams.h"
|
||||
#include "src/pending-compilation-error-handler.h"
|
||||
|
@ -20,6 +20,7 @@
|
||||
#include "src/heap/heap.h"
|
||||
#include "src/isolate-inl.h"
|
||||
#include "src/objects/js-regexp.h"
|
||||
#include "src/objects/templates.h"
|
||||
#include "src/snapshot/natives.h"
|
||||
#include "src/snapshot/snapshot.h"
|
||||
#include "src/wasm/wasm-js.h"
|
||||
|
@ -10,6 +10,7 @@
|
||||
#include "src/counters.h"
|
||||
#include "src/log.h"
|
||||
#include "src/objects-inl.h"
|
||||
#include "src/objects/templates.h"
|
||||
#include "src/prototype.h"
|
||||
#include "src/visitors.h"
|
||||
|
||||
|
@ -12,6 +12,7 @@
|
||||
#include "src/field-type.h"
|
||||
#include "src/ic/call-optimization.h"
|
||||
#include "src/objects-inl.h"
|
||||
#include "src/objects/templates.h"
|
||||
|
||||
namespace v8 {
|
||||
namespace internal {
|
||||
|
@ -17,6 +17,7 @@
|
||||
#include "src/globals.h"
|
||||
#include "src/heap/heap.h"
|
||||
#include "src/machine-type.h"
|
||||
#include "src/objects.h"
|
||||
#include "src/objects/data-handler.h"
|
||||
#include "src/objects/map.h"
|
||||
#include "src/objects/maybe-object.h"
|
||||
|
@ -20,6 +20,7 @@
|
||||
#include "src/feedback-vector.h"
|
||||
#include "src/field-index-inl.h"
|
||||
#include "src/isolate-inl.h"
|
||||
#include "src/objects/templates.h"
|
||||
#include "src/vector-slot-pair.h"
|
||||
|
||||
namespace v8 {
|
||||
|
@ -16,6 +16,7 @@
|
||||
#include "src/heap/mark-compact.h"
|
||||
#include "src/isolate.h"
|
||||
#include "src/objects/compilation-cache-inl.h"
|
||||
#include "src/objects/templates.h"
|
||||
#include "src/utils.h"
|
||||
|
||||
namespace v8 {
|
||||
|
@ -45,6 +45,7 @@
|
||||
#include "src/objects/regexp-match-info.h"
|
||||
#include "src/objects/scope-info.h"
|
||||
#include "src/objects/template-objects.h"
|
||||
#include "src/objects/templates.h"
|
||||
#include "src/property.h"
|
||||
#include "src/prototype.h"
|
||||
#include "src/transitions-inl.h"
|
||||
@ -579,7 +580,6 @@ CAST_ACCESSOR(DescriptorArray)
|
||||
CAST_ACCESSOR(EnumCache)
|
||||
CAST_ACCESSOR(FeedbackCell)
|
||||
CAST_ACCESSOR(Foreign)
|
||||
CAST_ACCESSOR(FunctionTemplateInfo)
|
||||
CAST_ACCESSOR(GlobalDictionary)
|
||||
CAST_ACCESSOR(HeapObject)
|
||||
CAST_ACCESSOR(InterceptorInfo)
|
||||
@ -605,7 +605,6 @@ CAST_ACCESSOR(NumberDictionary)
|
||||
CAST_ACCESSOR(Object)
|
||||
CAST_ACCESSOR(ObjectHashSet)
|
||||
CAST_ACCESSOR(ObjectHashTable)
|
||||
CAST_ACCESSOR(ObjectTemplateInfo)
|
||||
CAST_ACCESSOR(Oddball)
|
||||
CAST_ACCESSOR(OrderedHashMap)
|
||||
CAST_ACCESSOR(OrderedHashSet)
|
||||
@ -623,7 +622,6 @@ CAST_ACCESSOR(StackFrameInfo)
|
||||
CAST_ACCESSOR(StringSet)
|
||||
CAST_ACCESSOR(StringTable)
|
||||
CAST_ACCESSOR(Struct)
|
||||
CAST_ACCESSOR(TemplateInfo)
|
||||
CAST_ACCESSOR(TemplateObjectDescription)
|
||||
CAST_ACCESSOR(Tuple2)
|
||||
CAST_ACCESSOR(Tuple3)
|
||||
@ -2345,40 +2343,6 @@ bool PrototypeInfo::HasObjectCreateMap() {
|
||||
return cache->IsWeakCell() && !WeakCell::cast(cache)->cleared();
|
||||
}
|
||||
|
||||
bool FunctionTemplateInfo::instantiated() {
|
||||
return shared_function_info()->IsSharedFunctionInfo();
|
||||
}
|
||||
|
||||
bool FunctionTemplateInfo::BreakAtEntry() {
|
||||
Object* maybe_shared = shared_function_info();
|
||||
if (maybe_shared->IsSharedFunctionInfo()) {
|
||||
SharedFunctionInfo* shared = SharedFunctionInfo::cast(maybe_shared);
|
||||
return shared->BreakAtEntry();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
FunctionTemplateInfo* FunctionTemplateInfo::GetParent(Isolate* isolate) {
|
||||
Object* parent = parent_template();
|
||||
return parent->IsUndefined(isolate) ? nullptr
|
||||
: FunctionTemplateInfo::cast(parent);
|
||||
}
|
||||
|
||||
ObjectTemplateInfo* ObjectTemplateInfo::GetParent(Isolate* isolate) {
|
||||
Object* maybe_ctor = constructor();
|
||||
if (maybe_ctor->IsUndefined(isolate)) return nullptr;
|
||||
FunctionTemplateInfo* constructor = FunctionTemplateInfo::cast(maybe_ctor);
|
||||
while (true) {
|
||||
constructor = constructor->GetParent(isolate);
|
||||
if (constructor == nullptr) return nullptr;
|
||||
Object* maybe_obj = constructor->instance_template();
|
||||
if (!maybe_obj->IsUndefined(isolate)) {
|
||||
return ObjectTemplateInfo::cast(maybe_obj);
|
||||
}
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
ACCESSORS(PrototypeInfo, weak_cell, Object, kWeakCellOffset)
|
||||
ACCESSORS(PrototypeInfo, prototype_users, Object, kPrototypeUsersOffset)
|
||||
ACCESSORS(PrototypeInfo, object_create_map, Object, kObjectCreateMap)
|
||||
@ -2439,64 +2403,6 @@ bool CallHandlerInfo::IsSideEffectFreeCallHandlerInfo() const {
|
||||
return map() == GetHeap()->side_effect_free_call_handler_info_map();
|
||||
}
|
||||
|
||||
ACCESSORS(TemplateInfo, tag, Object, kTagOffset)
|
||||
ACCESSORS(TemplateInfo, serial_number, Object, kSerialNumberOffset)
|
||||
SMI_ACCESSORS(TemplateInfo, number_of_properties, kNumberOfProperties)
|
||||
ACCESSORS(TemplateInfo, property_list, Object, kPropertyListOffset)
|
||||
ACCESSORS(TemplateInfo, property_accessors, Object, kPropertyAccessorsOffset)
|
||||
|
||||
ACCESSORS(FunctionTemplateInfo, call_code, Object, kCallCodeOffset)
|
||||
ACCESSORS(FunctionTemplateInfo, prototype_template, Object,
|
||||
kPrototypeTemplateOffset)
|
||||
ACCESSORS(FunctionTemplateInfo, prototype_provider_template, Object,
|
||||
kPrototypeProviderTemplateOffset)
|
||||
|
||||
ACCESSORS(FunctionTemplateInfo, parent_template, Object, kParentTemplateOffset)
|
||||
ACCESSORS(FunctionTemplateInfo, named_property_handler, Object,
|
||||
kNamedPropertyHandlerOffset)
|
||||
ACCESSORS(FunctionTemplateInfo, indexed_property_handler, Object,
|
||||
kIndexedPropertyHandlerOffset)
|
||||
ACCESSORS(FunctionTemplateInfo, instance_template, Object,
|
||||
kInstanceTemplateOffset)
|
||||
ACCESSORS(FunctionTemplateInfo, class_name, Object, kClassNameOffset)
|
||||
ACCESSORS(FunctionTemplateInfo, signature, Object, kSignatureOffset)
|
||||
ACCESSORS(FunctionTemplateInfo, instance_call_handler, Object,
|
||||
kInstanceCallHandlerOffset)
|
||||
ACCESSORS(FunctionTemplateInfo, access_check_info, Object,
|
||||
kAccessCheckInfoOffset)
|
||||
ACCESSORS(FunctionTemplateInfo, shared_function_info, Object,
|
||||
kSharedFunctionInfoOffset)
|
||||
ACCESSORS(FunctionTemplateInfo, cached_property_name, Object,
|
||||
kCachedPropertyNameOffset)
|
||||
|
||||
SMI_ACCESSORS(FunctionTemplateInfo, flag, kFlagOffset)
|
||||
|
||||
ACCESSORS(ObjectTemplateInfo, constructor, Object, kConstructorOffset)
|
||||
ACCESSORS(ObjectTemplateInfo, data, Object, kDataOffset)
|
||||
|
||||
int ObjectTemplateInfo::embedder_field_count() const {
|
||||
Object* value = data();
|
||||
DCHECK(value->IsSmi());
|
||||
return EmbedderFieldCount::decode(Smi::ToInt(value));
|
||||
}
|
||||
|
||||
void ObjectTemplateInfo::set_embedder_field_count(int count) {
|
||||
DCHECK_LE(count, JSObject::kMaxEmbedderFields);
|
||||
return set_data(
|
||||
Smi::FromInt(EmbedderFieldCount::update(Smi::ToInt(data()), count)));
|
||||
}
|
||||
|
||||
bool ObjectTemplateInfo::immutable_proto() const {
|
||||
Object* value = data();
|
||||
DCHECK(value->IsSmi());
|
||||
return IsImmutablePrototype::decode(Smi::ToInt(value));
|
||||
}
|
||||
|
||||
void ObjectTemplateInfo::set_immutable_proto(bool immutable) {
|
||||
return set_data(Smi::FromInt(
|
||||
IsImmutablePrototype::update(Smi::ToInt(data()), immutable)));
|
||||
}
|
||||
|
||||
ACCESSORS(AllocationSite, transition_info_or_boilerplate, Object,
|
||||
kTransitionInfoOrBoilerplateOffset)
|
||||
|
||||
@ -2546,20 +2452,6 @@ ACCESSORS(SourcePositionTableWithFrameCache, source_position_table, ByteArray,
|
||||
ACCESSORS(SourcePositionTableWithFrameCache, stack_frame_cache,
|
||||
SimpleNumberDictionary, kStackFrameCacheIndex)
|
||||
|
||||
SMI_ACCESSORS(FunctionTemplateInfo, length, kLengthOffset)
|
||||
BOOL_ACCESSORS(FunctionTemplateInfo, flag, hidden_prototype,
|
||||
kHiddenPrototypeBit)
|
||||
BOOL_ACCESSORS(FunctionTemplateInfo, flag, undetectable, kUndetectableBit)
|
||||
BOOL_ACCESSORS(FunctionTemplateInfo, flag, needs_access_check,
|
||||
kNeedsAccessCheckBit)
|
||||
BOOL_ACCESSORS(FunctionTemplateInfo, flag, read_only_prototype,
|
||||
kReadOnlyPrototypeBit)
|
||||
BOOL_ACCESSORS(FunctionTemplateInfo, flag, remove_prototype,
|
||||
kRemovePrototypeBit)
|
||||
BOOL_ACCESSORS(FunctionTemplateInfo, flag, do_not_cache,
|
||||
kDoNotCacheBit)
|
||||
BOOL_ACCESSORS(FunctionTemplateInfo, flag, accept_any_receiver,
|
||||
kAcceptAnyReceiver)
|
||||
|
||||
FeedbackVector* JSFunction::feedback_vector() const {
|
||||
DCHECK(has_feedback_vector());
|
||||
@ -3207,10 +3099,6 @@ BIT_FIELD_ACCESSORS(AccessorInfo, flags, has_no_side_effect,
|
||||
BIT_FIELD_ACCESSORS(AccessorInfo, flags, initial_property_attributes,
|
||||
AccessorInfo::InitialAttributesBits)
|
||||
|
||||
bool FunctionTemplateInfo::IsTemplateFor(JSObject* object) {
|
||||
return IsTemplateFor(object->map());
|
||||
}
|
||||
|
||||
bool AccessorInfo::IsCompatibleReceiver(Object* receiver) {
|
||||
if (!HasExpectedReceiverType()) return true;
|
||||
if (!receiver->IsJSObject()) return false;
|
||||
|
208
src/objects.h
208
src/objects.h
@ -954,6 +954,7 @@ class EnumCache;
|
||||
class FixedArrayBase;
|
||||
class PropertyArray;
|
||||
class FunctionLiteral;
|
||||
class FunctionTemplateInfo;
|
||||
class JSGlobalObject;
|
||||
class JSPromise;
|
||||
class KeyAccumulator;
|
||||
@ -963,6 +964,7 @@ class FieldType;
|
||||
class Module;
|
||||
class ModuleInfoEntry;
|
||||
class ObjectHashTable;
|
||||
class ObjectTemplateInfo;
|
||||
class ObjectVisitor;
|
||||
class PropertyCell;
|
||||
class PropertyDescriptor;
|
||||
@ -974,6 +976,7 @@ class FeedbackCell;
|
||||
class FeedbackMetadata;
|
||||
class FeedbackVector;
|
||||
class WeakCell;
|
||||
class TemplateInfo;
|
||||
class TransitionArray;
|
||||
class TemplateList;
|
||||
template <typename T>
|
||||
@ -4674,211 +4677,6 @@ class CallHandlerInfo : public Tuple3 {
|
||||
DISALLOW_IMPLICIT_CONSTRUCTORS(CallHandlerInfo);
|
||||
};
|
||||
|
||||
|
||||
class TemplateInfo: public Struct {
|
||||
public:
|
||||
DECL_ACCESSORS(tag, Object)
|
||||
DECL_ACCESSORS(serial_number, Object)
|
||||
DECL_INT_ACCESSORS(number_of_properties)
|
||||
DECL_ACCESSORS(property_list, Object)
|
||||
DECL_ACCESSORS(property_accessors, Object)
|
||||
|
||||
DECL_VERIFIER(TemplateInfo)
|
||||
|
||||
DECL_CAST(TemplateInfo)
|
||||
|
||||
static const int kTagOffset = HeapObject::kHeaderSize;
|
||||
static const int kSerialNumberOffset = kTagOffset + kPointerSize;
|
||||
static const int kNumberOfProperties = kSerialNumberOffset + kPointerSize;
|
||||
static const int kPropertyListOffset = kNumberOfProperties + kPointerSize;
|
||||
static const int kPropertyAccessorsOffset =
|
||||
kPropertyListOffset + kPointerSize;
|
||||
static const int kHeaderSize = kPropertyAccessorsOffset + kPointerSize;
|
||||
|
||||
static const int kFastTemplateInstantiationsCacheSize = 1 * KB;
|
||||
|
||||
// While we could grow the slow cache until we run out of memory, we put
|
||||
// a limit on it anyway to not crash for embedders that re-create templates
|
||||
// instead of caching them.
|
||||
static const int kSlowTemplateInstantiationsCacheSize = 1 * MB;
|
||||
|
||||
private:
|
||||
DISALLOW_IMPLICIT_CONSTRUCTORS(TemplateInfo);
|
||||
};
|
||||
|
||||
// See the api-exposed FunctionTemplate for more information.
|
||||
class FunctionTemplateInfo: public TemplateInfo {
|
||||
public:
|
||||
// Handler invoked when calling an instance of this FunctionTemplateInfo.
|
||||
// Either CallInfoHandler or Undefined.
|
||||
DECL_ACCESSORS(call_code, Object)
|
||||
|
||||
// ObjectTemplateInfo or Undefined, used for the prototype property of the
|
||||
// resulting JSFunction instance of this FunctionTemplate.
|
||||
DECL_ACCESSORS(prototype_template, Object)
|
||||
|
||||
// In the case the prototype_template is Undefined we use the
|
||||
// protoype_provider_template to retrieve the instance prototype. Either
|
||||
// contains an ObjectTemplateInfo or Undefined.
|
||||
DECL_ACCESSORS(prototype_provider_template, Object)
|
||||
|
||||
// Used to create protoype chains. The parent_template's prototype is set as
|
||||
// __proto__ of this FunctionTemplate's instance prototype. Is either a
|
||||
// FunctionTemplateInfo or Undefined.
|
||||
DECL_ACCESSORS(parent_template, Object)
|
||||
|
||||
// Returns an InterceptorInfo or Undefined for named properties.
|
||||
DECL_ACCESSORS(named_property_handler, Object)
|
||||
// Returns an InterceptorInfo or Undefined for indexed properties/elements.
|
||||
DECL_ACCESSORS(indexed_property_handler, Object)
|
||||
|
||||
// An ObjectTemplateInfo that is used when instantiating the JSFunction
|
||||
// associated with this FunctionTemplateInfo. Contains either an
|
||||
// ObjectTemplateInfo or Undefined. A default instance_template is assigned
|
||||
// upon first instantiation if it's Undefined.
|
||||
DECL_ACCESSORS(instance_template, Object)
|
||||
|
||||
DECL_ACCESSORS(class_name, Object)
|
||||
|
||||
// If the signature is a FunctionTemplateInfo it is used to check whether the
|
||||
// receiver calling the associated JSFunction is a compatible receiver, i.e.
|
||||
// it is an instance of the signare FunctionTemplateInfo or any of the
|
||||
// receiver's prototypes are.
|
||||
DECL_ACCESSORS(signature, Object)
|
||||
|
||||
// Either a CallHandlerInfo or Undefined. If an instance_call_handler is
|
||||
// provided the instances created from the associated JSFunction are marked as
|
||||
// callable.
|
||||
DECL_ACCESSORS(instance_call_handler, Object)
|
||||
|
||||
DECL_ACCESSORS(access_check_info, Object)
|
||||
DECL_ACCESSORS(shared_function_info, Object)
|
||||
|
||||
// Internal field to store a flag bitfield.
|
||||
DECL_INT_ACCESSORS(flag)
|
||||
|
||||
// "length" property of the final JSFunction.
|
||||
DECL_INT_ACCESSORS(length)
|
||||
|
||||
// Either the_hole or a private symbol. Used to cache the result on
|
||||
// the receiver under the the cached_property_name when this
|
||||
// FunctionTemplateInfo is used as a getter.
|
||||
DECL_ACCESSORS(cached_property_name, Object)
|
||||
|
||||
// Begin flag bits ---------------------
|
||||
DECL_BOOLEAN_ACCESSORS(hidden_prototype)
|
||||
DECL_BOOLEAN_ACCESSORS(undetectable)
|
||||
|
||||
// If set, object instances created by this function
|
||||
// requires access check.
|
||||
DECL_BOOLEAN_ACCESSORS(needs_access_check)
|
||||
|
||||
DECL_BOOLEAN_ACCESSORS(read_only_prototype)
|
||||
|
||||
// If set, do not create a prototype property for the associated
|
||||
// JSFunction. This bit implies that neither the prototype_template nor the
|
||||
// prototype_provoider_template are instantiated.
|
||||
DECL_BOOLEAN_ACCESSORS(remove_prototype)
|
||||
|
||||
// If set, do not attach a serial number to this FunctionTemplate and thus do
|
||||
// not keep an instance boilerplate around.
|
||||
DECL_BOOLEAN_ACCESSORS(do_not_cache)
|
||||
|
||||
// If not set an access may be performed on calling the associated JSFunction.
|
||||
DECL_BOOLEAN_ACCESSORS(accept_any_receiver)
|
||||
// End flag bits ---------------------
|
||||
|
||||
DECL_CAST(FunctionTemplateInfo)
|
||||
|
||||
// Dispatched behavior.
|
||||
DECL_PRINTER(FunctionTemplateInfo)
|
||||
DECL_VERIFIER(FunctionTemplateInfo)
|
||||
|
||||
static const int kInvalidSerialNumber = 0;
|
||||
|
||||
static const int kCallCodeOffset = TemplateInfo::kHeaderSize;
|
||||
static const int kPrototypeTemplateOffset =
|
||||
kCallCodeOffset + kPointerSize;
|
||||
static const int kPrototypeProviderTemplateOffset =
|
||||
kPrototypeTemplateOffset + kPointerSize;
|
||||
static const int kParentTemplateOffset =
|
||||
kPrototypeProviderTemplateOffset + kPointerSize;
|
||||
static const int kNamedPropertyHandlerOffset =
|
||||
kParentTemplateOffset + kPointerSize;
|
||||
static const int kIndexedPropertyHandlerOffset =
|
||||
kNamedPropertyHandlerOffset + kPointerSize;
|
||||
static const int kInstanceTemplateOffset =
|
||||
kIndexedPropertyHandlerOffset + kPointerSize;
|
||||
static const int kClassNameOffset = kInstanceTemplateOffset + kPointerSize;
|
||||
static const int kSignatureOffset = kClassNameOffset + kPointerSize;
|
||||
static const int kInstanceCallHandlerOffset = kSignatureOffset + kPointerSize;
|
||||
static const int kAccessCheckInfoOffset =
|
||||
kInstanceCallHandlerOffset + kPointerSize;
|
||||
static const int kSharedFunctionInfoOffset =
|
||||
kAccessCheckInfoOffset + kPointerSize;
|
||||
static const int kFlagOffset = kSharedFunctionInfoOffset + kPointerSize;
|
||||
static const int kLengthOffset = kFlagOffset + kPointerSize;
|
||||
static const int kCachedPropertyNameOffset = kLengthOffset + kPointerSize;
|
||||
static const int kSize = kCachedPropertyNameOffset + kPointerSize;
|
||||
|
||||
static Handle<SharedFunctionInfo> GetOrCreateSharedFunctionInfo(
|
||||
Isolate* isolate, Handle<FunctionTemplateInfo> info,
|
||||
MaybeHandle<Name> maybe_name);
|
||||
// Returns parent function template or null.
|
||||
inline FunctionTemplateInfo* GetParent(Isolate* isolate);
|
||||
// Returns true if |object| is an instance of this function template.
|
||||
inline bool IsTemplateFor(JSObject* object);
|
||||
bool IsTemplateFor(Map* map);
|
||||
inline bool instantiated();
|
||||
|
||||
inline bool BreakAtEntry();
|
||||
|
||||
// Helper function for cached accessors.
|
||||
static MaybeHandle<Name> TryGetCachedPropertyName(Isolate* isolate,
|
||||
Handle<Object> getter);
|
||||
|
||||
private:
|
||||
// Bit position in the flag, from least significant bit position.
|
||||
static const int kHiddenPrototypeBit = 0;
|
||||
static const int kUndetectableBit = 1;
|
||||
static const int kNeedsAccessCheckBit = 2;
|
||||
static const int kReadOnlyPrototypeBit = 3;
|
||||
static const int kRemovePrototypeBit = 4;
|
||||
static const int kDoNotCacheBit = 5;
|
||||
static const int kAcceptAnyReceiver = 6;
|
||||
|
||||
DISALLOW_IMPLICIT_CONSTRUCTORS(FunctionTemplateInfo);
|
||||
};
|
||||
|
||||
|
||||
class ObjectTemplateInfo: public TemplateInfo {
|
||||
public:
|
||||
DECL_ACCESSORS(constructor, Object)
|
||||
DECL_ACCESSORS(data, Object)
|
||||
DECL_INT_ACCESSORS(embedder_field_count)
|
||||
DECL_BOOLEAN_ACCESSORS(immutable_proto)
|
||||
|
||||
DECL_CAST(ObjectTemplateInfo)
|
||||
|
||||
// Dispatched behavior.
|
||||
DECL_PRINTER(ObjectTemplateInfo)
|
||||
DECL_VERIFIER(ObjectTemplateInfo)
|
||||
|
||||
static const int kConstructorOffset = TemplateInfo::kHeaderSize;
|
||||
// LSB is for immutable_proto, higher bits for embedder_field_count
|
||||
static const int kDataOffset = kConstructorOffset + kPointerSize;
|
||||
static const int kSize = kDataOffset + kPointerSize;
|
||||
|
||||
// Starting from given object template's constructor walk up the inheritance
|
||||
// chain till a function template that has an instance template is found.
|
||||
inline ObjectTemplateInfo* GetParent(Isolate* isolate);
|
||||
|
||||
private:
|
||||
class IsImmutablePrototype : public BitField<bool, 0, 1> {};
|
||||
class EmbedderFieldCount
|
||||
: public BitField<int, IsImmutablePrototype::kNext, 29> {};
|
||||
};
|
||||
|
||||
class StackFrameInfo : public Struct {
|
||||
public:
|
||||
DECL_INT_ACCESSORS(line_number)
|
||||
|
@ -11,6 +11,7 @@
|
||||
#include "src/objects-inl.h"
|
||||
#include "src/objects/descriptor-array.h"
|
||||
#include "src/objects/shared-function-info.h"
|
||||
#include "src/objects/templates-inl.h"
|
||||
#include "src/property.h"
|
||||
#include "src/transitions.h"
|
||||
|
||||
|
@ -7,6 +7,7 @@
|
||||
|
||||
#include "src/objects/script.h"
|
||||
|
||||
#include "src/objects/shared-function-info.h"
|
||||
#include "src/objects/string-inl.h"
|
||||
|
||||
// Has to be the last include (doesn't have include guards):
|
||||
|
134
src/objects/templates-inl.h
Normal file
134
src/objects/templates-inl.h
Normal file
@ -0,0 +1,134 @@
|
||||
// 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_TEMPLATES_INL_H_
|
||||
#define V8_OBJECTS_TEMPLATES_INL_H_
|
||||
|
||||
#include "src/objects/templates.h"
|
||||
|
||||
#include "src/heap/heap-inl.h"
|
||||
|
||||
// Has to be the last include (doesn't have include guards):
|
||||
#include "src/objects/object-macros.h"
|
||||
|
||||
namespace v8 {
|
||||
namespace internal {
|
||||
|
||||
ACCESSORS(TemplateInfo, tag, Object, kTagOffset)
|
||||
ACCESSORS(TemplateInfo, serial_number, Object, kSerialNumberOffset)
|
||||
SMI_ACCESSORS(TemplateInfo, number_of_properties, kNumberOfProperties)
|
||||
ACCESSORS(TemplateInfo, property_list, Object, kPropertyListOffset)
|
||||
ACCESSORS(TemplateInfo, property_accessors, Object, kPropertyAccessorsOffset)
|
||||
|
||||
ACCESSORS(FunctionTemplateInfo, call_code, Object, kCallCodeOffset)
|
||||
ACCESSORS(FunctionTemplateInfo, prototype_template, Object,
|
||||
kPrototypeTemplateOffset)
|
||||
ACCESSORS(FunctionTemplateInfo, prototype_provider_template, Object,
|
||||
kPrototypeProviderTemplateOffset)
|
||||
ACCESSORS(FunctionTemplateInfo, parent_template, Object, kParentTemplateOffset)
|
||||
ACCESSORS(FunctionTemplateInfo, named_property_handler, Object,
|
||||
kNamedPropertyHandlerOffset)
|
||||
ACCESSORS(FunctionTemplateInfo, indexed_property_handler, Object,
|
||||
kIndexedPropertyHandlerOffset)
|
||||
ACCESSORS(FunctionTemplateInfo, instance_template, Object,
|
||||
kInstanceTemplateOffset)
|
||||
ACCESSORS(FunctionTemplateInfo, class_name, Object, kClassNameOffset)
|
||||
ACCESSORS(FunctionTemplateInfo, signature, Object, kSignatureOffset)
|
||||
ACCESSORS(FunctionTemplateInfo, instance_call_handler, Object,
|
||||
kInstanceCallHandlerOffset)
|
||||
ACCESSORS(FunctionTemplateInfo, access_check_info, Object,
|
||||
kAccessCheckInfoOffset)
|
||||
ACCESSORS(FunctionTemplateInfo, shared_function_info, Object,
|
||||
kSharedFunctionInfoOffset)
|
||||
ACCESSORS(FunctionTemplateInfo, cached_property_name, Object,
|
||||
kCachedPropertyNameOffset)
|
||||
SMI_ACCESSORS(FunctionTemplateInfo, length, kLengthOffset)
|
||||
BOOL_ACCESSORS(FunctionTemplateInfo, flag, hidden_prototype,
|
||||
kHiddenPrototypeBit)
|
||||
BOOL_ACCESSORS(FunctionTemplateInfo, flag, undetectable, kUndetectableBit)
|
||||
BOOL_ACCESSORS(FunctionTemplateInfo, flag, needs_access_check,
|
||||
kNeedsAccessCheckBit)
|
||||
BOOL_ACCESSORS(FunctionTemplateInfo, flag, read_only_prototype,
|
||||
kReadOnlyPrototypeBit)
|
||||
BOOL_ACCESSORS(FunctionTemplateInfo, flag, remove_prototype,
|
||||
kRemovePrototypeBit)
|
||||
BOOL_ACCESSORS(FunctionTemplateInfo, flag, do_not_cache, kDoNotCacheBit)
|
||||
BOOL_ACCESSORS(FunctionTemplateInfo, flag, accept_any_receiver,
|
||||
kAcceptAnyReceiver)
|
||||
SMI_ACCESSORS(FunctionTemplateInfo, flag, kFlagOffset)
|
||||
|
||||
ACCESSORS(ObjectTemplateInfo, constructor, Object, kConstructorOffset)
|
||||
ACCESSORS(ObjectTemplateInfo, data, Object, kDataOffset)
|
||||
|
||||
CAST_ACCESSOR(TemplateInfo)
|
||||
CAST_ACCESSOR(FunctionTemplateInfo)
|
||||
CAST_ACCESSOR(ObjectTemplateInfo)
|
||||
|
||||
bool FunctionTemplateInfo::instantiated() {
|
||||
return shared_function_info()->IsSharedFunctionInfo();
|
||||
}
|
||||
|
||||
bool FunctionTemplateInfo::BreakAtEntry() {
|
||||
Object* maybe_shared = shared_function_info();
|
||||
if (maybe_shared->IsSharedFunctionInfo()) {
|
||||
SharedFunctionInfo* shared = SharedFunctionInfo::cast(maybe_shared);
|
||||
return shared->BreakAtEntry();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
FunctionTemplateInfo* FunctionTemplateInfo::GetParent(Isolate* isolate) {
|
||||
Object* parent = parent_template();
|
||||
return parent->IsUndefined(isolate) ? nullptr
|
||||
: FunctionTemplateInfo::cast(parent);
|
||||
}
|
||||
|
||||
ObjectTemplateInfo* ObjectTemplateInfo::GetParent(Isolate* isolate) {
|
||||
Object* maybe_ctor = constructor();
|
||||
if (maybe_ctor->IsUndefined(isolate)) return nullptr;
|
||||
FunctionTemplateInfo* constructor = FunctionTemplateInfo::cast(maybe_ctor);
|
||||
while (true) {
|
||||
constructor = constructor->GetParent(isolate);
|
||||
if (constructor == nullptr) return nullptr;
|
||||
Object* maybe_obj = constructor->instance_template();
|
||||
if (!maybe_obj->IsUndefined(isolate)) {
|
||||
return ObjectTemplateInfo::cast(maybe_obj);
|
||||
}
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
int ObjectTemplateInfo::embedder_field_count() const {
|
||||
Object* value = data();
|
||||
DCHECK(value->IsSmi());
|
||||
return EmbedderFieldCount::decode(Smi::ToInt(value));
|
||||
}
|
||||
|
||||
void ObjectTemplateInfo::set_embedder_field_count(int count) {
|
||||
DCHECK_LE(count, JSObject::kMaxEmbedderFields);
|
||||
return set_data(
|
||||
Smi::FromInt(EmbedderFieldCount::update(Smi::ToInt(data()), count)));
|
||||
}
|
||||
|
||||
bool ObjectTemplateInfo::immutable_proto() const {
|
||||
Object* value = data();
|
||||
DCHECK(value->IsSmi());
|
||||
return IsImmutablePrototype::decode(Smi::ToInt(value));
|
||||
}
|
||||
|
||||
void ObjectTemplateInfo::set_immutable_proto(bool immutable) {
|
||||
return set_data(Smi::FromInt(
|
||||
IsImmutablePrototype::update(Smi::ToInt(data()), immutable)));
|
||||
}
|
||||
|
||||
bool FunctionTemplateInfo::IsTemplateFor(JSObject* object) {
|
||||
return IsTemplateFor(object->map());
|
||||
}
|
||||
|
||||
} // namespace internal
|
||||
} // namespace v8
|
||||
|
||||
#include "src/objects/object-macros-undef.h"
|
||||
|
||||
#endif // V8_OBJECTS_TEMPLATES_INL_H_
|
223
src/objects/templates.h
Normal file
223
src/objects/templates.h
Normal file
@ -0,0 +1,223 @@
|
||||
// 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_TEMPLATES_H_
|
||||
#define V8_OBJECTS_TEMPLATES_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 {
|
||||
|
||||
class TemplateInfo : public Struct {
|
||||
public:
|
||||
DECL_ACCESSORS(tag, Object)
|
||||
DECL_ACCESSORS(serial_number, Object)
|
||||
DECL_INT_ACCESSORS(number_of_properties)
|
||||
DECL_ACCESSORS(property_list, Object)
|
||||
DECL_ACCESSORS(property_accessors, Object)
|
||||
|
||||
DECL_VERIFIER(TemplateInfo)
|
||||
|
||||
DECL_CAST(TemplateInfo)
|
||||
|
||||
static const int kTagOffset = HeapObject::kHeaderSize;
|
||||
static const int kSerialNumberOffset = kTagOffset + kPointerSize;
|
||||
static const int kNumberOfProperties = kSerialNumberOffset + kPointerSize;
|
||||
static const int kPropertyListOffset = kNumberOfProperties + kPointerSize;
|
||||
static const int kPropertyAccessorsOffset =
|
||||
kPropertyListOffset + kPointerSize;
|
||||
static const int kHeaderSize = kPropertyAccessorsOffset + kPointerSize;
|
||||
|
||||
static const int kFastTemplateInstantiationsCacheSize = 1 * KB;
|
||||
|
||||
// While we could grow the slow cache until we run out of memory, we put
|
||||
// a limit on it anyway to not crash for embedders that re-create templates
|
||||
// instead of caching them.
|
||||
static const int kSlowTemplateInstantiationsCacheSize = 1 * MB;
|
||||
|
||||
private:
|
||||
DISALLOW_IMPLICIT_CONSTRUCTORS(TemplateInfo);
|
||||
};
|
||||
|
||||
// See the api-exposed FunctionTemplate for more information.
|
||||
class FunctionTemplateInfo : public TemplateInfo {
|
||||
public:
|
||||
// Handler invoked when calling an instance of this FunctionTemplateInfo.
|
||||
// Either CallInfoHandler or Undefined.
|
||||
DECL_ACCESSORS(call_code, Object)
|
||||
|
||||
// ObjectTemplateInfo or Undefined, used for the prototype property of the
|
||||
// resulting JSFunction instance of this FunctionTemplate.
|
||||
DECL_ACCESSORS(prototype_template, Object)
|
||||
|
||||
// In the case the prototype_template is Undefined we use the
|
||||
// protoype_provider_template to retrieve the instance prototype. Either
|
||||
// contains an ObjectTemplateInfo or Undefined.
|
||||
DECL_ACCESSORS(prototype_provider_template, Object)
|
||||
|
||||
// Used to create protoype chains. The parent_template's prototype is set as
|
||||
// __proto__ of this FunctionTemplate's instance prototype. Is either a
|
||||
// FunctionTemplateInfo or Undefined.
|
||||
DECL_ACCESSORS(parent_template, Object)
|
||||
|
||||
// Returns an InterceptorInfo or Undefined for named properties.
|
||||
DECL_ACCESSORS(named_property_handler, Object)
|
||||
// Returns an InterceptorInfo or Undefined for indexed properties/elements.
|
||||
DECL_ACCESSORS(indexed_property_handler, Object)
|
||||
|
||||
// An ObjectTemplateInfo that is used when instantiating the JSFunction
|
||||
// associated with this FunctionTemplateInfo. Contains either an
|
||||
// ObjectTemplateInfo or Undefined. A default instance_template is assigned
|
||||
// upon first instantiation if it's Undefined.
|
||||
DECL_ACCESSORS(instance_template, Object)
|
||||
|
||||
DECL_ACCESSORS(class_name, Object)
|
||||
|
||||
// If the signature is a FunctionTemplateInfo it is used to check whether the
|
||||
// receiver calling the associated JSFunction is a compatible receiver, i.e.
|
||||
// it is an instance of the signare FunctionTemplateInfo or any of the
|
||||
// receiver's prototypes are.
|
||||
DECL_ACCESSORS(signature, Object)
|
||||
|
||||
// Either a CallHandlerInfo or Undefined. If an instance_call_handler is
|
||||
// provided the instances created from the associated JSFunction are marked as
|
||||
// callable.
|
||||
DECL_ACCESSORS(instance_call_handler, Object)
|
||||
|
||||
DECL_ACCESSORS(access_check_info, Object)
|
||||
DECL_ACCESSORS(shared_function_info, Object)
|
||||
|
||||
// Internal field to store a flag bitfield.
|
||||
DECL_INT_ACCESSORS(flag)
|
||||
|
||||
// "length" property of the final JSFunction.
|
||||
DECL_INT_ACCESSORS(length)
|
||||
|
||||
// Either the_hole or a private symbol. Used to cache the result on
|
||||
// the receiver under the the cached_property_name when this
|
||||
// FunctionTemplateInfo is used as a getter.
|
||||
DECL_ACCESSORS(cached_property_name, Object)
|
||||
|
||||
// Begin flag bits ---------------------
|
||||
DECL_BOOLEAN_ACCESSORS(hidden_prototype)
|
||||
DECL_BOOLEAN_ACCESSORS(undetectable)
|
||||
|
||||
// If set, object instances created by this function
|
||||
// requires access check.
|
||||
DECL_BOOLEAN_ACCESSORS(needs_access_check)
|
||||
|
||||
DECL_BOOLEAN_ACCESSORS(read_only_prototype)
|
||||
|
||||
// If set, do not create a prototype property for the associated
|
||||
// JSFunction. This bit implies that neither the prototype_template nor the
|
||||
// prototype_provoider_template are instantiated.
|
||||
DECL_BOOLEAN_ACCESSORS(remove_prototype)
|
||||
|
||||
// If set, do not attach a serial number to this FunctionTemplate and thus do
|
||||
// not keep an instance boilerplate around.
|
||||
DECL_BOOLEAN_ACCESSORS(do_not_cache)
|
||||
|
||||
// If not set an access may be performed on calling the associated JSFunction.
|
||||
DECL_BOOLEAN_ACCESSORS(accept_any_receiver)
|
||||
// End flag bits ---------------------
|
||||
|
||||
DECL_CAST(FunctionTemplateInfo)
|
||||
|
||||
// Dispatched behavior.
|
||||
DECL_PRINTER(FunctionTemplateInfo)
|
||||
DECL_VERIFIER(FunctionTemplateInfo)
|
||||
|
||||
static const int kInvalidSerialNumber = 0;
|
||||
|
||||
static const int kCallCodeOffset = TemplateInfo::kHeaderSize;
|
||||
static const int kPrototypeTemplateOffset = kCallCodeOffset + kPointerSize;
|
||||
static const int kPrototypeProviderTemplateOffset =
|
||||
kPrototypeTemplateOffset + kPointerSize;
|
||||
static const int kParentTemplateOffset =
|
||||
kPrototypeProviderTemplateOffset + kPointerSize;
|
||||
static const int kNamedPropertyHandlerOffset =
|
||||
kParentTemplateOffset + kPointerSize;
|
||||
static const int kIndexedPropertyHandlerOffset =
|
||||
kNamedPropertyHandlerOffset + kPointerSize;
|
||||
static const int kInstanceTemplateOffset =
|
||||
kIndexedPropertyHandlerOffset + kPointerSize;
|
||||
static const int kClassNameOffset = kInstanceTemplateOffset + kPointerSize;
|
||||
static const int kSignatureOffset = kClassNameOffset + kPointerSize;
|
||||
static const int kInstanceCallHandlerOffset = kSignatureOffset + kPointerSize;
|
||||
static const int kAccessCheckInfoOffset =
|
||||
kInstanceCallHandlerOffset + kPointerSize;
|
||||
static const int kSharedFunctionInfoOffset =
|
||||
kAccessCheckInfoOffset + kPointerSize;
|
||||
static const int kFlagOffset = kSharedFunctionInfoOffset + kPointerSize;
|
||||
static const int kLengthOffset = kFlagOffset + kPointerSize;
|
||||
static const int kCachedPropertyNameOffset = kLengthOffset + kPointerSize;
|
||||
static const int kSize = kCachedPropertyNameOffset + kPointerSize;
|
||||
|
||||
static Handle<SharedFunctionInfo> GetOrCreateSharedFunctionInfo(
|
||||
Isolate* isolate, Handle<FunctionTemplateInfo> info,
|
||||
MaybeHandle<Name> maybe_name);
|
||||
// Returns parent function template or null.
|
||||
inline FunctionTemplateInfo* GetParent(Isolate* isolate);
|
||||
// Returns true if |object| is an instance of this function template.
|
||||
inline bool IsTemplateFor(JSObject* object);
|
||||
bool IsTemplateFor(Map* map);
|
||||
inline bool instantiated();
|
||||
|
||||
inline bool BreakAtEntry();
|
||||
|
||||
// Helper function for cached accessors.
|
||||
static MaybeHandle<Name> TryGetCachedPropertyName(Isolate* isolate,
|
||||
Handle<Object> getter);
|
||||
|
||||
private:
|
||||
// Bit position in the flag, from least significant bit position.
|
||||
static const int kHiddenPrototypeBit = 0;
|
||||
static const int kUndetectableBit = 1;
|
||||
static const int kNeedsAccessCheckBit = 2;
|
||||
static const int kReadOnlyPrototypeBit = 3;
|
||||
static const int kRemovePrototypeBit = 4;
|
||||
static const int kDoNotCacheBit = 5;
|
||||
static const int kAcceptAnyReceiver = 6;
|
||||
|
||||
DISALLOW_IMPLICIT_CONSTRUCTORS(FunctionTemplateInfo);
|
||||
};
|
||||
|
||||
class ObjectTemplateInfo : public TemplateInfo {
|
||||
public:
|
||||
DECL_ACCESSORS(constructor, Object)
|
||||
DECL_ACCESSORS(data, Object)
|
||||
DECL_INT_ACCESSORS(embedder_field_count)
|
||||
DECL_BOOLEAN_ACCESSORS(immutable_proto)
|
||||
|
||||
DECL_CAST(ObjectTemplateInfo)
|
||||
|
||||
// Dispatched behavior.
|
||||
DECL_PRINTER(ObjectTemplateInfo)
|
||||
DECL_VERIFIER(ObjectTemplateInfo)
|
||||
|
||||
static const int kConstructorOffset = TemplateInfo::kHeaderSize;
|
||||
// LSB is for immutable_proto, higher bits for embedder_field_count
|
||||
static const int kDataOffset = kConstructorOffset + kPointerSize;
|
||||
static const int kSize = kDataOffset + kPointerSize;
|
||||
|
||||
// Starting from given object template's constructor walk up the inheritance
|
||||
// chain till a function template that has an instance template is found.
|
||||
inline ObjectTemplateInfo* GetParent(Isolate* isolate);
|
||||
|
||||
private:
|
||||
class IsImmutablePrototype : public BitField<bool, 0, 1> {};
|
||||
class EmbedderFieldCount
|
||||
: public BitField<int, IsImmutablePrototype::kNext, 29> {};
|
||||
};
|
||||
|
||||
} // namespace internal
|
||||
} // namespace v8
|
||||
|
||||
#include "src/objects/object-macros-undef.h"
|
||||
|
||||
#endif // V8_OBJECTS_TEMPLATES_H_
|
@ -13,6 +13,7 @@
|
||||
#include "src/heap/factory.h"
|
||||
#include "src/isolate.h"
|
||||
#include "src/objects-inl.h"
|
||||
#include "src/objects/templates.h"
|
||||
#include "src/parsing/parse-info.h"
|
||||
#include "src/trap-handler/trap-handler.h"
|
||||
#include "src/wasm/wasm-engine.h"
|
||||
|
Loading…
Reference in New Issue
Block a user