diff options
author | Rodney van den Velden <rodneymichael2002@gmail.com> | 2022-01-09 23:42:14 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-01-09 23:42:14 +0100 |
commit | c487b7ed54a36edcf324005a6ff6e76663544e06 (patch) | |
tree | aedba39a381f1cfc7b98a83e80b12fd149921c8d | |
parent | bd53567acf7d7bb28e51c0137054c5a9d9e19bf1 (diff) |
fix: expose "Deno.memoryUsage()" in worker context (#13293)
-rw-r--r-- | cli/tests/testdata/workers/test.ts | 29 | ||||
-rw-r--r-- | runtime/js/90_deno_ns.js | 1 | ||||
-rw-r--r-- | runtime/js/99_main.js | 1 |
3 files changed, 30 insertions, 1 deletions
diff --git a/cli/tests/testdata/workers/test.ts b/cli/tests/testdata/workers/test.ts index 1c345f80b..43df417fb 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<string, number>, + ), + ["rss", "heapTotal", "heapUsed", "external"], + ); + w.terminate(); + }, +}); diff --git a/runtime/js/90_deno_ns.js b/runtime/js/90_deno_ns.js index b19f6d575..f7f518427 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 190ff24da..3a56d93dc 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, { |