1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-11-29 16:30:56 -05:00

fix console instanceof Console (#2073)

This commit is contained in:
迷渡 2019-04-08 21:25:01 +08:00 committed by Ryan Dahl
parent 1746a3ac69
commit cdb72afd8d
3 changed files with 14 additions and 0 deletions

View file

@ -483,14 +483,18 @@ type PrintFunc = (x: string, isErr?: boolean) => void;
const countMap = new Map<string, number>();
const timerMap = new Map<string, number>();
export const isConsoleInstance = Symbol("isConsoleInstance");
export class Console {
indentLevel: number;
collapsedAt: number | null;
[isConsoleInstance]: boolean = false;
/** @internal */
constructor(private printFunc: PrintFunc) {
this.indentLevel = 0;
this.collapsedAt = null;
this[isConsoleInstance] = true;
}
/** Writes the arguments to stdout */
@ -730,6 +734,10 @@ export class Console {
cursorTo(stdout, 0, 0);
clearScreenDown(stdout);
};
static [Symbol.hasInstance](instance: Console): boolean {
return instance[isConsoleInstance];
}
}
/**

View file

@ -20,6 +20,11 @@ test(function consoleShouldBeANamespace() {
assertEquals(prototype2, Object.prototype);
});
test(function consoleHasRightInstance() {
assert(console instanceof Console);
assertEquals({} instanceof Console, false);
});
test(function consoleTestAssertShouldNotThrowError() {
console.assert(true);

View file

@ -52,6 +52,7 @@ Object.freeze(window.Deno);
// by ObjectCreate(%ObjectPrototype%), instead of %ObjectPrototype%.
let console = Object.create({}) as consoleTypes.Console;
Object.assign(console, new consoleTypes.Console(core.print));
console[consoleTypes.isConsoleInstance] = true;
// Globally available functions and object instances.
window.atob = textEncoding.atob;