diff options
author | toasted-nutbread <toasted-nutbread@users.noreply.github.com> | 2019-12-08 15:23:59 -0500 |
---|---|---|
committer | toasted-nutbread <toasted-nutbread@users.noreply.github.com> | 2019-12-08 16:01:29 -0500 |
commit | 0156869a3d8c4236594035e072b084b7c2ea8f16 (patch) | |
tree | 58695662f01fe90b0b3fa7340059d14f9ca23e09 /ext/bg/js/util.js | |
parent | dbd9a5414938df1613866743a0c8a2a683101ac1 (diff) |
Optimize utilIsolate
Diffstat (limited to 'ext/bg/js/util.js')
-rw-r--r-- | ext/bg/js/util.js | 16 |
1 files changed, 14 insertions, 2 deletions
diff --git a/ext/bg/js/util.js b/ext/bg/js/util.js index 8175fdff..93bb7047 100644 --- a/ext/bg/js/util.js +++ b/ext/bg/js/util.js @@ -16,8 +16,20 @@ * along with this program. If not, see <http://www.gnu.org/licenses/>. */ -function utilIsolate(data) { - return JSON.parse(JSON.stringify(data)); +function utilIsolate(value) { + if (value === null) { return null; } + + switch (typeof value) { + case 'boolean': + case 'number': + case 'string': + case 'bigint': + case 'symbol': + return value; + } + + const stringValue = JSON.stringify(value); + return typeof stringValue === 'string' ? JSON.parse(stringValue) : null; } function utilBackgroundIsolate(data) { |