From 10a5fb3a400ee74b8560dc49d029f4ae574e39bf Mon Sep 17 00:00:00 2001 From: redhoodsu Date: Tue, 8 Oct 2019 14:30:58 +0800 Subject: [PATCH] feat(console): disable js execution --- doc/TOOL_API.md | 1 + src/Console/Console.js | 12 ++++++++++++ 2 files changed, 13 insertions(+) diff --git a/doc/TOOL_API.md b/doc/TOOL_API.md index 259f8e9..dbb6873 100644 --- a/doc/TOOL_API.md +++ b/doc/TOOL_API.md @@ -10,6 +10,7 @@ Display console logs. Implementation detail follows the [console api spec](https |Name |Type |Desc | |-------------------|-------|-------------------------------| +|jsExecution |boolean|Enable JavaScript execution | |catchGlobalErr |boolean|Catch global errors | |overrideConsole |boolean|Override console | |displayExtraInfo |boolean|Display extra information | diff --git a/src/Console/Console.js b/src/Console/Console.js index fe7b2f9..2fe63df 100644 --- a/src/Console/Console.js +++ b/src/Console/Console.js @@ -87,6 +87,11 @@ export default class Console extends Tool { this._unregisterListener() this._rmCfg() } + _enableJsExecution(enabled) { + const $el = this._$el.find('.eruda-js-input') + + enabled ? $el.show() : $el.hide() + } _registerListener() { this._scaleListener = scale => (this._scale = scale) @@ -212,6 +217,7 @@ export default class Console extends Tool { if (!settings) return settings + .remove(cfg, 'jsExecution') .remove(cfg, 'catchGlobalErr') .remove(cfg, 'overrideConsole') .remove(cfg, 'displayExtraInfo') @@ -231,6 +237,7 @@ export default class Console extends Tool { const cfg = (this.config = Settings.createCfg('console', { catchGlobalErr: true, + jsExecution: true, overrideConsole: true, displayExtraInfo: false, displayUnenumerable: true, @@ -247,6 +254,7 @@ export default class Console extends Tool { let maxLogNum = cfg.get('maxLogNum') maxLogNum = maxLogNum === 'infinite' ? maxLogNum : +maxLogNum + this._enableJsExecution(cfg.get('jsExecution')) if (cfg.get('catchGlobalErr')) this.catchGlobalErr() if (cfg.get('overrideConsole')) this.overrideConsole() if (cfg.get('useWorker') && isWorkerSupported) stringify.useWorker = true @@ -259,6 +267,8 @@ export default class Console extends Tool { cfg.on('change', (key, val) => { switch (key) { + case 'jsExecution': + return this._enableJsExecution(val) case 'catchGlobalErr': return val ? this.catchGlobalErr() : this.ignoreGlobalErr() case 'overrideConsole': @@ -282,9 +292,11 @@ export default class Console extends Tool { }) const settings = container.get('settings') + if (!settings) return settings .text('Console') + .switch(cfg, 'jsExecution', 'Enable JavaScript execution') .switch(cfg, 'catchGlobalErr', 'Catch Global Errors') .switch(cfg, 'overrideConsole', 'Override Console') .switch(cfg, 'displayIfErr', 'Auto Display If Error Occurs')