diff options
author | Nayeem Rahman <nayeemrmn99@gmail.com> | 2020-09-19 22:30:59 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-09-19 23:30:59 +0200 |
commit | aaa5e6613a739f8e2ff7579b69c2504bcdc37d4f (patch) | |
tree | d6c198b5bc222be4c097e7aa5e9504662c98a974 /cli/rt/40_performance.js | |
parent | 79e5b57663becad3614bce98e31c7d1d494cb50d (diff) |
fix(cli/rt): make some web API constructors illegal at runtime (#7468)
Diffstat (limited to 'cli/rt/40_performance.js')
-rw-r--r-- | cli/rt/40_performance.js | 24 |
1 files changed, 21 insertions, 3 deletions
diff --git a/cli/rt/40_performance.js b/cli/rt/40_performance.js index a785d23b1..b921ca43a 100644 --- a/cli/rt/40_performance.js +++ b/cli/rt/40_performance.js @@ -2,7 +2,7 @@ ((window) => { const { opNow } = window.__bootstrap.timers; - const { cloneValue } = window.__bootstrap.webUtil; + const { cloneValue, illegalConstructorKey } = window.__bootstrap.webUtil; const customInspect = Symbol.for("Deno.customInspect"); let performanceEntries = []; @@ -74,7 +74,11 @@ entryType, startTime, duration, + key, ) { + if (key != illegalConstructorKey) { + throw new TypeError("Illegal constructor."); + } this.#name = name; this.#entryType = entryType; this.#startTime = startTime; @@ -110,7 +114,7 @@ name, { detail = null, startTime = now() } = {}, ) { - super(name, "mark", startTime, 0); + super(name, "mark", startTime, 0, illegalConstructorKey); if (startTime < 0) { throw new TypeError("startTime cannot be negative"); } @@ -152,8 +156,12 @@ startTime, duration, detail = null, + key, ) { - super(name, "measure", startTime, duration); + if (key != illegalConstructorKey) { + throw new TypeError("Illegal constructor."); + } + super(name, "measure", startTime, duration, illegalConstructorKey); this.#detail = cloneValue(detail); } @@ -177,6 +185,12 @@ } class Performance { + constructor(key) { + if (key != illegalConstructorKey) { + throw new TypeError("Illegal constructor."); + } + } + clearMarks(markName) { if (markName == null) { performanceEntries = performanceEntries.filter( @@ -302,6 +316,7 @@ typeof startOrMeasureOptions === "object" ? startOrMeasureOptions.detail ?? null : null, + illegalConstructorKey, ); performanceEntries.push(entry); return entry; @@ -312,10 +327,13 @@ } } + const performance = new Performance(illegalConstructorKey); + window.__bootstrap.performance = { PerformanceEntry, PerformanceMark, PerformanceMeasure, Performance, + performance, }; })(this); |