mirror of
https://github.com/denoland/deno.git
synced 2024-12-23 07:44:48 -05:00
feat(std/node): Add "setImmediate" and "clearImmediate" to global scope (#8566)
Co-authored-by: Ben Noordhuis <info@bnoordhuis.nl>
This commit is contained in:
parent
d72310f139
commit
362be01abe
3 changed files with 39 additions and 0 deletions
5
std/node/global.d.ts
vendored
5
std/node/global.d.ts
vendored
|
@ -1,6 +1,7 @@
|
|||
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
|
||||
import { process as processModule } from "./process.ts";
|
||||
import { Buffer as bufferModule } from "./buffer.ts";
|
||||
import timers from "./timers.ts";
|
||||
|
||||
// d.ts files allow us to declare Buffer as a value and as a type
|
||||
// type something = Buffer | something_else; is quite common
|
||||
|
@ -8,6 +9,8 @@ import { Buffer as bufferModule } from "./buffer.ts";
|
|||
type GlobalType = {
|
||||
process: typeof processModule;
|
||||
Buffer: typeof bufferModule;
|
||||
setImmediate: typeof timers.setImmediate;
|
||||
clearImmediate: typeof timers.clearImmediate;
|
||||
};
|
||||
|
||||
declare global {
|
||||
|
@ -23,6 +26,8 @@ declare global {
|
|||
var process: typeof processModule;
|
||||
var Buffer: typeof bufferModule;
|
||||
type Buffer = bufferModule;
|
||||
var setImmediate: typeof timers.setImmediate;
|
||||
var clearImmediate: typeof timers.clearImmediate;
|
||||
}
|
||||
|
||||
export {};
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
/// <reference path="./global.d.ts" />
|
||||
import { process as processModule } from "./process.ts";
|
||||
import { Buffer as bufferModule } from "./buffer.ts";
|
||||
import timers from "./timers.ts";
|
||||
|
||||
Object.defineProperty(globalThis, "global", {
|
||||
value: globalThis,
|
||||
|
@ -24,4 +25,18 @@ Object.defineProperty(globalThis, "Buffer", {
|
|||
configurable: true,
|
||||
});
|
||||
|
||||
Object.defineProperty(globalThis, "setImmediate", {
|
||||
value: timers.setImmediate,
|
||||
enumerable: true,
|
||||
writable: true,
|
||||
configurable: true,
|
||||
});
|
||||
|
||||
Object.defineProperty(globalThis, "clearImmediate", {
|
||||
value: timers.clearImmediate,
|
||||
enumerable: true,
|
||||
writable: true,
|
||||
configurable: true,
|
||||
});
|
||||
|
||||
export {};
|
||||
|
|
|
@ -2,6 +2,7 @@ import "./global.ts";
|
|||
import { assert, assertStrictEquals } from "../testing/asserts.ts";
|
||||
import { Buffer as BufferModule } from "./buffer.ts";
|
||||
import processModule from "./process.ts";
|
||||
import timers from "./timers.ts";
|
||||
|
||||
// Definitions for this are quite delicate
|
||||
// This ensures modifications to the global namespace don't break on TypeScript
|
||||
|
@ -50,3 +51,21 @@ Deno.test("process is correctly defined", () => {
|
|||
assertStrictEquals(window.process, processModule);
|
||||
assert(window.process.arch);
|
||||
});
|
||||
|
||||
Deno.test("setImmediate is correctly defined", () => {
|
||||
// deno-lint-ignore no-undef
|
||||
assertStrictEquals(setImmediate, timers.setImmediate);
|
||||
// deno-lint-ignore no-undef
|
||||
assertStrictEquals(global.setImmediate, timers.setImmediate);
|
||||
assertStrictEquals(globalThis.setImmediate, timers.setImmediate);
|
||||
assertStrictEquals(window.setImmediate, timers.setImmediate);
|
||||
});
|
||||
|
||||
Deno.test("clearImmediate is correctly defined", () => {
|
||||
// deno-lint-ignore no-undef
|
||||
assertStrictEquals(clearImmediate, timers.clearImmediate);
|
||||
// deno-lint-ignore no-undef
|
||||
assertStrictEquals(global.clearImmediate, timers.clearImmediate);
|
||||
assertStrictEquals(globalThis.clearImmediate, timers.clearImmediate);
|
||||
assertStrictEquals(window.clearImmediate, timers.clearImmediate);
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue