mirror of
https://github.com/denoland/deno.git
synced 2024-10-29 08:58:01 -04:00
fix(node): add process.dlopen API (#19860)
Fixes https://github.com/denoland/deno/issues/19830
This commit is contained in:
parent
8a48fcc9d3
commit
7e1218cd8f
2 changed files with 16 additions and 5 deletions
|
@ -8,6 +8,7 @@ const internals = globalThis.__bootstrap.internals;
|
|||
const { core } = globalThis.__bootstrap;
|
||||
import { notImplemented, warnNotImplemented } from "ext:deno_node/_utils.ts";
|
||||
import { EventEmitter } from "node:events";
|
||||
import Module from "node:module";
|
||||
import { validateString } from "ext:deno_node/internal/validators.mjs";
|
||||
import {
|
||||
ERR_INVALID_ARG_TYPE,
|
||||
|
@ -291,6 +292,15 @@ function _kill(pid: number, sig: number): number {
|
|||
}
|
||||
}
|
||||
|
||||
// TODO(bartlomieju): flags is currently not supported.
|
||||
export function dlopen(module, filename, flags) {
|
||||
if (typeof flags !== "undefined") {
|
||||
warnNotImplemented("process.dlopen doesn't support 'flags' argument");
|
||||
}
|
||||
Module._extensions[".node"](module, filename);
|
||||
return module;
|
||||
}
|
||||
|
||||
export function kill(pid: number, sig: string | number = "SIGTERM") {
|
||||
if (pid != (pid | 0)) {
|
||||
throw new ERR_INVALID_ARG_TYPE("pid", "number", pid);
|
||||
|
@ -403,6 +413,8 @@ class Process extends EventEmitter {
|
|||
/** https://nodejs.org/api/process.html#process_process_nexttick_callback_args */
|
||||
nextTick = _nextTick;
|
||||
|
||||
dlopen = dlopen;
|
||||
|
||||
/** https://nodejs.org/api/process.html#process_process_events */
|
||||
override on(event: "exit", listener: (code: number) => void): this;
|
||||
override on(
|
||||
|
|
|
@ -7,6 +7,7 @@ export {
|
|||
assertThrows,
|
||||
} from "../test_util/std/testing/asserts.ts";
|
||||
export { fromFileUrl } from "../test_util/std/path/mod.ts";
|
||||
import process from "node:process";
|
||||
|
||||
const targetDir = Deno.execPath().replace(/[^\/\\]+$/, "");
|
||||
export const [libPrefix, libSuffix] = {
|
||||
|
@ -15,13 +16,11 @@ export const [libPrefix, libSuffix] = {
|
|||
windows: ["", "dll"],
|
||||
}[Deno.build.os];
|
||||
|
||||
const ops = Deno[Deno.internal].core.ops;
|
||||
|
||||
export function loadTestLibrary() {
|
||||
const specifier = `${targetDir}/${libPrefix}test_napi.${libSuffix}`;
|
||||
|
||||
// Internal, used in ext/node
|
||||
return ops.op_napi_open(specifier, {
|
||||
Buffer: {},
|
||||
});
|
||||
const module = {};
|
||||
process.dlopen(module, specifier);
|
||||
return module.exports;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue