diff options
author | Anonymous <65428781+00ff0000red@users.noreply.github.com> | 2021-01-24 07:05:18 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-01-24 16:05:18 +0100 |
commit | ad60e750d75471d7c7f31f9f40ff233a29aba332 (patch) | |
tree | b47acf39f22948e15d6ec1bdac917b0814fe0dad /runtime/js | |
parent | 2ca637962faeccb92e729dd0dd45b59410074afd (diff) |
fix(runtime/js): use DOMException in Performance#measure (#9142)
Diffstat (limited to 'runtime/js')
-rw-r--r-- | runtime/js/40_performance.js | 28 |
1 files changed, 21 insertions, 7 deletions
diff --git a/runtime/js/40_performance.js b/runtime/js/40_performance.js index d76c3f73a..f8f9ad769 100644 --- a/runtime/js/40_performance.js +++ b/runtime/js/40_performance.js @@ -3,6 +3,7 @@ ((window) => { const { opNow } = window.__bootstrap.timers; const { cloneValue, illegalConstructorKey } = window.__bootstrap.webUtil; + const { requiredArguments } = window.__bootstrap.webUtil; const customInspect = Symbol.for("Deno.customInspect"); let performanceEntries = []; @@ -21,7 +22,10 @@ if (typeof mark === "string") { const entry = findMostRecent(mark, "mark"); if (!entry) { - throw new SyntaxError(`Cannot find mark: "${mark}".`); + throw new DOMException( + `Cannot find mark: "${mark}".`, + "SyntaxError", + ); } return entry.startTime; } @@ -42,9 +46,7 @@ ); } - function now() { - return opNow(); - } + const now = opNow; class PerformanceEntry { #name = ""; @@ -115,10 +117,22 @@ name, options = {}, ) { - if (typeof options !== "object") { - throw new TypeError("Invalid options"); + requiredArguments("PerformanceMark", arguments.length, 1); + + // ensure options is object-ish, or null-ish + switch (typeof options) { + case "object": // includes null + case "function": + case "undefined": { + break; + } + default: { + throw new TypeError("Invalid options"); + } } - const { detail = null, startTime = now() } = options; + + const { detail = null, startTime = now() } = options ?? {}; + super(name, "mark", startTime, 0, illegalConstructorKey); if (startTime < 0) { throw new TypeError("startTime cannot be negative"); |