<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<!DOCTYPE bugzilla SYSTEM "https://bugs.webkit.org/page.cgi?id=bugzilla.dtd">

<bugzilla version="5.0.4.1"
          urlbase="https://bugs.webkit.org/"
          
          maintainer="admin@webkit.org"
>

    <bug>
          <bug_id>240219</bug_id>
          
          <creation_ts>2022-05-08 16:36:21 -0700</creation_ts>
          <short_desc>foo(optional [EnforceRange] unsigned long long offset = 0) IDL functions don&apos;t work when called like foo(undefined) or foo()</short_desc>
          <delta_ts>2026-01-23 06:43:34 -0800</delta_ts>
          <reporter_accessible>1</reporter_accessible>
          <cclist_accessible>1</cclist_accessible>
          <classification_id>1</classification_id>
          <classification>Unclassified</classification>
          <product>WebKit</product>
          <component>Bindings</component>
          <version>WebKit Nightly Build</version>
          <rep_platform>Unspecified</rep_platform>
          <op_sys>Unspecified</op_sys>
          <bug_status>RESOLVED</bug_status>
          <resolution>FIXED</resolution>
          
          <see_also>https://bugs.webkit.org/show_bug.cgi?id=240441</see_also>
          <bug_file_loc></bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords>InRadar</keywords>
          <priority>P2</priority>
          <bug_severity>Normal</bug_severity>
          <target_milestone>---</target_milestone>
          
          <blocked>232558</blocked>
          <everconfirmed>1</everconfirmed>
          <reporter name="Myles C. Maxfield">mmaxfield</reporter>
          <assigned_to name="Sam Weinig">sam</assigned_to>
          <cc>ahmad.saleem792</cc>
    
    <cc>cdumez</cc>
    
    <cc>sam</cc>
    
    <cc>webkit-bug-importer</cc>
          

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>1867540</commentid>
    <comment_count>0</comment_count>
    <who name="Myles C. Maxfield">mmaxfield</who>
    <bug_when>2022-05-08 16:36:21 -0700</bug_when>
    <thetext>In WebGPU, see mapAsync() and getMappedRange(). The C++ version of these functions never get called when the optional parameters with default values are specified by JS as undefined or omitted.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1867543</commentid>
    <comment_count>1</comment_count>
    <who name="Chris Dumez">cdumez</who>
    <bug_when>2022-05-08 16:51:23 -0700</bug_when>
    <thetext>I find his very surprising. Pretty sure we already have similar IDL in the code Base. I’d expect our generated code to call the implementation function with 0 if the parameter is omitted or undefined.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1868607</commentid>
    <comment_count>2</comment_count>
    <who name="Chris Dumez">cdumez</who>
    <bug_when>2022-05-12 18:11:08 -0700</bug_when>
    <thetext>I have just double-checked here and things seem to work as expected. I validated with the following patch:
```
diff --git a/Source/WebCore/dom/Document.cpp b/Source/WebCore/dom/Document.cpp
index 0636bd5b4363..370a789c0a9e 100644
--- a/Source/WebCore/dom/Document.cpp
+++ b/Source/WebCore/dom/Document.cpp
@@ -9202,6 +9202,11 @@ bool Document::isSameSiteForCookies(const URL&amp; url) const
     return domain.matches(url);
 }
 
+void Document::testOptionalUnsignedLongLong(uint64_t param)
+{
+    WTFLogAlways(&quot;CHRIS: Document::testOptionalUnsignedLongLong(%llu)&quot;, param);
+}
+
 } // namespace WebCore
 
 #undef DOCUMENT_RELEASE_LOG
diff --git a/Source/WebCore/dom/Document.h b/Source/WebCore/dom/Document.h
index 866abc6d7986..fcc1319cadb0 100644
--- a/Source/WebCore/dom/Document.h
+++ b/Source/WebCore/dom/Document.h
@@ -699,6 +699,8 @@ public:
 
     void cancelParsing();
 
+    void testOptionalUnsignedLongLong(uint64_t);
+
     ExceptionOr&lt;void&gt; write(Document* entryDocument, SegmentedString&amp;&amp;);
     WEBCORE_EXPORT ExceptionOr&lt;void&gt; write(Document* entryDocument, FixedVector&lt;String&gt;&amp;&amp;);
     WEBCORE_EXPORT ExceptionOr&lt;void&gt; writeln(Document* entryDocument, FixedVector&lt;String&gt;&amp;&amp;);
diff --git a/Source/WebCore/dom/Document.idl b/Source/WebCore/dom/Document.idl
index b5cc4978066a..db9726d66df7 100644
--- a/Source/WebCore/dom/Document.idl
+++ b/Source/WebCore/dom/Document.idl
@@ -94,6 +94,8 @@ typedef (HTMLScriptElement or SVGScriptElement) HTMLOrSVGScriptElement;
 
     // Non standard: It has been dropped from Blink already.
     RenderingContext? getCSSCanvasContext(DOMString contextId, DOMString name, long width, long height);
+
+    undefined testOptionalUnsignedLongLong(optional unsigned long long parameter = 0);
 };
 
 enum DocumentReadyState { &quot;loading&quot;, &quot;interactive&quot;, &quot;complete&quot; };
```

document.testOptionalUnsignedLongLong() -&gt; implementation called with 0
document.testOptionalUnsignedLongLong(0) -&gt; implementation called with 0
document.testOptionalUnsignedLongLong(1) -&gt; implementation called with 1
document.testOptionalUnsignedLongLong(undefined) -&gt; implementation called with 0

Works as expected IMO.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1868875</commentid>
    <comment_count>3</comment_count>
    <who name="Myles C. Maxfield">mmaxfield</who>
    <bug_when>2022-05-13 15:01:12 -0700</bug_when>
    <thetext>Cool, thanks for trying it out. I&apos;ll try to figure out why the WebGPU stuff isn&apos;t working then.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1869086</commentid>
    <comment_count>4</comment_count>
      <attachid>459381</attachid>
    <who name="Myles C. Maxfield">mmaxfield</who>
    <bug_when>2022-05-15 11:47:12 -0700</bug_when>
    <thetext>Created attachment 459381
Test file

Here is a test file demonstrating the problem. (You have to open it in DumpRenderTree; it&apos;s not hooked up into WK2 yet, and is intentionally disabled in Minibrowser.) The IDL has:

Promise&lt;undefined&gt; mapAsync(GPUMapModeFlags mode, optional GPUSize64 offset = 0, optional GPUSize64 size);

And if you call it like

buffer.mapAsync(GPUMapMode.WRITE);

then our generated bindings code does this:

auto offset = convert&lt;IDLEnforceRangeAdaptor&lt;IDLUnsignedLongLong&gt;&gt;(*lexicalGlobalObject, argument1.value());

which gets sent to:

double JSValue::toNumberSlowCase(JSGlobalObject* globalObject) const
{
    ...
    return isUndefined() ? PNaN : 0; // null and false both convert to 0.
}

and then sent to

static double enforceRange(JSGlobalObject&amp; lexicalGlobalObject, double x, double minimum, double maximum)
{
    ...
    if (std::isnan(x) || std::isinf(x)) {
        throwTypeError(&amp;lexicalGlobalObject, scope, rangeErrorString(x, minimum, maximum));
        return 0;
    }
    ...
}</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1869106</commentid>
    <comment_count>5</comment_count>
    <who name="Radar WebKit Bug Importer">webkit-bug-importer</who>
    <bug_when>2022-05-15 16:37:12 -0700</bug_when>
    <thetext>&lt;rdar://problem/93317646&gt;</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1869884</commentid>
    <comment_count>6</comment_count>
    <who name="Myles C. Maxfield">mmaxfield</who>
    <bug_when>2022-05-17 18:03:12 -0700</bug_when>
    <thetext>Pull request: https://github.com/WebKit/WebKit/pull/710</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1896006</commentid>
    <comment_count>7</comment_count>
    <who name="Ahmad Saleem">ahmad.saleem792</who>
    <bug_when>2022-09-03 04:04:05 -0700</bug_when>
    <thetext>In Pull Request from Comment 06, there is mention that it was landed as part of following:

https://trac.webkit.org/changeset/294373/webkit

Is anything else needed here?

BY THE WAY - the test file show &quot;failure&quot; in all browsers (Chrome Canary 107, Firefox Nightly 106 and Safari Technology Preview 152).</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1896977</commentid>
    <comment_count>8</comment_count>
    <who name="Myles C. Maxfield">mmaxfield</who>
    <bug_when>2022-09-07 22:41:16 -0700</bug_when>
    <thetext>Yes, there is more to do here. The bug itself isn&apos;t fixed; that pull request just worked around the problem.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2174328</commentid>
    <comment_count>9</comment_count>
    <who name="Sam Weinig">sam</who>
    <bug_when>2026-01-22 17:55:33 -0800</bug_when>
    <thetext>This only is an issue for types annotated with [EnforceRange]. The fix is to disable the &quot;WillConvertUndefinedToDefaultParameterValue&quot; optimization for  [EnforceRange] types.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2174329</commentid>
    <comment_count>10</comment_count>
    <who name="Sam Weinig">sam</who>
    <bug_when>2026-01-22 18:00:29 -0800</bug_when>
    <thetext>Pull request: https://github.com/WebKit/WebKit/pull/57096</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2174457</commentid>
    <comment_count>11</comment_count>
    <who name="EWS">ews-feeder</who>
    <bug_when>2026-01-23 06:43:30 -0800</bug_when>
    <thetext>Committed 306087@main (8e68a118b1aa): &lt;https://commits.webkit.org/306087@main&gt;

Reviewed commits have been landed. Closing PR #57096 and removing active labels.</thetext>
  </long_desc>
      
          <attachment
              isobsolete="0"
              ispatch="0"
              isprivate="0"
          >
            <attachid>459381</attachid>
            <date>2022-05-15 11:47:12 -0700</date>
            <delta_ts>2022-05-15 11:47:12 -0700</delta_ts>
            <desc>Test file</desc>
            <filename>webgpu.html</filename>
            <type>text/html</type>
            <size>478</size>
            <attacher name="Myles C. Maxfield">mmaxfield</attacher>
            
              <data encoding="base64">PCFET0NUWVBFIGh0bWw+CjxodG1sPgo8aGVhZD4KPC9oZWFkPgo8Ym9keT4KPHNjcmlwdD4KYXN5
bmMgZnVuY3Rpb24gcnVuKCkgewogICAgbGV0IGFkYXB0ZXIgPSBhd2FpdCBuYXZpZ2F0b3IuZ3B1
LnJlcXVlc3RBZGFwdGVyKCk7CiAgICBsZXQgZGV2aWNlID0gYXdhaXQgYWRhcHRlci5yZXF1ZXN0
RGV2aWNlKCk7CiAgICBsZXQgYnVmZmVyID0gZGV2aWNlLmNyZWF0ZUJ1ZmZlcih7c2l6ZTogMTI4
LCB1c2FnZTogR1BVQnVmZmVyVXNhZ2UuTUFQX1dSSVRFfSk7CiAgICAvL2F3YWl0IGJ1ZmZlci5t
YXBBc3luYyhHUFVNYXBNb2RlLldSSVRFLCAwLCAxMjgpOwogICAgYXdhaXQgYnVmZmVyLm1hcEFz
eW5jKEdQVU1hcE1vZGUuV1JJVEUpOwp9CnJ1bigpLnRoZW4oZnVuY3Rpb24oKSB7CiAgICBhbGVy
dCgiZG9uZSIpOwp9LCBmdW5jdGlvbigpIHsKICAgIGFsZXJ0KCJmYWlsdXJlIik7Cn0pOwo8L3Nj
cmlwdD4KPC9ib2R5Pgo8L2h0bWw+Cg==
</data>

          </attachment>
      

    </bug>

</bugzilla>