@blamejs/pki 0.5.14 → 0.5.16
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/CHANGELOG.md +44 -0
- package/README.md +1 -1
- package/lib/attrcert-sign.js +511 -2
- package/lib/attrcert-verify.js +21 -0
- package/lib/cmp-verify.js +425 -82
- package/lib/guard-all.js +2 -0
- package/lib/guard-async.js +14 -2
- package/lib/guard-bytes.js +183 -93
- package/lib/guard-compress.js +32 -12
- package/lib/guard-der.js +30 -7
- package/lib/guard-encoding.js +28 -12
- package/lib/guard-header.js +18 -7
- package/lib/guard-identifier.js +146 -79
- package/lib/guard-intrinsic.js +318 -0
- package/lib/guard-json.js +39 -12
- package/lib/guard-limits.js +15 -6
- package/lib/guard-name.js +72 -23
- package/lib/guard-parsed.js +83 -35
- package/lib/guard-range.js +17 -4
- package/lib/guard-secret.js +15 -1
- package/lib/guard-text.js +35 -6
- package/lib/guard-time.js +13 -4
- package/lib/path-validate.js +5 -0
- package/lib/schema-attrcert.js +19 -1
- package/package.json +1 -1
- package/sbom.cdx.json +6 -6
package/lib/guard-identifier.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
// SPDX-License-Identifier: Apache-2.0
|
|
2
2
|
// Copyright (c) blamejs contributors
|
|
3
3
|
"use strict";
|
|
4
|
-
var
|
|
4
|
+
var intrinsic = require("./guard-intrinsic");
|
|
5
|
+
var util = { types: intrinsic.types };
|
|
5
6
|
//
|
|
6
7
|
// @internal -- no operator-facing namespace. The documented surface is the
|
|
7
8
|
// consumers whose identifier-string integrity composes this guard (pki.oid
|
|
@@ -22,6 +23,63 @@ var util = require("util");
|
|
|
22
23
|
// silent false-reject). Every string-form identifier check routes through here so
|
|
23
24
|
// the string and DER forms cannot diverge.
|
|
24
25
|
|
|
26
|
+
// Everything this module reads from the runtime, taken at load. `util.types` above is the slot
|
|
27
|
+
// predicate set, which answers whether a value is a Proxy -- the question that decides whether an
|
|
28
|
+
// options bag can be asked honestly what it holds at all.
|
|
29
|
+
//
|
|
30
|
+
// The array test decides whether a value is walked as a list, so one answering `false` makes the
|
|
31
|
+
// index scan report nothing and every index rule keyed on that scan applies to nothing, which is
|
|
32
|
+
// how an accessor under index 0 reaches a copy loop the refusal should have turned the call away
|
|
33
|
+
// for. The reflective operations are this module's honesty walk itself: `getOwnPropertyDescriptor`
|
|
34
|
+
// learns whether a field is an accessor, `getPrototypeOf` and `ownKeys` walk a chain, and a
|
|
35
|
+
// replacement for either lets an options bag report one shape while answering as another. The array
|
|
36
|
+
// and collection operations run on lists and sets this module owns, where `Array.prototype` and
|
|
37
|
+
// `Set.prototype` are what a caller can still reach: a `forEach` replaced with a no-op makes the
|
|
38
|
+
// name scan report nothing over perfectly real keys, and a `has` answering `true` ends a chain walk
|
|
39
|
+
// at the first prototype. See guard-intrinsic for the whole captured set.
|
|
40
|
+
var _isArray = intrinsic.isArray;
|
|
41
|
+
var _create = intrinsic.create;
|
|
42
|
+
var _getPrototypeOf = intrinsic.getPrototypeOf;
|
|
43
|
+
var _setPrototypeOf = intrinsic.setPrototypeOf;
|
|
44
|
+
var _getOwnPropertyDescriptor = intrinsic.getOwnPropertyDescriptor;
|
|
45
|
+
var _getOwnPropertyNames = intrinsic.getOwnPropertyNames;
|
|
46
|
+
var _defineProperty = intrinsic.defineProperty;
|
|
47
|
+
var _ownKeys = intrinsic.ownKeys;
|
|
48
|
+
var _isView = intrinsic.isView;
|
|
49
|
+
var _isInteger = intrinsic.isInteger;
|
|
50
|
+
var _stringify = intrinsic.stringify;
|
|
51
|
+
var _forEach = intrinsic.forEach;
|
|
52
|
+
var _map = intrinsic.map;
|
|
53
|
+
var _filter = intrinsic.filter;
|
|
54
|
+
var _every = intrinsic.every;
|
|
55
|
+
var _some = intrinsic.some;
|
|
56
|
+
var _indexOf = intrinsic.indexOf;
|
|
57
|
+
var _sort = intrinsic.sort;
|
|
58
|
+
var _setAdd = intrinsic.setAdd;
|
|
59
|
+
var _setHas = intrinsic.setHas;
|
|
60
|
+
var _mapGet = intrinsic.mapGet;
|
|
61
|
+
var _mapSet = intrinsic.mapSet;
|
|
62
|
+
var _mapHas = intrinsic.mapHas;
|
|
63
|
+
var _Set = intrinsic.Set;
|
|
64
|
+
var _Map = intrinsic.Map;
|
|
65
|
+
var _charCodeAt = intrinsic.uncurry(String.prototype.charCodeAt);
|
|
66
|
+
var _strSplit = intrinsic.uncurry(String.prototype.split);
|
|
67
|
+
// This module's whole job is deciding whether a caller's name is in a known set, and that decision
|
|
68
|
+
// is one `hasOwnProperty` call. Reading it and its `call` off their prototypes leaves the answer
|
|
69
|
+
// with whoever replaced either, which classifies an unknown option as an allowed one.
|
|
70
|
+
var _hasOwn = intrinsic.hasOwn;
|
|
71
|
+
// The index test below IS `String(Number(k)) === k`, and the readable-index scan orders and bounds
|
|
72
|
+
// its results with the same two conversions. Both are writable properties of globalThis: one
|
|
73
|
+
// replacement decides which own names this module reports as elements, in what order, and where the
|
|
74
|
+
// scan stops -- which is what every consumer's density and accessor refusal is built on.
|
|
75
|
+
var _String = intrinsic.String;
|
|
76
|
+
var _Number = intrinsic.Number;
|
|
77
|
+
var _BigInt = intrinsic.BigInt;
|
|
78
|
+
var _Object = intrinsic.Object;
|
|
79
|
+
var _BufferProto = intrinsic.BufferProto;
|
|
80
|
+
// Appended by index rather than through `push`, so the growth reads no prototype method at all.
|
|
81
|
+
function _append(arr, v) { _defineProperty(arr, arr.length, { value: v, writable: true, enumerable: true, configurable: true }); }
|
|
82
|
+
|
|
25
83
|
// The dotted-decimal grammar, walked instead of matched. `(0|[1-9]\d*)(\.(0|[1-9]\d*))+`
|
|
26
84
|
// nests a quantified group inside a quantified group with an alternation in each,
|
|
27
85
|
// which is the shape whose cost on a rejecting string is a property of the pattern
|
|
@@ -34,14 +92,14 @@ function _isDottedDecimal(str) {
|
|
|
34
92
|
if (str.length === 0) return false;
|
|
35
93
|
var arcs = 0, digits = 0, leadingZero = false;
|
|
36
94
|
for (var i = 0; i < str.length; i++) {
|
|
37
|
-
var c = str
|
|
95
|
+
var c = _charCodeAt(str, i);
|
|
38
96
|
if (c === 0x2e) { // "."
|
|
39
97
|
if (digits === 0 || leadingZero) return false; // empty arc, or "01"
|
|
40
98
|
arcs++; digits = 0; leadingZero = false;
|
|
41
99
|
continue;
|
|
42
100
|
}
|
|
43
101
|
if (c < 0x30 || c > 0x39) return false; // not a digit
|
|
44
|
-
if (digits === 1 && str
|
|
102
|
+
if (digits === 1 && _charCodeAt(str, i - 1) === 0x30) leadingZero = true;
|
|
45
103
|
digits++;
|
|
46
104
|
}
|
|
47
105
|
if (digits === 0 || leadingZero) return false; // trailing "." or a final "01"
|
|
@@ -72,9 +130,15 @@ function assertCanonicalOid(str, E, code, label, boundsCode) {
|
|
|
72
130
|
}
|
|
73
131
|
if (boundsCode === null) return str;
|
|
74
132
|
var bcode = boundsCode === undefined ? code : boundsCode;
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
133
|
+
// The arc bound below is a bound on THESE parts, so the split that produces them settles it. One
|
|
134
|
+
// returning different pieces has the check read a first and second arc the identifier does not
|
|
135
|
+
// carry, and an out-of-range OID passes a range test performed on other numbers.
|
|
136
|
+
var parts = _strSplit(str, ".");
|
|
137
|
+
// Captured: these two arcs are what the bound below is a bound ON, and `BigInt` is a writable
|
|
138
|
+
// property of globalThis, so a replacement returns whatever it likes for the arcs and the range
|
|
139
|
+
// test is then performed on numbers the identifier does not carry.
|
|
140
|
+
var root = _BigInt(parts[0]);
|
|
141
|
+
var second = _BigInt(parts[1]);
|
|
78
142
|
if (root > 2n) throw E(bcode, who + " root arc must be 0, 1, or 2 (X.660)");
|
|
79
143
|
if (root < 2n && second > 39n) throw E(bcode, who + " second arc must be 0..39 under roots 0 and 1 (X.660)");
|
|
80
144
|
return str;
|
|
@@ -111,14 +175,14 @@ function assertCanonicalOid(str, E, code, label, boundsCode) {
|
|
|
111
175
|
// @guard-shape Object\.keys\(\w+(?:\.\w+)*\)\.forEach\(function \((\w+)\) \{\s*if \(![\w.]+\[\1\]\) (?:\{\s*)?throw
|
|
112
176
|
function assertKnownKeys(obj, known, E, code, message) {
|
|
113
177
|
_refuseUnenumerable(obj, E, code, "the options");
|
|
114
|
-
var describe = typeof message === "function" ? message : function (k) { return message +
|
|
115
|
-
_readableNames(obj)
|
|
116
|
-
if (
|
|
178
|
+
var describe = typeof message === "function" ? message : function (k) { return message + _stringify(k); };
|
|
179
|
+
_forEach(_readableNames(obj), function (k) {
|
|
180
|
+
if (_hasOwn(known, k)) return;
|
|
117
181
|
// A Symbol reaches the message as its description, before either form of `message` sees it.
|
|
118
182
|
// JSON.stringify returns undefined for one, so a caller's own builder (which stringifies the
|
|
119
183
|
// key itself) would name the refused option "undefined" and leave nothing to search for.
|
|
120
184
|
// Normalizing here rather than in the default builder keeps both forms reading the same.
|
|
121
|
-
throw E(code, describe(typeof k === "symbol" ?
|
|
185
|
+
throw E(code, describe(typeof k === "symbol" ? _String(k) : k));
|
|
122
186
|
});
|
|
123
187
|
}
|
|
124
188
|
|
|
@@ -138,10 +202,10 @@ function assertKnownKeys(obj, known, E, code, message) {
|
|
|
138
202
|
// The residual is a planted function REPLACING one of these twelve. No verb reads `opts.toString`
|
|
139
203
|
// as an option, so that smuggles nothing; it breaks the runtime at large, not this check.
|
|
140
204
|
var _PRISTINE_OBJECT_PROTO = (function () {
|
|
141
|
-
var s =
|
|
142
|
-
["constructor", "hasOwnProperty", "isPrototypeOf", "propertyIsEnumerable", "toLocaleString",
|
|
205
|
+
var s = _create(null);
|
|
206
|
+
_forEach(["constructor", "hasOwnProperty", "isPrototypeOf", "propertyIsEnumerable", "toLocaleString",
|
|
143
207
|
"toString", "valueOf", "__defineGetter__", "__defineSetter__", "__lookupGetter__",
|
|
144
|
-
"__lookupSetter__", "__proto__"]
|
|
208
|
+
"__lookupSetter__", "__proto__"], function (k) { s[k] = 1; });
|
|
145
209
|
return s;
|
|
146
210
|
})();
|
|
147
211
|
|
|
@@ -182,9 +246,9 @@ function _requireFactory(E) {
|
|
|
182
246
|
function _refuseUnenumerable(v, E, code, label) {
|
|
183
247
|
_requireFactory(E);
|
|
184
248
|
if (v === null || typeof v !== "object") return;
|
|
185
|
-
var visited = new
|
|
186
|
-
for (var o = v; o && !visited
|
|
187
|
-
visited
|
|
249
|
+
var visited = new _Set();
|
|
250
|
+
for (var o = v; o && !_setHas(visited, o); o = _getPrototypeOf(o)) {
|
|
251
|
+
_setAdd(visited, o);
|
|
188
252
|
if (!util.types.isProxy(o)) continue;
|
|
189
253
|
throw E(code, label + (o === v ? " is" : " inherits from") + " a Proxy, whose reported keys " +
|
|
190
254
|
"need not match what it answers, so an option it holds cannot be found; pass a plain object");
|
|
@@ -204,10 +268,10 @@ function _refuseUnenumerable(v, E, code, label) {
|
|
|
204
268
|
// The walk stops at an object already seen, since a prototype chain is finite only while it is
|
|
205
269
|
// acyclic and a Proxy can make it otherwise. See the note on _readableNames.
|
|
206
270
|
function _isMethodOf(from, k, fn) {
|
|
207
|
-
var visited = new
|
|
208
|
-
for (var o = from; o && !visited
|
|
209
|
-
visited
|
|
210
|
-
var d =
|
|
271
|
+
var visited = new _Set();
|
|
272
|
+
for (var o = from; o && !_setHas(visited, o); o = _getPrototypeOf(o)) {
|
|
273
|
+
_setAdd(visited, o);
|
|
274
|
+
var d = _getOwnPropertyDescriptor(o, k);
|
|
211
275
|
if (!d) continue;
|
|
212
276
|
return !d.get && !d.set && d.value === fn;
|
|
213
277
|
}
|
|
@@ -216,8 +280,8 @@ function _isMethodOf(from, k, fn) {
|
|
|
216
280
|
|
|
217
281
|
// Every name that can supply a value to a later `obj.foo`. `Object.keys` reports a subset of
|
|
218
282
|
// those: own enumerable names only. Four ordinary object shapes answer the lookup while showing
|
|
219
|
-
// that enumeration nothing. A value on the prototype (`
|
|
220
|
-
// non-enumerable own value (`
|
|
283
|
+
// that enumeration nothing. A value on the prototype (`_create({ password: "pw" })`). A
|
|
284
|
+
// non-enumerable own value (`_defineProperty(o, "password", { enumerable: false })`). A
|
|
221
285
|
// class getter, which class syntax also defines non-enumerable. And a polluted
|
|
222
286
|
// `Object.prototype`. On each of them `pki.key.export` accepts the bag, ignores the password it
|
|
223
287
|
// can read, and returns the private key in the clear, which is the case the refusal exists to
|
|
@@ -264,8 +328,8 @@ function _isMethodOf(from, k, fn) {
|
|
|
264
328
|
// reaches neither the check nor the verb. A leading zero is excluded by the same comparison,
|
|
265
329
|
// since "01" is a named property too.
|
|
266
330
|
function _isArrayIndex(k) {
|
|
267
|
-
var n =
|
|
268
|
-
return
|
|
331
|
+
var n = _Number(k);
|
|
332
|
+
return _isInteger(n) && n >= 0 && n < 4294967295 && _String(n) === k;
|
|
269
333
|
}
|
|
270
334
|
|
|
271
335
|
// Is this value one whose own `length` and indices are structure rather than supplied names?
|
|
@@ -280,7 +344,7 @@ function _isArrayIndex(k) {
|
|
|
280
344
|
// properties that stay set and answer on a later read. Counting it as indexed drops both from the
|
|
281
345
|
// names reported and from the copy the verb is handed.
|
|
282
346
|
function _isIndexedKind(v) {
|
|
283
|
-
return
|
|
347
|
+
return _isArray(v) || (_isView(v) && !util.types.isDataView(v));
|
|
284
348
|
}
|
|
285
349
|
|
|
286
350
|
// The names the built-in collection kinds define on their prototypes, written out rather than
|
|
@@ -288,7 +352,7 @@ function _isIndexedKind(v) {
|
|
|
288
352
|
// what belongs on it asks the polluted object to vouch for itself.
|
|
289
353
|
//
|
|
290
354
|
// One set covering every kind, because a LEVEL is what gets read and a level's kind cannot be
|
|
291
|
-
// established without asking a prototype who it is. `
|
|
355
|
+
// established without asking a prototype who it is. `_create(Map.prototype)` holds no map
|
|
292
356
|
// and inherits `size`; a foreign array's prototype is not this realm's. Both are answered by
|
|
293
357
|
// asking whether the NAME is one a kind defines, which no realm and no lookalike changes.
|
|
294
358
|
//
|
|
@@ -336,12 +400,12 @@ var _SHARED_MEMBERS = _SHARED_PROTO_MEMBERS;
|
|
|
336
400
|
// an array, `buffer` is a byte view's member and not an array's, so that getter is the caller's
|
|
337
401
|
// option and gets reported.
|
|
338
402
|
//
|
|
339
|
-
// A value with no collection slot answers with nothing. `
|
|
403
|
+
// A value with no collection slot answers with nothing. `_create(Map.prototype)` holds no
|
|
340
404
|
// map and still inherits `size`, and that is settled by the level test in the walk, which reads
|
|
341
405
|
// the members off the prototype the name was found on.
|
|
342
406
|
// The prototypes this realm installs a kind's members on. A level that IS one carries the
|
|
343
407
|
// language's members whatever the value in front of it turns out to be, which is how
|
|
344
|
-
// `
|
|
408
|
+
// `_create(Map.prototype)` keeps `size` while holding no map.
|
|
345
409
|
//
|
|
346
410
|
// Typed arrays are recognized through the prototype they all share rather than by naming each
|
|
347
411
|
// constructor, so a kind the list never mentioned is covered: `Float16Array` arrived on Node 24
|
|
@@ -350,14 +414,14 @@ var _SHARED_MEMBERS = _SHARED_PROTO_MEMBERS;
|
|
|
350
414
|
// only its own: `size` on `Array.prototype` is nothing the language put there, so exempting it
|
|
351
415
|
// because some other kind has a member by that name hands back the hole this walk exists to
|
|
352
416
|
// close, for anyone who plants it in a shape that reads as built-in.
|
|
353
|
-
var _TYPED_ARRAY_PROTO =
|
|
417
|
+
var _TYPED_ARRAY_PROTO = _getPrototypeOf(Uint8Array.prototype);
|
|
354
418
|
var _INTRINSIC_HOLDERS = (function () {
|
|
355
|
-
var m = new
|
|
356
|
-
function pair(ctor, members) { if (ctor && ctor.prototype) m
|
|
419
|
+
var m = new _Map([[_TYPED_ARRAY_PROTO, _TYPED_PROTO_MEMBERS]]);
|
|
420
|
+
function pair(ctor, members) { if (ctor && ctor.prototype) _mapSet(m, ctor.prototype, members); }
|
|
357
421
|
pair(Array, _ARRAY_PROTO_MEMBERS);
|
|
358
422
|
pair(RegExp, _REGEXP_PROTO_MEMBERS);
|
|
359
|
-
[Map, Set]
|
|
360
|
-
[WeakMap, WeakSet]
|
|
423
|
+
_forEach([Map, Set], function (c) { pair(c, _SIZED_PROTO_MEMBERS); });
|
|
424
|
+
_forEach([WeakMap, WeakSet], function (c) { pair(c, _WEAK_PROTO_MEMBERS); });
|
|
361
425
|
pair(ArrayBuffer, _ARRAYBUFFER_PROTO_MEMBERS);
|
|
362
426
|
pair(typeof SharedArrayBuffer === "function" ? SharedArrayBuffer : null, _SHARED_PROTO_MEMBERS);
|
|
363
427
|
pair(DataView, _DATAVIEW_PROTO_MEMBERS);
|
|
@@ -371,13 +435,13 @@ var _INTRINSIC_HOLDERS = (function () {
|
|
|
371
435
|
//
|
|
372
436
|
// Reading a global can run a getter, and a deprecated one can throw; a fault here would break
|
|
373
437
|
// this module's load over a name it does not need.
|
|
374
|
-
|
|
438
|
+
_forEach(_getOwnPropertyNames(globalThis), function (n) {
|
|
375
439
|
var C;
|
|
376
440
|
try { C = globalThis[n]; }
|
|
377
441
|
catch (_e) { /* allow:swallow-unverified this runs once at load over whatever globals the host defines, and no global in a supported runtime throws on read, so no test drives it; it is here so an embedder's throwing accessor cannot stop this module loading over a name it does not need */ return; }
|
|
378
442
|
if (typeof C !== "function" || typeof C.BYTES_PER_ELEMENT !== "number") return;
|
|
379
|
-
if (!C.prototype ||
|
|
380
|
-
m
|
|
443
|
+
if (!C.prototype || _getPrototypeOf(C.prototype) !== _TYPED_ARRAY_PROTO) return;
|
|
444
|
+
_mapSet(m, C.prototype, _CONCRETE_TYPED_MEMBERS);
|
|
381
445
|
});
|
|
382
446
|
return m;
|
|
383
447
|
})();
|
|
@@ -387,7 +451,7 @@ var _INTRINSIC_HOLDERS = (function () {
|
|
|
387
451
|
// the table above, the concrete typed-array ones included, so an object that merely sits over one
|
|
388
452
|
// of them is a caller's and its names are theirs.
|
|
389
453
|
function _holderMembers(o) {
|
|
390
|
-
return _INTRINSIC_HOLDERS
|
|
454
|
+
return _mapHas(_INTRINSIC_HOLDERS, o) ? _mapGet(_INTRINSIC_HOLDERS, o) : null;
|
|
391
455
|
}
|
|
392
456
|
|
|
393
457
|
// Is this one of Node's Buffers? A byte view whose chain reaches `Buffer.prototype`, asked by
|
|
@@ -400,10 +464,10 @@ function _holderMembers(o) {
|
|
|
400
464
|
// carrying somebody else's exception. A prototype identity is not writable from outside.
|
|
401
465
|
function _isNodeBuffer(v) {
|
|
402
466
|
if (!util.types.isUint8Array(v)) return false;
|
|
403
|
-
var visited = new
|
|
404
|
-
for (var o = v; o && !visited
|
|
405
|
-
visited
|
|
406
|
-
if (o ===
|
|
467
|
+
var visited = new _Set();
|
|
468
|
+
for (var o = v; o && !_setHas(visited, o); o = _getPrototypeOf(o)) {
|
|
469
|
+
_setAdd(visited, o);
|
|
470
|
+
if (o === _BufferProto) return true;
|
|
407
471
|
}
|
|
408
472
|
return false;
|
|
409
473
|
}
|
|
@@ -413,10 +477,10 @@ function _kindMembers(v) {
|
|
|
413
477
|
// prototype in the chain supplies is handled by the level test at the walk; a name that only
|
|
414
478
|
// looks like a member, on a class of the caller's, is the option they wrote.
|
|
415
479
|
if (v === null || v === undefined) return [];
|
|
416
|
-
if (
|
|
480
|
+
if (_isArray(v)) return _ARRAY_MEMBERS;
|
|
417
481
|
if (_isNodeBuffer(v)) return _BUFFER_KIND_MEMBERS;
|
|
418
482
|
if (util.types.isDataView(v)) return _DATAVIEW_MEMBERS;
|
|
419
|
-
if (
|
|
483
|
+
if (_isView(v)) return _VIEW_MEMBERS;
|
|
420
484
|
if (util.types.isArrayBuffer(v)) return _ARRAYBUFFER_MEMBERS;
|
|
421
485
|
if (util.types.isSharedArrayBuffer(v)) return _SHARED_MEMBERS;
|
|
422
486
|
if (util.types.isRegExp(v)) return _REGEXP_MEMBERS;
|
|
@@ -456,25 +520,28 @@ function _looksIntrinsic(d) {
|
|
|
456
520
|
// is on Node 24 and was not among the constructors named here, and the moment a typed array of an
|
|
457
521
|
// unlisted kind arrived its `BYTES_PER_ELEMENT` read as an option its caller never wrote.
|
|
458
522
|
function _shadowsAnother(v, k, holder) {
|
|
459
|
-
var visited = new
|
|
523
|
+
var visited = new _Set();
|
|
460
524
|
var past = false;
|
|
461
|
-
for (var o = v; o !== null && o !== undefined && !visited
|
|
462
|
-
visited
|
|
525
|
+
for (var o = v; o !== null && o !== undefined && !_setHas(visited, o); o = _getPrototypeOf(o)) {
|
|
526
|
+
_setAdd(visited, o);
|
|
463
527
|
if (o === holder) { past = true; continue; }
|
|
464
|
-
if (past &&
|
|
528
|
+
if (past && _getOwnPropertyDescriptor(o, k)) return true;
|
|
465
529
|
}
|
|
466
530
|
return false;
|
|
467
531
|
}
|
|
468
532
|
|
|
469
533
|
function _readableNames(obj) {
|
|
470
|
-
var seen =
|
|
534
|
+
var seen = _create(null);
|
|
471
535
|
var out = [];
|
|
472
536
|
// A primitive supplies no option names, and `Reflect.ownKeys` refuses one outright. The walk
|
|
473
537
|
// starts above it rather than on it, so a caller who hands a number or a string where an
|
|
474
538
|
// options bag belongs gets their own verb's refusal for the wrong type from the door that
|
|
475
539
|
// checks types, instead of a raw TypeError from in here about a reflection method they never
|
|
476
540
|
// called. `null` and `undefined` have no chain at all and stop immediately.
|
|
477
|
-
|
|
541
|
+
// Boxed through the captured `Object`. This decides which names the scan below then examines, so
|
|
542
|
+
// a replacement wraps a primitive as an object of its own choosing and the guard reads a name set
|
|
543
|
+
// and a prototype chain the caller supplied rather than the value's.
|
|
544
|
+
var o = (obj === null || obj === undefined) ? null : _Object(obj);
|
|
478
545
|
// Whether the value's own `length` and indices are structure. That is true of an array and a
|
|
479
546
|
// byte view and of nothing else: a Map, a Set and an ArrayBuffer have no own `length`, so
|
|
480
547
|
// skipping the name there would discard one the caller had put on themselves.
|
|
@@ -491,17 +558,17 @@ function _readableNames(obj) {
|
|
|
491
558
|
// walk therefore stops at an object it has already visited. A second lap over the same objects
|
|
492
559
|
// yields no name the first did not, so the reported names stay complete. Without the test a
|
|
493
560
|
// caller's argument hangs the verb before a single option has been read.
|
|
494
|
-
var visited = new
|
|
495
|
-
while (o && !visited
|
|
496
|
-
visited
|
|
561
|
+
var visited = new _Set();
|
|
562
|
+
while (o && !_setHas(visited, o)) {
|
|
563
|
+
_setAdd(visited, o);
|
|
497
564
|
var inherited = (o !== obj);
|
|
498
|
-
var above =
|
|
565
|
+
var above = _getPrototypeOf(o);
|
|
499
566
|
// The root of the chain is the last level before null, which is what `Object.prototype` is.
|
|
500
567
|
// Its position holds in every realm. A value built in a `vm` context or a worker thread
|
|
501
568
|
// carries that realm's root above it, so an identity test against the local object misses it
|
|
502
569
|
// and the foreign `__proto__` accessor reads as a name the caller supplied.
|
|
503
570
|
//
|
|
504
|
-
// The level has to be an inherited one. A caller's own `
|
|
571
|
+
// The level has to be an inherited one. A caller's own `_create(null)` has no prototype
|
|
505
572
|
// either, and treating the bag itself as a root skips the names they set on it.
|
|
506
573
|
var atObjectProto = inherited && above === null;
|
|
507
574
|
// A kind's own prototype gets no exemption as a level. Passing one over whole hides anything
|
|
@@ -513,7 +580,7 @@ function _readableNames(obj) {
|
|
|
513
580
|
// Reflect.ownKeys, because Object.getOwnPropertyNames never returns a Symbol key and a
|
|
514
581
|
// caller can write one. Such a name cannot answer `opts.password`, so it reaches no verb,
|
|
515
582
|
// but it is still an option supplied and not read, which is the whole thing being refused.
|
|
516
|
-
|
|
583
|
+
_forEach(_ownKeys(o), function (k) {
|
|
517
584
|
if (seen[k]) return;
|
|
518
585
|
// The indices of an array or a byte view are its structure, whichever level they are read
|
|
519
586
|
// from. Both kinds answer an integer-keyed read from their elements before any prototype is
|
|
@@ -528,18 +595,18 @@ function _readableNames(obj) {
|
|
|
528
595
|
// below, which exempts the accessor where the language installed it and reports an override.
|
|
529
596
|
if (indexedSelf && k === "length" && !inherited) return;
|
|
530
597
|
if (_isOwnStructuralName(obj, k)) return;
|
|
531
|
-
var d =
|
|
598
|
+
var d = _getOwnPropertyDescriptor(o, k);
|
|
532
599
|
// A name a built-in kind defines, on a level above the value and shaped the way the
|
|
533
600
|
// language leaves it. Own is deliberately excluded: an own `detached` on a buffer shadows
|
|
534
601
|
// the intrinsic getter, so `opts.detached` answers with what the caller wrote, and
|
|
535
602
|
// pki.cms.sign reads an option under exactly that name.
|
|
536
603
|
// A member of the value's own kind, or one sitting on a prototype the language installs
|
|
537
|
-
// members on. The second is what carries `
|
|
604
|
+
// members on. The second is what carries `_create(Map.prototype)`, which holds no map
|
|
538
605
|
// and inherits `size` all the same. Neither alone is enough: without the level test a class
|
|
539
606
|
// of the caller's could name a getter after any kind's member and have it passed over.
|
|
540
607
|
var here = _holderMembers(o);
|
|
541
608
|
if (inherited && _looksIntrinsic(d) && !_shadowsAnother(obj, k, o) &&
|
|
542
|
-
(here === null ? members
|
|
609
|
+
(here === null ? _indexOf(members, k) !== -1 : _indexOf(here, k) !== -1)) return;
|
|
543
610
|
// Object.prototype is decided here and nowhere else. A member is one of the twelve the spec
|
|
544
611
|
// names, still shaped like one: a data property holding a function, or the `__proto__`
|
|
545
612
|
// accessor. Anything else on it was planted and is reported.
|
|
@@ -551,7 +618,7 @@ function _readableNames(obj) {
|
|
|
551
618
|
if (atObjectProto) {
|
|
552
619
|
if (_PRISTINE_OBJECT_PROTO[k] && _looksBuiltIn(d)) return;
|
|
553
620
|
seen[k] = 1;
|
|
554
|
-
out
|
|
621
|
+
_append(out, k);
|
|
555
622
|
return;
|
|
556
623
|
}
|
|
557
624
|
// A method: a data property holding a function that is either inherited, where a class
|
|
@@ -563,7 +630,7 @@ function _readableNames(obj) {
|
|
|
563
630
|
if (d && !d.get && !d.set && typeof d.value === "function" &&
|
|
564
631
|
(inherited || _isMethodOf(above, k, d.value))) return;
|
|
565
632
|
seen[k] = 1;
|
|
566
|
-
out
|
|
633
|
+
_append(out, k);
|
|
567
634
|
});
|
|
568
635
|
o = above;
|
|
569
636
|
}
|
|
@@ -592,7 +659,7 @@ function readableNames(obj, E, code, label) {
|
|
|
592
659
|
// The name walk above drops every index of an indexed kind, since an index is structure rather
|
|
593
660
|
// than a name a caller supplied. Something still has to answer which indices there ARE, and the
|
|
594
661
|
// answer is not `Reflect.ownKeys`: an array consults its prototype chain for a hole, so
|
|
595
|
-
// `
|
|
662
|
+
// `_setPrototypeOf([,], {0: signer})` reads `[signer]` to a `for` loop, to `forEach`, and to
|
|
596
663
|
// every consumer of the value, while its own keys report an empty array. A copy built from the own
|
|
597
664
|
// keys alone holds a hole where the original answers, which is the same divergence between the
|
|
598
665
|
// value checked and the value used that this family exists to close - here it silently shortens a
|
|
@@ -616,22 +683,22 @@ function readableNames(obj, E, code, label) {
|
|
|
616
683
|
// (a length-one array holding its only element on its prototype, copied to a hole) is the guard.
|
|
617
684
|
function readableIndices(obj, E, code, label) {
|
|
618
685
|
_refuseUnenumerable(obj, E, code, label);
|
|
619
|
-
if (!
|
|
620
|
-
var own =
|
|
686
|
+
if (!_isArray(obj)) return [];
|
|
687
|
+
var own = _getOwnPropertyDescriptor(obj, "length");
|
|
621
688
|
var limit = own ? own.value : 0;
|
|
622
|
-
var seen =
|
|
689
|
+
var seen = _create(null);
|
|
623
690
|
var out = [];
|
|
624
|
-
var visited = new
|
|
625
|
-
for (var o = obj; o && !visited
|
|
626
|
-
visited
|
|
627
|
-
|
|
691
|
+
var visited = new _Set();
|
|
692
|
+
for (var o = obj; o && !_setHas(visited, o); o = _getPrototypeOf(o)) {
|
|
693
|
+
_setAdd(visited, o);
|
|
694
|
+
_forEach(_ownKeys(o), function (k) {
|
|
628
695
|
if (typeof k !== "string" || !_isArrayIndex(k) || seen[k]) return;
|
|
629
|
-
if (
|
|
696
|
+
if (_Number(k) >= limit) return;
|
|
630
697
|
seen[k] = 1;
|
|
631
|
-
out
|
|
698
|
+
_append(out, k);
|
|
632
699
|
});
|
|
633
700
|
}
|
|
634
|
-
return out
|
|
701
|
+
return _sort(out, function (a, b) { return _Number(a) - _Number(b); });
|
|
635
702
|
}
|
|
636
703
|
|
|
637
704
|
// The object kinds that are never an options bag, named so the refusal says which mistake was
|
|
@@ -679,7 +746,7 @@ function optionsObject(opts, E, code, label) {
|
|
|
679
746
|
// polluted the caller is then refused for a name they never wrote. A caller who does pass `{}`
|
|
680
747
|
// is a different case and keeps the refusal: `opts.password` answers on their object, so the
|
|
681
748
|
// option is readable and unread, which is exactly what is being refused.
|
|
682
|
-
if (opts === null || opts === undefined) return
|
|
749
|
+
if (opts === null || opts === undefined) return _create(null);
|
|
683
750
|
// `typeof` asks the value nothing, so it is safe on any argument. Every question after it comes
|
|
684
751
|
// once the value has been refused as a Proxy, because each one walks the prototype chain and so
|
|
685
752
|
// runs a `getPrototypeOf` trap, which took this door out through the caller's own exception
|
|
@@ -729,10 +796,10 @@ function optionsObject(opts, E, code, label) {
|
|
|
729
796
|
// The descriptor a name resolves to, from wherever on the chain it is found. Only the first
|
|
730
797
|
// level carrying it matters, since that is the one a read reaches.
|
|
731
798
|
function _descriptorHolder(v, k) {
|
|
732
|
-
var visited = new
|
|
733
|
-
for (var o = v; o !== null && o !== undefined && !visited
|
|
734
|
-
visited
|
|
735
|
-
var d =
|
|
799
|
+
var visited = new _Set();
|
|
800
|
+
for (var o = v; o !== null && o !== undefined && !_setHas(visited, o); o = _getPrototypeOf(o)) {
|
|
801
|
+
_setAdd(visited, o);
|
|
802
|
+
var d = _getOwnPropertyDescriptor(o, k);
|
|
736
803
|
if (d) return d;
|
|
737
804
|
}
|
|
738
805
|
return null;
|
|
@@ -752,7 +819,7 @@ function refuseAccessorFields(obj, names, E, code, label) {
|
|
|
752
819
|
var holder = _descriptorHolder(obj, names[i]);
|
|
753
820
|
if (holder && (holder.get || holder.set)) {
|
|
754
821
|
throw E(code, label + " supplies " +
|
|
755
|
-
|
|
822
|
+
_stringify(typeof names[i] === "symbol" ? _String(names[i]) : names[i]) +
|
|
756
823
|
" through an accessor, whose value can differ between the check and the read; pass an " +
|
|
757
824
|
"object whose fields are plain values");
|
|
758
825
|
}
|
|
@@ -767,7 +834,7 @@ function _settle(opts, E, code, label) {
|
|
|
767
834
|
try { void opts[names[i]]; }
|
|
768
835
|
catch (_e) {
|
|
769
836
|
throw E(code, label + ": reading " +
|
|
770
|
-
|
|
837
|
+
_stringify(typeof names[i] === "symbol" ? _String(names[i]) : names[i]) + " threw");
|
|
771
838
|
}
|
|
772
839
|
}
|
|
773
840
|
}
|
|
@@ -776,7 +843,7 @@ function _settle(opts, E, code, label) {
|
|
|
776
843
|
readAll(before);
|
|
777
844
|
var after = _readableNames(opts);
|
|
778
845
|
var same = after.length === before.length;
|
|
779
|
-
for (var j = 0; same && j < after.length; j++) same = before
|
|
846
|
+
for (var j = 0; same && j < after.length; j++) same = _indexOf(before, after[j]) !== -1;
|
|
780
847
|
if (!same) {
|
|
781
848
|
throw E(code, label + " changes which options it carries while they are read, so no set of " +
|
|
782
849
|
"them can be checked; pass an object whose properties are plain values");
|