diff --git a/cli/tests/testdata/workers/test.ts b/cli/tests/testdata/workers/test.ts index 1c345f80b7..43df417fb3 100644 --- a/cli/tests/testdata/workers/test.ts +++ b/cli/tests/testdata/workers/test.ts @@ -798,3 +798,32 @@ Deno.test({ worker.terminate(); }, }); + +Deno.test({ + name: "worker Deno.memoryUsage", + fn: async function () { + const w = new Worker( + /** + * Source code + * self.onmessage = function() {self.postMessage(Deno.memoryUsage())} + */ + "data:application/typescript;base64,c2VsZi5vbm1lc3NhZ2UgPSBmdW5jdGlvbigpIHtzZWxmLnBvc3RNZXNzYWdlKERlbm8ubWVtb3J5VXNhZ2UoKSl9", + { type: "module", name: "tsWorker", deno: true }, + ); + + w.postMessage(null); + + const memoryUsagePromise = deferred(); + w.onmessage = function (evt) { + memoryUsagePromise.resolve(evt.data); + }; + + assertEquals( + Object.keys( + await memoryUsagePromise as unknown as Record, + ), + ["rss", "heapTotal", "heapUsed", "external"], + ); + w.terminate(); + }, +}); diff --git a/runtime/js/90_deno_ns.js b/runtime/js/90_deno_ns.js index b19f6d5752..f7f5184272 100644 --- a/runtime/js/90_deno_ns.js +++ b/runtime/js/90_deno_ns.js @@ -29,6 +29,7 @@ makeTempDir: __bootstrap.fs.makeTempDir, makeTempFileSync: __bootstrap.fs.makeTempFileSync, makeTempFile: __bootstrap.fs.makeTempFile, + memoryUsage: core.memoryUsage, mkdirSync: __bootstrap.fs.mkdirSync, mkdir: __bootstrap.fs.mkdir, chdir: __bootstrap.fs.chdir, diff --git a/runtime/js/99_main.js b/runtime/js/99_main.js index 190ff24da5..3a56d93dc4 100644 --- a/runtime/js/99_main.js +++ b/runtime/js/99_main.js @@ -588,7 +588,6 @@ delete Object.prototype.__proto__; [internalSymbol]: internals, resources: core.resources, close: core.close, - memoryUsage: core.memoryUsage, ...denoNs, }; ObjectDefineProperties(finalDenoNs, {