Skip to content

Commit 394862e

Browse files
committed
Test for asyncIterator existance before defining
1 parent c224a82 commit 394862e

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

src/harness/unittests/forAwaitOfEvaluation.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,17 @@ namespace ts {
1818
throw new Error(`Module '${id}' could not be found.`);
1919
}
2020

21+
// Define a custom "Symbol" constructor to attach missing built-in symbols without
22+
// modifying the global "Symbol" constructor
2123
// tslint:disable-next-line:variable-name
2224
const FakeSymbol: SymbolConstructor = ((description?: string) => Symbol(description)) as any;
2325
(<any>FakeSymbol).prototype = Symbol.prototype;
2426
for (const key of Object.getOwnPropertyNames(Symbol)) {
2527
Object.defineProperty(FakeSymbol, key, Object.getOwnPropertyDescriptor(Symbol, key)!);
2628
}
27-
(<any>FakeSymbol).asyncIterator = (<any>FakeSymbol).asyncIterator || Symbol.for("Symbol.asyncIterator");
29+
30+
// Add "asyncIterator" if missing
31+
if (!hasProperty(FakeSymbol, "asyncIterator")) Object.defineProperty(FakeSymbol, "asyncIterator", { value: Symbol.for("Symbol.asyncIterator"), configurable: true });
2832

2933
function evaluate(result: compiler.CompilationResult) {
3034
const output = result.getOutput(sourceFile, "js")!;

0 commit comments

Comments
 (0)