Skip to content

Instantly share code, notes, and snippets.

🐍
code code code code

Gus Caplan devsnek

🐍
code code code code
Block or report user

Report or block devsnek

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View x.js
new Promise((resolve, reject) => {
const timeout = setTimeout(() => {
clearInterval(interval);
reject(new Error('timed out'));
}, 5000);
const interval = setInterval(() => {
const x = doSomething();
if (x !== undefined) {
clearInterval(interval);
clearTimeout(timeout);
View WeakValueMap.mjs
const KEYS = 1;
const VALUES = 2;
const KEYS_VALUES = 3;
export default class WeakValueMap {
#map = new Map();
#group = new FinalizationGroup((iterator) => {
for (const key of iterator) {
this.#map.delete(key);
}
View ZoneWithPromiseTracking.mjs
import EventEmitter from 'events';
import {
AsyncResource,
executionAsyncId,
createHook,
} from 'async_hooks';
const zones = new Map();
export default class Zone extends EventEmitter {
View Zone.js
'use strict';
const {
AsyncResource,
executionAsyncId,
createHook,
} = require('async_hooks');
const EventEmitter = require('events');
const util = require('util');
View react_hooks_but_not_broken.js
'use strict';
const stateMap = new WeakMap();
function useState(key, init) {
const update = (v) => stateMap.set(key, v);
if (stateMap.has(key)) {
return [stateMap.get(key), update];
}
stateMap.set(key, init);
return [init, update];
View step.diff
diff --git a/.eslintrc.js b/.eslintrc.js
index fee700a..37d2a52 100644
--- a/.eslintrc.js
+++ b/.eslintrc.js
@@ -29,6 +29,8 @@ module.exports = {
'no-restricted-syntax': 'off',
'no-use-before-define': 'off',
'no-continue': 'off',
+ 'no-extra-parens': 'error',
+ 'require-yield': 'off',
View IteratorStuff.js
'use strict';
const IteratorPrototype = Object.getPrototypeOf(
Object.getPrototypeOf(
[][Symbol.iterator](),
),
);
const AsyncIteratorPrototype = Object.getPrototypeOf(
Object.getPrototypeOf(
View eshost.js
'use strict';
const {
initializeAgent,
inspect,
Realm,
Value,
Descriptor,
Abstract,
Completion,
View Zone.js
'use strict';
const {
AsyncResource,
executionAsyncId,
createHook,
} = require('async_hooks');
const EventEmitter = require('events');
const util = require('util');
View js_references.diff
diff --git a/src/abstract-ops/testing-comparison.mjs b/src/abstract-ops/testing-comparison.mjs
index c03de47..032d52f 100644
--- a/src/abstract-ops/testing-comparison.mjs
+++ b/src/abstract-ops/testing-comparison.mjs
@@ -38,6 +38,8 @@ export function RequireObjectCoercible(argument) {
return surroundingAgent.Throw('TypeError', 'undefined cannot be convered to an object');
case 'Null':
return surroundingAgent.Throw('TypeError', 'null cannot be converted to an object');
+ case 'ReferenceValue':
+ return surroundingAgent.Throw('TypeError', 'reference cannot be converted to an object');
You can’t perform that action at this time.