Skip to content

Commit 251eeb1

Browse files
committed
Digital Credentials API: add default toJSON() to DigitalCredential interface
https://bugs.webkit.org/show_bug.cgi?id=295018 rdar://problem/154733737 Reviewed by Abrar Rahman Protyasha. Spec change: w3c-fedid/digital-credentials#179 * Adds a default `toJSON()` method to the `DigitalCredential` interface. * Adds JSON strinfication check for incoming request, as required by the spec. Canonical link: https://commits.webkit.org/296963@main
1 parent d123daf commit 251eeb1

8 files changed

Lines changed: 31 additions & 0 deletions

File tree

LayoutTests/http/wpt/identity/idl.https-expected.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,4 +83,5 @@ PASS DigitalCredential interface: existence and properties of interface prototyp
8383
PASS DigitalCredential interface: attribute protocol
8484
PASS DigitalCredential interface: attribute data
8585
PASS DigitalCredential interface: operation userAgentAllowsProtocol(DOMString)
86+
PASS DigitalCredential interface: operation toJSON()
8687

LayoutTests/http/wpt/identity/idl.https.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
readonly attribute DOMString protocol;
2323
readonly attribute Uint8Array data;
2424
static boolean userAgentAllowsProtocol(DOMString protocol);
25+
[Default] object toJSON();
2526
};
2627
</script>
2728
<script>

LayoutTests/imported/w3c/web-platform-tests/digital-credentials/get.tentative.https-expected.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,5 @@ PASS navigator.credentials.get() promise is rejected if called with an aborted s
1111
FAIL navigator.credentials.get() promise is rejected if abort controller is aborted after call to get(). promise_rejects_dom: function "function() { throw e }" threw object "NotSupportedError: Digital credentials are not supported." that is not a DOMException AbortError: property "code" is equal to 9, expected 20
1212
FAIL navigator.credentials.get() promise is rejected if abort controller is aborted after call to get() in cross-origin iframe. assert_equals: expected "AbortError" but got "NotAllowedError"
1313
PASS Mediation is required to get a DigitalCredential.
14+
PASS Throws TypeError when request data is not JSON stringifiable.
1415

LayoutTests/imported/w3c/web-platform-tests/digital-credentials/get.tentative.https.html

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,4 +231,24 @@
231231
);
232232
}
233233
}, "Mediation is required to get a DigitalCredential.");
234+
235+
promise_test(async t => {
236+
const throwingValues = [
237+
BigInt(123),
238+
(() => { const o = {}; o.self = o; return o; })(),
239+
Symbol("foo")
240+
];
241+
242+
for (const badValue of throwingValues) {
243+
const options = makeGetOptions("openid4vp");
244+
options.digital.requests[0].data = badValue;
245+
246+
await promise_rejects_js(
247+
t,
248+
TypeError,
249+
navigator.credentials.get(options),
250+
`Should throw for: ${String(badValue)}`
251+
);
252+
}
253+
}, "Throws TypeError when request data is not JSON stringifiable.");
234254
</script>

LayoutTests/platform/ios/imported/w3c/web-platform-tests/digital-credentials/get.tentative.https-expected.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,5 @@ PASS navigator.credentials.get() promise is rejected if called with an aborted s
1313
FAIL navigator.credentials.get() promise is rejected if abort controller is aborted after call to get(). promise_rejects_dom: function "function() { throw e }" threw object "NotSupportedError: Digital credentials are not supported." that is not a DOMException AbortError: property "code" is equal to 9, expected 20
1414
FAIL navigator.credentials.get() promise is rejected if abort controller is aborted after call to get() in cross-origin iframe. assert_equals: expected "AbortError" but got "NotAllowedError"
1515
PASS Mediation is required to get a DigitalCredential.
16+
PASS Throws TypeError when request data is not JSON stringifiable.
1617

LayoutTests/platform/mac-sonoma/imported/w3c/web-platform-tests/digital-credentials/get.tentative.https-expected.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,5 @@ PASS navigator.credentials.get() promise is rejected if called with an aborted s
1111
FAIL navigator.credentials.get() promise is rejected if abort controller is aborted after call to get(). promise_rejects_dom: function "function() { throw e }" threw object "NotSupportedError: Digital credentials are not supported." that is not a DOMException AbortError: property "code" is equal to 9, expected 20
1212
FAIL navigator.credentials.get() promise is rejected if abort controller is aborted after call to get() in cross-origin iframe. assert_equals: expected "AbortError" but got "NotAllowedError"
1313
PASS Mediation is required to get a DigitalCredential.
14+
PASS Throws TypeError when request data is not JSON stringifiable.
1415

Source/WebCore/Modules/identity/DigitalCredential.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,11 @@ static ExceptionOr<UnvalidatedDigitalCredentialRequest> jsToCredentialRequest(co
6868
auto scope = DECLARE_THROW_SCOPE(document.globalObject()->vm());
6969
auto* globalObject = document.globalObject();
7070

71+
// Check that the object is JSON stringifiable.
72+
JSC::JSONStringify(globalObject, request.data.get(), 0);
73+
if (scope.exception()) [[unlikely]]
74+
return Exception { ExceptionCode::ExistingExceptionError };
75+
7176
switch (request.protocol) {
7277
case IdentityCredentialProtocol::OrgIsoMdoc: {
7378
auto result = convertDictionary<MobileDocumentRequest>(*globalObject, request.data.get());

Source/WebCore/Modules/identity/DigitalCredential.idl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,5 @@
3232
[SameObject] readonly attribute object data;
3333
readonly attribute IdentityCredentialProtocol protocol;
3434
static boolean userAgentAllowsProtocol(DOMString protocol);
35+
[Default] object toJSON();
3536
};

0 commit comments

Comments
 (0)