src: remove unused PromiseWrap-related code

PromiseWrap has been removed in
https://github.com/nodejs/node/pull/39135 and we do not have any
internal object setting the internal field at 0 as a promise
(we always set the first field as an aligned pointer to
the embedder ID). As result GetAssignedPromiseWrapAsyncId()
always just returns AsyncWrap::kInvalidAsyncId and turn
the removed block into noops. So the block just can be removed.

PR-URL: https://github.com/nodejs/node/pull/49335
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Darshan Sen <raisinten@gmail.com>
Reviewed-By: Gerhard Stöbich <deb2001-github@yahoo.de>
This commit is contained in:
Joyee Cheung
2023-09-01 13:26:32 +01:00
committed by GitHub
parent 457cedda9d
commit 295572ec67

View File

@@ -43,28 +43,6 @@ static Maybe<double> GetAssignedPromiseAsyncId(Environment* env,
: v8::Just(AsyncWrap::kInvalidAsyncId);
}
static Maybe<double> GetAssignedPromiseWrapAsyncId(Environment* env,
Local<Promise> promise,
Local<Value> id_symbol) {
// This check is imperfect. If the internal field is set, it should
// be an object. If it's not, we just ignore it. Ideally v8 would
// have had GetInternalField returning a MaybeLocal but this works
// for now.
Local<Value> promiseWrap = promise->GetInternalField(0).As<Value>();
if (promiseWrap->IsObject()) {
Local<Value> maybe_async_id;
if (!promiseWrap.As<Object>()->Get(env->context(), id_symbol)
.ToLocal(&maybe_async_id)) {
return v8::Just(AsyncWrap::kInvalidAsyncId);
}
return maybe_async_id->IsNumber()
? maybe_async_id->NumberValue(env->context())
: v8::Just(AsyncWrap::kInvalidAsyncId);
} else {
return v8::Just(AsyncWrap::kInvalidAsyncId);
}
}
void PromiseRejectCallback(PromiseRejectMessage message) {
static std::atomic<uint64_t> unhandledRejections{0};
static std::atomic<uint64_t> rejectionsHandledAfter{0};
@@ -122,17 +100,6 @@ void PromiseRejectCallback(PromiseRejectMessage message) {
if (!GetAssignedPromiseAsyncId(env, promise, env->trigger_async_id_symbol())
.To(&trigger_async_id)) return;
if (async_id == AsyncWrap::kInvalidAsyncId &&
trigger_async_id == AsyncWrap::kInvalidAsyncId) {
// That means that promise might be a PromiseWrap, so we'll
// check there as well.
if (!GetAssignedPromiseWrapAsyncId(env, promise, env->async_id_symbol())
.To(&async_id)) return;
if (!GetAssignedPromiseWrapAsyncId(
env, promise, env->trigger_async_id_symbol())
.To(&trigger_async_id)) return;
}
if (async_id != AsyncWrap::kInvalidAsyncId &&
trigger_async_id != AsyncWrap::kInvalidAsyncId) {
env->async_hooks()->push_async_context(