Skip to content
Permalink
Browse files

fix `console instanceof Console` (denoland#2073)

  • Loading branch information...
justjavac authored and ry committed Apr 8, 2019
1 parent 1746a3a commit cdb72afd8d91978573f0fa897844aee853983b44
Showing with 14 additions and 0 deletions.
  1. +8 −0 js/console.ts
  2. +5 −0 js/console_test.ts
  3. +1 −0 js/globals.ts
@@ -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;

0 comments on commit cdb72af

Please sign in to comment.
You can’t perform that action at this time.