Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nodejs/node.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'deps/v8/src/builtins/promise-then.tq')
-rw-r--r--deps/v8/src/builtins/promise-then.tq117
1 files changed, 56 insertions, 61 deletions
diff --git a/deps/v8/src/builtins/promise-then.tq b/deps/v8/src/builtins/promise-then.tq
index 45f8fd0c81f..3de6d277d84 100644
--- a/deps/v8/src/builtins/promise-then.tq
+++ b/deps/v8/src/builtins/promise-then.tq
@@ -6,74 +6,69 @@
namespace promise {
- macro
- IsPromiseSpeciesLookupChainIntact(
- nativeContext: NativeContext, promiseMap: Map): bool {
- const promisePrototype =
- nativeContext[NativeContextSlot::PROMISE_PROTOTYPE_INDEX];
- if (IsForceSlowPath()) return false;
- if (promiseMap.prototype != promisePrototype) return false;
- return !IsPromiseSpeciesProtectorCellInvalid();
- }
-
- // https://tc39.es/ecma262/#sec-promise.prototype.then
- transitioning javascript builtin
- PromisePrototypeThen(js-implicit context: NativeContext, receiver: JSAny)(
- onFulfilled: JSAny, onRejected: JSAny): JSAny {
- // 1. Let promise be the this value.
- // 2. If IsPromise(promise) is false, throw a TypeError exception.
- const promise = Cast<JSPromise>(receiver) otherwise ThrowTypeError(
- MessageTemplate::kIncompatibleMethodReceiver, 'Promise.prototype.then',
- receiver);
+macro
+IsPromiseSpeciesLookupChainIntact(
+ nativeContext: NativeContext, promiseMap: Map): bool {
+ const promisePrototype =
+ nativeContext[NativeContextSlot::PROMISE_PROTOTYPE_INDEX];
+ if (IsForceSlowPath()) return false;
+ if (promiseMap.prototype != promisePrototype) return false;
+ return !IsPromiseSpeciesProtectorCellInvalid();
+}
- // 3. Let C be ? SpeciesConstructor(promise, %Promise%).
- const promiseFun = UnsafeCast<JSFunction>(
- context[NativeContextSlot::PROMISE_FUNCTION_INDEX]);
+// https://tc39.es/ecma262/#sec-promise.prototype.then
+transitioning javascript builtin
+PromisePrototypeThen(js-implicit context: NativeContext, receiver: JSAny)(
+ onFulfilled: JSAny, onRejected: JSAny): JSAny {
+ // 1. Let promise be the this value.
+ // 2. If IsPromise(promise) is false, throw a TypeError exception.
+ const promise = Cast<JSPromise>(receiver) otherwise ThrowTypeError(
+ MessageTemplate::kIncompatibleMethodReceiver, 'Promise.prototype.then',
+ receiver);
- // 4. Let resultCapability be ? NewPromiseCapability(C).
- let resultPromiseOrCapability: JSPromise|PromiseCapability;
- let resultPromise: JSAny;
- try {
- if (IsPromiseSpeciesLookupChainIntact(context, promise.map)) {
- goto AllocateAndInit;
- }
+ // 3. Let C be ? SpeciesConstructor(promise, %Promise%).
+ const promiseFun = UnsafeCast<JSFunction>(
+ context[NativeContextSlot::PROMISE_FUNCTION_INDEX]);
- const constructor = SpeciesConstructor(promise, promiseFun);
- if (TaggedEqual(constructor, promiseFun)) {
- goto AllocateAndInit;
- } else {
- const promiseCapability = NewPromiseCapability(constructor, True);
- resultPromiseOrCapability = promiseCapability;
- resultPromise = promiseCapability.promise;
- }
+ // 4. Let resultCapability be ? NewPromiseCapability(C).
+ let resultPromiseOrCapability: JSPromise|PromiseCapability;
+ let resultPromise: JSAny;
+ try {
+ if (IsPromiseSpeciesLookupChainIntact(context, promise.map)) {
+ goto AllocateAndInit;
}
- label AllocateAndInit {
- const resultJSPromise = NewJSPromise(promise);
- resultPromiseOrCapability = resultJSPromise;
- resultPromise = resultJSPromise;
+
+ const constructor = SpeciesConstructor(promise, promiseFun);
+ if (TaggedEqual(constructor, promiseFun)) {
+ goto AllocateAndInit;
+ } else {
+ const promiseCapability = NewPromiseCapability(constructor, True);
+ resultPromiseOrCapability = promiseCapability;
+ resultPromise = promiseCapability.promise;
}
+ } label AllocateAndInit {
+ const resultJSPromise = NewJSPromise(promise);
+ resultPromiseOrCapability = resultJSPromise;
+ resultPromise = resultJSPromise;
+ }
- // We do some work of the PerformPromiseThen operation here, in that
- // we check the handlers and turn non-callable handlers into undefined.
- // This is because this is the one and only callsite of PerformPromiseThen
- // that has to do this.
+ // We do some work of the PerformPromiseThen operation here, in that
+ // we check the handlers and turn non-callable handlers into undefined.
+ // This is because this is the one and only callsite of PerformPromiseThen
+ // that has to do this.
- // 3. If IsCallable(onFulfilled) is false, then
- // a. Set onFulfilled to undefined.
- const onFulfilled = TaggedIsCallable(onFulfilled) ?
- UnsafeCast<Callable>(onFulfilled) :
- Undefined;
+ // 3. If IsCallable(onFulfilled) is false, then
+ // a. Set onFulfilled to undefined.
+ const onFulfilled = CastOrDefault<Callable>(onFulfilled, Undefined);
- // 4. If IsCallable(onRejected) is false, then
- // a. Set onRejected to undefined.
- const onRejected = TaggedIsCallable(onRejected) ?
- UnsafeCast<Callable>(onRejected) :
- Undefined;
+ // 4. If IsCallable(onRejected) is false, then
+ // a. Set onRejected to undefined.
+ const onRejected = CastOrDefault<Callable>(onRejected, Undefined);
- // 5. Return PerformPromiseThen(promise, onFulfilled, onRejected,
- // resultCapability).
- PerformPromiseThenImpl(
- promise, onFulfilled, onRejected, resultPromiseOrCapability);
- return resultPromise;
- }
+ // 5. Return PerformPromiseThen(promise, onFulfilled, onRejected,
+ // resultCapability).
+ PerformPromiseThenImpl(
+ promise, onFulfilled, onRejected, resultPromiseOrCapability);
+ return resultPromise;
+}
}