Skip to content

fix(node/inspector): Session constructor should not throw #25041

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

Merged
merged 1 commit into from
Aug 14, 2024
Merged
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
26 changes: 7 additions & 19 deletions ext/node/polyfills/inspector.ts
Original file line number Diff line number Diff line change
@@ -1,26 +1,18 @@
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
// Copyright Joyent and Node contributors. All rights reserved. MIT license.

// TODO(petamoriken): enable prefer-primordials for node polyfills
// deno-lint-ignore-file prefer-primordials

import { EventEmitter } from "node:events";
import { notImplemented } from "ext:deno_node/_utils.ts";
import { primordials } from "ext:core/mod.js";

const connectionSymbol = Symbol("connectionProperty");
const messageCallbacksSymbol = Symbol("messageCallbacks");
const nextIdSymbol = Symbol("nextId");
const onMessageSymbol = Symbol("onMessage");
const {
SafeMap,
} = primordials;

class Session extends EventEmitter {
[connectionSymbol]: null;
[nextIdSymbol]: number;
[messageCallbacksSymbol]: Map<string, (e: Error) => void>;

constructor() {
super();
notImplemented("inspector.Session.prototype.constructor");
}
#connection = null;
#nextId = 1;
#messageCallbacks = new SafeMap();

/** Connects the session to the inspector back-end. */
connect() {
Expand All @@ -33,10 +25,6 @@ class Session extends EventEmitter {
notImplemented("inspector.Session.prototype.connectToMainThread");
}

[onMessageSymbol](_message: string) {
notImplemented("inspector.Session.prototype[Symbol('onMessage')]");
}

/** Posts a message to the inspector back-end. */
post(
_method: string,
Expand Down
6 changes: 5 additions & 1 deletion tests/unit_node/inspector_test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
import inspector from "node:inspector";
import inspector, { Session } from "node:inspector";
import { assertEquals } from "@std/assert/equals";

Deno.test("[node/inspector] - importing inspector works", () => {
assertEquals(typeof inspector.open, "function");
});

Deno.test("[node/inspector] - Session constructor should not throw", () => {
new Session();
});