Skip to content
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
address comment: use named functions
  • Loading branch information
BridgeAR committed Jun 30, 2017
commit 8918fc88481fbbf2a249c2f44cb4aca476103548
14 changes: 9 additions & 5 deletions lib/async_hooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,9 @@ const init_symbol = Symbol('init');
const before_symbol = Symbol('before');
const after_symbol = Symbol('after');
const destroy_symbol = Symbol('destroy');
const emitBeforeN = emitHookFactory(before_symbol);
const emitAfterN = emitHookFactory(after_symbol);
const emitDestroyN = emitHookFactory(destroy_symbol);
const emitBeforeN = emitHookFactory(before_symbol, 'emitBeforeN');
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you change the N to Native while you are at it? That short naming convention really annoys me.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess in that case the the S should also be renamed but I can't think of what it stands for right now. Does it stand for Script?

const emitAfterN = emitHookFactory(after_symbol, 'emitAfterN');
const emitDestroyN = emitHookFactory(destroy_symbol, 'emitDestroyN');

// Setup the callbacks that node::AsyncWrap will call when there are hooks to
// process. They use the same functions as the JS embedder API. These callbacks
Expand Down Expand Up @@ -345,10 +345,10 @@ function emitInitS(asyncId, type, triggerAsyncId, resource) {
}
}

function emitHookFactory(symbol) {
function emitHookFactory(symbol, name) {
// Called from native. The asyncId stack handling is taken care of there
// before this is called.
return function(asyncId) {
const fn = function(asyncId) {
processing_hook = true;
// Use a single try/catch for all hook to avoid setting up one per
// iteration.
Expand All @@ -367,6 +367,10 @@ function emitHookFactory(symbol) {
restoreTmpHooks();
}
};
Object.defineProperty(fn, 'name', {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mind leaving a comment that explains this sets the anonymous function name such it looks good in stack traces.

value: name
});
return fn;
}


Expand Down