aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdrian Kummerlaender2015-08-22 20:56:21 +0200
committerAdrian Kummerlaender2015-08-22 20:56:21 +0200
commitd58de87c338415457c6ff9f546f707a51ca42493 (patch)
treef025e00f7114563d6657cd98a71685f95283e4fe
parenta1e95832074ef46e3f97a8086d8a3a821fa92521 (diff)
downloadMetaTerm-d58de87c338415457c6ff9f546f707a51ca42493.tar
MetaTerm-d58de87c338415457c6ff9f546f707a51ca42493.tar.gz
MetaTerm-d58de87c338415457c6ff9f546f707a51ca42493.tar.bz2
MetaTerm-d58de87c338415457c6ff9f546f707a51ca42493.tar.lz
MetaTerm-d58de87c338415457c6ff9f546f707a51ca42493.tar.xz
MetaTerm-d58de87c338415457c6ff9f546f707a51ca42493.tar.zst
MetaTerm-d58de87c338415457c6ff9f546f707a51ca42493.zip
Replaced unnecessary `eval` calls in settings getter and setter
-rw-r--r--src/SettingsHandler.qml43
-rw-r--r--src/command/commands.js2
2 files changed, 9 insertions, 36 deletions
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: {