Last active
August 8, 2019 11:25
-
-
Save sounisi5011/f8d460c214fca27f7e8bb78786aa69c9 to your computer and use it in GitHub Desktop.
Symbol.asyncIterator polyfill
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'), | |
}); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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