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:
parent
bcea8cae21
commit
4b2470135d
3 changed files with 30 additions and 1 deletions
29
cli/tests/testdata/workers/test.ts
vendored
29
cli/tests/testdata/workers/test.ts
vendored
|
@ -798,3 +798,32 @@ Deno.test({
|
||||||
worker.terminate();
|
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();
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
|
@ -29,6 +29,7 @@
|
||||||
makeTempDir: __bootstrap.fs.makeTempDir,
|
makeTempDir: __bootstrap.fs.makeTempDir,
|
||||||
makeTempFileSync: __bootstrap.fs.makeTempFileSync,
|
makeTempFileSync: __bootstrap.fs.makeTempFileSync,
|
||||||
makeTempFile: __bootstrap.fs.makeTempFile,
|
makeTempFile: __bootstrap.fs.makeTempFile,
|
||||||
|
memoryUsage: core.memoryUsage,
|
||||||
mkdirSync: __bootstrap.fs.mkdirSync,
|
mkdirSync: __bootstrap.fs.mkdirSync,
|
||||||
mkdir: __bootstrap.fs.mkdir,
|
mkdir: __bootstrap.fs.mkdir,
|
||||||
chdir: __bootstrap.fs.chdir,
|
chdir: __bootstrap.fs.chdir,
|
||||||
|
|
|
@ -588,7 +588,6 @@ delete Object.prototype.__proto__;
|
||||||
[internalSymbol]: internals,
|
[internalSymbol]: internals,
|
||||||
resources: core.resources,
|
resources: core.resources,
|
||||||
close: core.close,
|
close: core.close,
|
||||||
memoryUsage: core.memoryUsage,
|
|
||||||
...denoNs,
|
...denoNs,
|
||||||
};
|
};
|
||||||
ObjectDefineProperties(finalDenoNs, {
|
ObjectDefineProperties(finalDenoNs, {
|
||||||
|
|
Loading…
Reference in a new issue