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:
parent
1746a3ac69
commit
cdb72afd8d
3 changed files with 14 additions and 0 deletions
|
@ -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];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in a new issue