Skip to content
This repository was archived by the owner on Jul 30, 2024. It is now read-only.

Commit cefa785

Browse files
committed
Allow passing Any to console
1 parent 2a38924 commit cefa785

File tree

2 files changed

+42
-33
lines changed

2 files changed

+42
-33
lines changed

app/nodejs-v10/src/test/scala/io/scalajs/nodejs/console_module/ConsoleTest.scala

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,22 @@ class ConsoleTest extends AnyFunSpec with BeforeAndAfterEach {
2929
Console.debug("a")
3030
Console.error("a")
3131
Console.trace("")
32+
33+
Console.log(ScalaNativeObject(1))
34+
Console.info(ScalaNativeObject(1))
35+
Console.warn(ScalaNativeObject(1))
36+
Console.debug(ScalaNativeObject(1))
37+
Console.error(ScalaNativeObject(1))
38+
Console.trace(ScalaNativeObject(1))
3239
}
3340

3441
it("should accept multiple arguments") {
35-
Console.log("a", 1)
36-
Console.info("a", 2)
37-
Console.warn("a", 3)
38-
Console.debug("a", 4)
39-
Console.error("a", 5)
40-
Console.trace("", 6)
42+
Console.log("a", 1, ScalaNativeObject(1))
43+
Console.info("a", 2, ScalaNativeObject(1))
44+
Console.warn("a", 3, ScalaNativeObject(1))
45+
Console.debug(ScalaNativeObject(1), "a", 4)
46+
Console.error(ScalaNativeObject(1), "a", 5)
47+
Console.trace(ScalaNativeObject(1), "a", 6)
4148
}
4249

4350
it("should be passed to foreach") {
@@ -73,3 +80,5 @@ class ConsoleTest extends AnyFunSpec with BeforeAndAfterEach {
7380
console.timeEnd(label)
7481
}
7582
}
83+
84+
case class ScalaNativeObject(a: Int, b: Option[Int] = None)

app/nodejs-v14/src/main/scala/io/scalajs/nodejs/console_module/Console.scala

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ class Console protected () extends js.Object {
4040
* @param message The error message
4141
* @param optionalParams The arguments passed to `message`
4242
*/
43-
def assert(value: js.Any, message: String, optionalParams: Any*): Unit = js.native
43+
def assert(value: Any, message: String, optionalParams: Any*): Unit = js.native
4444

4545
/**
4646
* A simple assertion test that verifies whether `value` is truthy.
@@ -49,7 +49,7 @@ class Console protected () extends js.Object {
4949
* @param value The value tested for being truthy
5050
* @param optionalParams The arguments passed to the error message
5151
*/
52-
def assert(value: js.Any, optionalParams: Any*): Unit = js.native
52+
def assert(value: Any, optionalParams: Any*): Unit = js.native
5353

5454
/**
5555
* When `stdout` is a TTY, calling `console.clear()` will attempt to clear the TTY.
@@ -78,22 +78,22 @@ class Console protected () extends js.Object {
7878
/**
7979
* The `console.debug()` function is an alias for `console.log()`.
8080
*/
81-
def debug(data: js.Any, args: js.Any*): Unit = js.native
82-
def debug(data: js.Any): Unit = js.native
83-
def debug(): Unit = js.native
81+
def debug(data: Any, args: Any*): Unit = js.native
82+
def debug(data: Any): Unit = js.native
83+
def debug(): Unit = js.native
8484

8585
/**
8686
* Uses [[io.scalajs.nodejs.util.Util.inspect()]] on `obj` and prints the resulting string to `stdout`.
8787
* This function bypasses any custom `inspect()` function defined on `obj`.
8888
*/
89-
def dir(obj: js.Any, options: ConsoleDirOptions): Unit = js.native
90-
def dir(obj: js.Any): Unit = js.native
89+
def dir(obj: Any, options: ConsoleDirOptions): Unit = js.native
90+
def dir(obj: Any): Unit = js.native
9191

9292
/**
9393
* This method calls[[log()]] passing it the arguments received.
9494
* Please note that this method does not produce any XML formatting
9595
*/
96-
def dirxml(data: js.Any*): Unit = js.native
96+
def dirxml(data: Any*): Unit = js.native
9797

9898
/**
9999
* Prints to `stderr` with newline.
@@ -106,9 +106,9 @@ class Console protected () extends js.Object {
106106
*
107107
* @param args
108108
*/
109-
def error(data: js.Any, args: js.Any*): Unit = js.native
110-
def error(data: js.Any): Unit = js.native
111-
def error(): Unit = js.native
109+
def error(data: Any, args: Any*): Unit = js.native
110+
def error(data: Any): Unit = js.native
111+
def error(): Unit = js.native
112112

113113
/**
114114
* Increases indentation of subsequent lines by two spaces.
@@ -123,7 +123,7 @@ class Console protected () extends js.Object {
123123
* An alias for [[group()]]
124124
* @param label
125125
*/
126-
def groupCollapsed(label: js.Any*): Unit = js.native
126+
def groupCollapsed(label: Any*): Unit = js.native
127127

128128
/**
129129
* Decreases indentation of subsequent lines by two spaces.
@@ -133,18 +133,18 @@ class Console protected () extends js.Object {
133133
/**
134134
* The `console.info()` function is an alias for [[log()]].
135135
*/
136-
def info(data: js.Any, args: js.Any*): Unit = js.native
137-
def info(data: js.Any): Unit = js.native
138-
def info(): Unit = js.native
136+
def info(data: Any, args: Any*): Unit = js.native
137+
def info(data: Any): Unit = js.native
138+
def info(): Unit = js.native
139139

140140
/**
141141
* Prints to `stdout` with newline.
142142
* Multiple arguments can be passed, with the first used as the primary message and all additional used as
143143
* substitution values similar to `printf(3)` (the arguments are all passed to `util.format()`).
144144
*/
145-
def log(data: js.Any, args: js.Any*): Unit = js.native
146-
def log(data: js.Any): Unit = js.native
147-
def log(): Unit = js.native
145+
def log(data: Any, args: Any*): Unit = js.native
146+
def log(data: Any): Unit = js.native
147+
def log(): Unit = js.native
148148

149149
/**
150150
* Try to construct a table with the columns of the properties of `tabularData` (or use `properties`) and
@@ -153,8 +153,8 @@ class Console protected () extends js.Object {
153153
* @param tabularData
154154
* @param properties Alternate properties for constructing the table.
155155
*/
156-
def table(tabularData: js.Any, properties: js.Array[String]): Unit = js.native
157-
def table(tabularData: js.Any): Unit = js.native
156+
def table(tabularData: Any, properties: js.Array[String]): Unit = js.native
157+
def table(tabularData: Any): Unit = js.native
158158

159159
/**
160160
* Starts a timer that can be used to compute the duration of an operation.
@@ -175,22 +175,22 @@ class Console protected () extends js.Object {
175175
/**
176176
* Stops a timer that was previously started by calling [[time()]] and prints the result to `.stdout`.`
177177
*/
178-
def timeLog(label: String, data: js.Any*): Unit = js.native
178+
def timeLog(label: String, data: Any*): Unit = js.native
179179

180180
/**
181181
* Prints to `stderr` the string `'Trace: '`, followed by the [[io.scalajs.nodejs.util.Util.format()]] formatted
182182
* message and stack trace to the current position in the code.
183183
*/
184-
def trace(data: js.Any, args: js.Any*): Unit = js.native
185-
def trace(data: js.Any): Unit = js.native
186-
def trace(): Unit = js.native
184+
def trace(data: Any, args: Any*): Unit = js.native
185+
def trace(data: Any): Unit = js.native
186+
def trace(): Unit = js.native
187187

188188
/**
189189
* The `console.warn()` function is an alias for [[error()]
190190
*/
191-
def warn(data: js.Any, args: js.Any*): Unit = js.native
192-
def warn(data: js.Any): Unit = js.native
193-
def warn(): Unit = js.native
191+
def warn(data: Any, args: Any*): Unit = js.native
192+
def warn(data: Any): Unit = js.native
193+
def warn(): Unit = js.native
194194

195195
/**
196196
* This method does not display anything unless used in the inspector.

0 commit comments

Comments
 (0)