From 32a1fcf5f865a165e18cd61cb18276b41787fe8c Mon Sep 17 00:00:00 2001 From: Dayoung Lee Date: Tue, 26 Sep 2023 12:49:34 +0900 Subject: [PATCH] [CfgEditor] Check properties existence in loop This commit checks properties' existence in for loop. ONE-vscode-DCO-1.0-Signed-off-by: Dayoung Lee --- media/CfgEditor/displaycfg.js | 7 ++-- media/CfgEditor/index.js | 56 +++++++++++++++++--------------- media/CfgEditor/updateContent.js | 10 +++--- 3 files changed, 40 insertions(+), 33 deletions(-) diff --git a/media/CfgEditor/displaycfg.js b/media/CfgEditor/displaycfg.js index 268e980c1..4f19d4b1e 100644 --- a/media/CfgEditor/displaycfg.js +++ b/media/CfgEditor/displaycfg.js @@ -149,9 +149,10 @@ export function displayCfgToEditor(cfg) { oneOptimize?.["output_path"] ); for (const optName in oneOptimizationList) { - document.getElementById("checkboxOptimize" + optName).checked = cfgBoolean( - oneOptimize?.[optName] - ); + if (Object.prototype.hasOwnProperty.call(oneOptimizationList, optName)) { + document.getElementById("checkboxOptimize" + optName).checked = + cfgBoolean(oneOptimize?.[optName]); + } } const oneQuantize = cfg["one-quantize"]; diff --git a/media/CfgEditor/index.js b/media/CfgEditor/index.js index 553d0bc4d..82bfcf5f7 100644 --- a/media/CfgEditor/index.js +++ b/media/CfgEditor/index.js @@ -347,35 +347,39 @@ function registerOptimizeOptions() { }); for (const optName in oneOptimizationList) { - let row = document.createElement("vscode-data-grid-row"); - - let cellSwitch = document.createElement("vscode-data-grid-cell"); - let checkbox = document.createElement("vscode-checkbox"); - checkbox.setAttribute("id", "checkboxOptimize" + optName); - cellSwitch.appendChild(checkbox); - cellSwitch.setAttribute("grid-column", "1"); - row.appendChild(cellSwitch); - - let cellName = document.createElement("vscode-data-grid-cell"); - cellName.textContent = optName; - cellName.setAttribute("grid-column", "2"); - row.appendChild(cellName); - - let cellDescription = document.createElement("vscode-data-grid-cell"); - cellDescription.textContent = oneOptimizationList[optName].description; - cellDescription.setAttribute("grid-column", "3"); - row.appendChild(cellDescription); - - basicOptimizeTable.appendChild(row); + if (Object.prototype.hasOwnProperty.call(oneOptimizationList, optName)) { + let row = document.createElement("vscode-data-grid-row"); + + let cellSwitch = document.createElement("vscode-data-grid-cell"); + let checkbox = document.createElement("vscode-checkbox"); + checkbox.setAttribute("id", "checkboxOptimize" + optName); + cellSwitch.appendChild(checkbox); + cellSwitch.setAttribute("grid-column", "1"); + row.appendChild(cellSwitch); + + let cellName = document.createElement("vscode-data-grid-cell"); + cellName.textContent = optName; + cellName.setAttribute("grid-column", "2"); + row.appendChild(cellName); + + let cellDescription = document.createElement("vscode-data-grid-cell"); + cellDescription.textContent = oneOptimizationList[optName].description; + cellDescription.setAttribute("grid-column", "3"); + row.appendChild(cellDescription); + + basicOptimizeTable.appendChild(row); + } } for (const optName in oneOptimizationList) { - document - .getElementById("checkboxOptimize" + optName) - .addEventListener("click", function () { - updateOptimize(); - applyUpdates(); - }); + if (Object.prototype.hasOwnProperty.call(oneOptimizationList, optName)) { + document + .getElementById("checkboxOptimize" + optName) + .addEventListener("click", function () { + updateOptimize(); + applyUpdates(); + }); + } } } diff --git a/media/CfgEditor/updateContent.js b/media/CfgEditor/updateContent.js index f1cc7766a..979ed5b19 100644 --- a/media/CfgEditor/updateContent.js +++ b/media/CfgEditor/updateContent.js @@ -286,10 +286,12 @@ export function updateOptimize() { ); for (const optName in oneOptimizationList) { - content += iniKeyValueString( - optName, - document.getElementById("checkboxOptimize" + optName).checked - ); + if (Object.prototype.hasOwnProperty.call(oneOptimizationList, optName)) { + content += iniKeyValueString( + optName, + document.getElementById("checkboxOptimize" + optName).checked + ); + } } postMessageToVsCode({