2021-01-11 12:13:41 -05:00
|
|
|
// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license.
|
2021-09-02 11:38:19 -04:00
|
|
|
// deno-lint-ignore-file no-window-prefix
|
2020-09-27 06:22:32 -04:00
|
|
|
import { assert, unitTest } from "./test_util.ts";
|
2019-01-16 17:57:15 -05:00
|
|
|
|
2021-08-05 07:08:58 -04:00
|
|
|
unitTest(function globalThisExists() {
|
2019-01-16 17:57:15 -05:00
|
|
|
assert(globalThis != null);
|
|
|
|
});
|
|
|
|
|
2021-08-05 07:08:58 -04:00
|
|
|
unitTest(function noInternalGlobals() {
|
2020-09-04 07:52:19 -04:00
|
|
|
// globalThis.__bootstrap should not be there.
|
|
|
|
for (const key of Object.keys(globalThis)) {
|
|
|
|
assert(!key.startsWith("_"));
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2021-08-05 07:08:58 -04:00
|
|
|
unitTest(function windowExists() {
|
2019-01-16 17:57:15 -05:00
|
|
|
assert(window != null);
|
|
|
|
});
|
|
|
|
|
2021-08-05 07:08:58 -04:00
|
|
|
unitTest(function selfExists() {
|
2020-02-26 05:49:38 -05:00
|
|
|
assert(self != null);
|
|
|
|
});
|
|
|
|
|
2021-08-05 07:08:58 -04:00
|
|
|
unitTest(function windowWindowExists() {
|
2019-01-16 17:57:15 -05:00
|
|
|
assert(window.window === window);
|
|
|
|
});
|
|
|
|
|
2021-08-05 07:08:58 -04:00
|
|
|
unitTest(function windowSelfExists() {
|
2020-02-26 05:49:38 -05:00
|
|
|
assert(window.self === window);
|
|
|
|
});
|
|
|
|
|
2021-08-05 07:08:58 -04:00
|
|
|
unitTest(function globalThisEqualsWindow() {
|
2019-01-16 17:57:15 -05:00
|
|
|
assert(globalThis === window);
|
|
|
|
});
|
2019-02-05 08:12:58 -05:00
|
|
|
|
2021-08-05 07:08:58 -04:00
|
|
|
unitTest(function globalThisEqualsSelf() {
|
2020-02-26 05:49:38 -05:00
|
|
|
assert(globalThis === self);
|
|
|
|
});
|
|
|
|
|
2021-08-05 07:08:58 -04:00
|
|
|
unitTest(function globalThisInstanceofWindow() {
|
2020-10-11 18:04:43 -04:00
|
|
|
assert(globalThis instanceof Window);
|
|
|
|
});
|
|
|
|
|
2021-08-05 07:08:58 -04:00
|
|
|
unitTest(function globalThisConstructorLength() {
|
2020-11-14 07:10:23 -05:00
|
|
|
assert(globalThis.constructor.length === 0);
|
|
|
|
});
|
|
|
|
|
2021-08-05 07:08:58 -04:00
|
|
|
unitTest(function globalThisInstanceofEventTarget() {
|
2020-10-11 18:04:43 -04:00
|
|
|
assert(globalThis instanceof EventTarget);
|
|
|
|
});
|
|
|
|
|
2021-08-05 07:08:58 -04:00
|
|
|
unitTest(function navigatorInstanceofNavigator() {
|
2021-03-08 07:27:49 -05:00
|
|
|
// TODO(nayeemrmn): Add `Navigator` to deno_lint globals.
|
|
|
|
// deno-lint-ignore no-undef
|
|
|
|
assert(navigator instanceof Navigator);
|
|
|
|
});
|
|
|
|
|
2021-08-05 07:08:58 -04:00
|
|
|
unitTest(function DenoNamespaceExists() {
|
2019-02-12 10:08:56 -05:00
|
|
|
assert(Deno != null);
|
|
|
|
});
|
|
|
|
|
2021-08-05 07:08:58 -04:00
|
|
|
unitTest(function DenoNamespaceEqualsWindowDeno() {
|
2019-02-12 10:08:56 -05:00
|
|
|
assert(Deno === window.Deno);
|
|
|
|
});
|
|
|
|
|
2021-08-05 07:08:58 -04:00
|
|
|
unitTest(function DenoNamespaceIsNotFrozen() {
|
2021-06-21 17:17:35 -04:00
|
|
|
assert(!Object.isFrozen(Deno));
|
2019-02-12 10:08:56 -05:00
|
|
|
});
|
|
|
|
|
2021-08-05 07:08:58 -04:00
|
|
|
unitTest(function webAssemblyExists() {
|
2019-02-05 08:12:58 -05:00
|
|
|
assert(typeof WebAssembly.compile === "function");
|
|
|
|
});
|
2019-04-19 20:39:54 -04:00
|
|
|
|
2020-06-02 00:24:44 -04:00
|
|
|
declare global {
|
|
|
|
namespace Deno {
|
2020-06-19 05:05:37 -04:00
|
|
|
// deno-lint-ignore no-explicit-any
|
2020-06-02 00:24:44 -04:00
|
|
|
var core: any;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-06-21 17:17:35 -04:00
|
|
|
unitTest(function DenoNamespaceConfigurable() {
|
|
|
|
const desc = Object.getOwnPropertyDescriptor(globalThis, "Deno");
|
|
|
|
assert(desc);
|
|
|
|
assert(desc.configurable);
|
|
|
|
assert(!desc.writable);
|
|
|
|
});
|
2019-04-19 20:39:54 -04:00
|
|
|
|
2021-08-05 07:08:58 -04:00
|
|
|
unitTest(function DenoCoreNamespaceIsImmutable() {
|
2019-04-19 20:39:54 -04:00
|
|
|
const { print } = Deno.core;
|
|
|
|
try {
|
|
|
|
Deno.core.print = 1;
|
2020-06-19 05:05:37 -04:00
|
|
|
} catch {
|
|
|
|
// pass
|
|
|
|
}
|
2019-04-19 20:39:54 -04:00
|
|
|
assert(print === Deno.core.print);
|
|
|
|
try {
|
|
|
|
delete Deno.core.print;
|
2020-06-19 05:05:37 -04:00
|
|
|
} catch {
|
|
|
|
// pass
|
|
|
|
}
|
2019-04-19 20:39:54 -04:00
|
|
|
assert(print === Deno.core.print);
|
|
|
|
});
|
2019-08-31 15:16:30 -04:00
|
|
|
|
2021-08-05 07:08:58 -04:00
|
|
|
unitTest(async function windowQueueMicrotask() {
|
2019-08-31 15:16:30 -04:00
|
|
|
let resolve1: () => void | undefined;
|
|
|
|
let resolve2: () => void | undefined;
|
|
|
|
let microtaskDone = false;
|
2021-08-05 07:08:58 -04:00
|
|
|
const p1 = new Promise<void>((res) => {
|
|
|
|
resolve1 = () => {
|
2019-11-13 13:42:34 -05:00
|
|
|
microtaskDone = true;
|
|
|
|
res();
|
|
|
|
};
|
|
|
|
});
|
2021-08-05 07:08:58 -04:00
|
|
|
const p2 = new Promise<void>((res) => {
|
|
|
|
resolve2 = () => {
|
2019-11-13 13:42:34 -05:00
|
|
|
assert(microtaskDone);
|
|
|
|
res();
|
|
|
|
};
|
|
|
|
});
|
2019-08-31 15:16:30 -04:00
|
|
|
window.queueMicrotask(resolve1!);
|
|
|
|
setTimeout(resolve2!, 0);
|
|
|
|
await p1;
|
|
|
|
await p2;
|
|
|
|
});
|