core-functions
Advanced tools
Comparing version 2.0.17 to 2.0.18
{ | ||
"name": "core-functions", | ||
"version": "2.0.17", | ||
"version": "2.0.18", | ||
"description": "Core functions, utilities and classes for working with Node/JavaScript primitives and built-in objects, including strings, booleans, Promises, base 64, Arrays, Objects, standard AppErrors, etc.", | ||
@@ -5,0 +5,0 @@ "author": "Byron du Preez", |
@@ -1,2 +0,2 @@ | ||
# core-functions v2.0.17 | ||
# core-functions v2.0.18 | ||
@@ -107,2 +107,6 @@ Core functions, utilities and classes for working with Node/JavaScript primitives and built-in objects, including | ||
### 2.0.18 | ||
- Backport of 3.0.11 changes to `strings` module: | ||
- Changed `stringify` to survive a getter that throws an error | ||
### 2.0.17 | ||
@@ -109,0 +113,0 @@ - Backport of the `errors` module from version 3.0.10 |
'use strict'; | ||
// noinspection JSUnusedGlobalSymbols | ||
/** | ||
@@ -172,7 +173,12 @@ * Module containing utilities for working with strings. | ||
const propertyName = names[i]; | ||
const propertyValue = value[propertyName]; | ||
if (i > 0) { | ||
result += ','; | ||
} | ||
result += `"${propertyName}":${stringifyWithHistory(propertyValue, `${name}.${propertyName}`, true)}` | ||
// Avoid failing if an error is thrown from a getter | ||
try { | ||
const propertyValue = value[propertyName]; | ||
result += `"${propertyName}":${stringifyWithHistory(propertyValue, `${name}.${propertyName}`, true)}`; | ||
} catch (err) { | ||
result += `"${propertyName}":[Getter failed - ${err}]`; | ||
} | ||
} | ||
@@ -179,0 +185,0 @@ result += '}'; |
@@ -21,2 +21,3 @@ 'use strict'; | ||
function wrap(value, wrapInString) { | ||
// noinspection JSPrimitiveTypeWrapperUsage | ||
return wrapInString && !(value instanceof String) ? new String(value) : value; | ||
@@ -717,2 +718,19 @@ } | ||
t.end(); | ||
}); | ||
test('stringify must survive a broken getter', t => { | ||
const o = {x: {reading: true}, get y() { return this.x.reading; }}; | ||
let expected = '{"x":{"reading":true},"y":true}'; | ||
t.equal(Strings.stringify(o), expected, `stringify({x: {reading: true}, get y() { return this.x.reading; }}) must be '${expected}'`); | ||
// Now break the 'y' getter | ||
o.x = null; | ||
t.throws(() => o.y, TypeError, 'o.y must throw a TypeError'); | ||
t.throws(() => o['y'], TypeError, `o['y'] must throw a TypeError`); | ||
// but regardless, stringify must NOT break | ||
expected = '{"x":null,"y":[Getter failed - TypeError: Cannot read property \'reading\' of null]}'; | ||
t.equal(Strings.stringify(o), expected, `stringify({x: null, get y() { return this.x.reading; }}) must be '${expected}'`); | ||
t.end(); | ||
}); |
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
251556
4748
218