@agoric/make-hardener
Advanced tools
@@ -24,10 +24,46 @@ 'use strict'; | ||
| function makeHardener(initialFringe) { | ||
| /** | ||
| * @typedef HardenerOptions | ||
| * @type {object} | ||
| * @property {WeakSet=} fringeSet WeakSet to use for the fringeSet | ||
| * @property {Function=} naivePrepareObject Call with object before hardening | ||
| */ | ||
| /** | ||
| * Create a `harden` function. | ||
| * | ||
| * @param {Iterable} initialFringe Objects considered already hardened | ||
| * @param {HardenerOptions=} options Options for creation | ||
| */ | ||
| function makeHardener(initialFringe, options = {}) { | ||
| const { freeze, getOwnPropertyDescriptors, getPrototypeOf } = Object; | ||
| const { ownKeys } = Reflect; | ||
| // Objects that we won't freeze, either because we've frozen them already, | ||
| // or they were one of the initial roots (terminals). These objects form | ||
| // the "fringe" of the hardened object graph. | ||
| const fringeSet = new WeakSet(initialFringe); | ||
| let { fringeSet } = options; | ||
| if (fringeSet) { | ||
| if ( | ||
| typeof fringeSet.add !== 'function' || | ||
| typeof fringeSet.has !== 'function' | ||
| ) { | ||
| throw new TypeError( | ||
| `options.fringeSet must have add() and has() methods`, | ||
| ); | ||
| } | ||
| // Populate the supplied fringeSet with our initialFringe. | ||
| if (initialFringe) { | ||
| for (const fringe of initialFringe) { | ||
| fringeSet.add(fringe); | ||
| } | ||
| } | ||
| } else { | ||
| // Use a new empty fringe. | ||
| fringeSet = new WeakSet(initialFringe); | ||
| } | ||
| const naivePrepareObject = options && options.naivePrepareObject; | ||
| function harden(root) { | ||
@@ -60,3 +96,8 @@ const toFreeze = new Set(); | ||
| function freezeAndTraverse(obj) { | ||
| // Immediately freeze the object to ensure reactive | ||
| // Apply the naive preparer if they specified one. | ||
| if (naivePrepareObject) { | ||
| naivePrepareObject(obj); | ||
| } | ||
| // Now freeze the object to ensure reactive | ||
| // objects such as proxies won't add properties | ||
@@ -114,5 +155,18 @@ // during traversal, before they get frozen. | ||
| // all reachable properties have already been frozen by this point | ||
| throw new TypeError( | ||
| `prototype ${p} of ${path} is not already in the fringeSet`, | ||
| ); | ||
| let msg; | ||
| try { | ||
| msg = `prototype ${p} of ${path} is not already in the fringeSet`; | ||
| } catch (e) { | ||
| // `${(async _=>_).__proto__}` fails in most engines | ||
| msg = | ||
| 'a prototype of something is not already in the fringeset (and .toString failed)'; | ||
| try { | ||
| console.log(msg); | ||
| console.log('the prototype:', p); | ||
| console.log('of something:', path); | ||
| } catch (_e) { | ||
| // console.log might be missing in restrictive SES realms | ||
| } | ||
| } | ||
| throw new TypeError(msg); | ||
| } | ||
@@ -119,0 +173,0 @@ }); |
@@ -22,10 +22,46 @@ // Adapted from SES/Caja - Copyright (C) 2011 Google Inc. | ||
| function makeHardener(initialFringe) { | ||
| /** | ||
| * @typedef HardenerOptions | ||
| * @type {object} | ||
| * @property {WeakSet=} fringeSet WeakSet to use for the fringeSet | ||
| * @property {Function=} naivePrepareObject Call with object before hardening | ||
| */ | ||
| /** | ||
| * Create a `harden` function. | ||
| * | ||
| * @param {Iterable} initialFringe Objects considered already hardened | ||
| * @param {HardenerOptions=} options Options for creation | ||
| */ | ||
| function makeHardener(initialFringe, options = {}) { | ||
| const { freeze, getOwnPropertyDescriptors, getPrototypeOf } = Object; | ||
| const { ownKeys } = Reflect; | ||
| // Objects that we won't freeze, either because we've frozen them already, | ||
| // or they were one of the initial roots (terminals). These objects form | ||
| // the "fringe" of the hardened object graph. | ||
| const fringeSet = new WeakSet(initialFringe); | ||
| let { fringeSet } = options; | ||
| if (fringeSet) { | ||
| if ( | ||
| typeof fringeSet.add !== 'function' || | ||
| typeof fringeSet.has !== 'function' | ||
| ) { | ||
| throw new TypeError( | ||
| `options.fringeSet must have add() and has() methods`, | ||
| ); | ||
| } | ||
| // Populate the supplied fringeSet with our initialFringe. | ||
| if (initialFringe) { | ||
| for (const fringe of initialFringe) { | ||
| fringeSet.add(fringe); | ||
| } | ||
| } | ||
| } else { | ||
| // Use a new empty fringe. | ||
| fringeSet = new WeakSet(initialFringe); | ||
| } | ||
| const naivePrepareObject = options && options.naivePrepareObject; | ||
| function harden(root) { | ||
@@ -58,3 +94,8 @@ const toFreeze = new Set(); | ||
| function freezeAndTraverse(obj) { | ||
| // Immediately freeze the object to ensure reactive | ||
| // Apply the naive preparer if they specified one. | ||
| if (naivePrepareObject) { | ||
| naivePrepareObject(obj); | ||
| } | ||
| // Now freeze the object to ensure reactive | ||
| // objects such as proxies won't add properties | ||
@@ -112,5 +153,18 @@ // during traversal, before they get frozen. | ||
| // all reachable properties have already been frozen by this point | ||
| throw new TypeError( | ||
| `prototype ${p} of ${path} is not already in the fringeSet`, | ||
| ); | ||
| let msg; | ||
| try { | ||
| msg = `prototype ${p} of ${path} is not already in the fringeSet`; | ||
| } catch (e) { | ||
| // `${(async _=>_).__proto__}` fails in most engines | ||
| msg = | ||
| 'a prototype of something is not already in the fringeset (and .toString failed)'; | ||
| try { | ||
| console.log(msg); | ||
| console.log('the prototype:', p); | ||
| console.log('of something:', path); | ||
| } catch (_e) { | ||
| // console.log might be missing in restrictive SES realms | ||
| } | ||
| } | ||
| throw new TypeError(msg); | ||
| } | ||
@@ -117,0 +171,0 @@ }); |
@@ -28,10 +28,46 @@ (function (global, factory) { | ||
| function makeHardener(initialFringe) { | ||
| /** | ||
| * @typedef HardenerOptions | ||
| * @type {object} | ||
| * @property {WeakSet=} fringeSet WeakSet to use for the fringeSet | ||
| * @property {Function=} naivePrepareObject Call with object before hardening | ||
| */ | ||
| /** | ||
| * Create a `harden` function. | ||
| * | ||
| * @param {Iterable} initialFringe Objects considered already hardened | ||
| * @param {HardenerOptions=} options Options for creation | ||
| */ | ||
| function makeHardener(initialFringe, options = {}) { | ||
| const { freeze, getOwnPropertyDescriptors, getPrototypeOf } = Object; | ||
| const { ownKeys } = Reflect; | ||
| // Objects that we won't freeze, either because we've frozen them already, | ||
| // or they were one of the initial roots (terminals). These objects form | ||
| // the "fringe" of the hardened object graph. | ||
| const fringeSet = new WeakSet(initialFringe); | ||
| let { fringeSet } = options; | ||
| if (fringeSet) { | ||
| if ( | ||
| typeof fringeSet.add !== 'function' || | ||
| typeof fringeSet.has !== 'function' | ||
| ) { | ||
| throw new TypeError( | ||
| `options.fringeSet must have add() and has() methods`, | ||
| ); | ||
| } | ||
| // Populate the supplied fringeSet with our initialFringe. | ||
| if (initialFringe) { | ||
| for (const fringe of initialFringe) { | ||
| fringeSet.add(fringe); | ||
| } | ||
| } | ||
| } else { | ||
| // Use a new empty fringe. | ||
| fringeSet = new WeakSet(initialFringe); | ||
| } | ||
| const naivePrepareObject = options && options.naivePrepareObject; | ||
| function harden(root) { | ||
@@ -64,3 +100,8 @@ const toFreeze = new Set(); | ||
| function freezeAndTraverse(obj) { | ||
| // Immediately freeze the object to ensure reactive | ||
| // Apply the naive preparer if they specified one. | ||
| if (naivePrepareObject) { | ||
| naivePrepareObject(obj); | ||
| } | ||
| // Now freeze the object to ensure reactive | ||
| // objects such as proxies won't add properties | ||
@@ -118,5 +159,18 @@ // during traversal, before they get frozen. | ||
| // all reachable properties have already been frozen by this point | ||
| throw new TypeError( | ||
| `prototype ${p} of ${path} is not already in the fringeSet`, | ||
| ); | ||
| let msg; | ||
| try { | ||
| msg = `prototype ${p} of ${path} is not already in the fringeSet`; | ||
| } catch (e) { | ||
| // `${(async _=>_).__proto__}` fails in most engines | ||
| msg = | ||
| 'a prototype of something is not already in the fringeset (and .toString failed)'; | ||
| try { | ||
| console.log(msg); | ||
| console.log('the prototype:', p); | ||
| console.log('of something:', path); | ||
| } catch (_e) { | ||
| // console.log might be missing in restrictive SES realms | ||
| } | ||
| } | ||
| throw new TypeError(msg); | ||
| } | ||
@@ -123,0 +177,0 @@ }); |
+1
-1
| { | ||
| "name": "@agoric/make-hardener", | ||
| "version": "0.0.5", | ||
| "version": "0.0.6", | ||
| "description": "Create a 'hardener' which freezes the API surface of a set of objects", | ||
@@ -5,0 +5,0 @@ "main": "dist/make-hardener.cjs.js", |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
35174
15.8%517
39.73%0
-100%0
-100%