Skip to content

Commit

Permalink
[shared storage] Add SharedStorageSet/Append/Delete/Clear IDL Interface
Browse files Browse the repository at this point in the history
Implement the constructor for `SharedStorageSetMethod`, etc. The
error handling logic mirrors the existing sharedStorage.set(), etc.
To allow code reuse, the sharedStorage.set(), etc. methods
now creates the object and early return on exceptions.

Note that even though we no longer explicitly call resolver->Reject()
for sharedStorage.set(), etc., Chrome still converts thrown
exceptions to rejected promises (to adhere to the specification [1]),
so the end result is the same.

This prepares for the implementation of the
`sharedStorage.batchUpdate(methods)` method, as part of the Web Lock
integration proposal:
- WICG/shared-storage#199
- WICG/shared-storage#205

[1] https://w3ctag.github.io/promises-guide/#always-return-promises

Bug: 373899210
Change-Id: Ie4edfedbe755afeb3db5ca557fd74482bac96138
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6054694
Commit-Queue: Yao Xiao <yaoxia@chromium.org>
Reviewed-by: Cammie Smith Barnes <cammie@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1390779}
  • Loading branch information
yaoxiachromium authored and chromium-wpt-export-bot committed Dec 3, 2024
1 parent 7ef95a1 commit 6a83407
Showing 1 changed file with 56 additions and 0 deletions.
56 changes: 56 additions & 0 deletions shared-storage/setters.tentative.https.sub.html
Original file line number Diff line number Diff line change
Expand Up @@ -48,5 +48,61 @@
return sharedStorage.delete("a");
}, 'sharedStorage.delete');

test(() => {
try {
let a = new SharedStorageSetMethod('a');
} catch (e) {
assert_equals(e.name, 'TypeError');
return;
}
assert_unreached("did not throw");
}, 'new SharedStorageSetMethod with 1 argument');

test(() => {
let a = new SharedStorageSetMethod('a', 'b');
}, 'new SharedStorageSetMethod with 2 arguments');

test(() => {
try {
let a = new SharedStorageAppendMethod('a');
} catch (e) {
assert_equals(e.name, 'TypeError');
return;
}
assert_unreached("did not throw");
}, 'new SharedStorageAppendMethod with 1 argument');

test(() => {
let a = new SharedStorageAppendMethod('a', 'b');
}, 'new SharedStorageAppendMethod with 2 arguments');

test(() => {
try {
let a = new SharedStorageDeleteMethod();
} catch (e) {
assert_equals(e.name, 'TypeError');
return;
}
assert_unreached("did not throw");
}, 'new SharedStorageDeleteMethod with no arguments');

test(() => {
let a = new SharedStorageDeleteMethod('a');
}, 'new SharedStorageDeleteMethod with 1 argument');

test(() => {
try {
let a = SharedStorageClearMethod();
} catch (e) {
assert_equals(e.name, 'TypeError');
return;
}
assert_unreached("did not throw");
}, 'call SharedStorageClearMethod() as a function');

test(() => {
let a = new SharedStorageClearMethod();
}, 'new SharedStorageClearMethod with no arguments');

</script>
</body>

0 comments on commit 6a83407

Please sign in to comment.