2018-02-10 09:36:55 -06:00
|
|
|
'use strict';
|
|
|
|
|
2021-04-12 16:02:33 +02:00
|
|
|
const {
|
2024-03-02 23:11:30 +01:00
|
|
|
Error,
|
|
|
|
StringPrototypeStartsWith,
|
2021-04-12 16:02:33 +02:00
|
|
|
globalThis,
|
|
|
|
} = primordials;
|
|
|
|
|
2018-02-10 09:36:55 -06:00
|
|
|
process.emitWarning(
|
2018-12-18 23:05:18 -08:00
|
|
|
'These APIs are for internal testing only. Do not use them.',
|
2018-02-10 09:36:55 -06:00
|
|
|
'internal/test/binding');
|
|
|
|
|
2024-03-02 23:11:30 +01:00
|
|
|
function filteredInternalBinding(id) {
|
|
|
|
// Disallows internal bindings with names that start with 'internal_only'
|
|
|
|
// which means it should not be exposed to users even with
|
|
|
|
// --expose-internals.
|
|
|
|
if (StringPrototypeStartsWith(id, 'internal_only')) {
|
|
|
|
// This code is only intended for internal errors and is not documented.
|
|
|
|
// Do not use the normal error system.
|
|
|
|
// eslint-disable-next-line no-restricted-syntax
|
|
|
|
const error = new Error(`No such binding: ${id}`);
|
|
|
|
error.code = 'ERR_INVALID_MODULE';
|
|
|
|
throw error;
|
|
|
|
}
|
|
|
|
return internalBinding(id);
|
|
|
|
}
|
|
|
|
|
2021-01-15 14:53:12 +01:00
|
|
|
if (module.isPreloading) {
|
2024-03-02 23:11:30 +01:00
|
|
|
globalThis.internalBinding = filteredInternalBinding;
|
2021-01-15 14:53:12 +01:00
|
|
|
globalThis.primordials = primordials;
|
|
|
|
}
|
|
|
|
|
2024-03-02 23:11:30 +01:00
|
|
|
module.exports = { internalBinding: filteredInternalBinding, primordials };
|