From d58de87c338415457c6ff9f546f707a51ca42493 Mon Sep 17 00:00:00 2001 From: Adrian Kummerlaender Date: Sat, 22 Aug 2015 20:56:21 +0200 Subject: Replaced unnecessary `eval` calls in settings getter and setter --- src/SettingsHandler.qml | 43 ++++++++----------------------------------- src/command/commands.js | 2 +- 2 files changed, 9 insertions(+), 36 deletions(-) (limited to 'src') diff --git a/src/SettingsHandler.qml b/src/SettingsHandler.qml index f281da1..fd13473 100644 --- a/src/SettingsHandler.qml +++ b/src/SettingsHandler.qml @@ -2,46 +2,19 @@ import QtQuick 2.0 import Qt.labs.settings 1.0 QtObject { - function getSetter(category, name) { - try { - var type = typeof eval(category + '.' + name); - - switch ( type ) { - case 'undefined': { - throw new ReferenceError(); - break; - } - case 'string': { - return function(value) { - return eval(category + '.' + name + ' = "' + value + '"'); - } - break; - } - default: { - return function(value) { - return eval(category + '.' + name + ' = ' + value); - } - break; - } - } - } - catch (exception) { + function read(category, name) { + if ( typeof this[category][name] === 'undefined' ) { throw category + '.' + name + ' doesnt exist.'; + } else { + return this[category][name]; } } - function read(category, name) { - try { - var value = eval(category + '.' + name); - - if ( typeof value === 'undefined' ) { - throw new ReferenceError(); - } else { - return value; - } - } - catch (exception) { + function set(category, name, value) { + if ( typeof this[category][name] === 'undefined' ) { throw category + '.' + name + ' doesnt exist.'; + } else { + this[category][name] = value; } } diff --git a/src/command/commands.js b/src/command/commands.js index d2a53af..333eb98 100644 --- a/src/command/commands.js +++ b/src/command/commands.js @@ -79,7 +79,7 @@ function set(output, args) { break; } case 3: { - settings.getSetter(args[0], args[1])(args[2]); + settings.set(args[0], args[1], args[2]); break; } default: { -- cgit v1.2.3