Skip to content

Commit 9abfe60

Browse files
committed
Remove the hack to fix percentage signs in Node.js.
Back when that hack was introduced in 1fc8d0526ba9b46049c0deefc3fe3fa93d3271b0, Node.js' `console.log` deduplicated consecutive `%` signs in its argument, even if it was a single argument. At the time we thought that was intentional, and we added our hack to have it behave in a more standard way for Scala.js. The deduplication with only 1 argument turned out to be a bug, recognized as such in nodejs/node#3396, when it was accidentally fixed in Node.js 4. It is now the documented behavior, see https://nodejs.org/api/util.html#util_util_format_format_args which is referenced from https://nodejs.org/api/console.html#console_console_log_data_args.
1 parent e375e36 commit 9abfe60

File tree

3 files changed

+7
-85
lines changed

3 files changed

+7
-85
lines changed

js-envs-test-kit/src/main/scala/org/scalajs/jsenv/test/RunTests.scala

Lines changed: 6 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -95,50 +95,19 @@ private[test] class RunTests(config: JSEnvSuiteConfig, withCom: Boolean) {
9595
}
9696
}
9797

98-
@Test // Node.js strips double percentage signs - #500
98+
// #500 Node.js used to strip double percentage signs even with only 1 argument
99+
@Test
99100
def percentageTest: Unit = {
100-
val counts = 1 to 15
101-
val argcs = 1 to 3
102-
val strings = counts.map("%" * _)
103-
104-
val strlists = for {
105-
count <- argcs
106-
string <- strings
107-
} yield List.fill(count)(string)
108-
109-
val codes = for {
110-
strlist <- strlists
111-
} yield {
112-
val args = strlist.map(s => s""""$s"""").mkString(", ")
113-
s"console.log($args);\n"
114-
}
101+
val strings = (1 to 15).map("%" * _)
102+
val code = strings.map(str => s"""console.log("$str");\n""").mkString("")
103+
val result = strings.mkString("", "\n", "\n")
115104

116-
val result = strlists.map(_.mkString(" ") + "\n").mkString("")
117-
118-
withRun(codes.mkString("")) {
105+
withRun(code) {
119106
_.expectOut(result)
120107
.closeRun()
121108
}
122109
}
123110

124-
@Test // Node.js console.log hack didn't allow to log non-Strings - #561
125-
def nonStringTest: Unit = {
126-
withRun("""
127-
console.log(1);
128-
console.log(undefined);
129-
console.log(null);
130-
console.log({});
131-
console.log([1,2]);
132-
""") {
133-
_.expectOut("1\n")
134-
.expectOut("undefined\n")
135-
.expectOut("null\n")
136-
.expectOut("[object Object]\n")
137-
.expectOut("1,2\n")
138-
.closeRun()
139-
}
140-
}
141-
142111
@Test
143112
def fastCloseTest: Unit = {
144113
/* This test also tests a failure mode where the ExternalJSRun is still

nodejs-env/src/main/scala/org/scalajs/jsenv/nodejs/NodeJSEnv.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ final class NodeJSEnv(config: NodeJSEnv.Config) extends JSEnv {
6868
}
6969

7070
private def initFiles: List[VirtualBinaryFile] = {
71-
val base = List(NodeJSEnv.runtimeEnv, Support.fixPercentConsole)
71+
val base = List(NodeJSEnv.runtimeEnv)
7272

7373
config.sourceMap match {
7474
case SourceMap.Disable => base

nodejs-env/src/main/scala/org/scalajs/jsenv/nodejs/Support.scala

Lines changed: 0 additions & 47 deletions
This file was deleted.

0 commit comments

Comments
 (0)