-
Notifications
You must be signed in to change notification settings - Fork 683
Make the assert an external method #170
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Related issue: #28 |
@galpeter, would the following constructions work correctly with the patch?
|
@@ -212,4 +212,6 @@ ECMA_MAGIC_STRING_DEF (ECMA_MAGIC_STRING__EMPTY, "") | |||
/* | |||
* Implementation-defined magic strings | |||
*/ | |||
ECMA_MAGIC_STRING_DEF (ECMA_MAGIC_STRING_ASSERT, "assert") | |||
ECMA_MAGIC_STRING_DEF (ECMA_MAGIC_STRING_ASSERT_FAILED, "Assertion failed") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The following convention is used for magic string identifiers:
- value of magic string ECMA_MAGIC_STRING_[identifier][^_CHAR|_U|_UL} is lower-cased "identifier";
- value of magic string ECMA_MAGIC_STRING_[identifier]_U is upper-cased "identifier";
- value of magic string ECMA_MAGIC_STRING_[identifier]_UL is "identifier" with mixed upper-case and lower-case characters;
- value of magic string ECMA_MAGIC_STRING_[identifier]_CHAR is a character;
- value of magic string ECMA_MAGIC_STRING__[identifier] is a string described by identifier, but could not be described using other cases.
Seems that we should use either __
case here, or introduce some new descriptor suffix like P
for magic strings with phrases.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay. Didn't know about these conventions. Maybe we should add it to the start of the file?
Anyways In think this case we should go with the __
version.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it is good idea to add comment with the conventions description to the file.
@ruben-ayrapetyan, I think yes as the error thrown by the assert is a common Error and not a TypeError. What I did basically is something like @egavrin described in the #28 issue (2nd comment). Consider the following code: try {
throw new TypeError("MyError");
assert(false, "message");
} catch (e) {
print(e.toString());
assert (e instanceof TypeError);
} will print out the |
@galpeter, I agree, in the case Otherwise, if
Is the behaviour expected? |
@ruben-ayrapetyan, I my eyes yes. One thing is true, it would change the behavior of the assert a bit. Consider the following code: try {
assert(false);
} catch (e) {
print(e.toString());
assert (e instanceof TypeError);
}
print("error"); With the patch the output will be
with an exit code of Without the patch the assert exits directly (thus nothing is displayed) and the exit code will be A few assert implementations of the assert just throw an Error, for example:
but there are other implementations which simply outputs a text to the console and continues the execution. |
@galpeter, thank you for explanation of your view point. |
9017696
to
c8796ec
Compare
@galpeter, we've discussed the behaviour a bit. Please, consider the following hypothetical js code:
In this hypothetic example, if the assertion So, it seems that throwing ECMA-defined error type in case of implementation-defined 'assertion failure' behaviour can lead to misunderstanding.
Neither of the implementations (at least of versions that I've checked) throw instance of First of them assert throws From other view point, we should consider use cases of our
What do you think about this? |
@ruben-ayrapetyan, certainly there are drawbacks if the assert throws an Error.
That works also I think. Upon reading over your message one other solution occurred to me: |
I think, the idea is great! Seems that currently it is better to use |
Splendid. |
308fc59
to
b76bd72
Compare
@ruben-ayrapetyan, I've updated the PR to provide the |
@@ -253,6 +301,9 @@ main (int argc, | |||
} | |||
} | |||
|
|||
jerry_api_release_value (&assert_value); | |||
jerry_api_release_object (global_obj_p); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These release
calls could be moved to line 284.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay, will do.
I've update the PR, now it prints out the |
{ | ||
JERRY_ERROR_MSG ("Script assertion failed\n"); | ||
exit (JERRY_STANDALONE_EXIT_CODE_FAIL); | ||
return false; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems that return false
would never be executed. So, we don't need the line, and also @return
section need to be changed to just true
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ahh.. yeah :) I've updated the PR with the requested changes.
/** | ||
* Provide the 'assert' implementation for the engine. | ||
* | ||
* @return true - if the argument was not a boolean value or it was false. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if the argument is not boolean false
, isn't it?
Currently the comment means "true, if assert (false)
is called".
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ahhh, yeah I wanted to write or it was boolean true
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
comment updated
Removed the internal assert implementation from the engine and provide externally an assert function via api calls. JerryScript-DCO-1.0-Signed-off-by: Peter Gal pgal.u-szeged@partner.samsung.com
Looks good to me. |
|
{ | ||
return true; | ||
} | ||
} | ||
return false; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't we remove these two functions at all? They seems unnecessary.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe that would be better in a different PR where all intrinsic like things are removed.
LGTM |
Rebased & merged: 77b01a6 |
Remove the assert intrinsic from the parser and instead
make it an external method. This allows us to redefine
the method if needed during runtime from JS.
JerryScript-DCO-1.0-Signed-off-by: Peter Gal pgal.u-szeged@partner.samsung.com