We talked about debugging information and an assertion form on es4-discuss a while ago, in a thread about the Error object. As a result of that discussion, I'm sending out a draft for an "assert" expression form. In addition, the Error object draft will be updated to accomodate a new subclass AssertionExpression, and a simple standard for debugging information will be added to the description of the Error classes.
The last detail from that discussion, about providing a way for programs to set the source origin and line numbers -- aiding translators -- is still open, but I am aware of how desirable this is for certain applications. Anyhow, here's the first draft spec for the assert expression. --larsTitle: assert expression
assert _expression_
NAME: "'assert' _expression_" FILE: spec/language/assert.html CATEGORY: Expressions (E262-3 chapter 11) SOURCES: REFERENCE [1] SPEC AUTHOR: Lars DRAFT STATUS: DRAFT 1 - 2008-04-11 REVIEWED AGAINST ES3: N/A REVIEWED AGAINST ERRATA: N/A REVIEWED AGAINST BASE DOC: N/A REVIEWED AGAINST PROPOSALS: N/A REVIEWED AGAINST CODE: NO REVIEWED AGAINST TICKETS: NO IMPLEMENTATION STATUS: ? TEST CASE STATUS: ? REFERENCES [1] Thread on [email protected] on the 'Error' object [2] The 'Error' object specification
Synopsis
A new _expression_ form assert is introduced. Assert
expressions simplify invariant checking in programs and allow programs
to request reification of debugging information.
Syntax
There are two forms of the assert _expression_.
"assert" "(" AssignmentExpression ")"
"assert" "(" AssignmentExpression "," AssignmentExpression ")"
The assert _expression_ is a new PrimaryExpression. The
identifier assert is contextually reserved.
NOTE The parentheses in the _expression_ are not optional, easing the
porting of many programs that already use a single-argument assert
function to provide similar (but simpler) functionality.
Semantics
The _expression_ assert(E) evaluates E to v and converts
v to a boolean b. If b is true then the result of the
assert _expression_ is v. Otherwise, an AssertionError is
thrown.
NOTE The class AssertionError is a new subclass of Error.
See [2].
The _expression_ assert(E1,E2) evaluates E1 to v1 and
converts v1 to a boolean b. If b is true then the
result of the assert _expression_ is v1. Otherwise, E2 is
evaluated to yield a new value v2, which is thrown.
Debugging information extraction
When an assertion _expression_ throws an exception value v and
v is an instance of a subclass of the pre-defined class Error,
then the run-time system should record information about the source
location of the assertion failure in the appropriate fields of v.
See [2].
NOTE The intent is that the context and backTrace fields of
the error object are given values that reflect the name or origin of
the program source and the line number within that source where the
assertion _expression_ occured. However, ES4 may not require that the
implementation support the recording of that information.
_______________________________________________ Es4-discuss mailing list [email protected] https://mail.mozilla.org/listinfo/es4-discuss
