Fix passing non-string value to print/println in node.js

See KT-15484
This commit is contained in:
Alexey Andreev
2017-03-21 18:45:49 +03:00
parent dbfa3fce2a
commit 7077de02e7
3 changed files with 14 additions and 5 deletions
+7 -2
View File
@@ -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
View File
@@ -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()