diff options
Diffstat (limited to 'deps/v8/src/objects/promise.h')
-rw-r--r-- | deps/v8/src/objects/promise.h | 94 |
1 files changed, 57 insertions, 37 deletions
diff --git a/deps/v8/src/objects/promise.h b/deps/v8/src/objects/promise.h index 0f7b4f23ce..0504eb0537 100644 --- a/deps/v8/src/objects/promise.h +++ b/deps/v8/src/objects/promise.h @@ -29,21 +29,28 @@ class PromiseReactionJobTask : public Microtask { DECL_ACCESSORS(argument, Object) DECL_ACCESSORS(context, Context) DECL_ACCESSORS(handler, HeapObject) - // [promise_or_capability]: Either a JSPromise or a PromiseCapability. + // [promise_or_capability]: Either a JSPromise (in case of native promises), + // a PromiseCapability (general case), or undefined (in case of await). DECL_ACCESSORS(promise_or_capability, HeapObject) - static const int kArgumentOffset = Microtask::kHeaderSize; - static const int kContextOffset = kArgumentOffset + kPointerSize; - static const int kHandlerOffset = kContextOffset + kPointerSize; - static const int kPromiseOrCapabilityOffset = kHandlerOffset + kPointerSize; - static const int kSize = kPromiseOrCapabilityOffset + kPointerSize; +// Layout description. +#define PROMISE_REACTION_JOB_FIELDS(V) \ + V(kArgumentOffset, kTaggedSize) \ + V(kContextOffset, kTaggedSize) \ + V(kHandlerOffset, kTaggedSize) \ + V(kPromiseOrCapabilityOffset, kTaggedSize) \ + /* Total size. */ \ + V(kSize, 0) + + DEFINE_FIELD_OFFSET_CONSTANTS(Microtask::kHeaderSize, + PROMISE_REACTION_JOB_FIELDS) +#undef PROMISE_REACTION_JOB_FIELDS // Dispatched behavior. DECL_CAST(PromiseReactionJobTask) DECL_VERIFIER(PromiseReactionJobTask) - private: - DISALLOW_IMPLICIT_CONSTRUCTORS(PromiseReactionJobTask); + OBJECT_CONSTRUCTORS(PromiseReactionJobTask, Microtask) }; // Struct to hold state required for a PromiseReactionJob of type "Fulfill". @@ -54,8 +61,7 @@ class PromiseFulfillReactionJobTask : public PromiseReactionJobTask { DECL_PRINTER(PromiseFulfillReactionJobTask) DECL_VERIFIER(PromiseFulfillReactionJobTask) - private: - DISALLOW_IMPLICIT_CONSTRUCTORS(PromiseFulfillReactionJobTask); + OBJECT_CONSTRUCTORS(PromiseFulfillReactionJobTask, PromiseReactionJobTask) }; // Struct to hold state required for a PromiseReactionJob of type "Reject". @@ -66,8 +72,7 @@ class PromiseRejectReactionJobTask : public PromiseReactionJobTask { DECL_PRINTER(PromiseRejectReactionJobTask) DECL_VERIFIER(PromiseRejectReactionJobTask) - private: - DISALLOW_IMPLICIT_CONSTRUCTORS(PromiseRejectReactionJobTask); + OBJECT_CONSTRUCTORS(PromiseRejectReactionJobTask, PromiseReactionJobTask) }; // A container struct to hold state required for PromiseResolveThenableJob. @@ -78,19 +83,25 @@ class PromiseResolveThenableJobTask : public Microtask { DECL_ACCESSORS(then, JSReceiver) DECL_ACCESSORS(thenable, JSReceiver) - static const int kContextOffset = Microtask::kHeaderSize; - static const int kPromiseToResolveOffset = kContextOffset + kPointerSize; - static const int kThenOffset = kPromiseToResolveOffset + kPointerSize; - static const int kThenableOffset = kThenOffset + kPointerSize; - static const int kSize = kThenableOffset + kPointerSize; +// Layout description. +#define PROMISE_RESOLVE_THENABLE_JOB_FIELDS(V) \ + V(kContextOffset, kTaggedSize) \ + V(kPromiseToResolveOffset, kTaggedSize) \ + V(kThenOffset, kTaggedSize) \ + V(kThenableOffset, kTaggedSize) \ + /* Total size. */ \ + V(kSize, 0) + + DEFINE_FIELD_OFFSET_CONSTANTS(Microtask::kHeaderSize, + PROMISE_RESOLVE_THENABLE_JOB_FIELDS) +#undef PROMISE_RESOLVE_THENABLE_JOB_FIELDS // Dispatched behavior. DECL_CAST(PromiseResolveThenableJobTask) DECL_PRINTER(PromiseResolveThenableJobTask) DECL_VERIFIER(PromiseResolveThenableJobTask) - private: - DISALLOW_IMPLICIT_CONSTRUCTORS(PromiseResolveThenableJobTask); + OBJECT_CONSTRUCTORS(PromiseResolveThenableJobTask, Microtask) }; // Struct to hold the state of a PromiseCapability. @@ -100,18 +111,23 @@ class PromiseCapability : public Struct { DECL_ACCESSORS(resolve, Object) DECL_ACCESSORS(reject, Object) - static const int kPromiseOffset = Struct::kHeaderSize; - static const int kResolveOffset = kPromiseOffset + kPointerSize; - static const int kRejectOffset = kResolveOffset + kPointerSize; - static const int kSize = kRejectOffset + kPointerSize; +// Layout description. +#define PROMISE_CAPABILITY_FIELDS(V) \ + V(kPromiseOffset, kTaggedSize) \ + V(kResolveOffset, kTaggedSize) \ + V(kRejectOffset, kTaggedSize) \ + /* Total size. */ \ + V(kSize, 0) + + DEFINE_FIELD_OFFSET_CONSTANTS(Struct::kHeaderSize, PROMISE_CAPABILITY_FIELDS) +#undef PROMISE_CAPABILITY_FIELDS // Dispatched behavior. DECL_CAST(PromiseCapability) DECL_PRINTER(PromiseCapability) DECL_VERIFIER(PromiseCapability) - private: - DISALLOW_IMPLICIT_CONSTRUCTORS(PromiseCapability); + OBJECT_CONSTRUCTORS(PromiseCapability, Struct); }; // A representation of promise reaction. This differs from the specification @@ -124,10 +140,8 @@ class PromiseCapability : public Struct { // // The PromiseReaction::promise_or_capability field can either hold a JSPromise // instance (in the fast case of a native promise) or a PromiseCapability in -// case of a Promise subclass. -// -// We need to keep the context in the PromiseReaction so that we can run -// the default handlers (in case they are undefined) in the proper context. +// case of a Promise subclass. In case of await it can also be undefined if +// PromiseHooks are disabled (see https://github.com/tc39/ecma262/pull/1146). // // The PromiseReaction objects form a singly-linked list, terminated by // Smi 0. On the JSPromise instance they are linked in reverse order, @@ -140,22 +154,28 @@ class PromiseReaction : public Struct { DECL_ACCESSORS(next, Object) DECL_ACCESSORS(reject_handler, HeapObject) DECL_ACCESSORS(fulfill_handler, HeapObject) + // [promise_or_capability]: Either a JSPromise (in case of native promises), + // a PromiseCapability (general case), or undefined (in case of await). DECL_ACCESSORS(promise_or_capability, HeapObject) - static const int kNextOffset = Struct::kHeaderSize; - static const int kRejectHandlerOffset = kNextOffset + kPointerSize; - static const int kFulfillHandlerOffset = kRejectHandlerOffset + kPointerSize; - static const int kPromiseOrCapabilityOffset = - kFulfillHandlerOffset + kPointerSize; - static const int kSize = kPromiseOrCapabilityOffset + kPointerSize; +// Layout description. +#define PROMISE_REACTION_FIELDS(V) \ + V(kNextOffset, kTaggedSize) \ + V(kRejectHandlerOffset, kTaggedSize) \ + V(kFulfillHandlerOffset, kTaggedSize) \ + V(kPromiseOrCapabilityOffset, kTaggedSize) \ + /* Total size. */ \ + V(kSize, 0) + + DEFINE_FIELD_OFFSET_CONSTANTS(Struct::kHeaderSize, PROMISE_REACTION_FIELDS) +#undef PROMISE_REACTION_FIELDS // Dispatched behavior. DECL_CAST(PromiseReaction) DECL_PRINTER(PromiseReaction) DECL_VERIFIER(PromiseReaction) - private: - DISALLOW_IMPLICIT_CONSTRUCTORS(PromiseReaction); + OBJECT_CONSTRUCTORS(PromiseReaction, Struct); }; } // namespace internal |