Skip to content

Instantly share code, notes, and snippets.

➜ v8 git:(69191fe7d6) eshost -t _test.js
┌────────────────┬───────────┐
│ chakra │ 4 │
├────────────────┼───────────┤
│ javascriptcore │ 4 │
├────────────────┼───────────┤
│ spidermonkey │ 4 │
├────────────────┼───────────┤
│ v8 │ undefined │
├────────────────┼───────────┤
Object.defineProperty(Number.prototype,Symbol.iterator,{
*value({ start = 0, step = 1 } = {}) {
var inc = this > 0 ? step : -step;
for (let i = start; Math.abs(i) <= Math.abs(this); i += inc) {
yield i;
}
},
enumerable: false,
writable: true,
configurable: true
// Based on https://web.archive.org/web/20160310120458/http://wiki.ecmascript.org/doku.php?id=strawman:scoped_object_extensions
// in whatever-extras.js
import Whatever from './whatever.js';
export extension Extensions = Whatever.protoype {
somethingComplex: function() { ... }
}
// in user code
@gsathya
gsathya / closure.js
Created March 7, 2018 00:54
Rethink PrivateName
function observed({kind, key, placement, descriptor, initializer}, privateFieldMaker) {
assert(kind == "field");
assert(placement == "own");
// Create a new anonymous private name as a key for a class element
let { get, set } = privateFieldMaker();
let underlyingDescriptor = { enumerable: false, configurable: false, writable: true };
let underlying = { kind, key: storage, placement, descriptor: underlyingDescriptor, initializer };
return {
kind: "method",
key,
➜ v8 (1f0419da93) ✗ python parse-mem.py
AST Node Count Total Size
VariableProxy 22049 529.2 kb
Literal 5635 90.176 kb
FunctionLiteral 968 77.52 kb
ObjectLiteral::Property 2430 58.344 kb
Assignment 1066 25.608 kb
ObjectLiteral 648 20.768 kb
Call 820 19.704 kb
ExpressionStatement 1191 19.072 kb
class X extends Promise {
static get [Symbol.species]() {
return Y;
}
}
class Y {
constructor(executor) {
return new Proxy(new Promise(executor), {});
}
{
class A {
constructor(arg) {
return arg;
}
}
class C extends A {
#x;
!(function(e) {
function t(r) {
if (n[r]) return n[r].exports;
var o = (n[r] = { exports: {}, id: r, loaded: !1 });
return e[r].call(o.exports, o, o.exports, t), (o.loaded = !0), o.exports;
}
var n = {};
return (t.m = e), (t.c = n), (t.p = "./"), t(0);
})(
(function(e) {
@gsathya
gsathya / transforms.js
Created March 20, 2017 22:23
dynamic import
// Original:
import("module/id").then(...);
// Node.js (synchronous require; easy):
Promise.resolve().then(_ => require("module/id")).then(...);
// AMD (async require; non-standard):
new Promise(resolve => require("module/id", resolve)).then(...);
// Webpack 2 (require.ensure is Webpack-specific):
gunasekaran@gunasekaran-macbookair ~/code/scratch [8:11:32]
> $ node
> var bluebird = require('bluebird');
undefined
> function f() {
... Promise.resolve().then(() => console.log('1'));
... bluebird.resolve().then(() => console.log('2'));
... Promise.resolve().then(() => console.log('3'));
... }
undefined