Skip to content

Instantly share code, notes, and snippets.

@sounisi5011
Last active August 8, 2019 11:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sounisi5011/f8d460c214fca27f7e8bb78786aa69c9 to your computer and use it in GitHub Desktop.
Save sounisi5011/f8d460c214fca27f7e8bb78786aa69c9 to your computer and use it in GitHub Desktop.
Symbol.asyncIterator polyfill
if(!Symbol.asyncIterator) {
Object.defineProperty(Symbol, 'asyncIterator', {
enumerable: false, // This line is optional
configurable: false, // This line is optional
writable: false, // This line is optional
value: Symbol('Symbol.asyncIterator'),
});
}
const assert = require('assert');
function equal(value, expected) {
assert.strictEqual(value, expected);
}
function truthy(value) {
assert.ok(value);
}
function falsy(value) {
assert.ifError(value);
}
equal(typeof Symbol.asyncIterator, 'symbol');
/* @see https://www.ecma-international.org/ecma-262/9.0/#table-1 */
equal(Symbol.asyncIterator.toString(), 'Symbol(Symbol.asyncIterator)');
falsy(Symbol.keyFor(Symbol.asyncIterator));
const desc = Object.getOwnPropertyDescriptor(Symbol, 'asyncIterator');
truthy(desc);
/* @see https://www.ecma-international.org/ecma-262/9.0/#sec-symbol.asynciterator */
equal(desc.configurable, false);
equal(desc.enumerable, false);
equal(desc.writable, false);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment