1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-11-27 16:10:57 -05:00

fix: expose "Deno.memoryUsage()" in worker context (#13293)

This commit is contained in:
Rodney van den Velden 2022-01-09 23:42:14 +01:00 committed by crowlkats
parent bcea8cae21
commit 4b2470135d
No known key found for this signature in database
GPG key ID: A82C9D461FC483E8
3 changed files with 30 additions and 1 deletions

View file

@ -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();
},
});

View file

@ -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,

View file

@ -588,7 +588,6 @@ delete Object.prototype.__proto__;
[internalSymbol]: internals,
resources: core.resources,
close: core.close,
memoryUsage: core.memoryUsage,
...denoNs,
};
ObjectDefineProperties(finalDenoNs, {