typeson-registry 14.2.0 → 14.2.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -1312,8 +1312,51 @@ const primitiveObjects = {
1312
1312
  test (x) {
1313
1313
  return toStringTag(x) === 'Number' && typeof x === 'object';
1314
1314
  },
1315
- replace: Number, // convert to primitive number
1316
- revive (n) { return new Number(n); } // Revive to an objectified number
1315
+ // `_encapsulate`'s nested-replace guard (`_stateObj.replaced`)
1316
+ // means a bare `NaN`/`Infinity`/`-Infinity`/`-0` returned here
1317
+ // would skip the sentinel treatment the bare `nan`/`infinity`/
1318
+ // `negativeZero` type specs normally give those values (since
1319
+ // we're already inside this spec's own `replace()`) -- JSON
1320
+ // can't represent them, so they'd otherwise silently become
1321
+ // `null` (or lose their sign, for `-0`). Encode them the same
1322
+ // way those specs do, directly, rather than relying on that
1323
+ // nested pass.
1324
+ replace (o) {
1325
+ const n = o.valueOf();
1326
+ if (Number.isNaN(n)) {
1327
+ return 'NaN';
1328
+ }
1329
+ if (n === Infinity) {
1330
+ return 'Infinity';
1331
+ }
1332
+ if (n === -Infinity) {
1333
+ return '-Infinity';
1334
+ }
1335
+ if (Object.is(n, -0)) {
1336
+ // A plain `0` here would be indistinguishable from a
1337
+ // genuine positive `0` once round-tripped through JSON
1338
+ // (which can't represent the sign), so this needs its
1339
+ // own sentinel too, same as the others above.
1340
+ return '-0';
1341
+ }
1342
+ return n;
1343
+ },
1344
+ // Revive to an objectified number
1345
+ revive (n) {
1346
+ if (n === 'NaN') {
1347
+ return new Number(NaN);
1348
+ }
1349
+ if (n === 'Infinity') {
1350
+ return new Number(Infinity);
1351
+ }
1352
+ if (n === '-Infinity') {
1353
+ return new Number(-Infinity);
1354
+ }
1355
+ if (n === '-0') {
1356
+ return new Number(-0);
1357
+ }
1358
+ return new Number(n);
1359
+ }
1317
1360
  }
1318
1361
  };
1319
1362
 
@@ -2071,8 +2114,25 @@ const structuredCloningThrowing = expObj.concat({
2071
2114
  // HTML-SPECIFIC
2072
2115
  'Event',
2073
2116
  // Also in Node `worker_threads` (currently experimental)
2074
- 'MessageChannel'
2117
+ 'MessageChannel',
2118
+ 'MessagePort'
2075
2119
  ].includes(stringTag) ||
2120
+ // Node's native `worker_threads` `MessageChannel`/
2121
+ // `MessagePort` don't set `Symbol.toStringTag` per
2122
+ // https://github.com/nodejs/node/issues/65527
2123
+ // (verified directly:
2124
+ // `{}.toString.call(new MessageChannel())` is
2125
+ // `"[object Object]"`, and `.port1`'s is
2126
+ // `"[object EventTarget]"`, its own base class), so the
2127
+ // `stringTag` check above can't catch them there; a real
2128
+ // browser's `MessagePort`/`MessageChannel` already match
2129
+ // via `stringTag` (or, for `MessagePort`, would need its
2130
+ // own `stringTag` entry if ever seen failing to match) --
2131
+ // this is purely a fallback for environments (like Node)
2132
+ // that don't set the tag.
2133
+ (val && val.constructor && [
2134
+ 'MessageChannel', 'MessagePort'
2135
+ ].includes(val.constructor.name)) ||
2076
2136
  // 1. `IsDetachedBuffer` (a process not called within the
2077
2137
  // ECMAScript spec)
2078
2138
  ([