Skip to content

Commit

Permalink
try catch errors when eval commands, fix issue Tencent#86
Browse files Browse the repository at this point in the history
  • Loading branch information
Maizify committed Dec 27, 2016
1 parent 169e2b0 commit 2266b8a
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 22 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
English | [简体中文](./CHANGELOG_CN.md)

#### V2.5.2 (2016-12-??)

- [FIX] Catch errors when eval custom commands in Log tab.


#### V2.5.1 (2016-10-18)

- [FIX] Fix `scrollHeight` error in some cases.
Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG_CN.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
[English](./CHANGELOG.md) | 简体中文

#### V2.5.2 (2016-12-??)

- 【修复】捕获执行自定义命令行时发生的错误。

#### V2.5.1 (2016-10-18)

- 【修复】修复一些情况下的 `scrollHeight` 错误。
Expand Down
2 changes: 1 addition & 1 deletion dist/vconsole.min.js

Large diffs are not rendered by default.

51 changes: 30 additions & 21 deletions src/log/default.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,29 +71,38 @@ class VConsoleDefaultTab extends VConsoleLogTab {
style: ''
});
// eval
let result = eval(cmd);
// print result to console
let $content;
if (tool.isArray(result) || tool.isObject(result)) {
$content = this.getFoldedLine(result);
} else {
if (tool.isNull(result)) {
result = 'null';
} else if (tool.isUndefined(result)) {
result = 'undefined';
} else if (tool.isFunction(result)) {
result = 'function()'
} else if (tool.isString(result)) {
result = '"' + result + '"';
try {
let result = eval(cmd);
// print result to console
let $content;
if (tool.isArray(result) || tool.isObject(result)) {
$content = this.getFoldedLine(result);
} else {
if (tool.isNull(result)) {
result = 'null';
} else if (tool.isUndefined(result)) {
result = 'undefined';
} else if (tool.isFunction(result)) {
result = 'function()'
} else if (tool.isString(result)) {
result = '"' + result + '"';
}
$content = $.render(tplItemCode, {content: result, type: 'output'});
}
$content = $.render(tplItemCode, {content: result, type: 'output'});
this.printLog({
logType: 'log',
content: $content,
noMeta: true,
style: ''
});
} catch (e) {
this.printLog({
logType: 'error',
logs: [e.message],
noMeta: true,
style: ''
});
}
this.printLog({
logType: 'log',
content: $content,
noMeta: true,
style: ''
});
}

} // END class
Expand Down

0 comments on commit 2266b8a

Please sign in to comment.