Browse Source

fix: avoid needless array creation in jsonDump

tophf 4 years ago
parent
commit
60da4e5e90
1 changed files with 4 additions and 1 deletions
  1. 4 1
      src/injected/web/util-web.js

+ 4 - 1
src/injected/web/util-web.js

@@ -27,7 +27,7 @@ const escFunc = m => escMap[m] || escCharCode(m::charCodeAt(0));
  * Thus, we use the native JSON.stringify() only in the content script context and only until
  * a userscript is injected into this context (due to `@inject-into` and/or a CSP problem).
  */
-export const jsonDump = (value, stack = []) => {
+export const jsonDump = (value, stack) => {
   let res;
   switch (value === null ? (res = 'null') : typeof value) {
   case 'bigint':
@@ -41,6 +41,9 @@ export const jsonDump = (value, stack = []) => {
     res = `"${value::replace(escRE, escFunc)}"`;
     break;
   case 'object':
+    if (!stack) {
+      stack = []; // Creating the array here, only when type is object.
+    }
     if (stack::indexOf(value) >= 0) {
       throw new ErrorSafe('Converting circular structure to JSON');
     }