Commit 4c4366e7 authored by Seth Brenith's avatar Seth Brenith Committed by V8 LUCI CQ

[cleanup] Use @doNotGenerateCppClass on fewer classes

Most Torque-defined extern classes already use CPP class generation. As
Nico pointed out in [1], it would be nice to convert the remaining
classes and remove this option. This change converts most of those
remaining classes. I know that the future of Torque-defined classes is a
subject of some debate right now, but I think that it's worth doing a
few mechanical changes to reduce the existing variety of options. A
couple of minor fixes in the Torque compiler were required so that it
generates correct code for shapes.

[1] https://docs.google.com/document/d/1q_gZLnXd4bGnCx3IUfbln46K3bSs9UHBGasy9McQtHI/edit#

Bug: v8:8952
Change-Id: I7e6087153a18d6ee80e67926793e8ba8e01d501e
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3015666Reviewed-by: 's avatarNico Hartmann <nicohartmann@chromium.org>
Reviewed-by: 's avatarAnton Bikineev <bikineev@chromium.org>
Commit-Queue: Seth Brenith <seth.brenith@microsoft.com>
Cr-Commit-Position: refs/heads/main@{#76586}
parent 3ac13ef5
......@@ -343,8 +343,6 @@ void BytecodeArray::BytecodeArrayVerify(Isolate* isolate) {
}
}
USE_TORQUE_VERIFIER(JSReceiver)
bool JSObject::ElementsAreSafeToExamine(PtrComprCageBase cage_base) const {
// If a GC was caused while constructing this object, the elements
// pointer may point to a one pointer filler map.
......@@ -785,8 +783,6 @@ void JSDate::JSDateVerify(Isolate* isolate) {
}
}
USE_TORQUE_VERIFIER(JSMessageObject)
void String::StringVerify(Isolate* isolate) {
TorqueGeneratedClassVerifiers::StringVerify(*this, isolate);
CHECK(length() >= 0 && length() <= Smi::kMaxValue);
......@@ -1139,19 +1135,13 @@ void JSWeakRef::JSWeakRefVerify(Isolate* isolate) {
}
void JSFinalizationRegistry::JSFinalizationRegistryVerify(Isolate* isolate) {
CHECK(IsJSFinalizationRegistry());
JSObjectVerify(isolate);
VerifyHeapPointer(isolate, cleanup());
CHECK(active_cells().IsUndefined(isolate) || active_cells().IsWeakCell());
TorqueGeneratedClassVerifiers::JSFinalizationRegistryVerify(*this, isolate);
if (active_cells().IsWeakCell()) {
CHECK(WeakCell::cast(active_cells()).prev().IsUndefined(isolate));
}
CHECK(cleared_cells().IsUndefined(isolate) || cleared_cells().IsWeakCell());
if (cleared_cells().IsWeakCell()) {
CHECK(WeakCell::cast(cleared_cells()).prev().IsUndefined(isolate));
}
CHECK(next_dirty().IsUndefined(isolate) ||
next_dirty().IsJSFinalizationRegistry());
}
void JSWeakMap::JSWeakMapVerify(Isolate* isolate) {
......
......@@ -26,7 +26,7 @@ struct WeakListVisitor;
template <class T>
Object VisitWeakList(Heap* heap, Object list, WeakObjectRetainer* retainer) {
Object undefined = ReadOnlyRoots(heap).undefined_value();
HeapObject undefined = ReadOnlyRoots(heap).undefined_value();
Object head = undefined;
T tail;
bool record_slots = MustRecordSlots(heap);
......@@ -47,7 +47,7 @@ Object VisitWeakList(Heap* heap, Object list, WeakObjectRetainer* retainer) {
} else {
// Subsequent elements in the list.
DCHECK(!tail.is_null());
WeakListVisitor<T>::SetWeakNext(tail, retained);
WeakListVisitor<T>::SetWeakNext(tail, HeapObject::cast(retained));
if (record_slots) {
HeapObject slot_holder = WeakListVisitor<T>::WeakNextHolder(tail);
int slot_offset = WeakListVisitor<T>::WeakNextOffset();
......@@ -187,7 +187,7 @@ struct WeakListVisitor<AllocationSite> {
template <>
struct WeakListVisitor<JSFinalizationRegistry> {
static void SetWeakNext(JSFinalizationRegistry obj, Object next) {
static void SetWeakNext(JSFinalizationRegistry obj, HeapObject next) {
obj.set_next_dirty(next, UPDATE_WEAK_WRITE_BARRIER);
}
......
......@@ -29,12 +29,10 @@ class JSArgumentsObject
// JSSloppyArgumentsObject is just a JSArgumentsObject with specific initial
// map. This initial map adds in-object properties for "length" and "callee".
class JSSloppyArgumentsObject : public JSArgumentsObject {
class JSSloppyArgumentsObject
: public TorqueGeneratedJSSloppyArgumentsObject<JSSloppyArgumentsObject,
JSArgumentsObject> {
public:
DEFINE_FIELD_OFFSET_CONSTANTS(
JSArgumentsObject::kHeaderSize,
TORQUE_GENERATED_JS_SLOPPY_ARGUMENTS_OBJECT_FIELDS)
// Indices of in-object properties.
static const int kLengthIndex = 0;
static const int kCalleeIndex = kLengthIndex + 1;
......@@ -45,13 +43,10 @@ class JSSloppyArgumentsObject : public JSArgumentsObject {
// JSStrictArgumentsObject is just a JSArgumentsObject with specific initial
// map. This initial map adds an in-object property for "length".
class JSStrictArgumentsObject : public JSArgumentsObject {
class JSStrictArgumentsObject
: public TorqueGeneratedJSStrictArgumentsObject<JSStrictArgumentsObject,
JSArgumentsObject> {
public:
// Layout description.
DEFINE_FIELD_OFFSET_CONSTANTS(
JSArgumentsObject::kHeaderSize,
TORQUE_GENERATED_JS_STRICT_ARGUMENTS_OBJECT_FIELDS)
// Indices of in-object properties.
static const int kLengthIndex = 0;
STATIC_ASSERT(kLengthIndex == JSSloppyArgumentsObject::kLengthIndex);
......
......@@ -14,14 +14,12 @@ macro IsJSArgumentsObjectWithLength(implicit context: Context)(o: Object):
}
// Just a starting shape for JSObject; properties can move after initialization.
@doNotGenerateCppClass
extern shape JSSloppyArgumentsObject extends JSArgumentsObject {
length: JSAny;
callee: JSAny;
}
// Just a starting shape for JSObject; properties can move after initialization.
@doNotGenerateCppClass
extern shape JSStrictArgumentsObject extends JSArgumentsObject {
length: JSAny;
}
......
......@@ -15,11 +15,10 @@
namespace v8 {
namespace internal {
OBJECT_CONSTRUCTORS_IMPL(JSArray, JSObject)
OBJECT_CONSTRUCTORS_IMPL(JSArrayIterator, JSObject)
#include "torque-generated/src/objects/js-array-tq-inl.inc"
CAST_ACCESSOR(JSArray)
CAST_ACCESSOR(JSArrayIterator)
TQ_OBJECT_CONSTRUCTORS_IMPL(JSArray)
TQ_OBJECT_CONSTRUCTORS_IMPL(JSArrayIterator)
DEF_GETTER(JSArray, length, Object) {
return TaggedField<Object, kLengthOffset>::load(cage_base, *this);
......@@ -70,9 +69,6 @@ bool JSArray::HasArrayPrototype(Isolate* isolate) {
return map().prototype() == *isolate->initial_array_prototype();
}
ACCESSORS(JSArrayIterator, iterated_object, Object, kIteratedObjectOffset)
ACCESSORS(JSArrayIterator, next_index, Object, kNextIndexOffset)
SMI_ACCESSORS(JSArrayIterator, raw_kind, kKindOffset)
IterationKind JSArrayIterator::kind() const {
......
......@@ -16,12 +16,14 @@
namespace v8 {
namespace internal {
#include "torque-generated/src/objects/js-array-tq.inc"
// The JSArray describes JavaScript Arrays
// Such an array can be in one of two modes:
// - fast, backing storage is a FixedArray and length <= elements.length();
// Please note: push and pop can be used to grow and shrink the array.
// - slow, backing storage is a HashTable with numbers as keys.
class JSArray : public JSObject {
class JSArray : public TorqueGeneratedJSArray<JSArray, JSObject> {
public:
// [length]: The length property.
DECL_ACCESSORS(length, Object)
......@@ -109,8 +111,6 @@ class JSArray : public JSObject {
// to Proxies and objects with a hidden prototype.
inline bool HasArrayPrototype(Isolate* isolate);
DECL_CAST(JSArray)
// Dispatched behavior.
DECL_PRINTER(JSArray)
DECL_VERIFIER(JSArray)
......@@ -118,9 +118,6 @@ class JSArray : public JSObject {
// Number of element slots to pre-allocate for an empty array.
static const int kPreallocatedArrayElements = 4;
DEFINE_FIELD_OFFSET_CONSTANTS(JSObject::kHeaderSize,
TORQUE_GENERATED_JS_ARRAY_FIELDS)
static const int kLengthDescriptorIndex = 0;
// Max. number of elements being copied in Array builtins.
......@@ -144,7 +141,7 @@ class JSArray : public JSObject {
AllocationMemento::kSize) >>
kDoubleSizeLog2;
OBJECT_CONSTRUCTORS(JSArray, JSObject);
TQ_OBJECT_CONSTRUCTORS(JSArray)
};
Handle<Object> CacheInitialJSArrayMaps(Isolate* isolate,
......@@ -153,52 +150,20 @@ Handle<Object> CacheInitialJSArrayMaps(Isolate* isolate,
// The JSArrayIterator describes JavaScript Array Iterators Objects, as
// defined in ES section #sec-array-iterator-objects.
class JSArrayIterator : public JSObject {
class JSArrayIterator
: public TorqueGeneratedJSArrayIterator<JSArrayIterator, JSObject> {
public:
DECL_PRINTER(JSArrayIterator)
DECL_VERIFIER(JSArrayIterator)
DECL_CAST(JSArrayIterator)
// [iterated_object]: the [[IteratedObject]] inobject property.
DECL_ACCESSORS(iterated_object, Object)
// [next_index]: The [[ArrayIteratorNextIndex]] inobject property.
// The next_index is always a positive integer, and it points to
// the next index that is to be returned by this iterator. It's
// possible range is fixed depending on the [[iterated_object]]:
//
// 1. For JSArray's the next_index is always in Unsigned32
// range, and when the iterator reaches the end it's set
// to kMaxUInt32 to indicate that this iterator should
// never produce values anymore even if the "length"
// property of the JSArray changes at some later point.
// 2. For JSTypedArray's the next_index is always in
// UnsignedSmall range, and when the iterator terminates
// it's set to Smi::kMaxValue.
// 3. For all other JSReceiver's it's always between 0 and
// kMaxSafeInteger, and the latter value is used to mark
// termination.
//
// It's important that for 1. and 2. the value fits into the
// Unsigned32 range (UnsignedSmall is a subset of Unsigned32),
// since we use this knowledge in the fast-path for the array
// iterator next calls in TurboFan (in the JSCallReducer) to
// keep the index in Word32 representation. This invariant is
// checked in JSArrayIterator::JSArrayIteratorVerify().
DECL_ACCESSORS(next_index, Object)
// [kind]: the [[ArrayIterationKind]] inobject property.
inline IterationKind kind() const;
inline void set_kind(IterationKind kind);
DEFINE_FIELD_OFFSET_CONSTANTS(JSObject::kHeaderSize,
TORQUE_GENERATED_JS_ARRAY_ITERATOR_FIELDS)
private:
DECL_INT_ACCESSORS(raw_kind)
OBJECT_CONSTRUCTORS(JSArrayIterator, JSObject);
TQ_OBJECT_CONSTRUCTORS(JSArrayIterator)
};
} // namespace internal
......
......@@ -4,10 +4,34 @@
extern enum IterationKind extends uint31 { kKeys, kValues, kEntries }
@doNotGenerateCppClass
extern class JSArrayIterator extends JSObject {
iterated_object: JSReceiver;
// [next_index]: The [[ArrayIteratorNextIndex]] inobject property.
// The next_index is always a positive integer, and it points to
// the next index that is to be returned by this iterator. It's
// possible range is fixed depending on the [[iterated_object]]:
//
// 1. For JSArray's the next_index is always in Unsigned32
// range, and when the iterator reaches the end it's set
// to kMaxUInt32 to indicate that this iterator should
// never produce values anymore even if the "length"
// property of the JSArray changes at some later point.
// 2. For JSTypedArray's the next_index is always in
// UnsignedSmall range, and when the iterator terminates
// it's set to Smi::kMaxValue.
// 3. For all other JSReceiver's it's always between 0 and
// kMaxSafeInteger, and the latter value is used to mark
// termination.
//
// It's important that for 1. and 2. the value fits into the
// Unsigned32 range (UnsignedSmall is a subset of Unsigned32),
// since we use this knowledge in the fast-path for the array
// iterator next calls in TurboFan (in the JSCallReducer) to
// keep the index in Word32 representation. This invariant is
// checked in JSArrayIterator::JSArrayIteratorVerify().
next_index: Number;
kind: SmiTagged<IterationKind>;
}
......@@ -25,7 +49,6 @@ macro CreateArrayIterator(implicit context: NativeContext)(
};
}
@doNotGenerateCppClass
extern class JSArray extends JSObject {
macro IsEmpty(): bool {
return this.length == 0;
......
......@@ -27,9 +27,7 @@ namespace internal {
TQ_OBJECT_CONSTRUCTORS_IMPL(JSFunctionOrBoundFunction)
TQ_OBJECT_CONSTRUCTORS_IMPL(JSBoundFunction)
OBJECT_CONSTRUCTORS_IMPL(JSFunction, JSFunctionOrBoundFunction)
CAST_ACCESSOR(JSFunction)
TQ_OBJECT_CONSTRUCTORS_IMPL(JSFunction)
ACCESSORS(JSFunction, raw_feedback_cell, FeedbackCell, kFeedbackCellOffset)
RELEASE_ACQUIRE_ACCESSORS(JSFunction, raw_feedback_cell, FeedbackCell,
......@@ -218,12 +216,6 @@ NativeContext JSFunction::native_context() {
return context().native_context();
}
void JSFunction::set_context(HeapObject value, WriteBarrierMode mode) {
DCHECK(value.IsUndefined() || value.IsContext());
WRITE_FIELD(*this, kContextOffset, value);
CONDITIONAL_WRITE_BARRIER(*this, kContextOffset, value, mode);
}
RELEASE_ACQUIRE_ACCESSORS_CHECKED(JSFunction, prototype_or_initial_map,
HeapObject, kPrototypeOrInitialMapOffset,
map().has_prototype_slot())
......
......@@ -53,7 +53,8 @@ class JSBoundFunction
};
// JSFunction describes JavaScript functions.
class JSFunction : public JSFunctionOrBoundFunction {
class JSFunction
: public TorqueGeneratedJSFunction<JSFunction, JSFunctionOrBoundFunction> {
public:
// [prototype_or_initial_map]:
DECL_RELEASE_ACQUIRE_ACCESSORS(prototype_or_initial_map, HeapObject)
......@@ -70,8 +71,6 @@ class JSFunction : public JSFunctionOrBoundFunction {
inline Context context();
DECL_RELAXED_GETTER(context, Context)
inline bool has_context() const;
inline void set_context(HeapObject context,
WriteBarrierMode mode = UPDATE_WRITE_BARRIER);
inline JSGlobalProxy global_proxy();
inline NativeContext native_context();
inline int length();
......@@ -275,8 +274,6 @@ class JSFunction : public JSFunctionOrBoundFunction {
// Prints the name of the function using PrintF.
void PrintName(FILE* out = stdout);
DECL_CAST(JSFunction)
// Calculate the instance size and in-object properties count.
// {CalculateExpectedNofProperties} can trigger compilation.
static V8_WARN_UNUSED_RESULT int CalculateExpectedNofProperties(
......@@ -310,18 +307,6 @@ class JSFunction : public JSFunctionOrBoundFunction {
// ES6 section 19.2.3.5 Function.prototype.toString ( ).
static Handle<String> ToString(Handle<JSFunction> function);
struct FieldOffsets {
DEFINE_FIELD_OFFSET_CONSTANTS(JSFunctionOrBoundFunction::kHeaderSize,
TORQUE_GENERATED_JS_FUNCTION_FIELDS)
};
static constexpr int kSharedFunctionInfoOffset =
FieldOffsets::kSharedFunctionInfoOffset;
static constexpr int kContextOffset = FieldOffsets::kContextOffset;
static constexpr int kFeedbackCellOffset = FieldOffsets::kFeedbackCellOffset;
static constexpr int kCodeOffset = FieldOffsets::kCodeOffset;
static constexpr int kPrototypeOrInitialMapOffset =
FieldOffsets::kPrototypeOrInitialMapOffset;
class BodyDescriptor;
private:
......@@ -329,9 +314,15 @@ class JSFunction : public JSFunctionOrBoundFunction {
DECL_RELEASE_ACQUIRE_ACCESSORS(raw_code, CodeT)
// JSFunction doesn't have a fixed header size:
// Hide JSFunctionOrBoundFunction::kHeaderSize to avoid confusion.
// Hide TorqueGeneratedClass::kHeaderSize to avoid confusion.
static const int kHeaderSize;
// Hide generated accessors; custom accessors are called "shared".
DECL_ACCESSORS(shared_function_info, SharedFunctionInfo)
// Hide generated accessors; custom accessors are called "raw_feedback_cell".
DECL_ACCESSORS(feedback_cell, FeedbackCell)
// Returns the set of code kinds of compilation artifacts (bytecode,
// generated code) attached to this JSFunction.
// Note that attached code objects that are marked_for_deoptimization are not
......@@ -348,9 +339,9 @@ class JSFunction : public JSFunctionOrBoundFunction {
public:
static constexpr int kSizeWithoutPrototype = kPrototypeOrInitialMapOffset;
static constexpr int kSizeWithPrototype = FieldOffsets::kHeaderSize;
static constexpr int kSizeWithPrototype = TorqueGeneratedClass::kHeaderSize;
OBJECT_CONSTRUCTORS(JSFunction, JSFunctionOrBoundFunction);
TQ_OBJECT_CONSTRUCTORS(JSFunction)
};
} // namespace internal
......
......@@ -18,7 +18,6 @@ extern class JSBoundFunction extends JSFunctionOrBoundFunction {
}
@highestInstanceTypeWithinParentClassRange
@doNotGenerateCppClass
extern class JSFunction extends JSFunctionOrBoundFunction {
shared_function_info: SharedFunctionInfo;
context: Context;
......
......@@ -31,25 +31,22 @@ namespace internal {
#include "torque-generated/src/objects/js-objects-tq-inl.inc"
OBJECT_CONSTRUCTORS_IMPL(JSReceiver, HeapObject)
TQ_OBJECT_CONSTRUCTORS_IMPL(JSReceiver)
TQ_OBJECT_CONSTRUCTORS_IMPL(JSObject)
TQ_OBJECT_CONSTRUCTORS_IMPL(JSCustomElementsObject)
TQ_OBJECT_CONSTRUCTORS_IMPL(JSSpecialObject)
TQ_OBJECT_CONSTRUCTORS_IMPL(JSAsyncFromSyncIterator)
TQ_OBJECT_CONSTRUCTORS_IMPL(JSDate)
OBJECT_CONSTRUCTORS_IMPL(JSGlobalObject, JSSpecialObject)
TQ_OBJECT_CONSTRUCTORS_IMPL(JSGlobalObject)
TQ_OBJECT_CONSTRUCTORS_IMPL(JSGlobalProxy)
JSIteratorResult::JSIteratorResult(Address ptr) : JSObject(ptr) {}
OBJECT_CONSTRUCTORS_IMPL(JSMessageObject, JSObject)
TQ_OBJECT_CONSTRUCTORS_IMPL(JSMessageObject)
TQ_OBJECT_CONSTRUCTORS_IMPL(JSPrimitiveWrapper)
TQ_OBJECT_CONSTRUCTORS_IMPL(JSStringIterator)
NEVER_READ_ONLY_SPACE_IMPL(JSReceiver)
CAST_ACCESSOR(JSGlobalObject)
CAST_ACCESSOR(JSIteratorResult)
CAST_ACCESSOR(JSMessageObject)
CAST_ACCESSOR(JSReceiver)
DEF_GETTER(JSObject, elements, FixedArrayBase) {
return TaggedField<FixedArrayBase, kElementsOffset>::load(cage_base, *this);
......@@ -472,9 +469,6 @@ void JSObject::InitializeBody(Map map, int start_offset,
}
}
ACCESSORS(JSGlobalObject, native_context, NativeContext, kNativeContextOffset)
ACCESSORS(JSGlobalObject, global_proxy, JSGlobalProxy, kGlobalProxyOffset)
DEF_GETTER(JSGlobalObject, native_context_unchecked, Object) {
return TaggedField<Object, kNativeContextOffset>::load(cage_base, *this);
}
......@@ -501,9 +495,6 @@ void JSMessageObject::set_type(MessageTemplate value) {
set_raw_type(static_cast<int>(value));
}
ACCESSORS(JSMessageObject, argument, Object, kArgumentsOffset)
ACCESSORS(JSMessageObject, script, Script, kScriptOffset)
ACCESSORS(JSMessageObject, stack_frames, Object, kStackFramesOffset)
ACCESSORS(JSMessageObject, shared_info, HeapObject, kSharedInfoOffset)
ACCESSORS(JSMessageObject, bytecode_offset, Smi, kBytecodeOffsetOffset)
SMI_ACCESSORS(JSMessageObject, start_position, kStartPositionOffset)
......
......@@ -34,7 +34,7 @@ class IsCompiledScope;
// JSReceiver includes types on which properties can be defined, i.e.,
// JSObject and JSProxy.
class JSReceiver : public HeapObject {
class JSReceiver : public TorqueGeneratedJSReceiver<JSReceiver, HeapObject> {
public:
NEVER_READ_ONLY_SPACE
// Returns true if there is no slow (ie, dictionary) backing store.
......@@ -85,9 +85,6 @@ class JSReceiver : public HeapObject {
static void DeleteNormalizedProperty(Handle<JSReceiver> object,
InternalIndex entry);
DECL_CAST(JSReceiver)
DECL_VERIFIER(JSReceiver)
// ES6 section 7.1.1 ToPrimitive
V8_WARN_UNUSED_RESULT static MaybeHandle<Object> ToPrimitive(
Handle<JSReceiver> receiver,
......@@ -288,14 +285,17 @@ class JSReceiver : public HeapObject {
static const int kHashMask = PropertyArray::HashField::kMask;
DEFINE_FIELD_OFFSET_CONSTANTS(HeapObject::kHeaderSize,
TORQUE_GENERATED_JS_RECEIVER_FIELDS)
bool HasProxyInPrototype(Isolate* isolate);
// TC39 "Dynamic Code Brand Checks"
bool IsCodeLike(Isolate* isolate) const;
OBJECT_CONSTRUCTORS(JSReceiver, HeapObject);
private:
// Hide generated accessors; custom accessors are called
// "raw_properties_or_hash".
DECL_ACCESSORS(properties_or_hash, Object)
TQ_OBJECT_CONSTRUCTORS(JSReceiver)
};
// The JSObject describes real heap allocated JavaScript objects with
......@@ -996,21 +996,14 @@ class JSGlobalProxy
};
// JavaScript global object.
class JSGlobalObject : public JSSpecialObject {
class JSGlobalObject
: public TorqueGeneratedJSGlobalObject<JSGlobalObject, JSSpecialObject> {
public:
// [native context]: the natives corresponding to this global object.
DECL_ACCESSORS(native_context, NativeContext)
// [global proxy]: the global proxy object of the context
DECL_ACCESSORS(global_proxy, JSGlobalProxy)
DECL_RELEASE_ACQUIRE_ACCESSORS(global_dictionary, GlobalDictionary)
static void InvalidatePropertyCell(Handle<JSGlobalObject> object,
Handle<Name> name);
DECL_CAST(JSGlobalObject)
inline bool IsDetached();
// May be called by the concurrent GC when the global object is not
......@@ -1021,11 +1014,7 @@ class JSGlobalObject : public JSSpecialObject {
DECL_PRINTER(JSGlobalObject)
DECL_VERIFIER(JSGlobalObject)
// Layout description.
DEFINE_FIELD_OFFSET_CONSTANTS(JSSpecialObject::kHeaderSize,
TORQUE_GENERATED_JS_GLOBAL_OBJECT_FIELDS)
OBJECT_CONSTRUCTORS(JSGlobalObject, JSSpecialObject);
TQ_OBJECT_CONSTRUCTORS(JSGlobalObject)
};
// Representation for JS Wrapper objects, String, Number, Boolean, etc.
......@@ -1113,21 +1102,13 @@ class JSDate : public TorqueGeneratedJSDate<JSDate, JSObject> {
// error messages are not directly accessible from JavaScript to
// prevent leaking information to user code called during error
// formatting.
class JSMessageObject : public JSObject {
class JSMessageObject
: public TorqueGeneratedJSMessageObject<JSMessageObject, JSObject> {
public:
// [type]: the type of error message.
inline MessageTemplate type() const;
inline void set_type(MessageTemplate value);
// [arguments]: the arguments for formatting the error message.
DECL_ACCESSORS(argument, Object)
// [script]: the script from which the error message originated.
DECL_ACCESSORS(script, Script)
// [stack_frames]: an array of stack frames for this error object.
DECL_ACCESSORS(stack_frames, Object)
// Initializes the source positions in the object if possible. Does nothing if
// called more than once. If called when stack space is exhausted, then the
// source positions will be not be set and calling it again when there is more
......@@ -1159,14 +1140,9 @@ class JSMessageObject : public JSObject {
DECL_INT_ACCESSORS(error_level)
DECL_CAST(JSMessageObject)
// Dispatched behavior.
DECL_PRINTER(JSMessageObject)
DECL_VERIFIER(JSMessageObject)
DEFINE_FIELD_OFFSET_CONSTANTS(JSObject::kHeaderSize,
TORQUE_GENERATED_JS_MESSAGE_OBJECT_FIELDS)
// TODO(v8:8989): [torque] Support marker constants.
static const int kPointerFieldsEndOffset = kStartPositionOffset;
......@@ -1195,7 +1171,10 @@ class JSMessageObject : public JSObject {
DECL_INT_ACCESSORS(raw_type)
OBJECT_CONSTRUCTORS(JSMessageObject, JSObject);
// Hide generated accessors; custom accessors are named "raw_type".
DECL_INT_ACCESSORS(message_type)
TQ_OBJECT_CONSTRUCTORS(JSMessageObject)
};
// The [Async-from-Sync Iterator] object
......
......@@ -5,7 +5,6 @@
// JSReceiver corresponds to objects in the JS sense.
@abstract
@highestInstanceTypeWithinParentClassRange
@doNotGenerateCppClass
extern class JSReceiver extends HeapObject {
properties_or_hash: SwissNameDictionary|FixedArrayBase|PropertyArray|Smi;
}
......@@ -97,20 +96,24 @@ extern class JSGlobalProxy extends JSSpecialObject {
native_context: Object;
}
@doNotGenerateCppClass
extern class JSGlobalObject extends JSSpecialObject {
// [native context]: the natives corresponding to this global object.
native_context: NativeContext;
// [global proxy]: the global proxy object of the context
global_proxy: JSGlobalProxy;
}
extern class JSPrimitiveWrapper extends JSCustomElementsObject { value: JSAny; }
@doNotGenerateCppClass
extern class JSMessageObject extends JSObject {
// Tagged fields.
message_type: Smi;
arguments: Object;
// [argument]: the arguments for formatting the error message.
argument: Object;
// [script]: the script from which the error message originated.
script: Script;
// [stack_frames]: an array of stack frames for this error object.
stack_frames: Object;
shared_info: SharedFunctionInfo|Undefined;
......
......@@ -124,12 +124,10 @@ class JSProxy : public TorqueGeneratedJSProxy<JSProxy, JSReceiver> {
// JSProxyRevocableResult is just a JSObject with a specific initial map.
// This initial map adds in-object properties for "proxy" and "revoke".
// See https://tc39.github.io/ecma262/#sec-proxy.revocable
class JSProxyRevocableResult : public JSObject {
class JSProxyRevocableResult
: public TorqueGeneratedJSProxyRevocableResult<JSProxyRevocableResult,
JSObject> {
public:
// Layout description.
DEFINE_FIELD_OFFSET_CONSTANTS(
JSObject::kHeaderSize, TORQUE_GENERATED_JS_PROXY_REVOCABLE_RESULT_FIELDS)
// Indices of in-object properties.
static const int kProxyIndex = 0;
static const int kRevokeIndex = 1;
......
......@@ -7,7 +7,6 @@ extern class JSProxy extends JSReceiver {
handler: JSReceiver|Null;
}
@doNotGenerateCppClass
extern shape JSProxyRevocableResult extends JSObject {
proxy: JSAny;
revoke: JSAny;
......
......@@ -21,17 +21,9 @@ namespace internal {
#include "torque-generated/src/objects/js-regexp-tq-inl.inc"
TQ_OBJECT_CONSTRUCTORS_IMPL(JSRegExp)
OBJECT_CONSTRUCTORS_IMPL_CHECK_SUPER(JSRegExpResult, JSArray)
OBJECT_CONSTRUCTORS_IMPL_CHECK_SUPER(JSRegExpResultIndices, JSArray)
inline JSRegExpResultWithIndices::JSRegExpResultWithIndices(Address ptr)
: JSRegExpResult(ptr) {
SLOW_DCHECK(IsJSArray());
}
CAST_ACCESSOR(JSRegExpResult)
CAST_ACCESSOR(JSRegExpResultWithIndices)
CAST_ACCESSOR(JSRegExpResultIndices)
TQ_OBJECT_CONSTRUCTORS_IMPL(JSRegExpResult)
TQ_OBJECT_CONSTRUCTORS_IMPL(JSRegExpResultIndices)
TQ_OBJECT_CONSTRUCTORS_IMPL(JSRegExpResultWithIndices)
ACCESSORS(JSRegExp, last_index, Object, kLastIndexOffset)
......
......@@ -254,18 +254,13 @@ DEFINE_OPERATORS_FOR_FLAGS(JSRegExp::Flags)
// faster creation of RegExp exec results.
// This class just holds constants used when creating the result.
// After creation the result must be treated as a JSArray in all regards.
class JSRegExpResult : public JSArray {
class JSRegExpResult
: public TorqueGeneratedJSRegExpResult<JSRegExpResult, JSArray> {
public:
DECL_CAST(JSRegExpResult)
// TODO(joshualitt): We would like to add printers and verifiers to
// JSRegExpResult, and maybe JSRegExpResultIndices, but both have the same
// instance type as JSArray.
// Layout description.
DEFINE_FIELD_OFFSET_CONSTANTS(JSArray::kHeaderSize,
TORQUE_GENERATED_JS_REG_EXP_RESULT_FIELDS)
// Indices of in-object properties.
static const int kIndexIndex = 0;
static const int kInputIndex = 1;
......@@ -279,25 +274,20 @@ class JSRegExpResult : public JSArray {
static const int kMapIndexInContext = Context::REGEXP_RESULT_MAP_INDEX;
OBJECT_CONSTRUCTORS(JSRegExpResult, JSArray);
TQ_OBJECT_CONSTRUCTORS(JSRegExpResult)
};
class JSRegExpResultWithIndices : public JSRegExpResult {
class JSRegExpResultWithIndices
: public TorqueGeneratedJSRegExpResultWithIndices<JSRegExpResultWithIndices,
JSRegExpResult> {
public:
DECL_CAST(JSRegExpResultWithIndices)
// Layout description.
DEFINE_FIELD_OFFSET_CONSTANTS(
JSRegExpResult::kSize,
TORQUE_GENERATED_JS_REG_EXP_RESULT_WITH_INDICES_FIELDS)
static_assert(
JSRegExpResult::kInObjectPropertyCount == 6,
"JSRegExpResultWithIndices must be a subclass of JSRegExpResult");
static const int kIndicesIndex = 6;
static const int kInObjectPropertyCount = 7;
OBJECT_CONSTRUCTORS(JSRegExpResultWithIndices, JSRegExpResult);
TQ_OBJECT_CONSTRUCTORS(JSRegExpResultWithIndices)
};
// JSRegExpResultIndices is just a JSArray with a specific initial map.
......@@ -306,14 +296,10 @@ class JSRegExpResultWithIndices : public JSRegExpResult {
// faster creation of RegExp exec results.
// This class just holds constants used when creating the result.
// After creation the result must be treated as a JSArray in all regards.
class JSRegExpResultIndices : public JSArray {
class JSRegExpResultIndices
: public TorqueGeneratedJSRegExpResultIndices<JSRegExpResultIndices,
JSArray> {
public:
DECL_CAST(JSRegExpResultIndices)
// Layout description.
DEFINE_FIELD_OFFSET_CONSTANTS(
JSArray::kHeaderSize, TORQUE_GENERATED_JS_REG_EXP_RESULT_INDICES_FIELDS)
static Handle<JSRegExpResultIndices> BuildIndices(
Isolate* isolate, Handle<RegExpMatchInfo> match_info,
Handle<Object> maybe_names);
......@@ -325,7 +311,7 @@ class JSRegExpResultIndices : public JSArray {
// Descriptor index of groups.
static const int kGroupsDescriptorIndex = 1;
OBJECT_CONSTRUCTORS(JSRegExpResultIndices, JSArray);
TQ_OBJECT_CONSTRUCTORS(JSRegExpResultIndices)
};
} // namespace internal
......
......@@ -38,7 +38,6 @@ RegExpBuiltinsAssembler::FastStoreLastIndex(FastJSRegExp, Smi): void;
extern class JSRegExpConstructor extends JSFunction
generates 'TNode<JSFunction>';
@doNotGenerateCppClass
extern shape JSRegExpResult extends JSArray {
// In-object properties:
// The below fields are externally exposed.
......@@ -52,12 +51,10 @@ extern shape JSRegExpResult extends JSArray {
regexp_last_index: Smi;
}
@doNotGenerateCppClass
extern shape JSRegExpResultWithIndices extends JSRegExpResult {
indices: JSAny;
}
@doNotGenerateCppClass
extern shape JSRegExpResultIndices extends JSArray {
// In-object properties:
// The groups field is externally exposed.
......
......@@ -21,18 +21,7 @@ namespace internal {
TQ_OBJECT_CONSTRUCTORS_IMPL(WeakCell)
TQ_OBJECT_CONSTRUCTORS_IMPL(JSWeakRef)
OBJECT_CONSTRUCTORS_IMPL(JSFinalizationRegistry, JSObject)
ACCESSORS(JSFinalizationRegistry, native_context, NativeContext,
kNativeContextOffset)
ACCESSORS(JSFinalizationRegistry, cleanup, Object, kCleanupOffset)
ACCESSORS(JSFinalizationRegistry, active_cells, HeapObject, kActiveCellsOffset)
ACCESSORS(JSFinalizationRegistry, cleared_cells, HeapObject,
kClearedCellsOffset)
ACCESSORS(JSFinalizationRegistry, key_map, Object, kKeyMapOffset)
SMI_ACCESSORS(JSFinalizationRegistry, flags, kFlagsOffset)
ACCESSORS(JSFinalizationRegistry, next_dirty, Object, kNextDirtyOffset)
CAST_ACCESSOR(JSFinalizationRegistry)
TQ_OBJECT_CONSTRUCTORS_IMPL(JSFinalizationRegistry)
BIT_FIELD_ACCESSORS(JSFinalizationRegistry, flags, scheduled_for_cleanup,
JSFinalizationRegistry::ScheduledForCleanupBit)
......
......@@ -21,22 +21,12 @@ class WeakCell;
// FinalizationRegistry object from the JS Weak Refs spec proposal:
// https://github.com/tc39/proposal-weakrefs
class JSFinalizationRegistry : public JSObject {
class JSFinalizationRegistry
: public TorqueGeneratedJSFinalizationRegistry<JSFinalizationRegistry,
JSObject> {
public:
DECL_PRINTER(JSFinalizationRegistry)
EXPORT_DECL_VERIFIER(JSFinalizationRegistry)
DECL_CAST(JSFinalizationRegistry)
DECL_ACCESSORS(native_context, NativeContext)
DECL_ACCESSORS(cleanup, Object)
DECL_ACCESSORS(active_cells, HeapObject)
DECL_ACCESSORS(cleared_cells, HeapObject)
DECL_ACCESSORS(key_map, Object)
DECL_ACCESSORS(next_dirty, Object)
DECL_INT_ACCESSORS(flags)
DECL_BOOLEAN_ACCESSORS(scheduled_for_cleanup)
......@@ -72,14 +62,10 @@ class JSFinalizationRegistry : public JSObject {
Isolate* isolate, Address raw_finalization_registry,
Address raw_weak_cell);
// Layout description.
DEFINE_FIELD_OFFSET_CONSTANTS(
JSObject::kHeaderSize, TORQUE_GENERATED_JS_FINALIZATION_REGISTRY_FIELDS)
// Bitfields in flags.
DEFINE_TORQUE_GENERATED_FINALIZATION_REGISTRY_FLAGS()
OBJECT_CONSTRUCTORS(JSFinalizationRegistry, JSObject);
TQ_OBJECT_CONSTRUCTORS(JSFinalizationRegistry)
};
// Internal object for storing weak references in JSFinalizationRegistry.
......
......@@ -6,7 +6,6 @@ bitfield struct FinalizationRegistryFlags extends uint31 {
scheduled_for_cleanup: bool: 1 bit;
}
@doNotGenerateCppClass
extern class JSFinalizationRegistry extends JSObject {
native_context: NativeContext;
cleanup: Callable;
......
......@@ -8,7 +8,6 @@
#undef OBJECT_CONSTRUCTORS
#undef OBJECT_CONSTRUCTORS_IMPL
#undef OBJECT_CONSTRUCTORS_IMPL_CHECK_SUPER
#undef NEVER_READ_ONLY_SPACE
#undef NEVER_READ_ONLY_SPACE_IMPL
#undef DECL_PRIMITIVE_GETTER
......
......@@ -30,11 +30,6 @@
#define OBJECT_CONSTRUCTORS_IMPL(Type, Super) \
inline Type::Type(Address ptr) : Super(ptr) { SLOW_DCHECK(Is##Type()); }
// In these cases, we don't have our own instance type to check, so check the
// supertype instead. This happens for types denoting a NativeContext-dependent
// set of maps.
#define OBJECT_CONSTRUCTORS_IMPL_CHECK_SUPER(Type, Super) \
inline Type::Type(Address ptr) : Super(ptr) { SLOW_DCHECK(Is##Super()); }
#define NEVER_READ_ONLY_SPACE \
inline Heap* GetHeap() const; \
......
......@@ -3855,11 +3855,13 @@ namespace {
class ClassFieldOffsetGenerator : public FieldOffsetsGenerator {
public:
ClassFieldOffsetGenerator(std::ostream& header, std::ostream& inline_header,
const ClassType* type, std::string gen_name)
const ClassType* type, std::string gen_name,
const ClassType* parent)
: FieldOffsetsGenerator(type),
hdr_(header),
inl_(inline_header),
previous_field_end_("P::kHeaderSize"),
previous_field_end_((parent && parent->IsShape()) ? "P::kSize"
: "P::kHeaderSize"),
gen_name_(gen_name) {}
void WriteField(const Field& f, const std::string& size_string) override {
std::string field = "k" + CamelifyString(f.name_and_type.name) + "Offset";
......@@ -3981,7 +3983,7 @@ base::Optional<std::vector<Field>> GetOrderedUniqueIndexFields(
void CppClassGenerator::GenerateClass() {
// Is<name>_NonInline(HeapObject)
{
if (!type_->IsShape()) {
cpp::Function f("Is"s + name_ + "_NonInline");
f.SetDescription("Alias for HeapObject::Is"s + name_ +
"() that avoids inlining.");
......@@ -4046,7 +4048,8 @@ void CppClassGenerator::GenerateClass() {
}
hdr_ << "\n";
ClassFieldOffsetGenerator g(hdr_, inl_, type_, gen_name_);
ClassFieldOffsetGenerator g(hdr_, inl_, type_, gen_name_,
type_->GetSuperClass());
for (auto f : type_->fields()) {
CurrentSourcePosition::Scope scope(f.pos);
g.RecordOffsetFor(f);
......@@ -4174,6 +4177,15 @@ void CppClassGenerator::GenerateClassCasts() {
}
void CppClassGenerator::GenerateClassConstructors() {
const ClassType* typecheck_type = type_;
while (typecheck_type->IsShape()) {
typecheck_type = typecheck_type->GetSuperClass();
// Shapes have already been checked earlier to inherit from JSObject, so we
// should have found an appropriate type.
DCHECK(typecheck_type);
}
hdr_ << " public:\n";
hdr_ << " template <class DAlias = D>\n";
hdr_ << " constexpr " << gen_name_ << "() : P() {\n";
......@@ -4194,7 +4206,8 @@ void CppClassGenerator::GenerateClassConstructors() {
inl_ << "template<class D, class P>\n";
inl_ << "inline " << gen_name_T_ << "::" << gen_name_ << "(Address ptr)\n";
inl_ << " : P(ptr) {\n";
inl_ << " SLOW_DCHECK(Is" << name_ << "_NonInline(*this));\n";
inl_ << " SLOW_DCHECK(Is" << typecheck_type->name()
<< "_NonInline(*this));\n";
inl_ << "}\n";
inl_ << "template<class D, class P>\n";
......@@ -4204,7 +4217,7 @@ void CppClassGenerator::GenerateClassConstructors() {
inl_ << " SLOW_DCHECK("
<< "(allow_smi == HeapObject::AllowInlineSmiStorage::kAllowBeingASmi"
" && this->IsSmi()) || Is"
<< name_ << "_NonInline(*this));\n";
<< typecheck_type->name() << "_NonInline(*this));\n";
inl_ << "}\n";
}
......@@ -4603,9 +4616,11 @@ void ImplementationVisitor::GenerateClassDefinitions(
for (const ClassType* type : TypeOracle::GetClasses()) {
auto& streams = GlobalContext::GeneratedPerFile(type->AttributedToFile());
std::ostream& header = streams.class_definition_headerfile;
header << "class " << type->GetGeneratedTNodeTypeName() << ";\n";
forward_declarations << "class " << type->GetGeneratedTNodeTypeName()
<< ";\n";
std::string name = type->GenerateCppClassDefinitions()
? type->name()
: type->GetGeneratedTNodeTypeName();
header << "class " << name << ";\n";
forward_declarations << "class " << name << ";\n";
}
for (const ClassType* type : TypeOracle::GetClasses()) {
......
......@@ -31,6 +31,14 @@ Handle<JSFinalizationRegistry> ConstructJSFinalizationRegistry(
JSObject::New(finalization_registry_fun, finalization_registry_fun,
Handle<AllocationSite>::null())
.ToHandleChecked());
// JSObject::New filled all of the internal fields with undefined. Some of
// them have more restrictive types, so set those now.
finalization_registry->set_native_context(*isolate->native_context());
finalization_registry->set_cleanup(
isolate->native_context()->empty_function());
finalization_registry->set_flags(0);
#ifdef VERIFY_HEAP
finalization_registry->JSFinalizationRegistryVerify(isolate);
#endif // VERIFY_HEAP
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment