From 1429a32928361d31126629f0764ac3b31da8f0ee Mon Sep 17 00:00:00 2001 From: "Anthony J. Thibault" Date: Wed, 22 Feb 2017 16:28:52 -0800 Subject: [PATCH 1/3] Prevent use after free of ScriptEngine pointer when shutting down all scripts. Before this change, if you were running with the Debug defaultScripts.js option on, it could result in a dereference of a previously freed ScriptEngine pointer. To prevent this, defaultScripts.js no longer explicitly calls ScriptDiscoveryService.stopScript() on Script.scriptEnding. --- scripts/defaultScripts.js | 32 +++++--------------------------- 1 file changed, 5 insertions(+), 27 deletions(-) diff --git a/scripts/defaultScripts.js b/scripts/defaultScripts.js index 40a77eda55..e544f3cd1f 100644 --- a/scripts/defaultScripts.js +++ b/scripts/defaultScripts.js @@ -20,7 +20,7 @@ var DEFAULT_SCRIPTS = [ "system/bubble.js", "system/snapshot.js", "system/help.js", - "system/pal.js", //"system/mod.js", // older UX, if you prefer + "system/pal.js", // "system/mod.js", // older UX, if you prefer "system/goto.js", "system/marketplaces/marketplaces.js", "system/edit.js", @@ -54,9 +54,6 @@ if (previousSetting === true || previousSetting === 'true') { previousSetting = true; } - - - if (Menu.menuExists(MENU_CATEGORY) && !Menu.menuItemExists(MENU_CATEGORY, MENU_ITEM)) { Menu.addMenuItem({ menuName: MENU_CATEGORY, @@ -78,11 +75,11 @@ function runDefaultsSeparately() { Script.load(DEFAULT_SCRIPTS[i]); } } + // start all scripts if (Menu.isOptionChecked(MENU_ITEM)) { // we're debugging individual default scripts // so we load each into its own ScriptEngine instance - debuggingDefaultScripts = true; runDefaultsSeparately(); } else { // include all default scripts into this ScriptEngine @@ -90,32 +87,14 @@ if (Menu.isOptionChecked(MENU_ITEM)) { } function menuItemEvent(menuItem) { - if (menuItem == MENU_ITEM) { - - isChecked = Menu.isOptionChecked(MENU_ITEM); + if (menuItem === MENU_ITEM) { + var isChecked = Menu.isOptionChecked(MENU_ITEM); if (isChecked === true) { Settings.setValue(SETTINGS_KEY, true); } else if (isChecked === false) { Settings.setValue(SETTINGS_KEY, false); } - Window.alert('You must reload all scripts for this to take effect.') - } - - -} - - - -function stopLoadedScripts() { - // remove debug script loads - var runningScripts = ScriptDiscoveryService.getRunning(); - for (var i in runningScripts) { - var scriptName = runningScripts[i].name; - for (var j in DEFAULT_SCRIPTS) { - if (DEFAULT_SCRIPTS[j].slice(-scriptName.length) === scriptName) { - ScriptDiscoveryService.stopScript(runningScripts[i].url); - } - } + Window.alert('You must reload all scripts for this to take effect.'); } } @@ -126,7 +105,6 @@ function removeMenuItem() { } Script.scriptEnding.connect(function() { - stopLoadedScripts(); removeMenuItem(); }); From 83b3c12559b180cd697ce8dbe5f2d14df8dc8792 Mon Sep 17 00:00:00 2001 From: "Anthony J. Thibault" Date: Wed, 22 Feb 2017 17:01:31 -0800 Subject: [PATCH 2/3] Removed Window.alert() because it was blocking the defaultScripts thread. --- scripts/defaultScripts.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/defaultScripts.js b/scripts/defaultScripts.js index e544f3cd1f..f2791f0275 100644 --- a/scripts/defaultScripts.js +++ b/scripts/defaultScripts.js @@ -94,7 +94,7 @@ function menuItemEvent(menuItem) { } else if (isChecked === false) { Settings.setValue(SETTINGS_KEY, false); } - Window.alert('You must reload all scripts for this to take effect.'); + console.log('You must reload all scripts for this to take effect.'); } } From 84b29c6872b4a1c08d7d2ac4874715185fe519d4 Mon Sep 17 00:00:00 2001 From: "Anthony J. Thibault" Date: Thu, 23 Feb 2017 11:02:25 -0800 Subject: [PATCH 3/3] Reload all scripts when Debug defaultScripts.js is changed. --- scripts/defaultScripts.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/defaultScripts.js b/scripts/defaultScripts.js index f2791f0275..5d8813e988 100644 --- a/scripts/defaultScripts.js +++ b/scripts/defaultScripts.js @@ -94,7 +94,7 @@ function menuItemEvent(menuItem) { } else if (isChecked === false) { Settings.setValue(SETTINGS_KEY, false); } - console.log('You must reload all scripts for this to take effect.'); + Menu.triggerOption("Reload All Scripts"); } }