Closed seanshpark closed 9 years ago
@seanshpark I agree that functions like print
should be removed from the core and implemented separately using Emd. API, but what is the reason to disable assert?
Anyway, it can be implemented like that (http://stackoverflow.com/a/15313435/230855):
function assert(condition, message) {
if (!condition) {
message = message || "Assertion failed";
if (typeof Error !== "undefined") {
throw new Error(message);
}
throw message; // Fallback
}
}
BTW, I'd like to improve with smth like the following (http://wiki.ecmascript.org/doku.php?id=strawman:assert):
assert(x === 12); // throws an AssertionError if false, with a default error message
assert(x === 12, "I think it should be twelve") // throws an AssertionError if false, with the given error message
@egavrin , but what is the reason to disable assert?
is that test codes will have it's implementation of assert() as you mentioned. I was planning to prepare this in iotjs.
Looks like Jerry engine snatches assert()
expression for example, following program runs unexpectedly.
function assert(value) {
print(value);
}
assert(0);
IMHO: That is because the call to assert
is treated as a special intrinsic call, thus the defined assert function will not be called.
Fixed.
Thank you!
'assert' function itself is not included in ECMA spec but is included in JerryScript, opcodes-dumper.cpp programs embedding JerryScript will implement 'assert', including IoT.js. need some compile time option to disable internal 'assert' and maybe others like 'print'