1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-12-24 08:09:08 -05:00

fix(npm): add performance.markResourceTiming sham (#19123)

This commit shams "performance.markResourceTiming" API by
using a noop function. It is done to provide compatibility with
"npm:undici" package. We should look into actually implementing
this API properly, but I wanted to unblock support for "undici" and
"astro" for now.

Ref https://github.com/denoland/deno/issues/19065
This commit is contained in:
Bartek Iwańczuk 2023-05-16 05:16:24 +02:00 committed by GitHub
parent ab9a17eeee
commit 78fbc3f3f6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 7 additions and 2 deletions

View file

@ -32,6 +32,7 @@ static NODE_GLOBALS: &[&str] = &[
"setImmediate",
"setInterval",
"setTimeout",
"performance",
];
#[derive(Debug, Clone)]
@ -528,7 +529,7 @@ mod tests {
"var clearTimeout = globalThis.clearTimeout;var console = globalThis.console;",
"var global = globalThis.global;var process = globalThis.process;",
"var setImmediate = globalThis.setImmediate;var setInterval = globalThis.setInterval;",
"var setTimeout = globalThis.setTimeout;\n",
"var setTimeout = globalThis.setTimeout;var performance = globalThis.performance;\n",
"export const x = 1;"
),
NODE_GLOBAL_THIS_NAME,

View file

@ -907,7 +907,7 @@ Module.prototype.require = function (id) {
Module.wrapper = [
// We provide the non-standard APIs in the CommonJS wrapper
// to avoid exposing them in global namespace.
"(function (exports, require, module, __filename, __dirname, globalThis) { const { Buffer, clearImmediate, clearInterval, clearTimeout, console, global, process, setImmediate, setInterval, setTimeout} = globalThis; var window = undefined; (function () {",
"(function (exports, require, module, __filename, __dirname, globalThis) { const { Buffer, clearImmediate, clearInterval, clearTimeout, console, global, process, setImmediate, setInterval, setTimeout, performance} = globalThis; var window = undefined; (function () {",
"\n}).call(this); })",
];
Module.wrap = function (script) {

View file

@ -34,6 +34,7 @@ function initialize(
nodeGlobals.setImmediate = nativeModuleExports["timers"].setImmediate;
nodeGlobals.setInterval = nativeModuleExports["timers"].setInterval;
nodeGlobals.setTimeout = nativeModuleExports["timers"].setTimeout;
nodeGlobals.performance = nativeModuleExports["perf_hooks"].performance;
// add a hidden global for the esm code to use in order to reliably
// get node's globalThis

View file

@ -22,6 +22,8 @@ const performance:
timerify: any;
// deno-lint-ignore no-explicit-any
timeOrigin: any;
// deno-lint-ignore no-explicit-any
markResourceTiming: any;
} = {
clearMarks: (markName: string) => shimPerformance.clearMarks(markName),
eventLoopUtilization: () =>
@ -50,6 +52,7 @@ const performance:
timerify: () => notImplemented("timerify from performance"),
// deno-lint-ignore no-explicit-any
timeOrigin: (shimPerformance as any).timeOrigin,
markResourceTiming: () => {},
// @ts-ignore waiting on update in `deno`, but currently this is
// a circular dependency
toJSON: () => shimPerformance.toJSON(),