feat(node): add process.binding (#1662)

This commit is contained in:
Yoshiya Hinosawa 2021-12-02 02:29:24 +09:00 committed by GitHub
parent 04a55c008a
commit e5e9b4eaa4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
40 changed files with 267 additions and 1 deletions

View File

@ -143,6 +143,7 @@
"test-next-tick-ordering2.js",
"test-next-tick-when-exiting.js",
"test-next-tick.js",
"test-process-binding-internalbinding-allowlist.js",
"test-querystring-escape.js",
"test-querystring-maxKeys-non-finite.js",
"test-querystring-multichar-separator.js",

View File

@ -0,0 +1,48 @@
// deno-fmt-ignore-file
// deno-lint-ignore-file
// Copyright Joyent and Node contributors. All rights reserved. MIT license.
// Taken from Node 16.13.0
// This file is automatically generated by "node/_tools/setup.ts". Do not modify this file manually
// Flags: --no-warnings
'use strict';
const common = require('../common');
const assert = require('assert');
// Assert that allowed internalBinding modules are accessible via
// process.binding().
assert(process.binding('async_wrap'));
assert(process.binding('buffer'));
assert(process.binding('cares_wrap'));
assert(process.binding('constants'));
assert(process.binding('contextify'));
if (common.hasCrypto) { // eslint-disable-line node-core/crypto-check
assert(process.binding('crypto'));
}
assert(process.binding('fs'));
assert(process.binding('fs_event_wrap'));
assert(process.binding('http_parser'));
if (common.hasIntl) {
assert(process.binding('icu'));
}
assert(process.binding('inspector'));
assert(process.binding('js_stream'));
assert(process.binding('natives'));
assert(process.binding('os'));
assert(process.binding('pipe_wrap'));
assert(process.binding('signal_wrap'));
assert(process.binding('spawn_sync'));
assert(process.binding('stream_wrap'));
assert(process.binding('tcp_wrap'));
if (common.hasCrypto) { // eslint-disable-line node-core/crypto-check
assert(process.binding('tls_wrap'));
}
assert(process.binding('tty_wrap'));
assert(process.binding('udp_wrap'));
assert(process.binding('url'));
assert(process.binding('util'));
assert(process.binding('uv'));
assert(process.binding('v8'));
assert(process.binding('zlib'));

View File

@ -0,0 +1,3 @@
// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license.
export {};

View File

@ -0,0 +1,3 @@
// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license.
export {};

View File

@ -0,0 +1,3 @@
// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license.
export {};

View File

@ -0,0 +1,3 @@
// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license.
export {};

View File

@ -0,0 +1,3 @@
// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license.
export {};

View File

@ -0,0 +1,3 @@
// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license.
export {};

View File

@ -0,0 +1,3 @@
// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license.
export {};

View File

@ -0,0 +1,3 @@
// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license.
export {};

View File

@ -0,0 +1,3 @@
// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license.
export {};

View File

@ -0,0 +1,3 @@
// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license.
export {};

View File

@ -0,0 +1,3 @@
// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license.
export {};

View File

@ -0,0 +1,3 @@
// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license.
export {};

View File

@ -0,0 +1,3 @@
// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license.
export {};

View File

@ -0,0 +1,3 @@
// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license.
export {};

View File

@ -0,0 +1,107 @@
import * as asyncWrap from "./async_wrap.ts";
import * as buffer from "./buffer.ts";
import * as config from "./config.ts";
import * as caresWrap from "./cares_wrap.ts";
import * as constants from "./constants.ts";
import * as contextify from "./contextify.ts";
import * as crypto from "./crypto.ts";
import * as credentials from "./credentials.ts";
import * as errors from "./errors.ts";
import * as fs from "./fs.ts";
import * as fsDir from "./fs_dir.ts";
import * as fsEventWrap from "./fs_event_wrap.ts";
import * as heapUtils from "./heap_utils.ts";
import * as httpParser from "./http_parser.ts";
import * as icu from "./icu.ts";
import * as inspector from "./inspector.ts";
import * as jsStream from "./js_stream.ts";
import * as messaging from "./messaging.ts";
import * as moduleWrap from "./module_wrap.ts";
import * as nativeModule from "./native_module.ts";
import * as natives from "./natives.ts";
import * as options from "./options.ts";
import * as os from "./os.ts";
import * as pipeWrap from "./pipe_wrap.ts";
import * as performance from "./performance.ts";
import * as processMethods from "./process_methods.ts";
import * as report from "./report.ts";
import * as serdes from "./serdes.ts";
import * as signalWrap from "./signal_wrap.ts";
import * as spawnSync from "./spawn_sync.ts";
import * as streamWrap from "./stream_wrap.ts";
import * as stringDecoder from "./string_decoder.ts";
import * as symbols from "./symbols.ts";
import * as taskQueue from "./task_queue.ts";
import * as tcpWrap from "./tcp_wrap.ts";
import * as timers from "./timers.ts";
import * as tlsWrap from "./tls_wrap.ts";
import * as traceEvents from "./trace_events.ts";
import * as ttyWrap from "./tty_wrap.ts";
import * as types from "./types.ts";
import * as udpWrap from "./udp_wrap.ts";
import * as url from "./url.ts";
import * as util from "./util.ts";
import * as uv from "./uv.ts";
import * as v8 from "./v8.ts";
import * as worker from "./worker.ts";
import * as zlib from "./zlib.ts";
const modules = {
"async_wrap": asyncWrap,
buffer,
"cares_wrap": caresWrap,
config,
constants,
contextify,
credentials,
crypto,
errors,
fs,
"fs_dir": fsDir,
"fs_event_wrap": fsEventWrap,
"heap_utils": heapUtils,
"http_parser": httpParser,
icu,
inspector,
"js_stream": jsStream,
messaging,
"module_wrap": moduleWrap,
"native_module": nativeModule,
natives,
options,
os,
performance,
"pipe_wrap": pipeWrap,
"process_methods": processMethods,
report,
serdes,
"signal_wrap": signalWrap,
"spawn_sync": spawnSync,
"stream_wrap": streamWrap,
"string_decoder": stringDecoder,
symbols,
"task_queue": taskQueue,
"tcp_wrap": tcpWrap,
timers,
"tls_wrap": tlsWrap,
"trace_events": traceEvents,
"tty_wrap": ttyWrap,
types,
"udp_wrap": udpWrap,
url,
util,
uv,
v8,
worker,
zlib,
};
export type BindingName = keyof typeof modules;
export function getBinding(name: BindingName) {
const mod = modules[name];
if (!mod) {
throw new Error(`No such module: ${name}`);
}
return mod;
}

View File

@ -0,0 +1,3 @@
// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license.
export {};

View File

@ -0,0 +1,3 @@
// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license.
export {};

View File

@ -0,0 +1,3 @@
// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license.
export {};

View File

@ -0,0 +1,3 @@
// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license.
export {};

View File

@ -0,0 +1,3 @@
// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license.
export {};

View File

@ -0,0 +1,3 @@
// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license.
export {};

View File

@ -0,0 +1,3 @@
// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license.
export {};

View File

@ -0,0 +1,3 @@
// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license.
export {};

View File

@ -0,0 +1,3 @@
// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license.
export {};

View File

@ -0,0 +1,3 @@
// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license.
export {};

View File

@ -0,0 +1,3 @@
// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license.
export {};

View File

@ -0,0 +1,3 @@
// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license.
export {};

View File

@ -0,0 +1,3 @@
// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license.
export {};

View File

@ -0,0 +1,3 @@
// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license.
export {};

View File

@ -0,0 +1,3 @@
// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license.
export {};

View File

@ -0,0 +1,3 @@
// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license.
export {};

View File

@ -1,4 +1,3 @@
// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license.
//
// Adapted from Node.js. Copyright Joyent, Inc. and other Node contributors.
//

View File

@ -0,0 +1,3 @@
// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license.
export {};

View File

@ -0,0 +1,3 @@
// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license.
export {};

View File

@ -0,0 +1,3 @@
// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license.
export {};

View File

@ -0,0 +1,3 @@
// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license.
export {};

View File

@ -0,0 +1,3 @@
// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license.
export {};

View File

@ -32,6 +32,8 @@ export {
};
import { stderr, stdin, stdout } from "./_process/streams.ts";
export { stderr, stdin, stdout };
import { getBinding } from "./internal_binding/mod.ts";
import type { BindingName } from "./internal_binding/mod.ts";
const notImplementedEvents = [
"beforeExit",
@ -373,6 +375,10 @@ class Process extends EventEmitter {
/** https://nodejs.org/api/process.html#process_process_emitwarning_warning_options */
emitWarning = emitWarning;
binding(name: BindingName) {
return getBinding(name);
}
}
/** https://nodejs.org/api/process.html#process_process */