diff options
author | Alex Yatskov <FooSoft@users.noreply.github.com> | 2019-09-30 19:54:27 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-09-30 19:54:27 -0700 |
commit | 3c3a2c94746c972c6a7e9a84e108e13786367e31 (patch) | |
tree | 20d8f079fee2bbcf1c0237319c5556a49dda8a39 /ext/mixed/js | |
parent | 00d16433e705b916d4e078244b213cede8bff5bb (diff) | |
parent | 8b7558a757447b931ee0dd1b5d724673e98bc13d (diff) |
Merge pull request #230 from toasted-nutbread/edge-fixes
Use toIterable for cross-window origin objects
Diffstat (limited to 'ext/mixed/js')
-rw-r--r-- | ext/mixed/js/extension.js | 15 |
1 files changed, 13 insertions, 2 deletions
diff --git a/ext/mixed/js/extension.js b/ext/mixed/js/extension.js index d7085e5b..5c803132 100644 --- a/ext/mixed/js/extension.js +++ b/ext/mixed/js/extension.js @@ -17,13 +17,24 @@ */ +// toIterable is required on Edge for cross-window origin objects. function toIterable(value) { if (typeof Symbol !== 'undefined' && typeof value[Symbol.iterator] !== 'undefined') { return value; } - const array = JSON.parse(JSON.stringify(value)); - return Array.isArray(array) ? array : []; + if (value !== null && typeof value === 'object') { + const length = value.length; + if (typeof length === 'number' && Number.isFinite(length)) { + const array = []; + for (let i = 0; i < length; ++i) { + array.push(value[i]); + } + return array; + } + } + + throw 'Could not convert to iterable'; } function extensionHasChrome() { |