Skip to content

Commit 69787a2

Browse files
authored
Merge pull request #22852 from github/copilot/fix-storage-event-constructor
Align JavaScript StorageEvent externs with current Web IDL
2 parents ba95904 + 55dc322 commit 69787a2

5 files changed

Lines changed: 60 additions & 11 deletions

File tree

‎javascript/externs/web/webstorage.js‎

Lines changed: 34 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -97,16 +97,40 @@ WindowLocalStorage.prototype.localStorage;
9797
*/
9898
Window.prototype.localStorage;
9999

100+
/**
101+
* @record
102+
* @extends {EventInit}
103+
* @see https://html.spec.whatwg.org/multipage/webstorage.html#dictdef-storageeventinit
104+
*/
105+
function StorageEventInit() {}
106+
107+
/** @type {(?string|undefined)} */
108+
StorageEventInit.prototype.key;
109+
110+
/** @type {(?string|undefined)} */
111+
StorageEventInit.prototype.oldValue;
112+
113+
/** @type {(?string|undefined)} */
114+
StorageEventInit.prototype.newValue;
115+
116+
/** @type {(string|undefined)} */
117+
StorageEventInit.prototype.url;
118+
119+
/** @type {(?Storage|undefined)} */
120+
StorageEventInit.prototype.storageArea;
121+
100122
/**
101123
* This is the storage event interface.
102-
* @see http://www.w3.org/TR/2011/CR-webstorage-20111208/#the-storage-event
124+
* @see https://html.spec.whatwg.org/multipage/webstorage.html#the-storageevent-interface
103125
* @extends {Event}
104126
* @constructor
127+
* @param {string} type
128+
* @param {StorageEventInit=} opt_eventInitDict
105129
*/
106-
function StorageEvent() {}
130+
function StorageEvent(type, opt_eventInitDict) {}
107131

108132
/**
109-
* @type {string}
133+
* @type {?string}
110134
*/
111135
StorageEvent.prototype.key;
112136

@@ -132,17 +156,16 @@ StorageEvent.prototype.storageArea;
132156

133157
/**
134158
* @param {string} typeArg
135-
* @param {boolean} canBubbleArg
136-
* @param {boolean} cancelableArg
137-
* @param {string} keyArg
138-
* @param {?string} oldValueArg
139-
* @param {?string} newValueArg
140-
* @param {string} urlArg
141-
* @param {?Storage} storageAreaArg
159+
* @param {boolean=} canBubbleArg
160+
* @param {boolean=} cancelableArg
161+
* @param {?string=} keyArg
162+
* @param {?string=} oldValueArg
163+
* @param {?string=} newValueArg
164+
* @param {string=} urlArg
165+
* @param {?Storage=} storageAreaArg
142166
* @return {void}
143167
*/
144168
StorageEvent.prototype.initStorageEvent = function(typeArg, canBubbleArg,
145169
cancelableArg, keyArg,
146170
oldValueArg, newValueArg,
147171
urlArg, storageAreaArg) {};
148-
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
---
2+
category: minorAnalysis
3+
---
4+
* Valid arguments passed to the `StorageEvent` constructor no longer produce alerts from `js/superfluous-trailing-arguments`.

‎javascript/ql/test/query-tests/LanguageFeatures/SpuriousArguments/SpuriousArguments.expected‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
| reflection.js:6:15:6:15 | 1 | Superfluous argument passed to $@. | reflection.js:1:1:1:23 | functio ... eturn;} | function f0 |
88
| reflection.js:7:15:7:18 | 1 | Superfluous arguments passed to $@. | reflection.js:1:1:1:23 | functio ... eturn;} | function f0 |
99
| reflection.js:12:18:12:18 | 2 | Superfluous argument passed to $@. | reflection.js:2:1:2:24 | functio ... eturn;} | function f1 |
10+
| storageEvent.js:14:33:14:39 | "extra" | Superfluous argument passed to $@. | externs.js:55:1:55:49 | functio ... ict) {} | function StorageEvent |
1011
| thisparameter.ts:4:11:4:12 | 45 | Superfluous argument passed to $@. | thisparameter.ts:1:1:1:45 | functio ... eturn;} | function foo |
1112
| transformstream.ts:15:33:15:34 | {} | Superfluous argument passed to $@. | externs.js:48:1:48:76 | functio ... egy) {} | function TransformStream |
1213
| tst.js:10:3:10:5 | g() | Superfluous argument passed to $@. | tst.js:1:1:4:1 | functio ... x+19;\\n} | function f |

‎javascript/ql/test/query-tests/LanguageFeatures/SpuriousArguments/externs.js‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,4 +47,11 @@ Number.parseFloat = function(num) {};
4747
*/
4848
function TransformStream(transformer, writableStrategy, readableStrategy) {}
4949

50+
/**
51+
* @constructor
52+
* @param {string} type
53+
* @param {StorageEventInit=} opt_eventInitDict
54+
*/
55+
function StorageEvent(type, opt_eventInitDict) {}
56+
5057
/** @externs */
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
new StorageEvent("storage");
2+
new StorageEvent("storage", {});
3+
new StorageEvent("storage", { key: "k", newValue: "v" });
4+
new StorageEvent("storage", {
5+
key: null,
6+
oldValue: null,
7+
newValue: null,
8+
url: "",
9+
storageArea: null,
10+
bubbles: false,
11+
cancelable: false,
12+
composed: false
13+
});
14+
new StorageEvent("storage", {}, "extra"); // $ Alert

0 commit comments

Comments
 (0)