Fix passing non-string value to print/println in node.js
See KT-15484
This commit is contained in:
@@ -34,7 +34,7 @@ private abstract class BaseOutput {
|
||||
/** JsName used to make the declaration available outside of module to test it */
|
||||
@JsName("NodeJsOutput")
|
||||
private class NodeJsOutput(val outputStream: dynamic) : BaseOutput() {
|
||||
override fun print(message: Any?) = outputStream.write(message)
|
||||
override fun print(message: Any?) = outputStream.write(String(message))
|
||||
}
|
||||
|
||||
/** JsName used to make the declaration available outside of module to test it */
|
||||
@@ -49,7 +49,7 @@ private class OutputToConsoleLog : BaseOutput() {
|
||||
}
|
||||
|
||||
override fun println() {
|
||||
console.log()
|
||||
console.log("")
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+7
-2
@@ -3,7 +3,7 @@ var buffer = "";
|
||||
function writeToBuffer(a) {
|
||||
var type = typeof a;
|
||||
if (type === "undefined") return;
|
||||
if (type !== "string") throw Error("Expected string argument type, but got: " + type);
|
||||
if (type !== "string" && !(a instanceof String)) throw Error("Expected string argument type, but got: " + type);
|
||||
|
||||
buffer += a;
|
||||
}
|
||||
@@ -16,7 +16,12 @@ function writelnToBuffer(a) {
|
||||
var GLOBAL = (0, eval)("this");
|
||||
|
||||
GLOBAL.console = {
|
||||
log: writelnToBuffer
|
||||
log: function (a) {
|
||||
if (typeof a !== "undefined") {
|
||||
buffer += a
|
||||
}
|
||||
buffer += "\n";
|
||||
}
|
||||
};
|
||||
|
||||
GLOBAL.outputStream = {
|
||||
|
||||
+5
-1
@@ -6,7 +6,7 @@ val EXPECTED = """Hello, World
|
||||
^^
|
||||
^^
|
||||
***
|
||||
####
|
||||
##null23##
|
||||
"""
|
||||
|
||||
val EXPECTED_NEWLINE_FOR_EACH = """Hello
|
||||
@@ -18,6 +18,8 @@ val EXPECTED_NEWLINE_FOR_EACH = """Hello
|
||||
|
||||
***
|
||||
##
|
||||
null
|
||||
23
|
||||
##
|
||||
|
||||
"""
|
||||
@@ -35,6 +37,8 @@ fun test(expected: String, initCode: String, getResult: () -> String) {
|
||||
println()
|
||||
println("***")
|
||||
print("##")
|
||||
print(null)
|
||||
print(23)
|
||||
print("##")
|
||||
println()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user