@@ -11,8 +11,6 @@ const { customInspectSymbol, format } = require("util");
1111/**
1212 * @see https://developer.mozilla.org/en-US/docs/Web/API/Console_API
1313 */
14- // TODO (Tom Tang): It's easier to copy implementations from Node.js version 8 than Node.js 20,
15- // see https://github.com/nodejs/node/blob/v8.17.0/lib/console.js
1614// TODO (Tom Tang): adhere https://console.spec.whatwg.org/
1715class Console {
1816 /** @type {WriteFn } */
@@ -49,8 +47,15 @@ class Console {
4947 ignoreErrors = true ;
5048 options = { stdout, stderr, ignoreErrors } ;
5149 }
50+
5251 this . #writeToStdout = options . stdout . write ;
5352 this . #writeToStderr = options . stderr . write ;
53+
54+ this . log = ( ...args ) => this . #writeToStdout( this . #formatToStr( ...args ) ) ;
55+ this . debug = ( ...args ) => this . #writeToStdout( this . #formatToStr( ...args ) ) ;
56+ this . info = ( ...args ) => this . #writeToStdout( this . #formatToStr( ...args ) ) ;
57+ this . warn = ( ...args ) => this . #writeToStderr( this . #formatToStr( ...args ) ) ;
58+ this . error = ( ...args ) => this . #writeToStderr( this . #formatToStr( ...args ) ) ;
5459 }
5560
5661 /**
@@ -60,14 +65,6 @@ class Console {
6065 return format ( ...args ) + "\n"
6166 }
6267
63- log ( ...args ) {
64- this . #writeToStdout( this . #formatToStr( ...args ) )
65- }
66-
67- warn ( ...args ) {
68- this . #writeToStderr( this . #formatToStr( ...args ) )
69- }
70-
7168 // TODO (Tom Tang): implement more methods
7269
7370 /**
@@ -83,11 +80,6 @@ class Console {
8380 static customInspectSymbol = customInspectSymbol ;
8481}
8582
86- // https://github.com/nodejs/node/blob/v20.1.0/lib/internal/console/constructor.js#L681-L685
87- Console . prototype . debug = Console . prototype . log ;
88- Console . prototype . info = Console . prototype . log ;
89- Console . prototype . error = Console . prototype . warn ;
90-
9183if ( ! globalThis . console ) {
9284 globalThis . console = new Console (
9385 python . stdout /* sys.stdout */ ,
0 commit comments