From c4ea9321dcffbda9004461a7b0027cf5c893f3c0 Mon Sep 17 00:00:00 2001 From: toasted-nutbread Date: Sat, 2 May 2020 13:00:46 -0400 Subject: Validate document nodes before use (#493) * Validate document.body before use in loadScripts This also fixes an issue where reject wasn't being passed to loadScriptSentinel. * Validate document nodes before use in _getSiteColor * Validate document.body before use in _getViewport * Validate document.body before use in setContentScale * Validate document.body before use in docImposterCreate --- ext/mixed/js/dynamic-loader.js | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'ext/mixed/js') diff --git a/ext/mixed/js/dynamic-loader.js b/ext/mixed/js/dynamic-loader.js index 29672d36..51b6821b 100644 --- a/ext/mixed/js/dynamic-loader.js +++ b/ext/mixed/js/dynamic-loader.js @@ -31,8 +31,13 @@ const dynamicLoader = (() => { } function loadScripts(urls) { - return new Promise((resolve) => { + return new Promise((resolve, reject) => { const parent = document.body; + if (parent === null) { + reject(new Error('Missing body')); + return; + } + for (const url of urls) { const node = parent.querySelector(`script[src='${escapeCSSAttribute(url)}']`); if (node !== null) { continue; } @@ -43,12 +48,11 @@ const dynamicLoader = (() => { parent.appendChild(script); } - loadScriptSentinel(resolve); + loadScriptSentinel(parent, resolve, reject); }); } - function loadScriptSentinel(resolve, reject) { - const parent = document.body; + function loadScriptSentinel(parent, resolve, reject) { const script = document.createElement('script'); const sentinelEventName = 'dynamicLoaderSentinel'; -- cgit v1.2.3