Bug 169731 - Add support for ImplementedAs, Clamp, EnforceRange, TreatNullAs for dictionary members
Summary: Add support for ImplementedAs, Clamp, EnforceRange, TreatNullAs for dictionar...
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: Bindings (show other bugs)
Version: WebKit Nightly Build
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Jon Lee
URL:
Keywords:
: 169333 (view as bug list)
Depends on:
Blocks: 169732
  Show dependency treegraph
 
Reported: 2017-03-15 20:13 PDT by Jon Lee
Modified: 2017-03-24 12:25 PDT (History)
11 users (show)

See Also:


Attachments
Patch (24.43 KB, patch)
2017-03-15 20:29 PDT, Jon Lee
no flags Details | Formatted Diff | Diff
Archive of layout-test-results from ews102 for mac-elcapitan (788.95 KB, application/zip)
2017-03-15 21:39 PDT, Build Bot
no flags Details
Archive of layout-test-results from ews105 for mac-elcapitan-wk2 (874.16 KB, application/zip)
2017-03-15 21:42 PDT, Build Bot
no flags Details
Archive of layout-test-results from ews117 for mac-elcapitan (1.57 MB, application/zip)
2017-03-15 21:50 PDT, Build Bot
no flags Details
Archive of layout-test-results from ews121 for ios-simulator-wk2 (11.29 MB, application/zip)
2017-03-15 22:07 PDT, Build Bot
no flags Details
Patch (40.44 KB, patch)
2017-03-17 00:38 PDT, Jon Lee
achristensen: review+
Details | Formatted Diff | Diff
Patch for landing (25.13 KB, patch)
2017-03-17 19:16 PDT, Jon Lee
buildbot: commit-queue-
Details | Formatted Diff | Diff
Archive of layout-test-results from ews103 for mac-elcapitan (785.23 KB, application/zip)
2017-03-17 20:27 PDT, Build Bot
no flags Details
Patch for landing (42.58 KB, patch)
2017-03-17 20:33 PDT, Jon Lee
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Jon Lee 2017-03-15 20:13:38 PDT
Add support for ImplementedAs, Clamp, EnforceRange, TreatNullAs for dictionary members
Comment 1 Jon Lee 2017-03-15 20:29:38 PDT
Created attachment 304600 [details]
Patch
Comment 2 Build Bot 2017-03-15 21:39:13 PDT
Comment on attachment 304600 [details]
Patch

Attachment 304600 [details] did not pass mac-ews (mac):
Output: http://webkit-queues.webkit.org/results/3335541

New failing tests:
crypto/subtle/aes-gcm-encrypt-malformed-parameters.html
crypto/subtle/hmac-generate-key-malformed-parameters.html
imported/w3c/web-platform-tests/WebCryptoAPI/encrypt_decrypt/test_aes_gcm.html
imported/w3c/web-platform-tests/WebCryptoAPI/encrypt_decrypt/aes_gcm.worker.html
crypto/subtle/aes-generate-key-malformed-parameters.html
Comment 3 Build Bot 2017-03-15 21:39:17 PDT
Created attachment 304604 [details]
Archive of layout-test-results from ews102 for mac-elcapitan

The attached test failures were seen while running run-webkit-tests on the mac-ews.
Bot: ews102  Port: mac-elcapitan  Platform: Mac OS X 10.11.6
Comment 4 Build Bot 2017-03-15 21:42:31 PDT
Comment on attachment 304600 [details]
Patch

Attachment 304600 [details] did not pass mac-wk2-ews (mac-wk2):
Output: http://webkit-queues.webkit.org/results/3335546

New failing tests:
crypto/subtle/aes-gcm-encrypt-malformed-parameters.html
crypto/subtle/hmac-generate-key-malformed-parameters.html
imported/w3c/web-platform-tests/WebCryptoAPI/encrypt_decrypt/test_aes_gcm.html
imported/w3c/web-platform-tests/WebCryptoAPI/encrypt_decrypt/aes_gcm.worker.html
crypto/subtle/aes-generate-key-malformed-parameters.html
Comment 5 Build Bot 2017-03-15 21:42:34 PDT
Created attachment 304605 [details]
Archive of layout-test-results from ews105 for mac-elcapitan-wk2

The attached test failures were seen while running run-webkit-tests on the mac-wk2-ews.
Bot: ews105  Port: mac-elcapitan-wk2  Platform: Mac OS X 10.11.6
Comment 6 Build Bot 2017-03-15 21:50:35 PDT
Comment on attachment 304600 [details]
Patch

Attachment 304600 [details] did not pass mac-debug-ews (mac):
Output: http://webkit-queues.webkit.org/results/3335552

New failing tests:
crypto/subtle/aes-gcm-encrypt-malformed-parameters.html
crypto/subtle/hmac-generate-key-malformed-parameters.html
imported/w3c/web-platform-tests/WebCryptoAPI/encrypt_decrypt/test_aes_gcm.html
imported/w3c/web-platform-tests/WebCryptoAPI/encrypt_decrypt/aes_gcm.worker.html
crypto/subtle/aes-generate-key-malformed-parameters.html
Comment 7 Build Bot 2017-03-15 21:50:40 PDT
Created attachment 304606 [details]
Archive of layout-test-results from ews117 for mac-elcapitan

The attached test failures were seen while running run-webkit-tests on the mac-debug-ews.
Bot: ews117  Port: mac-elcapitan  Platform: Mac OS X 10.11.6
Comment 8 Build Bot 2017-03-15 22:07:38 PDT
Comment on attachment 304600 [details]
Patch

Attachment 304600 [details] did not pass ios-sim-ews (ios-simulator-wk2):
Output: http://webkit-queues.webkit.org/results/3335572

New failing tests:
crypto/subtle/aes-gcm-encrypt-malformed-parameters.html
crypto/subtle/hmac-generate-key-malformed-parameters.html
imported/w3c/web-platform-tests/WebCryptoAPI/encrypt_decrypt/test_aes_gcm.html
imported/w3c/web-platform-tests/WebCryptoAPI/encrypt_decrypt/aes_gcm.worker.html
crypto/subtle/aes-generate-key-malformed-parameters.html
Comment 9 Build Bot 2017-03-15 22:07:48 PDT
Created attachment 304610 [details]
Archive of layout-test-results from ews121 for ios-simulator-wk2

The attached test failures were seen while running run-webkit-tests on the ios-sim-ews.
Bot: ews121  Port: ios-simulator-wk2  Platform: Mac OS X 10.11.6
Comment 10 Jon Lee 2017-03-15 23:25:49 PDT
Jiewen and Brent, I think this patch is exposing bugs in subtle crypto. [EnforceRange] in AesGcmParams and AesKeyParams now throw TypeErrors.

Can you help me determine whether the tests need to be rewritten, or rebaselined?
Comment 11 Sam Weinig 2017-03-16 10:27:28 PDT
Comment on attachment 304600 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=304600&action=review

> Source/WebCore/bindings/scripts/CodeGeneratorJS.pm:1570
> +            # 5.1.1. Set a different key in case it is aliased with ImplementedAs.
> +            my $resultKey = $key;
> +            if ($member->extendedAttributes->{"ImplementedAs"}) {
> +                $resultKey = $member->extendedAttributes->{"ImplementedAs"};
> +            }

The 5.1 business is spec step language.  Since this implementation specific, it should not have a number.  Probably just a comment explaining why it's needed here.

> Source/WebCore/bindings/scripts/CodeGeneratorJS.pm:1586
> -            $result .= "        result.$key = convert<${IDLType}>(state, ${key}Value);\n";
> +
> +            my @conversionArguments = ();
> +            push(@conversionArguments, "state");
> +            push(@conversionArguments, "${key}Value");
> +            push(@conversionArguments, GetIntegerConversionConfiguration($member)) if $codeGenerator->IsIntegerType($type);
> +            push(@conversionArguments, GetStringConversionConfiguration($member)) if $codeGenerator->IsStringType($type);
> +            $result .= "        result.$resultKey = convert<${IDLType}>(" . join(", ", @conversionArguments) . ");\n";
>              $result .= "        RETURN_IF_EXCEPTION(throwScope, { });\n";

Ideally we would be able to use JSValueToNative, rather than repeating things here. Probably need to update the list of contexts to include IDLDictionaryMember.

> Source/WebCore/bindings/scripts/CodeGeneratorJS.pm:1632
> +                # 1.1. Set a different key in case it is aliased with ImplementedAs.
> +                my $resultKey = $key;
> +                if ($member->extendedAttributes->{"ImplementedAs"}) {
> +                    $resultKey = $member->extendedAttributes->{"ImplementedAs"};
> +                }

Again, spec language.
Comment 12 Jiewen Tan 2017-03-16 11:28:48 PDT
*** Bug 169333 has been marked as a duplicate of this bug. ***
Comment 13 Jiewen Tan 2017-03-16 11:34:18 PDT
(In reply to comment #10)
> Jiewen and Brent, I think this patch is exposing bugs in subtle crypto.
> [EnforceRange] in AesGcmParams and AesKeyParams now throw TypeErrors.
> 
> Can you help me determine whether the tests need to be rewritten, or
> rebaselined?

Ha, I didn't realize that we didn't support EnforceRange before. For tests cases under crypto/, rebaseline should be fine. However, I need to investigate why the w3c test cases fail.
Comment 14 Jiewen Tan 2017-03-16 11:43:40 PDT
(In reply to comment #13)
> (In reply to comment #10)
> > Jiewen and Brent, I think this patch is exposing bugs in subtle crypto.
> > [EnforceRange] in AesGcmParams and AesKeyParams now throw TypeErrors.
> > 
> > Can you help me determine whether the tests need to be rewritten, or
> > rebaselined?
> 
> Ha, I didn't realize that we didn't support EnforceRange before. For tests
> cases under crypto/, rebaseline should be fine. However, I need to
> investigate why the w3c test cases fail.

We can rebaseline the w3c tests as well. In my opinion, the expected results are wrong. We are doing the right thing. I will file bug reports against the w3c tests later on.
Comment 15 Jon Lee 2017-03-16 12:49:32 PDT
Sam, I took a stab at switching to JSValueToNative, and the way enumerations were written out changed.

Is this a better way to convert enumerations, or is it wrong? If it's the latter, then I will not attempt to switch, and will add a FIXME and file a new bug to do the conversion.

Here's an example of the change:

--- WebCore/bindings/scripts/test/JS/JSTestObj.cpp	2017-03-16 10:43:26.000000000 -0700
+++ /var/folders/sf/90xm7_w50ld3z7dmg4lm01ph0000gn/T/tmppGuUgJ/JSTestObj.cpp	2017-03-16 12:43:53.000000000 -0700
@@ -517,19 +517,19 @@
     }
     JSValue enumerationValueWithDefaultValue = isNullOrUndefined ? jsUndefined() : object->get(&state, Identifier::fromString(&state, "enumerationValueWithDefault"));
     if (!enumerationValueWithDefaultValue.isUndefined()) {
-        result.enumerationValueWithDefault = convert<IDLEnumeration<TestObj::EnumType>>(state, enumerationValueWithDefaultValue);
+        result.enumerationValueWithDefault = parseEnumeration<TestObj::EnumType>(state, enumerationValueWithDefaultValue);
         RETURN_IF_EXCEPTION(throwScope, { });
     } else
         result.enumerationValueWithDefault = TestObj::EnumType::EnumValue1;
     JSValue enumerationValueWithEmptyStringDefaultValue = isNullOrUndefined ? jsUndefined() : object->get(&state, Identifier::fromString(&state, "enumerationValueWithEmptyStringDefa
Comment 16 Jon Lee 2017-03-17 00:38:03 PDT
Created attachment 304765 [details]
Patch
Comment 17 Chris Dumez 2017-03-17 14:55:12 PDT
Comment on attachment 304765 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=304765&action=review

> Source/WebCore/ChangeLog:13
> +        (JSValueToNative): Bypass parseEnumeration serialization for enums if the context is an

This does not explain why we should do this. It is not obvious to me at least.

> Source/WebCore/bindings/scripts/CodeGeneratorJS.pm:1566
> +            my $implementedAsKey = $key;

nit: Could be on one line:
my $implementedAsKey = $member->extendedAttributes->{"ImplementedAs"} ? $member->extendedAttributes->{"ImplementedAs"} : $key;

> Source/WebCore/bindings/scripts/CodeGeneratorJS.pm:1621
> +                my $implementedAsKey = $key;

nit: Could be on one line:
my $implementedAsKey = $member->extendedAttributes->{"ImplementedAs"} ? $member->extendedAttributes->{"ImplementedAs"} : $key;
Comment 18 Alex Christensen 2017-03-17 18:32:20 PDT
Comment on attachment 304765 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=304765&action=review

> Source/WebCore/bindings/scripts/CodeGeneratorJS.pm:5550
> +    if ($codeGenerator->IsEnumType($type) && ref($context) ne "IDLDictionaryMember") {

Yep, explain this.  We might be able to do it a better way in the future.
Comment 19 Jon Lee 2017-03-17 18:53:06 PDT
Comment on attachment 304765 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=304765&action=review

>> Source/WebCore/ChangeLog:13
>> +        (JSValueToNative): Bypass parseEnumeration serialization for enums if the context is an
> 
> This does not explain why we should do this. It is not obvious to me at least.

I'll add an explanation here and a brief one in the code below. parseEnumeration returns std::optional, where we need it to throw a TypeError instead. To do this, we pass through so that it write out convert<IDLEnumeration<T>>.

>> Source/WebCore/bindings/scripts/CodeGeneratorJS.pm:1566
>> +            my $implementedAsKey = $key;
> 
> nit: Could be on one line:
> my $implementedAsKey = $member->extendedAttributes->{"ImplementedAs"} ? $member->extendedAttributes->{"ImplementedAs"} : $key;

Done.

>> Source/WebCore/bindings/scripts/CodeGeneratorJS.pm:1621
>> +                my $implementedAsKey = $key;
> 
> nit: Could be on one line:
> my $implementedAsKey = $member->extendedAttributes->{"ImplementedAs"} ? $member->extendedAttributes->{"ImplementedAs"} : $key;

Done.

>> Source/WebCore/bindings/scripts/CodeGeneratorJS.pm:5550
>> +    if ($codeGenerator->IsEnumType($type) && ref($context) ne "IDLDictionaryMember") {
> 
> Yep, explain this.  We might be able to do it a better way in the future.

Done.
Comment 20 Jon Lee 2017-03-17 19:16:04 PDT
Created attachment 304846 [details]
Patch for landing
Comment 21 Build Bot 2017-03-17 20:27:27 PDT
Comment on attachment 304846 [details]
Patch for landing

Attachment 304846 [details] did not pass mac-ews (mac):
Output: http://webkit-queues.webkit.org/results/3353570

New failing tests:
crypto/subtle/aes-gcm-encrypt-malformed-parameters.html
crypto/subtle/hmac-generate-key-malformed-parameters.html
imported/w3c/web-platform-tests/WebCryptoAPI/encrypt_decrypt/test_aes_gcm.html
imported/w3c/web-platform-tests/WebCryptoAPI/encrypt_decrypt/aes_gcm.worker.html
crypto/subtle/aes-generate-key-malformed-parameters.html
Comment 22 Build Bot 2017-03-17 20:27:35 PDT
Created attachment 304854 [details]
Archive of layout-test-results from ews103 for mac-elcapitan

The attached test failures were seen while running run-webkit-tests on the mac-ews.
Bot: ews103  Port: mac-elcapitan  Platform: Mac OS X 10.11.6
Comment 23 Jon Lee 2017-03-17 20:33:06 PDT
Created attachment 304855 [details]
Patch for landing
Comment 24 WebKit Commit Bot 2017-03-18 13:22:24 PDT
Comment on attachment 304855 [details]
Patch for landing

Clearing flags on attachment: 304855

Committed r214139: <http://trac.webkit.org/changeset/214139>
Comment 25 Alexey Proskuryakov 2017-03-18 17:41:07 PDT
Comment on attachment 304765 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=304765&action=review

> LayoutTests/imported/w3c/ChangeLog:10
> +        Rebaseline tests. The results seem to show a problem in the original tests.
> +        * web-platform-tests/WebCryptoAPI/encrypt_decrypt/aes_gcm.worker-expected.txt:
> +        * web-platform-tests/WebCryptoAPI/encrypt_decrypt/test_aes_gcm-expected.txt:

Do these failures occur in other browsers?