Skip to content

Commit b4f7cb8

Browse files
committed
Replace all direct member call to hasOwnProperty with Object.prototype.hasOwnProperty
Fix #90
1 parent f95a1ed commit b4f7cb8

9 files changed

+38
-29
lines changed

src/kcm/ui/ConfigGroup.qml

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ Kirigami.FormLayout {
4343
var loader = repeater.itemAt(i);
4444
if (loader.status == Loader.Ready) {
4545
loader.item.save();
46-
if (loader.item.hasOwnProperty("rawValue")) {
46+
if (Utils.hasProperty(loader.item, "rawValue")) {
4747
Utils.setRawValue(rawValue, loader.option.name, loader.item.rawValue);
4848
}
4949
}

src/kcm/ui/EnumOption.qml

+7-6
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import QtQuick
88
import QtQuick.Controls
99
import org.kde.kirigami as Kirigami
10+
import "utils.js" as Utils
1011

1112
Row {
1213
property string typeName
@@ -35,25 +36,25 @@ Row {
3536
Component.onCompleted: {
3637
var i = 0;
3738
while (true) {
38-
if (!properties.hasOwnProperty("Enum")) {
39+
if (!Utils.hasProperty(properties, "Enum")) {
3940
break;
4041
}
41-
if (!properties["Enum"].hasOwnProperty(i.toString())) {
42+
if (!Utils.hasProperty(properties["Enum"], i.toString())) {
4243
break;
4344
}
4445
var value = properties["Enum"][i.toString()];
4546
var text = "";
46-
if (properties.hasOwnProperty("EnumI18n")) {
47-
if (properties["EnumI18n"].hasOwnProperty(i.toString())) {
47+
if (Utils.hasProperty(properties, "EnumI18n")) {
48+
if (Utils.hasProperty(properties["EnumI18n"], i.toString())) {
4849
text = properties["EnumI18n"][i.toString()];
4950
}
5051
}
5152
if (text == "") {
5253
text = value;
5354
}
5455
var subconfigpath = "";
55-
if (properties.hasOwnProperty("SubConfigPath")) {
56-
if (properties["SubConfigPath"].hasOwnProperty(i.toString())) {
56+
if (Utils.hasProperty(properties, "SubConfigPath")) {
57+
if (Utils.hasProperty(properties["SubConfigPath"], i.toString())) {
5758
subconfigpath = properties["SubConfigPath"][i.toString()];
5859
}
5960
}

src/kcm/ui/ExternalOption.qml

+2-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
*/
77
import QtQuick
88
import QtQuick.Controls
9+
import "utils.js" as Utils
910

1011
Button {
1112
property string typeName
@@ -26,7 +27,7 @@ Button {
2627
}
2728

2829
Component.onCompleted: {
29-
if (properties.hasOwnProperty("LaunchSubConfig") && properties["LaunchSubConfig"] == "True") {
30+
if (Utils.hasProperty(properties, "LaunchSubConfig") && properties["LaunchSubConfig"] == "True") {
3031
subConfig = true;
3132
}
3233
}

src/kcm/ui/IntegerOption.qml

+3-2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
*/
77
import QtQuick
88
import QtQuick.Controls
9+
import "utils.js" as Utils
910

1011
SpinBox {
1112
property string typeName
@@ -27,10 +28,10 @@ SpinBox {
2728
}
2829

2930
Component.onCompleted: {
30-
if (properties.hasOwnProperty("IntMin")) {
31+
if (Utils.hasProperty(properties, "IntMin")) {
3132
validator.bottom = parseInt(properties.IntMin);
3233
}
33-
if (properties.hasOwnProperty("IntMax")) {
34+
if (Utils.hasProperty(properties, "IntMax")) {
3435
validator.top = parseInt(properties.IntMax);
3536
}
3637
load(rawValue);

src/kcm/ui/KeyListOption.qml

+5-4
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import QtQuick
88
import QtQuick.Layouts
99
import QtQuick.Controls
1010
import org.kde.kirigami as Kirigami
11+
import "utils.js" as Utils
1112

1213
RowLayout {
1314
id: keyList
@@ -26,19 +27,19 @@ RowLayout {
2627
}
2728
var i = 0;
2829
while (true) {
29-
if (!rawValue.hasOwnProperty(i.toString())) {
30+
if (!Utils.hasProperty(rawValue, i.toString())) {
3031
break;
3132
}
3233
var value = rawValue[i.toString()];
3334
listModel.append({
3435
"key": value
3536
});
36-
if (!keyList.rawValue.hasOwnProperty(i.toString()) || rawValue[i.toString()] !== keyList.rawValue[i.toString()]) {
37+
if (!Utils.hasProperty(keyList.rawValue, i.toString()) || rawValue[i.toString()] !== keyList.rawValue[i.toString()]) {
3738
diff = true;
3839
}
3940
i++;
4041
}
41-
if (keyList.rawValue.hasOwnProperty(i.toString())) {
42+
if (Utils.hasProperty(keyList.rawValue, i.toString())) {
4243
diff = true;
4344
}
4445
needsSave = diff;
@@ -70,7 +71,7 @@ RowLayout {
7071
KeyOption {
7172
Layout.fillWidth: true
7273
Layout.minimumWidth: Kirigami.Units.gridUnit * 9
73-
properties: keyList.properties.hasOwnProperty("ListConstrain") ? keyList.properties.ListConstrain : {}
74+
properties: Utils.hasProperty(keyList.properties, "ListConstrain") ? keyList.properties.ListConstrain : {}
7475
rawValue: model.key
7576

7677
onKeyStringChanged: {

src/kcm/ui/KeyOption.qml

+2-2
Original file line numberDiff line numberDiff line change
@@ -61,10 +61,10 @@ Button {
6161
}
6262

6363
Component.onCompleted: {
64-
if (properties.hasOwnProperty("AllowModifierLess")) {
64+
if (Utils.hasProperty(properties, "AllowModifierLess")) {
6565
allowModifierLess = properties.AllowModifierLess == "True";
6666
}
67-
if (properties.hasOwnProperty("AllowModifierOnly")) {
67+
if (Utils.hasProperty(properties, "AllowModifierOnly")) {
6868
allowModifierOnly = properties.AllowModifierOnly == "True";
6969
}
7070
load(rawValue);

src/kcm/ui/ListOption.qml

+7-6
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import QtQuick
88
import QtQuick.Layouts
99
import QtQuick.Controls
1010
import org.kde.kirigami as Kirigami
11+
import "utils.js" as Utils
1112

1213
ColumnLayout {
1314
id: listOption
@@ -36,7 +37,7 @@ ColumnLayout {
3637
}
3738
var i = 0;
3839
while (true) {
39-
if (!rawValue.hasOwnProperty(i.toString())) {
40+
if (!Utils.hasProperty(rawValue, i.toString())) {
4041
break;
4142
}
4243
var value = rawValue[i.toString()];
@@ -59,12 +60,12 @@ ColumnLayout {
5960
var i = 0;
6061
var enumMap = {};
6162
while (true) {
62-
if (!properties.Enum.hasOwnProperty(i.toString())) {
63+
if (!Utils.hasProperty(properties.Enum, i.toString())) {
6364
break;
6465
}
6566
var enumString = properties.Enum[i.toString()];
6667
var text = enumString;
67-
if (properties.hasOwnProperty("EnumI18n") && properties.EnumI18n.hasOwnProperty(i.toString())) {
68+
if (Utils.hasProperty(properties, "EnumI18n") && Utils.hasProperty(properties.EnumI18n, i.toString())) {
6869
text = properties.EnumI18n[i.toString()];
6970
}
7071
enumMap[enumString] = text;
@@ -76,15 +77,15 @@ ColumnLayout {
7677
subSubType = subType.substr(5);
7778
var strs = [];
7879
while (true) {
79-
if (!value.hasOwnProperty(i.toString())) {
80+
if (!Utils.hasProperty(value, i.toString())) {
8081
break;
8182
}
8283
var subValue = prettify(value[i.toString()]);
8384
strs.push(subValue);
8485
i++;
8586
}
8687
return i18n("[%1]", strs.join(" "));
87-
} else if (configPage.typeMap.hasOwnProperty(subType)) {
88+
} else if (Utils.hasProperty(configPage.typeMap, subType)) {
8889
for (var i = 0; i < configPage.typeMap[subTypeName].length; ++i) {
8990
var option = configPage.typeMap[subTypeName][i];
9091
if (option.name.length === 1 && option.name[0] === properties.ListDisplayOption) {
@@ -198,7 +199,7 @@ ColumnLayout {
198199
Kirigami.OverlaySheet {
199200
id: sheet
200201
property int editIndex: -1
201-
readonly property bool isSubConfig: configPage.typeMap.hasOwnProperty(subTypeName)
202+
readonly property bool isSubConfig: Utils.hasProperty(configPage.typeMap, subTypeName)
202203

203204
parent: configPage
204205

src/kcm/ui/OptionLoader.qml

+5-5
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@ Loader {
1616
property variant rawValue
1717

1818
ToolTip.delay: Kirigami.Units.toolTipDelay
19-
ToolTip.text: option.properties && option.properties.hasOwnProperty("Tooltip") ? option.properties["Tooltip"] : ""
19+
ToolTip.text: option.properties && Utils.hasProperty(option.properties, "Tooltip") ? option.properties["Tooltip"] : ""
2020
ToolTip.visible: {
21-
if (option.properties && option.properties.hasOwnProperty("Tooltip") && loader.item) {
22-
if (loader.item.hasOwnProperty("hovered")) {
21+
if (option.properties && Utils.hasProperty(option.properties, "Tooltip") && loader.item) {
22+
if (Utils.hasProperty(loader.item, "hovered")) {
2323
return loader.item.hovered;
2424
}
2525
}
@@ -34,9 +34,9 @@ Loader {
3434
} else if (data.type == "Enum") {
3535
return "EnumOption.qml";
3636
} else if (data.type == "String") {
37-
if (data.properties.hasOwnProperty("Font") && data.properties.Font == "True") {
37+
if (Utils.hasProperty(data.properties, "Font") && data.properties.Font == "True") {
3838
return "FontOption.qml";
39-
} else if (data.properties.hasOwnProperty("IsEnum") && data.properties.IsEnum == "True") {
39+
} else if (Utils.hasProperty(data.properties, "IsEnum") && data.properties.IsEnum == "True") {
4040
return "EnumOption.qml";
4141
} else {
4242
return "StringOption.qml";

src/kcm/ui/utils.js

+6-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
function hasProperty(obj, key) {
2+
return Object.prototype.hasOwnProperty.call(obj, key);
3+
}
4+
15
function getRawValue(rawValue, name) {
26
if (name.length == 0) {
37
return "";
@@ -6,7 +10,7 @@ function getRawValue(rawValue, name) {
610
return "";
711
}
812
for (var i = 0; i < name.length; i++) {
9-
if (rawValue.hasOwnProperty(name[i])) {
13+
if (hasProperty(rawValue, name[i])) {
1014
rawValue = rawValue[name[i]];
1115
} else {
1216
return "";
@@ -20,7 +24,7 @@ function setRawValue(rawValue, name, value) {
2024
if (i + 1 == name.length) {
2125
rawValue[name[i]] = value;
2226
} else {
23-
if (!rawValue.hasOwnProperty(name[i])) {
27+
if (!hasProperty(rawValue, name[i])) {
2428
rawValue[name[i]] = {};
2529
}
2630
rawValue = rawValue[name[i]];

0 commit comments

Comments
 (0)