Skip to content

Commit

Permalink
Calling browser.storage.set with undefined as a map value throws an e…
Browse files Browse the repository at this point in the history
…xception

https://bugs.webkit.org/show_bug.cgi?id=275746
rdar://130282050

Reviewed by Timothy Hatcher and Brian Weinstein.

We shouldn't throw an exception if undefined is passed as a value for {storageArea}.set().
This matches what we do currently in Safari.

* Source/WebKit/WebProcess/Extensions/API/Cocoa/WebExtensionAPIStorageAreaCocoa.mm:
(WebKit::WebExtensionAPIStorageArea::set):
* Tools/TestWebKitAPI/Tests/WebKitCocoa/WKWebExtensionAPIStorage.mm:
(TestWebKitAPI::TEST(WKWebExtensionAPIStorage, Set)):

Canonical link: https://commits.webkit.org/280265@main
  • Loading branch information
kiaraarose committed Jun 21, 2024
1 parent e127c6b commit bddd449
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,9 @@
auto *serializedData = mapObjects(items, ^NSString *(NSString *key, id object) {
ASSERT([object isKindOfClass:JSValue.class]);

if (((JSValue *)object).isUndefined)
return nil;

if (keyWithError)
return nil;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@
TEST(WKWebExtensionAPIStorage, Set)
{
auto *backgroundScript = Util::constructScript(@[
@"const data = { 'string': 'string', 'number': 1, 'boolean': true, 'dictionary': {'key': 'value'}, 'array': [1, true, 'string'], 'null': null }",
@"const data = { 'string': 'string', 'number': 1, 'boolean': true, 'dictionary': {'key': 'value'}, 'array': [1, true, 'string'], 'null': null, 'undefined': undefined }",
@"await browser?.storage?.local?.set(data)",

@"var result = await browser?.storage?.local?.get()",
Expand Down

0 comments on commit bddd449

Please sign in to comment.