diff options
author | Kenta Moriuchi <moriken@kimamass.com> | 2024-09-06 19:52:59 +0900 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-09-06 12:52:59 +0200 |
commit | f0a3d206422af3177e0f36ed22802c1ccc6f7654 (patch) | |
tree | 57ad718cc47b7b98c0bbd869d6c070adee3bf30a /ext/web | |
parent | 8ef08f1d294dbe7e3771202084ecbede73ca28aa (diff) |
fix(runtime): use more null proto objects again (#25040)
proceed with #23921
This PR is a preparation for
https://github.com/denoland/deno_lint/pull/1307
---------
Signed-off-by: Kenta Moriuchi <moriken@kimamass.com>
Co-authored-by: Luca Casonato <hello@lcas.dev>
Diffstat (limited to 'ext/web')
-rw-r--r-- | ext/web/01_dom_exception.js | 2 | ||||
-rw-r--r-- | ext/web/02_event.js | 8 | ||||
-rw-r--r-- | ext/web/06_streams.js | 1 | ||||
-rw-r--r-- | ext/web/10_filereader.js | 6 | ||||
-rw-r--r-- | ext/web/12_location.js | 28 | ||||
-rw-r--r-- | ext/web/13_message_port.js | 3 |
6 files changed, 46 insertions, 2 deletions
diff --git a/ext/web/01_dom_exception.js b/ext/web/01_dom_exception.js index f49337db5..38e4d088e 100644 --- a/ext/web/01_dom_exception.js +++ b/ext/web/01_dom_exception.js @@ -186,7 +186,7 @@ const entries = ObjectEntries({ }); for (let i = 0; i < entries.length; ++i) { const { 0: key, 1: value } = entries[i]; - const desc = { value, enumerable: true }; + const desc = { __proto__: null, value, enumerable: true }; ObjectDefineProperty(DOMException, key, desc); ObjectDefineProperty(DOMException.prototype, key, desc); } diff --git a/ext/web/02_event.js b/ext/web/02_event.js index 985578bcc..f031d0aed 100644 --- a/ext/web/02_event.js +++ b/ext/web/02_event.js @@ -392,6 +392,7 @@ const EventPrototype = Event.prototype; // Not spec compliant. The spec defines it as [LegacyUnforgeable] // but doing so has a big performance hit ReflectDefineProperty(Event.prototype, "isTrusted", { + __proto__: null, enumerable: true, get: isTrusted, }); @@ -402,7 +403,10 @@ function defineEnumerableProps( ) { for (let i = 0; i < props.length; ++i) { const prop = props[i]; - ReflectDefineProperty(Ctor.prototype, prop, { enumerable: true }); + ReflectDefineProperty(Ctor.prototype, prop, { + __proto__: null, + enumerable: true, + }); } } @@ -1274,6 +1278,7 @@ class CustomEvent extends Event { const CustomEventPrototype = CustomEvent.prototype; ReflectDefineProperty(CustomEvent.prototype, "detail", { + __proto__: null, enumerable: true, }); @@ -1417,6 +1422,7 @@ function defineEventHandler( ) { // HTML specification section 8.1.7.1 ObjectDefineProperty(emitter, `on${name}`, { + __proto__: null, get() { if (!this[_eventHandlers]) { return null; diff --git a/ext/web/06_streams.js b/ext/web/06_streams.js index 3da3fe36c..1dbf769b2 100644 --- a/ext/web/06_streams.js +++ b/ext/web/06_streams.js @@ -5420,6 +5420,7 @@ class ReadableStream { // TODO(lucacasonato): should be moved to webidl crate ReadableStream.prototype[SymbolAsyncIterator] = ReadableStream.prototype.values; ObjectDefineProperty(ReadableStream.prototype, SymbolAsyncIterator, { + __proto__: null, writable: true, enumerable: false, configurable: true, diff --git a/ext/web/10_filereader.js b/ext/web/10_filereader.js index 05f577114..05b45202d 100644 --- a/ext/web/10_filereader.js +++ b/ext/web/10_filereader.js @@ -454,36 +454,42 @@ webidl.configureInterface(FileReader); const FileReaderPrototype = FileReader.prototype; ObjectDefineProperty(FileReader, "EMPTY", { + __proto__: null, writable: false, enumerable: true, configurable: false, value: 0, }); ObjectDefineProperty(FileReader, "LOADING", { + __proto__: null, writable: false, enumerable: true, configurable: false, value: 1, }); ObjectDefineProperty(FileReader, "DONE", { + __proto__: null, writable: false, enumerable: true, configurable: false, value: 2, }); ObjectDefineProperty(FileReader.prototype, "EMPTY", { + __proto__: null, writable: false, enumerable: true, configurable: false, value: 0, }); ObjectDefineProperty(FileReader.prototype, "LOADING", { + __proto__: null, writable: false, enumerable: true, configurable: false, value: 1, }); ObjectDefineProperty(FileReader.prototype, "DONE", { + __proto__: null, writable: false, enumerable: true, configurable: false, diff --git a/ext/web/12_location.js b/ext/web/12_location.js index a819f6a07..2cda9f719 100644 --- a/ext/web/12_location.js +++ b/ext/web/12_location.js @@ -35,6 +35,7 @@ class Location { url.password = ""; ObjectDefineProperties(this, { hash: { + __proto__: null, get() { return url.hash; }, @@ -47,6 +48,7 @@ class Location { enumerable: true, }, host: { + __proto__: null, get() { return url.host; }, @@ -59,6 +61,7 @@ class Location { enumerable: true, }, hostname: { + __proto__: null, get() { return url.hostname; }, @@ -71,6 +74,7 @@ class Location { enumerable: true, }, href: { + __proto__: null, get() { return url.href; }, @@ -83,12 +87,14 @@ class Location { enumerable: true, }, origin: { + __proto__: null, get() { return url.origin; }, enumerable: true, }, pathname: { + __proto__: null, get() { return url.pathname; }, @@ -101,6 +107,7 @@ class Location { enumerable: true, }, port: { + __proto__: null, get() { return url.port; }, @@ -113,6 +120,7 @@ class Location { enumerable: true, }, protocol: { + __proto__: null, get() { return url.protocol; }, @@ -125,6 +133,7 @@ class Location { enumerable: true, }, search: { + __proto__: null, get() { return url.search; }, @@ -137,6 +146,7 @@ class Location { enumerable: true, }, ancestorOrigins: { + __proto__: null, get() { // TODO(nayeemrmn): Replace with a `DOMStringList` instance. return { @@ -148,6 +158,7 @@ class Location { enumerable: true, }, assign: { + __proto__: null, value: function assign() { throw new DOMException( `Cannot call "location.assign()".`, @@ -157,6 +168,7 @@ class Location { enumerable: true, }, reload: { + __proto__: null, value: function reload() { throw new DOMException( `Cannot call "location.reload()".`, @@ -166,6 +178,7 @@ class Location { enumerable: true, }, replace: { + __proto__: null, value: function replace() { throw new DOMException( `Cannot call "location.replace()".`, @@ -175,12 +188,14 @@ class Location { enumerable: true, }, toString: { + __proto__: null, value: function toString() { return url.href; }, enumerable: true, }, [SymbolFor("Deno.privateCustomInspect")]: { + __proto__: null, value: function (inspect, inspectOptions) { return `${this.constructor.name} ${ inspect({ @@ -203,6 +218,7 @@ class Location { ObjectDefineProperties(Location.prototype, { [SymbolToStringTag]: { + __proto__: null, value: "Location", configurable: true, }, @@ -224,6 +240,7 @@ class WorkerLocation { ObjectDefineProperties(WorkerLocation.prototype, { hash: { + __proto__: null, get() { const url = WeakMapPrototypeGet(workerLocationUrls, this); if (url == null) { @@ -235,6 +252,7 @@ ObjectDefineProperties(WorkerLocation.prototype, { enumerable: true, }, host: { + __proto__: null, get() { const url = WeakMapPrototypeGet(workerLocationUrls, this); if (url == null) { @@ -246,6 +264,7 @@ ObjectDefineProperties(WorkerLocation.prototype, { enumerable: true, }, hostname: { + __proto__: null, get() { const url = WeakMapPrototypeGet(workerLocationUrls, this); if (url == null) { @@ -257,6 +276,7 @@ ObjectDefineProperties(WorkerLocation.prototype, { enumerable: true, }, href: { + __proto__: null, get() { const url = WeakMapPrototypeGet(workerLocationUrls, this); if (url == null) { @@ -268,6 +288,7 @@ ObjectDefineProperties(WorkerLocation.prototype, { enumerable: true, }, origin: { + __proto__: null, get() { const url = WeakMapPrototypeGet(workerLocationUrls, this); if (url == null) { @@ -279,6 +300,7 @@ ObjectDefineProperties(WorkerLocation.prototype, { enumerable: true, }, pathname: { + __proto__: null, get() { const url = WeakMapPrototypeGet(workerLocationUrls, this); if (url == null) { @@ -290,6 +312,7 @@ ObjectDefineProperties(WorkerLocation.prototype, { enumerable: true, }, port: { + __proto__: null, get() { const url = WeakMapPrototypeGet(workerLocationUrls, this); if (url == null) { @@ -301,6 +324,7 @@ ObjectDefineProperties(WorkerLocation.prototype, { enumerable: true, }, protocol: { + __proto__: null, get() { const url = WeakMapPrototypeGet(workerLocationUrls, this); if (url == null) { @@ -312,6 +336,7 @@ ObjectDefineProperties(WorkerLocation.prototype, { enumerable: true, }, search: { + __proto__: null, get() { const url = WeakMapPrototypeGet(workerLocationUrls, this); if (url == null) { @@ -323,6 +348,7 @@ ObjectDefineProperties(WorkerLocation.prototype, { enumerable: true, }, toString: { + __proto__: null, value: function toString() { const url = WeakMapPrototypeGet(workerLocationUrls, this); if (url == null) { @@ -335,10 +361,12 @@ ObjectDefineProperties(WorkerLocation.prototype, { writable: true, }, [SymbolToStringTag]: { + __proto__: null, value: "WorkerLocation", configurable: true, }, [SymbolFor("Deno.privateCustomInspect")]: { + __proto__: null, value: function (inspect, inspectOptions) { return `${this.constructor.name} ${ inspect({ diff --git a/ext/web/13_message_port.js b/ext/web/13_message_port.js index d94ca1382..04697d6aa 100644 --- a/ext/web/13_message_port.js +++ b/ext/web/13_message_port.js @@ -132,14 +132,17 @@ class MessagePort extends EventTarget { constructor() { super(); ObjectDefineProperty(this, MessagePortReceiveMessageOnPortSymbol, { + __proto__: null, value: false, enumerable: false, }); ObjectDefineProperty(this, nodeWorkerThreadCloseCb, { + __proto__: null, value: null, enumerable: false, }); ObjectDefineProperty(this, nodeWorkerThreadCloseCbInvoked, { + __proto__: null, value: false, enumerable: false, }); |