jerryscript icon indicating copy to clipboard operation
jerryscript copied to clipboard

disable assert implementation

Open seanshpark opened this issue 11 years ago • 6 comments

'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'

seanshpark avatar May 08 '15 08:05 seanshpark

@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 avatar Jun 05 '15 21:06 egavrin

@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.

seanshpark avatar Jun 08 '15 06:06 seanshpark

Looks like Jerry engine snatches assert() expression for example, following program runs unexpectedly.

function assert(value) {
  print(value);
}
assert(0);

ILyoan avatar Jun 10 '15 07:06 ILyoan

IMHO: That is because the call to assert is treated as a special intrinsic call, thus the defined assert function will not be called.

galpeter avatar Jun 10 '15 08:06 galpeter

Fixed.

egavrin avatar Jun 30 '15 13:06 egavrin

Thank you!

seanshpark avatar Jul 01 '15 02:07 seanshpark