Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 3ad10e5

Browse filesBrowse files
danbevBethGriggs
authored andcommitted
src: add extractPromiseWrap function
Currently PromiseHook extracts the PromiseWrap from a Local<Promise> in two places. This commit extracts that code into a function instead. PR-URL: #19340 Reviewed-By: James M Snell <jasnell@gmail.com>
1 parent 610297e commit 3ad10e5
Copy full SHA for 3ad10e5

File tree

Expand file treeCollapse file tree

1 file changed

+9
-12
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

1 file changed

+9
-12
lines changed
Open diff view settings
Collapse file

‎src/async_wrap.cc‎

Copy file name to clipboardExpand all lines: src/async_wrap.cc
+9-12Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -301,31 +301,28 @@ void PromiseWrap::getIsChainedPromise(Local<String> property,
301301
info.Holder()->GetInternalField(kIsChainedPromiseField));
302302
}
303303

304-
static void PromiseHook(PromiseHookType type, Local<Promise> promise,
305-
Local<Value> parent, void* arg) {
306-
Environment* env = static_cast<Environment*>(arg);
304+
static PromiseWrap* extractPromiseWrap(Local<Promise> promise) {
307305
Local<Value> resource_object_value = promise->GetInternalField(0);
308-
PromiseWrap* wrap = nullptr;
309306
if (resource_object_value->IsObject()) {
310-
Local<Object> resource_object = resource_object_value.As<Object>();
311-
wrap = Unwrap<PromiseWrap>(resource_object);
307+
return Unwrap<PromiseWrap>(resource_object_value.As<Object>());
312308
}
309+
return nullptr;
310+
}
313311

312+
static void PromiseHook(PromiseHookType type, Local<Promise> promise,
313+
Local<Value> parent, void* arg) {
314+
Environment* env = static_cast<Environment*>(arg);
315+
PromiseWrap* wrap = extractPromiseWrap(promise);
314316
if (type == PromiseHookType::kInit || wrap == nullptr) {
315317
bool silent = type != PromiseHookType::kInit;
316-
PromiseWrap* parent_wrap = nullptr;
317318

318319
// set parent promise's async Id as this promise's triggerAsyncId
319320
if (parent->IsPromise()) {
320321
// parent promise exists, current promise
321322
// is a chained promise, so we set parent promise's id as
322323
// current promise's triggerAsyncId
323324
Local<Promise> parent_promise = parent.As<Promise>();
324-
Local<Value> parent_resource = parent_promise->GetInternalField(0);
325-
if (parent_resource->IsObject()) {
326-
parent_wrap = Unwrap<PromiseWrap>(parent_resource.As<Object>());
327-
}
328-
325+
PromiseWrap* parent_wrap = extractPromiseWrap(parent_promise);
329326
if (parent_wrap == nullptr) {
330327
parent_wrap = PromiseWrap::New(env, parent_promise, nullptr, true);
331328
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.