1 // Copyright 2018 the V8 project authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #ifndef V8_BUILTINS_BUILTINS_PROMISE_H_ 6 #define V8_BUILTINS_BUILTINS_PROMISE_H_ 7 8 #include "src/objects/contexts.h" 9 10 namespace v8 { 11 namespace internal { 12 13 class PromiseBuiltins { 14 public: 15 enum PromiseResolvingFunctionContextSlot { 16 // The promise which resolve/reject callbacks fulfill. 17 kPromiseSlot = Context::MIN_CONTEXT_SLOTS, 18 19 // Whether the callback was already invoked. 20 kAlreadyResolvedSlot, 21 22 // Whether to trigger a debug event or not. Used in catch 23 // prediction. 24 kDebugEventSlot, 25 kPromiseContextLength, 26 }; 27 28 // TODO(bmeurer): Move this to a proper context map in contexts.h? 29 // Similar to the AwaitContext that we introduced for await closures. 30 enum PromiseAllResolveElementContextSlots { 31 // Remaining elements count 32 kPromiseAllResolveElementRemainingSlot = Context::MIN_CONTEXT_SLOTS, 33 34 // Promise capability from Promise.all 35 kPromiseAllResolveElementCapabilitySlot, 36 37 // Values array from Promise.all 38 kPromiseAllResolveElementValuesSlot, 39 40 kPromiseAllResolveElementLength 41 }; 42 43 enum PromiseAnyRejectElementContextSlots { 44 // Remaining elements count 45 kPromiseAnyRejectElementRemainingSlot = Context::MIN_CONTEXT_SLOTS, 46 47 // Promise capability from Promise.any 48 kPromiseAnyRejectElementCapabilitySlot, 49 50 // errors array from Promise.any 51 kPromiseAnyRejectElementErrorsSlot, 52 kPromiseAnyRejectElementLength 53 }; 54 55 enum FunctionContextSlot { 56 kCapabilitySlot = Context::MIN_CONTEXT_SLOTS, 57 58 kCapabilitiesContextLength, 59 }; 60 61 // This is used by the Promise.prototype.finally builtin to store 62 // onFinally callback and the Promise constructor. 63 // TODO(gsathya): For native promises we can create a variant of 64 // this without extra space for the constructor to save memory. 65 enum PromiseFinallyContextSlot { 66 kOnFinallySlot = Context::MIN_CONTEXT_SLOTS, 67 kConstructorSlot, 68 69 kPromiseFinallyContextLength, 70 }; 71 72 // This is used by the ThenFinally and CatchFinally builtins to 73 // store the value to return or reason to throw. 74 enum PromiseValueThunkOrReasonContextSlot { 75 kValueSlot = Context::MIN_CONTEXT_SLOTS, 76 77 kPromiseValueThunkOrReasonContextLength, 78 }; 79 80 private: 81 DISALLOW_IMPLICIT_CONSTRUCTORS(PromiseBuiltins); 82 }; 83 84 } // namespace internal 85 } // namespace v8 86 87 #endif // V8_BUILTINS_BUILTINS_PROMISE_H_ 88