From 52bd09d2f07fff46afe7aea3a4a269f5493393a2 Mon Sep 17 00:00:00 2001 From: Jo-Philipp Wich Date: Mon, 30 Sep 2013 12:28:02 +0000 Subject: [PATCH] luci2: Switch LuCI2.ui.renderView() from new Function() to eval() and use "//@ sourceUrl" annotation to make demand-loaded views debuggable --- luci2/htdocs/luci2/luci2.js | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/luci2/htdocs/luci2/luci2.js b/luci2/htdocs/luci2/luci2.js index e401c7c..0d253ce 100644 --- a/luci2/htdocs/luci2/luci2.js +++ b/luci2/htdocs/luci2/luci2.js @@ -1979,13 +1979,22 @@ function LuCI2() if (_luci2._views[name] instanceof _luci2.ui.view) return _luci2._views[name].render(); - return $.ajax(_luci2.globals.resource + '/view/' + name + '.js', { + var url = _luci2.globals.resource + '/view/' + name + '.js'; + + return $.ajax(url, { method: 'GET', cache: true, dataType: 'text' }).then(function(data) { try { - var viewConstructor = (new Function(['L', '$'], 'return ' + data))(_luci2, $); + var viewConstructorSource = ( + '(function(L, $) {\n' + + 'return %s' + + '})(_luci2, $);\n\n' + + '//@ sourceURL=%s' + ).format(data, url); + + var viewConstructor = eval(viewConstructorSource); _luci2._views[name] = new viewConstructor({ name: name, @@ -1994,7 +2003,9 @@ function LuCI2() return _luci2._views[name].render(); } - catch(e) { }; + catch(e) { + alert('Unable to instantiate view "%s": %s'.format(url, e)); + }; return $.Deferred().resolve(); }); -- 2.11.0