summaryrefslogtreecommitdiff
path: root/cli/rt
diff options
context:
space:
mode:
Diffstat (limited to 'cli/rt')
-rw-r--r--cli/rt/01_web_util.js3
-rw-r--r--cli/rt/40_performance.js24
-rw-r--r--cli/rt/40_permissions.js26
-rw-r--r--cli/rt/99_main.js2
4 files changed, 46 insertions, 9 deletions
diff --git a/cli/rt/01_web_util.js b/cli/rt/01_web_util.js
index 1b7f7b83a..ee8992eb2 100644
--- a/cli/rt/01_web_util.js
+++ b/cli/rt/01_web_util.js
@@ -1,6 +1,8 @@
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
((window) => {
+ const illegalConstructorKey = Symbol("illegalConstructorKey");
+
function isInvalidDate(x) {
return isNaN(x.getTime());
}
@@ -146,6 +148,7 @@
}
window.__bootstrap.webUtil = {
+ illegalConstructorKey,
isInvalidDate,
requiredArguments,
immutableDefine,
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);
diff --git a/cli/rt/40_permissions.js b/cli/rt/40_permissions.js
index 983d0895a..982e4c842 100644
--- a/cli/rt/40_permissions.js
+++ b/cli/rt/40_permissions.js
@@ -2,6 +2,7 @@
((window) => {
const core = window.Deno.core;
+ const { illegalConstructorKey } = window.__bootstrap.webUtil;
function opQuery(desc) {
return core.jsonOpSync("op_query_permission", desc).state;
@@ -16,30 +17,45 @@
}
class PermissionStatus {
- constructor(state) {
+ constructor(state, key) {
+ if (key != illegalConstructorKey) {
+ throw new TypeError("Illegal constructor.");
+ }
this.state = state;
}
// TODO(kt3k): implement onchange handler
}
class Permissions {
+ constructor(key) {
+ if (key != illegalConstructorKey) {
+ throw new TypeError("Illegal constructor.");
+ }
+ }
+
query(desc) {
const state = opQuery(desc);
- return Promise.resolve(new PermissionStatus(state));
+ return Promise.resolve(
+ new PermissionStatus(state, illegalConstructorKey),
+ );
}
revoke(desc) {
const state = opRevoke(desc);
- return Promise.resolve(new PermissionStatus(state));
+ return Promise.resolve(
+ new PermissionStatus(state, illegalConstructorKey),
+ );
}
request(desc) {
const state = opRequest(desc);
- return Promise.resolve(new PermissionStatus(state));
+ return Promise.resolve(
+ new PermissionStatus(state, illegalConstructorKey),
+ );
}
}
- const permissions = new Permissions();
+ const permissions = new Permissions(illegalConstructorKey);
window.__bootstrap.permissions = {
permissions,
diff --git a/cli/rt/99_main.js b/cli/rt/99_main.js
index a15de081c..40ea8434b 100644
--- a/cli/rt/99_main.js
+++ b/cli/rt/99_main.js
@@ -235,7 +235,7 @@ delete Object.prototype.__proto__;
crypto: util.readOnly(crypto),
dispatchEvent: util.readOnly(EventTarget.prototype.dispatchEvent),
fetch: util.writable(fetch.fetch),
- performance: util.writable(new performance.Performance()),
+ performance: util.writable(performance.performance),
removeEventListener: util.readOnly(
EventTarget.prototype.removeEventListener,
),