Bug 149331 - [WebIDL] Specify default parameter values where it is useful
Summary: [WebIDL] Specify default parameter values where it is useful
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: DOM (show other bugs)
Version: WebKit Nightly Build
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Chris Dumez
URL:
Keywords: InRadar, WebExposed
Depends on: 149263
Blocks:
  Show dependency treegraph
 
Reported: 2015-09-17 20:16 PDT by Chris Dumez
Modified: 2015-09-19 17:45 PDT (History)
6 users (show)

See Also:


Attachments
Patch (33.67 KB, patch)
2015-09-17 22:15 PDT, Chris Dumez
no flags Details | Formatted Diff | Diff
Patch (33.57 KB, patch)
2015-09-19 16:55 PDT, Chris Dumez
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Chris Dumez 2015-09-17 20:16:45 PDT
Specify default parameter values where it is useful, that is to say where undefined would be converted to something else than the default value otherwise.
Comment 1 Chris Dumez 2015-09-17 20:17:08 PDT
rdar://problem/22545600
Comment 2 Chris Dumez 2015-09-17 22:15:29 PDT
Created attachment 261489 [details]
Patch
Comment 3 Darin Adler 2015-09-18 09:39:06 PDT
Comment on attachment 261489 [details]
Patch

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

> Source/WebCore/bindings/scripts/CodeGeneratorJS.pm:3387
> +                push(@$outputArray, "        $name = String(ASCIILiteral(" . $parameter->default . "));\n");

Why is the String() needed here?

> Source/WebCore/bindings/scripts/CodeGeneratorJS.pm:3389
> +                push(@$outputArray, "        $name = exec->uncheckedArgument($argsIndex).toString(exec)->value(exec);\n");

Why did you remove the early return when toString had an exception before calling value that the old code had?

> Source/WebCore/bindings/scripts/CodeGeneratorJS.pm:3396
> +                push(@$outputArray, "    auto* ${name}String = ${argValue}.toString(exec);\n");
> +                push(@$outputArray, "    auto& $name = ${name}String->value(exec);\n");

Same question here.
Comment 4 Chris Dumez 2015-09-18 10:41:46 PDT
Comment on attachment 261489 [details]
Patch

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

>> Source/WebCore/bindings/scripts/CodeGeneratorJS.pm:3387
>> +                push(@$outputArray, "        $name = String(ASCIILiteral(" . $parameter->default . "));\n");
> 
> Why is the String() needed here?

iirc, the compiler did not let me have different types (literal vs String) on both sides on the ternary but I can try without again.

>> Source/WebCore/bindings/scripts/CodeGeneratorJS.pm:3389
>> +                push(@$outputArray, "        $name = exec->uncheckedArgument($argsIndex).toString(exec)->value(exec);\n");
> 
> Why did you remove the early return when toString had an exception before calling value that the old code had?

I believe this was a bug. This is inconsistent with how we usually convert String in the bindings. In regular cases, we do .toString(exec)->value(exec) then do the exception check. However, we were doing it differently in the string enumeration case only which does not make much sense to me. If JSString::value() throws an exception, I think it makes sense to do the exception check after the call the value() as well. At the very least, it is consistent with how we usually convert strings.
Comment 5 Chris Dumez 2015-09-18 10:58:01 PDT
Comment on attachment 261489 [details]
Patch

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

>>> Source/WebCore/bindings/scripts/CodeGeneratorJS.pm:3389
>>> +                push(@$outputArray, "        $name = exec->uncheckedArgument($argsIndex).toString(exec)->value(exec);\n");
>> 
>> Why did you remove the early return when toString had an exception before calling value that the old code had?
> 
> I believe this was a bug. This is inconsistent with how we usually convert String in the bindings. In regular cases, we do .toString(exec)->value(exec) then do the exception check. However, we were doing it differently in the string enumeration case only which does not make much sense to me. If JSString::value() throws an exception, I think it makes sense to do the exception check after the call the value() as well. At the very least, it is consistent with how we usually convert strings.

I have just talked to Geoff about this:
1. Calling toString(exec)->value(exec) is safe because toString() will return an empty string (not null) in case of exception.
2. We should do an exception check after the call to value(exec) because it can throw in case it runs out of memory.
Comment 6 Darin Adler 2015-09-19 15:43:41 PDT
Comment on attachment 261489 [details]
Patch

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

>>> Source/WebCore/bindings/scripts/CodeGeneratorJS.pm:3387
>>> +                push(@$outputArray, "        $name = String(ASCIILiteral(" . $parameter->default . "));\n");
>> 
>> Why is the String() needed here?
> 
> iirc, the compiler did not let me have different types (literal vs String) on both sides on the ternary but I can try without again.

I don’t see a ternary. Maybe you had that in an earlier version.
Comment 7 Chris Dumez 2015-09-19 16:20:38 PDT
Comment on attachment 261489 [details]
Patch

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

>>>> Source/WebCore/bindings/scripts/CodeGeneratorJS.pm:3387
>>>> +                push(@$outputArray, "        $name = String(ASCIILiteral(" . $parameter->default . "));\n");
>>> 
>>> Why is the String() needed here?
>> 
>> iirc, the compiler did not let me have different types (literal vs String) on both sides on the ternary but I can try without again.
> 
> I don’t see a ternary. Maybe you had that in an earlier version.

Oh right, this iteration no longer has a ternary, sorry. I'll fix before landing.
Comment 8 Chris Dumez 2015-09-19 16:55:32 PDT
Created attachment 261591 [details]
Patch
Comment 9 WebKit Commit Bot 2015-09-19 17:45:44 PDT
Comment on attachment 261591 [details]
Patch

Clearing flags on attachment: 261591

Committed r190021: <http://trac.webkit.org/changeset/190021>
Comment 10 WebKit Commit Bot 2015-09-19 17:45:49 PDT
All reviewed patches have been landed.  Closing bug.