From 1073e2b8c818da3fb56fb3d4786b5cfc3742a41f Mon Sep 17 00:00:00 2001 From: Timur Shemsedinov Date: Mon, 31 Jul 2023 14:59:36 +0300 Subject: [PATCH] Add globals available in all supported node versions PR-URL: https://github.com/metarhia/metavm/pull/109 --- metavm.js | 6 ++++++ test/unit.js | 18 ++++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/metavm.js b/metavm.js index 0d54f2b..d1eef50 100644 --- a/metavm.js +++ b/metavm.js @@ -25,6 +25,12 @@ const EMPTY_CONTEXT = vm.createContext(Object.freeze({}), CONTEXT_OPTIONS); const COMMON_CONTEXT = vm.createContext( Object.freeze({ + AbortController, + Event, + EventTarget, + MessageChannel, + MessageEvent, + MessagePort, Buffer, URL, URLSearchParams, diff --git a/test/unit.js b/test/unit.js index 6369a42..abd6f2c 100644 --- a/test/unit.js +++ b/test/unit.js @@ -220,6 +220,24 @@ metatests.test('Create common context', async (test) => { test.strictSame(typeof context, 'object'); test.strictSame(context.console, console); test.strictSame(context.global, undefined); + test.strictSame(context.AbortController, AbortController); + test.strictSame(context.Buffer, Buffer); + test.strictSame(context.Event, Event); + test.strictSame(context.EventTarget, EventTarget); + test.strictSame(context.MessageChannel, MessageChannel); + test.strictSame(context.MessageEvent, MessageEvent); + test.strictSame(context.MessagePort, MessagePort); + test.strictSame(context.URL, URL); + test.strictSame(context.URLSearchParams, URLSearchParams); + test.strictSame(context.TextDecoder, TextDecoder); + test.strictSame(context.TextEncoder, TextEncoder); + test.strictSame(context.queueMicrotask, queueMicrotask); + test.strictSame(context.setTimeout, setTimeout); + test.strictSame(context.setImmediate, setImmediate); + test.strictSame(context.setInterval, setInterval); + test.strictSame(context.clearTimeout, clearTimeout); + test.strictSame(context.clearImmediate, clearImmediate); + test.strictSame(context.clearInterval, clearInterval); test.end(); });