pouchdb-json
Advanced tools
Comparing version 6.0.7 to 6.1.0
@@ -9,3 +9,6 @@ 'use strict'; | ||
function slowJsonParse(str) { | ||
function safeJsonParse(str) { | ||
// This try/catch guards against stack overflow errors. | ||
// JSON.parse() is faster than vuvuzela.parse() but vuvuzela | ||
// cannot overflow. | ||
try { | ||
@@ -19,18 +22,2 @@ return JSON.parse(str); | ||
function safeJsonParse(str) { | ||
// try/catch is deoptimized in V8, leading to slower | ||
// times than we'd like to have. Most documents are _not_ | ||
// huge, and do not require a slower code path just to parse them. | ||
// We can be pretty sure that a document under 50000 characters | ||
// will not be so deeply nested as to throw a stack overflow error | ||
// (depends on the engine and available memory, though, so this is | ||
// just a hunch). 50000 was chosen based on the average length | ||
// of this string in our test suite, to try to find a number that covers | ||
// most of our test cases (26 over this size, 26378 under it). | ||
if (str.length < 50000) { | ||
return JSON.parse(str); | ||
} | ||
return slowJsonParse(str); | ||
} | ||
function safeJsonStringify(json) { | ||
@@ -37,0 +24,0 @@ try { |
{ | ||
"name": "pouchdb-json", | ||
"version": "6.0.7", | ||
"version": "6.1.0", | ||
"description": "PouchDB utilities for safely stringifying and parsing JSON.", | ||
@@ -5,0 +5,0 @@ "main": "./lib/index.js", |
import vuvuzela from 'vuvuzela'; | ||
function slowJsonParse(str) { | ||
function safeJsonParse(str) { | ||
// This try/catch guards against stack overflow errors. | ||
// JSON.parse() is faster than vuvuzela.parse() but vuvuzela | ||
// cannot overflow. | ||
try { | ||
@@ -12,18 +15,2 @@ return JSON.parse(str); | ||
function safeJsonParse(str) { | ||
// try/catch is deoptimized in V8, leading to slower | ||
// times than we'd like to have. Most documents are _not_ | ||
// huge, and do not require a slower code path just to parse them. | ||
// We can be pretty sure that a document under 50000 characters | ||
// will not be so deeply nested as to throw a stack overflow error | ||
// (depends on the engine and available memory, though, so this is | ||
// just a hunch). 50000 was chosen based on the average length | ||
// of this string in our test suite, to try to find a number that covers | ||
// most of our test cases (26 over this size, 26378 under it). | ||
if (str.length < 50000) { | ||
return JSON.parse(str); | ||
} | ||
return slowJsonParse(str); | ||
} | ||
export default safeJsonParse; | ||
export default safeJsonParse; |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
14106
52