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

fix(runtime/js): use DOMException in Performance#measure (#9142)

This commit is contained in:
Anonymous 2021-01-24 07:05:18 -08:00 committed by GitHub
parent 2ca637962f
commit ad60e750d7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 22 additions and 17 deletions

View file

@ -164,16 +164,7 @@
"mark-errors", "mark-errors",
"mark-measure-return-objects", "mark-measure-return-objects",
"mark.any", "mark.any",
{ "measure_syntax_err",
"name": "measure_syntax_err",
"expectFail": [
// TODO(lucacasonato): re-enable when #9009 is fixed.
"self.performance.measure(\"measure\", \"mark\"), where \"mark\" is a non-existent mark, throws a SyntaxError exception.",
"self.performance.measure(\"measure\", \"mark\", \"existing_mark\"), where \"mark\" is a non-existent mark, throws a SyntaxError exception.",
"self.performance.measure(\"measure\", \"existing_mark\", \"mark\"), where \"mark\" is a non-existent mark, throws a SyntaxError exception.",
"self.performance.measure(\"measure\", \"mark\", \"mark\"), where \"mark\" is a non-existent mark, throws a SyntaxError exception."
]
},
"measure-l3", "measure-l3",
"structured-serialize-detail", "structured-serialize-detail",
"user_timing_exists" "user_timing_exists"

View file

@ -3,6 +3,7 @@
((window) => { ((window) => {
const { opNow } = window.__bootstrap.timers; const { opNow } = window.__bootstrap.timers;
const { cloneValue, illegalConstructorKey } = window.__bootstrap.webUtil; const { cloneValue, illegalConstructorKey } = window.__bootstrap.webUtil;
const { requiredArguments } = window.__bootstrap.webUtil;
const customInspect = Symbol.for("Deno.customInspect"); const customInspect = Symbol.for("Deno.customInspect");
let performanceEntries = []; let performanceEntries = [];
@ -21,7 +22,10 @@
if (typeof mark === "string") { if (typeof mark === "string") {
const entry = findMostRecent(mark, "mark"); const entry = findMostRecent(mark, "mark");
if (!entry) { if (!entry) {
throw new SyntaxError(`Cannot find mark: "${mark}".`); throw new DOMException(
`Cannot find mark: "${mark}".`,
"SyntaxError",
);
} }
return entry.startTime; return entry.startTime;
} }
@ -42,9 +46,7 @@
); );
} }
function now() { const now = opNow;
return opNow();
}
class PerformanceEntry { class PerformanceEntry {
#name = ""; #name = "";
@ -115,10 +117,22 @@
name, name,
options = {}, options = {},
) { ) {
if (typeof options !== "object") { requiredArguments("PerformanceMark", arguments.length, 1);
throw new TypeError("Invalid options");
// 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); super(name, "mark", startTime, 0, illegalConstructorKey);
if (startTime < 0) { if (startTime < 0) {
throw new TypeError("startTime cannot be negative"); throw new TypeError("startTime cannot be negative");