2019-01-21 14:03:30 -05:00
|
|
|
// Copyright 2018-2019 the Deno authors. All rights reserved. MIT license.
|
2019-01-16 17:57:15 -05:00
|
|
|
import { test, assert } from "./test_util.ts";
|
|
|
|
|
2019-04-21 16:40:10 -04:00
|
|
|
test(function globalThisExists(): void {
|
2019-01-16 17:57:15 -05:00
|
|
|
assert(globalThis != null);
|
|
|
|
});
|
|
|
|
|
2019-04-21 16:40:10 -04:00
|
|
|
test(function windowExists(): void {
|
2019-01-16 17:57:15 -05:00
|
|
|
assert(window != null);
|
|
|
|
});
|
|
|
|
|
2019-04-21 16:40:10 -04:00
|
|
|
test(function windowWindowExists(): void {
|
2019-01-16 17:57:15 -05:00
|
|
|
assert(window.window === window);
|
|
|
|
});
|
|
|
|
|
2019-04-21 16:40:10 -04:00
|
|
|
test(function globalThisEqualsWindow(): void {
|
2019-01-16 17:57:15 -05:00
|
|
|
assert(globalThis === window);
|
|
|
|
});
|
2019-02-05 08:12:58 -05:00
|
|
|
|
2019-04-21 16:40:10 -04:00
|
|
|
test(function DenoNamespaceExists(): void {
|
2019-02-12 10:08:56 -05:00
|
|
|
assert(Deno != null);
|
|
|
|
});
|
|
|
|
|
2019-04-21 16:40:10 -04:00
|
|
|
test(function DenoNamespaceEqualsWindowDeno(): void {
|
2019-02-12 10:08:56 -05:00
|
|
|
assert(Deno === window.Deno);
|
|
|
|
});
|
|
|
|
|
2019-04-21 16:40:10 -04:00
|
|
|
test(function DenoNamespaceIsFrozen(): void {
|
2019-02-12 10:08:56 -05:00
|
|
|
assert(Object.isFrozen(Deno));
|
|
|
|
});
|
|
|
|
|
2019-04-21 16:40:10 -04:00
|
|
|
test(function webAssemblyExists(): void {
|
2019-02-05 08:12:58 -05:00
|
|
|
assert(typeof WebAssembly.compile === "function");
|
|
|
|
});
|
2019-04-19 20:39:54 -04:00
|
|
|
|
2019-04-21 16:40:10 -04:00
|
|
|
test(function DenoNamespaceImmutable(): void {
|
2019-04-19 20:39:54 -04:00
|
|
|
const denoCopy = window.Deno;
|
|
|
|
try {
|
|
|
|
// @ts-ignore
|
|
|
|
Deno = 1;
|
|
|
|
} catch {}
|
|
|
|
assert(denoCopy === Deno);
|
|
|
|
try {
|
|
|
|
// @ts-ignore
|
|
|
|
window.Deno = 1;
|
|
|
|
} catch {}
|
|
|
|
assert(denoCopy === Deno);
|
|
|
|
try {
|
|
|
|
delete window.Deno;
|
|
|
|
} catch {}
|
|
|
|
assert(denoCopy === Deno);
|
|
|
|
|
|
|
|
const { readFile } = Deno;
|
|
|
|
try {
|
|
|
|
// @ts-ignore
|
|
|
|
Deno.readFile = 1;
|
|
|
|
} catch {}
|
|
|
|
assert(readFile === Deno.readFile);
|
|
|
|
try {
|
|
|
|
delete window.Deno.readFile;
|
|
|
|
} catch {}
|
|
|
|
assert(readFile === Deno.readFile);
|
|
|
|
|
|
|
|
// @ts-ignore
|
|
|
|
const { print } = Deno.core;
|
|
|
|
try {
|
|
|
|
// @ts-ignore
|
|
|
|
Deno.core.print = 1;
|
|
|
|
} catch {}
|
|
|
|
// @ts-ignore
|
|
|
|
assert(print === Deno.core.print);
|
|
|
|
try {
|
|
|
|
// @ts-ignore
|
|
|
|
delete Deno.core.print;
|
|
|
|
} catch {}
|
|
|
|
// @ts-ignore
|
|
|
|
assert(print === Deno.core.print);
|
|
|
|
});
|
2019-08-31 15:16:30 -04:00
|
|
|
|
|
|
|
test(async function windowQueueMicrotask(): Promise<void> {
|
|
|
|
let resolve1: () => void | undefined;
|
|
|
|
let resolve2: () => void | undefined;
|
|
|
|
let microtaskDone = false;
|
2019-11-13 13:42:34 -05:00
|
|
|
const p1 = new Promise((res): void => {
|
|
|
|
resolve1 = (): void => {
|
|
|
|
microtaskDone = true;
|
|
|
|
res();
|
|
|
|
};
|
|
|
|
});
|
|
|
|
const p2 = new Promise((res): void => {
|
|
|
|
resolve2 = (): void => {
|
|
|
|
assert(microtaskDone);
|
|
|
|
res();
|
|
|
|
};
|
|
|
|
});
|
2019-08-31 15:16:30 -04:00
|
|
|
window.queueMicrotask(resolve1!);
|
|
|
|
setTimeout(resolve2!, 0);
|
|
|
|
await p1;
|
|
|
|
await p2;
|
|
|
|
});
|