From 0156869a3d8c4236594035e072b084b7c2ea8f16 Mon Sep 17 00:00:00 2001 From: toasted-nutbread Date: Sun, 8 Dec 2019 15:23:59 -0500 Subject: Optimize utilIsolate --- ext/bg/js/util.js | 16 ++++++++++++++-- 1 file 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 . */ -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) { -- cgit v1.2.3