Skip to content

Instantly share code, notes, and snippets.

@MarkTiedemann
Last active April 11, 2022 20:30
Show Gist options
  • Select an option

  • Save MarkTiedemann/429666e3c07ad2a7c554c1ec8a2b04ec to your computer and use it in GitHub Desktop.

Select an option

Save MarkTiedemann/429666e3c07ad2a7c554c1ec8a2b04ec to your computer and use it in GitHub Desktop.
// node --disallow-code-generation-from-strings eval.mjs
console.log(eval("1 + 1"));
// => EvalError: Code generation from strings disallowed for this context
// node --experimental-fetch fetch.mjs
const res = await fetch("https://nodejs.org/dist/index.json");
const json = await res.json();
console.log(json[0].version);
// => v17.9.0
// node --frozen-intrinsics primordials.mjs
Array.prototype.push = () => {};
// With --frozen-intrinsics:
// => TypeError: Cannot assign to read only property 'push'
const a = [];
a.push(1);
console.log(a);
// Without --frozen-intrinsics:
// => []
// node --disable-proto=throw proto.mjs
({}).__proto__.isAdmin = true;
// With --disable-proto:
// => Error: Accessing Object.prototype.__proto__ has been disallowed with --disable-proto=throw
const user = {};
console.log(user.isAdmin);
// Without --disable-proto:
// => true
// node --experimental-network-imports --experimental-global-webcrypto uuid.mjs
import validateUUID from "https://unpkg.com/[email protected]/dist/esm-node/validate.js";
const uuid = crypto.randomUUID();
console.log(validateUUID(uuid)); // => true
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment