Skip to content

Instantly share code, notes, and snippets.

View jorendorff's full-sized avatar

Jason Orendorff jorendorff

View GitHub Profile
// Taken from http://dxr.mozilla.org/mozilla-central/source/js/xpconnect/tests/chrome/test_xrayToJS.xul
...
// Test constructors that can be instantiated with zero arguments.
for (var c of simpleConstructors) {
ok(iwin[c], "Constructors appear: " + c);
is(iwin[c], Cu.unwaiveXrays(iwin.wrappedJSObject[c]),
"we end up with the appropriate constructor: " + c);
is(Cu.unwaiveXrays(Cu.waiveXrays(new iwin[c]).constructor), iwin[c],
Before:
// Test constructors that can be instantiated with zero arguments.
for (var c of simpleConstructors) {
ok(iwin[c], "Constructors appear: " + c);
is(iwin[c], Cu.unwaiveXrays(iwin.wrappedJSObject[c]),
"we end up with the appropriate constructor: " + c);
is(Cu.unwaiveXrays(Cu.waiveXrays(new iwin[c]).constructor), iwin[c],
"constructor property is set up right: " + c);
let expectedProto = /Opaque/.test(new iwin[c]) ? iwin['Object'].prototype
On Tue, Apr 7, 2015 at 4:54 PM, Brendan Eich <brendan@mozilla.org> wrote:
> BT: we found several sites that are broken by the new function.name
> algorithm. [...]
>
> [...]
>
> ARB: which is one of these webpages?
>
> BT: cheezburger.com, the comments won't load.
>
for (VAR of ITERABLE)
STATEMENT
----
var $iterator = (ITERABLE)[Symbol.iterator]();
var $skipReturn;
try {
while (true) {
$skipReturn = true;
// *** Before *****************************************************************
// The program operated on a large document tree (DOM-like, but not exactly DOM).
// It had several functions that needed to walk the entire tree,
// which was done with recursion, like this:
function stripGrammar(doc) {
...
function visit(parent) {
for (var [i, child] of parent.content.entries()) {
if (typeof child === "object") {
if (getJitCompilerOptions()["ion.warmup.trigger"] <= 90)
setJitCompilerOption("ion.warmup.trigger", 90);
function notSoEmpty2(i) {
var a = { v: i, notunboxed: undefined };
assertRecoveredOnBailout(a, true);
}
for (var i = 0; i < 100; i++) {
print(i);
/*
* Evaluate the expression `expr` in a scope that includes (a) the global scope; and
* (b) the key-value pairs in `scope`.
*
* evalInScope({a: 3, b: 4}, "a + b") ===> 7
*
* It's up to the caller to make sure that `expr` really is a JS expression and
* that it doesn't do anything unwanted; and that the keys of `scope` really are JS
* identifiers. (That is, don't use this with a `scope` or `expr` you don't trust!)
*/

The best trick in computing is called virtualization. It's a very general-purpose technique for doing astonishing things. Here's how it works.

  1. Take any picture.

  2. Draw an outline around something in the picture.

  3. Now replace either everything inside the outline, or everything outside the outline, with something totally unexpected. There is just one rule: your replacement must behave just enough like what was there before that nobody on the other side of the line notices that anything has changed.

  • the problem: hoisting

    • closures in loops: sadface

    • is this worth solving?

      • the closures in loops thing is pretty bad; ideally we want things to work the first time
  • but still, maybe not

@jorendorff
jorendorff / random7-boring.js
Last active October 7, 2023 23:22
Make a random7 function from a random5 function.
function random7() {
while (true) {
var n = random5() + 5 * random5();
if (n < 21)
return n % 7;
}
}