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

Commit a2469df

Browse files
authored
Merge pull request #299 from exoego/any-logging
[console] Allow passing scala.Any to console
2 parents e8f632b + acad267 commit a2469df

File tree

2 files changed

+44
-31
lines changed

2 files changed

+44
-31
lines changed

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

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,28 @@ 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") {
3542
Console.log("a", 1)
3643
Console.info("a", 2)
3744
Console.warn("a", 3)
3845
Console.debug("a", 4)
39-
Console.error("a", 5)
40-
Console.trace("", 6)
46+
Console.error(ScalaNativeObject(1), 5)
47+
Console.trace("", ScalaNativeObject(1))
48+
Console.log("a", 1, ScalaNativeObject(1))
49+
Console.info("a", 2, ScalaNativeObject(1))
50+
Console.warn("a", 3, ScalaNativeObject(1))
51+
Console.debug(ScalaNativeObject(1), "a", 4)
52+
Console.error(ScalaNativeObject(1), "a", 5)
53+
Console.trace(ScalaNativeObject(1), "a", 6)
4154
}
4255

4356
it("should be passed to foreach") {
@@ -73,3 +86,5 @@ class ConsoleTest extends AnyFunSpec with BeforeAndAfterEach {
7386
console.timeEnd(label)
7487
}
7588
}
89+
90+
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 & 29 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, arg1: 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.
@@ -103,12 +103,10 @@ class Console protected () extends js.Object {
103103
* If formatting elements (e.g. `%d`) are not found in the first string then[[io.scalajs.nodejs.util.Util.inspect()]]
104104
* is called on each argument and the resulting string values are concatenated. See [[io.scalajs.nodejs.util.Util.format()]]
105105
* for more information.
106-
*
107-
* @param args
108106
*/
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
107+
def error(data: Any, arg1: Any, args: Any*): Unit = js.native
108+
def error(data: Any): Unit = js.native
109+
def error(): Unit = js.native
112110

113111
/**
114112
* Increases indentation of subsequent lines by two spaces.
@@ -123,7 +121,7 @@ class Console protected () extends js.Object {
123121
* An alias for [[group()]]
124122
* @param label
125123
*/
126-
def groupCollapsed(label: js.Any*): Unit = js.native
124+
def groupCollapsed(label: Any*): Unit = js.native
127125

128126
/**
129127
* Decreases indentation of subsequent lines by two spaces.
@@ -133,18 +131,18 @@ class Console protected () extends js.Object {
133131
/**
134132
* The `console.info()` function is an alias for [[log()]].
135133
*/
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
134+
def info(data: Any, arg1: Any, args: Any*): Unit = js.native
135+
def info(data: Any): Unit = js.native
136+
def info(): Unit = js.native
139137

140138
/**
141139
* Prints to `stdout` with newline.
142140
* Multiple arguments can be passed, with the first used as the primary message and all additional used as
143141
* substitution values similar to `printf(3)` (the arguments are all passed to `util.format()`).
144142
*/
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
143+
def log(data: Any, arg1: Any, args: Any*): Unit = js.native
144+
def log(data: Any): Unit = js.native
145+
def log(): Unit = js.native
148146

149147
/**
150148
* Try to construct a table with the columns of the properties of `tabularData` (or use `properties`) and
@@ -153,8 +151,8 @@ class Console protected () extends js.Object {
153151
* @param tabularData
154152
* @param properties Alternate properties for constructing the table.
155153
*/
156-
def table(tabularData: js.Any, properties: js.Array[String]): Unit = js.native
157-
def table(tabularData: js.Any): Unit = js.native
154+
def table(tabularData: Any, properties: js.Array[String]): Unit = js.native
155+
def table(tabularData: Any): Unit = js.native
158156

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

180178
/**
181179
* Prints to `stderr` the string `'Trace: '`, followed by the [[io.scalajs.nodejs.util.Util.format()]] formatted
182180
* message and stack trace to the current position in the code.
183181
*/
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
182+
def trace(data: Any, arg1: Any, args: Any*): Unit = js.native
183+
def trace(data: Any): Unit = js.native
184+
def trace(): Unit = js.native
187185

188186
/**
189187
* The `console.warn()` function is an alias for [[error()]
190188
*/
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
189+
def warn(data: Any, arg1: Any, args: Any*): Unit = js.native
190+
def warn(data: Any): Unit = js.native
191+
def warn(): Unit = js.native
194192

195193
/**
196194
* This method does not display anything unless used in the inspector.

0 commit comments

Comments
 (0)