Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

src: move process.binding('performance') to internalBinding #22029

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 1 addition & 1 deletion lib/internal/bootstrap/node.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@
workerThreadSetup.setupStdio();
}

const perf = process.binding('performance');
const perf = internalBinding('performance');
const {
NODE_PERFORMANCE_MILESTONE_BOOTSTRAP_COMPLETE,
} = perf.constants;
Expand Down
7 changes: 1 addition & 6 deletions lib/internal/test/binding.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,5 @@ process.emitWarning(
'tracked by any versioning system or deprecation process.',
'internal/test/binding');

// These exports should be scoped as specifically as possible
// to avoid exposing APIs because even with that warning and
// this file being internal people will still try to abuse it.
Copy link
Member

Choose a reason for hiding this comment

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

Is there any reason to switch from the original idea of limiting the set of exports as much as possible here?

Copy link
Member

Choose a reason for hiding this comment

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

This was here for a reason. I'm really kinda -1 on changing it without first exploring alternatives.

Copy link
Member Author

Choose a reason for hiding this comment

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

The reason is to help keep this maintainable. We use process.binding quite a bit in tests and it's far less maintainable to expose each individual property as exports on this object. I understand the reasoning but this approach keeps this test object as simple as possible.

Copy link
Member Author

Choose a reason for hiding this comment

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

For instance, process.binding() appears 157 times in test/parallel. Several of those are duplicates, but supporting all of those would mean managing a very large number of exports on internal/test/binding

Copy link
Member

Choose a reason for hiding this comment

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

I agree with @jasnell. I do not see a different way for doing this, could you come up with a different approach @apapirovski?

Copy link
Member Author

Choose a reason for hiding this comment

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

Ping @apapirovski ... there's really not a scalable way of picking and choosing the exports here so if you have a suggested alternative please let me know.

const { internalBinding } = require('internal/bootstrap/loaders');
module.exports = {
ModuleWrap: internalBinding('module_wrap').ModuleWrap,
};
module.exports = { internalBinding };
Copy link
Member

Choose a reason for hiding this comment

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

If I am not mistaken this file is now actually obsolete.

Copy link
Member Author

Choose a reason for hiding this comment

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

No it is not. This is the only way internalBinding is accessible by tests

3 changes: 2 additions & 1 deletion lib/perf_hooks.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
'use strict';

const { internalBinding } = require('internal/bootstrap/loaders');
const {
PerformanceEntry,
mark: _mark,
Expand All @@ -12,7 +13,7 @@ const {
timeOriginTimestamp,
timerify,
constants
} = process.binding('performance');
} = internalBinding('performance');

const {
NODE_PERFORMANCE_ENTRY_TYPE_NODE,
Expand Down
2 changes: 1 addition & 1 deletion src/node_perf.cc
Original file line number Diff line number Diff line change
Expand Up @@ -454,4 +454,4 @@ void Initialize(Local<Object> target,
} // namespace performance
} // namespace node

NODE_BUILTIN_MODULE_CONTEXT_AWARE(performance, node::performance::Initialize)
NODE_MODULE_CONTEXT_AWARE_INTERNAL(performance, node::performance::Initialize)
3 changes: 2 additions & 1 deletion test/parallel/test-internal-module-wrap.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
require('../common');
const assert = require('assert');

const { ModuleWrap } = require('internal/test/binding');
const { internalBinding } = require('internal/test/binding');
const { ModuleWrap } = internalBinding('module_wrap');
const { getPromiseDetails, isPromise } = process.binding('util');
const setTimeoutAsync = require('util').promisify(setTimeout);

Expand Down
5 changes: 3 additions & 2 deletions test/parallel/test-performance-gc.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,16 @@
const common = require('../common');
const assert = require('assert');
const {
PerformanceObserver
PerformanceObserver,
constants
} = require('perf_hooks');

const {
NODE_PERFORMANCE_GC_MAJOR,
NODE_PERFORMANCE_GC_MINOR,
NODE_PERFORMANCE_GC_INCREMENTAL,
NODE_PERFORMANCE_GC_WEAKCB
} = process.binding('performance').constants;
} = constants;

const kinds = [
NODE_PERFORMANCE_GC_MAJOR,
Expand Down
4 changes: 3 additions & 1 deletion test/parallel/test-performanceobserver.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
// Flags: --expose-internals
'use strict';

const common = require('../common');
const Countdown = require('../common/countdown');
const assert = require('assert');
const { internalBinding } = require('internal/test/binding');
const {
observerCounts: counts
} = process.binding('performance');
} = internalBinding('performance');
const {
performance,
PerformanceObserver,
Expand Down