Skip to content
This repository has been archived by the owner on Dec 28, 2021. It is now read-only.

Commit

Permalink
Do not crash the IDE when logging non-string objects. (#1313)
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelMauderer authored Mar 12, 2021
1 parent c33a470 commit ff5e927
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 9 deletions.
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,12 @@
preprocessor. This allows providing visualization with standard library
functionalities or defining utilities that are shared between multiple
visualizations.
- [Fix issue with multiple instances of the IDE running.][1314]. This fixes an
- [Fix issue with multiple instances of the IDE running.][1314] This fixes an
issue where multiple instances of the IDE (or even other applications) could
lead to the IDE not working.
- [Allow JS to log arbitrary objects.][1313] Previously using `console.log` in a
visualisation or during development woudl crash the IDE. Now it correctly logs
the string representation of the object.
- [Fix mouse cursor offset on systems with fractional display scaling][1064].
Instead of there being an offset between visible cursor and cursor selection
this works now with any display scaling.
Expand All @@ -47,6 +50,7 @@ you can find their release notes
[1209]: https://github.com/enso-org/ide/pull/1209
[1291]: https://github.com/enso-org/ide/pull/1291
[1314]: https://github.com/enso-org/ide/pull/1314
[1313]: https://github.com/enso-org/ide/pull/1313
[1064]: https://github.com/enso-org/ide/pull/1064
[1316]: https://github.com/enso-org/ide/pull/1316
[1318]: https://github.com/enso-org/ide/pull/1318
Expand Down
21 changes: 13 additions & 8 deletions src/js/lib/content/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -250,14 +250,19 @@ class LogRouter {
this.handleError(...args)
} else if (name == 'log') {
let firstArg = args[0]
if (firstArg !== undefined && firstArg.startsWith("%c")) {
let firstArgBody = firstArg.slice(2);
let bodyStartIndex = firstArgBody.indexOf("%c");
if (bodyStartIndex !== -1) {
let body = firstArgBody.slice(bodyStartIndex + 3);
let is_error = body.startsWith("[E]");
if (is_error) {
this.handleError(body)
if (firstArg !== undefined) {
if (!(typeof firstArg === 'string' || firstArg instanceof String)) {
firstArg = firstArg.toString()
}
if (firstArg.startsWith('%c')) {
let firstArgBody = firstArg.slice(2)
let bodyStartIndex = firstArgBody.indexOf('%c')
if (bodyStartIndex !== -1) {
let body = firstArgBody.slice(bodyStartIndex + 3)
let is_error = body.startsWith('[E]')
if (is_error) {
this.handleError(body)
}
}
}
}
Expand Down

0 comments on commit ff5e927

Please sign in to comment.