Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@agoric/make-hardener

Package Overview
Dependencies
Maintainers
3
Versions
13
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@agoric/make-hardener - npm Package Compare versions

Comparing version 0.0.5 to 0.0.6

66

dist/make-hardener.cjs.js

@@ -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 @@ });

2

package.json
{
"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",

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc