blob: d989ab54a9564f95eb1d3844b7e2f3c957cc175e (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
|
// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license.
// deno-lint-ignore-file no-window-prefix
import { assert, unitTest } from "./test_util.ts";
unitTest(function globalThisExists() {
assert(globalThis != null);
});
unitTest(function noInternalGlobals() {
// globalThis.__bootstrap should not be there.
for (const key of Object.keys(globalThis)) {
assert(!key.startsWith("_"));
}
});
unitTest(function windowExists() {
assert(window != null);
});
unitTest(function selfExists() {
assert(self != null);
});
unitTest(function windowWindowExists() {
assert(window.window === window);
});
unitTest(function windowSelfExists() {
assert(window.self === window);
});
unitTest(function globalThisEqualsWindow() {
assert(globalThis === window);
});
unitTest(function globalThisEqualsSelf() {
assert(globalThis === self);
});
unitTest(function globalThisInstanceofWindow() {
assert(globalThis instanceof Window);
});
unitTest(function globalThisConstructorLength() {
assert(globalThis.constructor.length === 0);
});
unitTest(function globalThisInstanceofEventTarget() {
assert(globalThis instanceof EventTarget);
});
unitTest(function navigatorInstanceofNavigator() {
// TODO(nayeemrmn): Add `Navigator` to deno_lint globals.
// deno-lint-ignore no-undef
assert(navigator instanceof Navigator);
});
unitTest(function DenoNamespaceExists() {
assert(Deno != null);
});
unitTest(function DenoNamespaceEqualsWindowDeno() {
assert(Deno === window.Deno);
});
unitTest(function DenoNamespaceIsNotFrozen() {
assert(!Object.isFrozen(Deno));
});
unitTest(function webAssemblyExists() {
assert(typeof WebAssembly.compile === "function");
});
declare global {
namespace Deno {
// deno-lint-ignore no-explicit-any
var core: any;
}
}
unitTest(function DenoNamespaceConfigurable() {
const desc = Object.getOwnPropertyDescriptor(globalThis, "Deno");
assert(desc);
assert(desc.configurable);
assert(!desc.writable);
});
unitTest(function DenoCoreNamespaceIsImmutable() {
const { print } = Deno.core;
try {
Deno.core.print = 1;
} catch {
// pass
}
assert(print === Deno.core.print);
try {
delete Deno.core.print;
} catch {
// pass
}
assert(print === Deno.core.print);
});
unitTest(async function windowQueueMicrotask() {
let resolve1: () => void | undefined;
let resolve2: () => void | undefined;
let microtaskDone = false;
const p1 = new Promise<void>((res) => {
resolve1 = () => {
microtaskDone = true;
res();
};
});
const p2 = new Promise<void>((res) => {
resolve2 = () => {
assert(microtaskDone);
res();
};
});
window.queueMicrotask(resolve1!);
setTimeout(resolve2!, 0);
await p1;
await p2;
});
|