overte-Armored-Dragon/scripts/defaultScripts.js
Anthony J. Thibault 1429a32928 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.
2017-02-23 10:28:15 -08:00

111 lines
3 KiB
JavaScript

"use strict";
/* jslint vars: true, plusplus: true */
//
// defaultScripts.js
// examples
//
// Copyright 2014 High Fidelity, Inc.
//
// Distributed under the Apache License, Version 2.0.
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
//
var DEFAULT_SCRIPTS = [
"system/progress.js",
"system/away.js",
"system/audio.js",
"system/hmd.js",
"system/menu.js",
"system/bubble.js",
"system/snapshot.js",
"system/help.js",
"system/pal.js", // "system/mod.js", // older UX, if you prefer
"system/goto.js",
"system/marketplaces/marketplaces.js",
"system/edit.js",
"system/tablet-users.js",
"system/selectAudioDevice.js",
"system/notifications.js",
"system/controllers/controllerDisplayManager.js",
"system/controllers/handControllerGrab.js",
"system/controllers/handControllerPointer.js",
"system/controllers/squeezeHands.js",
"system/controllers/grab.js",
"system/controllers/teleport.js",
"system/controllers/toggleAdvancedMovementForHandControllers.js",
"system/dialTone.js",
"system/firstPersonHMD.js",
"system/tablet-ui/tabletUI.js"
];
// add a menu item for debugging
var MENU_CATEGORY = "Developer";
var MENU_ITEM = "Debug defaultScripts.js";
var SETTINGS_KEY = '_debugDefaultScriptsIsChecked';
var previousSetting = Settings.getValue(SETTINGS_KEY);
if (previousSetting === '' || previousSetting === false || previousSetting === 'false') {
previousSetting = false;
}
if (previousSetting === true || previousSetting === 'true') {
previousSetting = true;
}
if (Menu.menuExists(MENU_CATEGORY) && !Menu.menuItemExists(MENU_CATEGORY, MENU_ITEM)) {
Menu.addMenuItem({
menuName: MENU_CATEGORY,
menuItemName: MENU_ITEM,
isCheckable: true,
isChecked: previousSetting,
grouping: "Advanced"
});
}
function runDefaultsTogether() {
for (var j in DEFAULT_SCRIPTS) {
Script.include(DEFAULT_SCRIPTS[j]);
}
}
function runDefaultsSeparately() {
for (var i in DEFAULT_SCRIPTS) {
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
runDefaultsSeparately();
} else {
// include all default scripts into this ScriptEngine
runDefaultsTogether();
}
function menuItemEvent(menuItem) {
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 removeMenuItem() {
if (!Menu.isOptionChecked(MENU_ITEM)) {
Menu.removeMenuItem(MENU_CATEGORY, MENU_ITEM);
}
}
Script.scriptEnding.connect(function() {
removeMenuItem();
});
Menu.menuItemEvent.connect(menuItemEvent);