Skip to content
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

console.assert should not throw error #1335

Merged
merged 6 commits into from
Dec 14, 2018
Merged

console.assert should not throw error #1335

merged 6 commits into from
Dec 14, 2018

Conversation

justjavac
Copy link
Contributor

In the previous implementation #102, console.assert throws an error. I think console.assert should not throw an error.

Before Node.js v10.0.0, however, a falsy assertion would also cause an AssertionError to be thrown. This discrepancy was fixed with Node v10, so that console.assert() now acts the same in both Node and the browser.

https://developer.mozilla.org/en-US/docs/Web/API/console/assert


And in https://console.spec.whatwg.org/#assert, console.assert is defined as follows:

assert(condition, ...data)

  1. If condition is true, return.
  2. Let message be a string without any formatting specifiers indicating generically an assertion failure (such as "Assertion failed").
  3. If data is empty, append message to data.
  4. Otherwise:
    1. Let first be data[0].
    2. If Type(first) is not String, then prepend message to data.
    3. Otherwise:
      1. Let concat be the concatenation of message, U+003A (:), U+0020 SPACE, and first.
      2. Set data[0] to concat.
  5. Perform Logger("assert", data).

Copy link
Member

@ry ry left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool - I didn't know that. Looks good.

Can you please remove the additional integration tests you added? Those are relatively expensive to run and I don't think it's warranted for this. The unit test you added is sufficient.

@justjavac
Copy link
Contributor Author

I have deleted the integration tests.


Shouldn't console.assert output be tested?

console.assert()

before:

Error: Assertion failed: // with U+003A (:) and U+0020(SPACE) at the end

after:

Assertion failed

@justjavac
Copy link
Contributor Author

I found a typo error in tests, I seny another pr #1342

Copy link
Member

@ry ry left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM - thanks

@ry ry merged commit 769994b into denoland:master Dec 14, 2018
ry added a commit to ry/deno that referenced this pull request Dec 14, 2018
- console.assert should not throw error (denoland#1335)
- Support more modes in deno.open (denoland#1282, denoland#1336)
- Simplify code fetch logic (denoland#1322)
- readDir entry mode (denoland#1326)
- Use stderr for exceptions (denoland#1303)
- console.log formatting improvements (denoland#1327, denoland#1299)
- Expose TooLarge error code for buffers (denoland#1298)
@ry ry mentioned this pull request Dec 14, 2018
ry added a commit that referenced this pull request Dec 14, 2018
- console.assert should not throw error (#1335)
- Support more modes in deno.open (#1282, #1336)
- Simplify code fetch logic (#1322)
- readDir entry mode (#1326)
- Use stderr for exceptions (#1303)
- console.log formatting improvements (#1327, #1299)
- Expose TooLarge error code for buffers (#1298)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants