@calcit/procs 0.28.0 → 0.28.1
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/lib/calcit-data.mjs +47 -10
- package/lib/package.json +1 -1
- package/package.json +1 -1
package/lib/calcit-data.mjs
CHANGED
|
@@ -225,6 +225,9 @@ let defaultHash_struct = valueHash("struct:");
|
|
|
225
225
|
let defaultHash_enum = valueHash("enum:");
|
|
226
226
|
let defaultHash_cirru_quote = valueHash("cirru-quote:");
|
|
227
227
|
let defaultHash_unknown = valueHash("unknown:");
|
|
228
|
+
let defaultHash_buffer = valueHash("buffer:");
|
|
229
|
+
/** Identity hashes for host values, kept outside the objects so frozen or DOM objects are never mutated. */
|
|
230
|
+
let hostValueHashes = new WeakMap();
|
|
228
231
|
let fnHashCounter = 0;
|
|
229
232
|
let jsObjectHashCounter = 0;
|
|
230
233
|
export let hashFunction = (x) => {
|
|
@@ -265,15 +268,20 @@ export let hashFunction = (x) => {
|
|
|
265
268
|
if (typeof x === "function") {
|
|
266
269
|
// method values are closures created on the fly (see invoke_method_closure);
|
|
267
270
|
// hash by method name so equal methods share the same hash, matching isEqual
|
|
271
|
+
// cache in a WeakMap instead of writing onto the function, so frozen functions hash safely
|
|
272
|
+
const cachedFn = hostValueHashes.get(x);
|
|
273
|
+
if (cachedFn != null) {
|
|
274
|
+
return cachedFn;
|
|
275
|
+
}
|
|
268
276
|
const methodName = x.__calcitMethodName;
|
|
269
277
|
if (methodName != null) {
|
|
270
278
|
let h = mergeValueHash(defaultHash_fn, methodName);
|
|
271
|
-
x
|
|
279
|
+
hostValueHashes.set(x, h);
|
|
272
280
|
return h;
|
|
273
281
|
}
|
|
274
282
|
fnHashCounter = fnHashCounter + 1;
|
|
275
283
|
let h = mergeValueHash(defaultHash_fn, fnHashCounter);
|
|
276
|
-
x
|
|
284
|
+
hostValueHashes.set(x, h);
|
|
277
285
|
return h;
|
|
278
286
|
}
|
|
279
287
|
if (x instanceof CalcitRef) {
|
|
@@ -397,15 +405,28 @@ export let hashFunction = (x) => {
|
|
|
397
405
|
base = hashCirru(base, x.value);
|
|
398
406
|
return base;
|
|
399
407
|
}
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
408
|
+
if (x instanceof Uint8Array) {
|
|
409
|
+
// Buffers are values: equal bytes must hash equally, matching native Buffer equality.
|
|
410
|
+
let base = mergeValueHash(defaultHash_buffer, x.length);
|
|
411
|
+
for (let idx = 0; idx < x.length; idx++) {
|
|
412
|
+
base = mergeValueHash(base, x[idx]);
|
|
413
|
+
}
|
|
414
|
+
return base;
|
|
415
|
+
}
|
|
416
|
+
if (typeof x === "object" || typeof x === "function") {
|
|
417
|
+
// Host values compare by identity, so they hash by identity as well.
|
|
418
|
+
let cached = hostValueHashes.get(x);
|
|
419
|
+
if (cached != null) {
|
|
420
|
+
return cached;
|
|
421
|
+
}
|
|
422
|
+
jsObjectHashCounter = jsObjectHashCounter + 1;
|
|
423
|
+
let hashHostValue = mergeValueHash(defaultHash_unknown, jsObjectHashCounter);
|
|
424
|
+
hostValueHashes.set(x, hashHostValue);
|
|
425
|
+
return hashHostValue;
|
|
426
|
+
}
|
|
427
|
+
console.warn(`[warn] calcit-js has no method for hashing this: ${String(x)}`);
|
|
405
428
|
jsObjectHashCounter = jsObjectHashCounter + 1;
|
|
406
|
-
|
|
407
|
-
x[calcit_dirty_hash_key] = hashJsObject;
|
|
408
|
-
return hashJsObject;
|
|
429
|
+
return mergeValueHash(defaultHash_unknown, jsObjectHashCounter);
|
|
409
430
|
};
|
|
410
431
|
/// traverse Cirru tree to make unique hash
|
|
411
432
|
let hashCirru = (base, x) => {
|
|
@@ -826,6 +847,22 @@ export let _$n__$e_ = (x, y) => {
|
|
|
826
847
|
}
|
|
827
848
|
return false;
|
|
828
849
|
}
|
|
850
|
+
if (x instanceof Uint8Array) {
|
|
851
|
+
if (!(y instanceof Uint8Array) || x.length !== y.length) {
|
|
852
|
+
return false;
|
|
853
|
+
}
|
|
854
|
+
for (let idx = 0; idx < x.length; idx++) {
|
|
855
|
+
if (x[idx] !== y[idx]) {
|
|
856
|
+
return false;
|
|
857
|
+
}
|
|
858
|
+
}
|
|
859
|
+
return true;
|
|
860
|
+
}
|
|
861
|
+
if (tx === "object") {
|
|
862
|
+
// Host objects (DOM nodes, JS class instances, BufList) compare by identity;
|
|
863
|
+
// identical references were accepted at the top of this function.
|
|
864
|
+
return false;
|
|
865
|
+
}
|
|
829
866
|
throw new Error("Missing handler for this type");
|
|
830
867
|
};
|
|
831
868
|
// overwrite internary comparator of ternary-tree
|
package/lib/package.json
CHANGED