[WebIDL] Enable strict type checking for operations' nullable parameters of wrapper...
authorcdumez@apple.com <cdumez@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 30 Jul 2016 08:35:06 +0000 (08:35 +0000)
committercdumez@apple.com <cdumez@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 30 Jul 2016 08:35:06 +0000 (08:35 +0000)
https://bugs.webkit.org/show_bug.cgi?id=160374

Reviewed by Youenn Fablet.

LayoutTests/imported/w3c:

Rebaseline W3C test now that one more check is passing.

* web-platform-tests/dom/nodes/DOMImplementation-createDocument-expected.txt:

Source/WebCore:

Enable strict type checking for operations' nullable parameters of
wrapper types to comply with the Web IDL specification:
- http://heycam.github.io/webidl/#es-nullable-type
- http://heycam.github.io/webidl/#es-interface

For such parameters, if the JS passes a value that is not null /
undefined and does not have the expected wrapper type, then we now
throw a TypeError instead of silently converting the value to null.

This behavior is consistent with Chrome and Firefox. It also helps
identify bugs in JavaScript code.

No new tests, rebaselined existing tests.

* bindings/scripts/CodeGeneratorJS.pm:
(GenerateParametersCheck):
* bindings/scripts/test/JS/JSTestObj.cpp:
(WebCore::jsTestObjPrototypeFunctionMethodWithOptionalNullableWrapper):
(WebCore::jsTestObjPrototypeFunctionMethodWithOptionalNullableWrapperIsNull):
(WebCore::jsTestObjPrototypeFunctionMethodWithOptionalXPathNSResolver):
(WebCore::jsTestObjPrototypeFunctionOverloadedMethod1):
(WebCore::jsTestObjPrototypeFunctionOverloadedMethod2):
(WebCore::jsTestObjPrototypeFunctionOverloadedMethod6):
(WebCore::jsTestObjPrototypeFunctionOverloadedMethodWithOptionalParameter1):
(WebCore::jsTestObjPrototypeFunctionOverloadedMethodWithOptionalParameter2):
(WebCore::jsTestObjPrototypeFunctionConvert2):
(WebCore::jsTestObjPrototypeFunctionStrictFunctionWithSequence):
(WebCore::jsTestObjPrototypeFunctionConditionalMethod3): Deleted.
(WebCore::jsTestObjPrototypeFunctionOverloadedMethod5): Deleted.
(WebCore::jsTestObjPrototypeFunctionOverloadedMethod): Deleted.
(WebCore::jsTestObjPrototypeFunctionOrange): Deleted.

LayoutTests:

Update / rebaseline existing tests to reflect behavior change. Also fix
several bugs in tests that became obvious now that we throw.

* editing/execCommand/indent-pre-expected.txt:
* editing/execCommand/indent-pre.html:
* editing/selection/4895428-2.html:
* editing/selection/move-by-word-visually-null-box.html:
* fast/dom/DOMImplementation/detached-doctype.html:
* fast/dom/MutationObserver/observe-attributes.html:
* fast/dom/Node/contains-method-expected.txt:
* fast/dom/Node/script-tests/contains-method.js:
* fast/dom/Window/webkitConvertPoint.html:
* fast/dom/adopt-node-crash-2.html:
* fast/dom/incompatible-operations-expected.txt:
* fast/dom/incompatible-operations.html:
* fast/events/selectstart-by-arrow-keys.html:
* fast/images/image-copy-memory-usage.html:
* fast/xsl/xslt-processor-expected.txt:
* http/tests/misc/webtiming-cross-origin-and-back1.html:
* platform/mac/fast/dom/Window/webkitConvertPoint-expected.txt:
* svg/custom/unicode-in-tspan-multi-svg-crash.html:

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@203941 268f45cc-cd09-0410-ab3c-d52691b4dbfc

24 files changed:
LayoutTests/ChangeLog
LayoutTests/editing/execCommand/indent-pre-expected.txt
LayoutTests/editing/execCommand/indent-pre.html
LayoutTests/editing/selection/4895428-2.html
LayoutTests/editing/selection/move-by-word-visually-null-box.html
LayoutTests/fast/dom/DOMImplementation/detached-doctype.html
LayoutTests/fast/dom/MutationObserver/observe-attributes.html
LayoutTests/fast/dom/Node/contains-method-expected.txt
LayoutTests/fast/dom/Node/script-tests/contains-method.js
LayoutTests/fast/dom/Window/webkitConvertPoint.html
LayoutTests/fast/dom/adopt-node-crash-2.html
LayoutTests/fast/dom/incompatible-operations-expected.txt
LayoutTests/fast/dom/incompatible-operations.html
LayoutTests/fast/events/selectstart-by-arrow-keys.html
LayoutTests/fast/images/image-copy-memory-usage.html
LayoutTests/fast/xsl/xslt-processor-expected.txt
LayoutTests/http/tests/misc/webtiming-cross-origin-and-back1.html
LayoutTests/imported/w3c/ChangeLog
LayoutTests/imported/w3c/web-platform-tests/dom/nodes/DOMImplementation-createDocument-expected.txt
LayoutTests/platform/mac/fast/dom/Window/webkitConvertPoint-expected.txt
LayoutTests/svg/custom/unicode-in-tspan-multi-svg-crash.html
Source/WebCore/ChangeLog
Source/WebCore/bindings/scripts/CodeGeneratorJS.pm
Source/WebCore/bindings/scripts/test/JS/JSTestObj.cpp

index bce6d22..00bc0a8 100644 (file)
@@ -1,3 +1,32 @@
+2016-07-30  Chris Dumez  <cdumez@apple.com>
+
+        [WebIDL] Enable strict type checking for operations' nullable parameters of wrapper types
+        https://bugs.webkit.org/show_bug.cgi?id=160374
+
+        Reviewed by Youenn Fablet.
+
+        Update / rebaseline existing tests to reflect behavior change. Also fix
+        several bugs in tests that became obvious now that we throw.
+
+        * editing/execCommand/indent-pre-expected.txt:
+        * editing/execCommand/indent-pre.html:
+        * editing/selection/4895428-2.html:
+        * editing/selection/move-by-word-visually-null-box.html:
+        * fast/dom/DOMImplementation/detached-doctype.html:
+        * fast/dom/MutationObserver/observe-attributes.html:
+        * fast/dom/Node/contains-method-expected.txt:
+        * fast/dom/Node/script-tests/contains-method.js:
+        * fast/dom/Window/webkitConvertPoint.html:
+        * fast/dom/adopt-node-crash-2.html:
+        * fast/dom/incompatible-operations-expected.txt:
+        * fast/dom/incompatible-operations.html:
+        * fast/events/selectstart-by-arrow-keys.html:
+        * fast/images/image-copy-memory-usage.html:
+        * fast/xsl/xslt-processor-expected.txt:
+        * http/tests/misc/webtiming-cross-origin-and-back1.html:
+        * platform/mac/fast/dom/Window/webkitConvertPoint-expected.txt:
+        * svg/custom/unicode-in-tspan-multi-svg-crash.html:
+
 2016-07-29  Chris Dumez  <cdumez@apple.com>
 
         Window's named properties should be exposed on a WindowProperties object in its prototype
index 3644251..5f1a137 100644 (file)
@@ -102,7 +102,7 @@ function setSelection(node)
     var textNode = node.firstChild;
     if (textNode.nodeType != Node.TEXT_NODE)
         throw "Wrong node type: " + textNode;
-    execSetSelectionCommand(textNode, 0, 0);
+    execSetSelectionCommand(textNode, 0, null);
 }
 
 function verifyTextSelection(startNode, startOffset, endNode, endOffset)
index 3cd0c51..bdea94f 100644 (file)
@@ -30,7 +30,7 @@ function setSelection(node)
     var textNode = node.firstChild;
     if (textNode.nodeType != Node.TEXT_NODE)
         throw "Wrong node type: " + textNode;
-    execSetSelectionCommand(textNode, 0, 0);
+    execSetSelectionCommand(textNode, 0, null);
 }
 
 function verifyTextSelection(startNode, startOffset, endNode, endOffset)
index 6bf1cda..8ba6967 100644 (file)
@@ -18,7 +18,7 @@ function runTest() {
     if (!window.testRunner)
         return;
     var cell = document.getElementById("cell");
-    cell.addEventListener(handleBlur, "DOMBlurEvent");
+    cell.addEventListener("DOMBlurEvent", handleBlur);
     var div = document.getElementById("div");
     div.focus();
     document.execCommand("SelectAll");
index 0f421b8..2432117 100644 (file)
@@ -9,7 +9,7 @@ onload = function() {
 
         // Test NULL VisiblePosition.
         var selection = getSelection();
-        selection.setPosition(0, 0);
+        selection.setPosition(null, 0);
         selection.modify("move", "right", "-webkit-visual-word");
         document.body.innerHTML = "Crash test passed";
     } finally {
index 99bb35b..43771b3 100644 (file)
@@ -14,7 +14,7 @@ if (window.testRunner)
     testRunner.dumpAsText();
 
 var o = document.implementation.createDocumentType('x', null, null);
-var doc = document.implementation.createDocument("doc", null, 0);
+var doc = document.implementation.createDocument("doc", null, null);
 for (i in o) {
     try { o[i]; } catch (e) {}
     try { o[i](); } catch (e) {}
index 70fdabd..36e23c5 100644 (file)
@@ -595,7 +595,7 @@ function testAttributeFilterNonHTMLDocument() {
     function start() {
         debug('Testing that attributeFilter respects case with non-HTML elements.');
 
-        svgDoc = document.implementation.createDocument('http://www.w3.org/2000/svg', 'svg', 'svg');
+        svgDoc = document.implementation.createDocument('http://www.w3.org/2000/svg', 'svg', null);
         mutations = null;
         observer = new MutationObserver(function(m) {
             mutations = m;
index 5bf7f58..3aeb1a1 100644 (file)
@@ -12,7 +12,7 @@ PASS document.contains(test1TextChild) is true
 PASS document.contains(document) is true
 PASS test1.contains(test1) is true
 PASS test1TextChild.contains(test1TextChild) is true
-PASS test1.contains(123) is false
+PASS test1.contains(123) threw exception TypeError: Argument 1 ('other') to Node.contains must be an instance of Node.
 PASS test1.contains(null) is false
 PASS document.contains(iframe) is false
 PASS iframe.contains(iframe) is true
index 99c7417..a8dc218 100644 (file)
@@ -14,7 +14,7 @@ shouldBeTrue("document.contains(test1TextChild)");
 shouldBeTrue("document.contains(document)");
 shouldBeTrue("test1.contains(test1)");
 shouldBeTrue("test1TextChild.contains(test1TextChild)");
-shouldBeFalse("test1.contains(123)");
+shouldThrow("test1.contains(123)");
 shouldBeFalse("test1.contains(null)");
 
 // Cross document tests
index c3b5e2b..b507d85 100644 (file)
             description("This test exercises the webkitConvertPointFromNodeToPage() function");
             
             debug("Test parameter passing - should not crash");
-            var point = webkitConvertPointFromNodeToPage(new WebKitPoint(0, 0));
-            if (point == null)
-                testPassed("Missing parameter test");
-            else
-                testFailed("Missing parameter test");
-            debug("Test did not crash and therefore was successful");
+            shouldThrow("webkitConvertPointFromNodeToPage(new WebKitPoint(0, 0))");
             debug("");
             point = webkitConvertPointFromNodeToPage(null, new WebKitPoint(0, 0));
             if (point == null)
index 1c1566a..7efea0a 100644 (file)
@@ -25,6 +25,8 @@ function doit()
     if (window.testRunner)
         testRunner.notifyDone();
 }
-document.addEventListener("DOMContentLoaded", setTimeout("doit()", 1), false);
+document.addEventListener("DOMContentLoaded", function() {
+    setTimeout("doit()", 1);
+}, false);
 </script>
 </html>
index 6145797..6eaed9a 100644 (file)
@@ -6,8 +6,8 @@ On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE
 PASS aNode.appendChild(aDOMImplementation) threw exception TypeError: Argument 1 ('node') to Node.appendChild must be an instance of Node.
 PASS aNode.appendChild('knort') threw exception TypeError: Argument 1 ('node') to Node.appendChild must be an instance of Node.
 PASS aNode.appendChild(void 0) threw exception TypeError: Argument 1 ('node') to Node.appendChild must be an instance of Node.
-PASS aNode.isSameNode(aDOMImplementation) is false
-PASS aNode.isSameNode('foo') is false
+PASS aNode.isSameNode(aDOMImplementation) threw exception TypeError: Argument 1 ('other') to Node.isSameNode must be an instance of Node.
+PASS aNode.isSameNode('foo') threw exception TypeError: Argument 1 ('other') to Node.isSameNode must be an instance of Node.
 PASS aNode.isSameNode(void 0) is false
 PASS aNode.lookupPrefix(aDOMImplementation) is null
 PASS aNode.lookupPrefix(void 0) is null
index 20d9597..d127ba4 100644 (file)
@@ -34,8 +34,8 @@ shouldThrow("aNode.appendChild('knort')");
 
 shouldThrow("aNode.appendChild(void 0)");
 
-shouldBeFalse("aNode.isSameNode(aDOMImplementation)");
-shouldBeFalse("aNode.isSameNode('foo')");
+shouldThrow("aNode.isSameNode(aDOMImplementation)");
+shouldThrow("aNode.isSameNode('foo')");
 shouldBeFalse("aNode.isSameNode(void 0)");
 shouldBe("aNode.lookupPrefix(aDOMImplementation)", "null");
 shouldBe("aNode.lookupPrefix(void 0)", "null");
index e5fdeab..775b138 100644 (file)
@@ -39,7 +39,7 @@ if (window.testRunner) {
 
     // On Mac, home/end doesn't move caret so manually select " World".
     if (navigator.platform.indexOf('Mac') == 0)
-        window.getSelection().setBaseAndExtent(div.firstChild, div.textContent.indexOf('World'), div.textContent.length);
+        window.getSelection().setBaseAndExtent(div.firstChild, div.textContent.indexOf('World'));
 
     eventSender.keyDown("leftArrow");
     logResult('Check (Left arrow)', 1);
index 354e746..b34b7cb 100644 (file)
@@ -41,7 +41,7 @@
                            // Add a listener for clipboard copy events which will then check how much memory was used to perform
                            // the copy and also finish the test. setTimeout() is used with a zero delay in order to cause this to
                            // run after the copy is finished.
-                           document.getElementById("animationFrame").contentWindow.document.addEventListener("copy",
+                           document.getElementById("animationFrame").contentWindow.document.addEventListener("copy", function() {
                                setTimeout(
                                        function()
                                    {
@@ -50,7 +50,7 @@
                                        shouldBeTrue("changeInCommittedVMBytes < 200000000");
                                        window.finishJSTest();
                                    },
-                                   0),
+                                   0) },
                                false);
 
                            // Exit if execCommand("copy") is not supported since that is needed to automatically copy the animation
index 32bd47f..168845f 100644 (file)
@@ -60,7 +60,7 @@ Success
 2.2 fragment with undefined output document:
 Success
 2.3 use non-DOMDocument output parameter:
-****Failure**** (expected exception, instead got result: "null")
+Success
 2.4 transform to same fragment twice:
 Success
 2.5 transformed fragment containing only text:
index 2d963ad..ce88c67 100644 (file)
@@ -7,7 +7,9 @@ if (window.testRunner)
 function doRedirect() {
     window.location = "http://127.0.0.1:8000/misc/resources/webtiming-cross-origin-and-back-redirect1.php";
 }
-addEventListener("load", setTimeout(doRedirect, 0));
+addEventListener("load", function() {
+    setTimeout(doRedirect, 0);
+});
 </script>
 </head>
 <body>
index ae946aa..ea28755 100644 (file)
@@ -1,3 +1,14 @@
+2016-07-30  Chris Dumez  <cdumez@apple.com>
+
+        [WebIDL] Enable strict type checking for operations' nullable parameters of wrapper types
+        https://bugs.webkit.org/show_bug.cgi?id=160374
+
+        Reviewed by Youenn Fablet.
+
+        Rebaseline W3C test now that one more check is passing.
+
+        * web-platform-tests/dom/nodes/DOMImplementation-createDocument-expected.txt:
+
 2016-07-29  Chris Dumez  <cdumez@apple.com>
 
         Window's named properties should be exposed on a WindowProperties object in its prototype
index 80e1917..493562c 100644 (file)
@@ -267,7 +267,7 @@ PASS createDocument test 153: "foo:","xmlns:foo",null,"NAMESPACE_ERR"
 PASS createDocument test 154: "foo:","xmlfoo:bar",null,null 
 PASS createDocument test 154: metadata for "foo:","xmlfoo:bar",null 
 PASS createDocument test 154: characterSet aliases for "foo:","xmlfoo:bar",null 
-FAIL createDocument test 155: null,null,false,object "TypeError" assert_throws: function "function () { document.implementation.createDocument(name..." did not throw
+PASS createDocument test 155: null,null,false,object "TypeError" 
 PASS createDocument test 156: null,null,null,null 
 PASS createDocument test 156: metadata for null,null,null 
 PASS createDocument test 156: characterSet aliases for null,null,null 
index 92f5a8f..c325a3f 100644 (file)
@@ -27,8 +27,7 @@ This test exercises the webkitConvertPointFromNodeToPage() function
 On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
 
 Test parameter passing - should not crash
-PASS Missing parameter test
-Test did not crash and therefore was successful
+PASS webkitConvertPointFromNodeToPage(new WebKitPoint(0, 0)) threw exception TypeError: Argument 1 ('node') to Window.webkitConvertPointFromNodeToPage must be an instance of Node.
 
 PASS null parameter test a
 Test did not crash and therefore was successful
index 2d1246d..c8ea3d4 100644 (file)
@@ -14,7 +14,7 @@
       document.designMode='on';
       filterInFirstRoot = document.getElementById('filterInFirstRoot');
       useElement = document.getElementById('useElement');
-      window.getSelection().setBaseAndExtent(filterInFirstRoot, useElement, 5);
+      window.getSelection().setBaseAndExtent(filterInFirstRoot, 0);
       document.execCommand('ForwardDelete');
       document.designMode='off';
     }
index b47792f..7087a3a 100644 (file)
@@ -1,3 +1,42 @@
+2016-07-30  Chris Dumez  <cdumez@apple.com>
+
+        [WebIDL] Enable strict type checking for operations' nullable parameters of wrapper types
+        https://bugs.webkit.org/show_bug.cgi?id=160374
+
+        Reviewed by Youenn Fablet.
+
+        Enable strict type checking for operations' nullable parameters of
+        wrapper types to comply with the Web IDL specification:
+        - http://heycam.github.io/webidl/#es-nullable-type
+        - http://heycam.github.io/webidl/#es-interface
+
+        For such parameters, if the JS passes a value that is not null /
+        undefined and does not have the expected wrapper type, then we now
+        throw a TypeError instead of silently converting the value to null.
+
+        This behavior is consistent with Chrome and Firefox. It also helps
+        identify bugs in JavaScript code.
+
+        No new tests, rebaselined existing tests.
+
+        * bindings/scripts/CodeGeneratorJS.pm:
+        (GenerateParametersCheck):
+        * bindings/scripts/test/JS/JSTestObj.cpp:
+        (WebCore::jsTestObjPrototypeFunctionMethodWithOptionalNullableWrapper):
+        (WebCore::jsTestObjPrototypeFunctionMethodWithOptionalNullableWrapperIsNull):
+        (WebCore::jsTestObjPrototypeFunctionMethodWithOptionalXPathNSResolver):
+        (WebCore::jsTestObjPrototypeFunctionOverloadedMethod1):
+        (WebCore::jsTestObjPrototypeFunctionOverloadedMethod2):
+        (WebCore::jsTestObjPrototypeFunctionOverloadedMethod6):
+        (WebCore::jsTestObjPrototypeFunctionOverloadedMethodWithOptionalParameter1):
+        (WebCore::jsTestObjPrototypeFunctionOverloadedMethodWithOptionalParameter2):
+        (WebCore::jsTestObjPrototypeFunctionConvert2):
+        (WebCore::jsTestObjPrototypeFunctionStrictFunctionWithSequence):
+        (WebCore::jsTestObjPrototypeFunctionConditionalMethod3): Deleted.
+        (WebCore::jsTestObjPrototypeFunctionOverloadedMethod5): Deleted.
+        (WebCore::jsTestObjPrototypeFunctionOverloadedMethod): Deleted.
+        (WebCore::jsTestObjPrototypeFunctionOrange): Deleted.
+
 2016-07-29  Chris Dumez  <cdumez@apple.com>
 
         Window's named properties should be exposed on a WindowProperties object in its prototype
index 9d361eb..42c2da8 100644 (file)
@@ -3750,7 +3750,7 @@ sub GenerateParametersCheck
             my $isTearOff = $codeGenerator->IsSVGTypeNeedingTearOff($type) && $interfaceName !~ /List$/;
             my $shouldPassByReference = $isTearOff || ShouldPassWrapperByReference($parameter, $interface);
 
-            if ($function->signature->extendedAttributes->{"StrictTypeChecking"} && !$shouldPassByReference && $codeGenerator->IsWrapperType($type)) {
+            if (!$shouldPassByReference && $codeGenerator->IsWrapperType($type)) {
                 $implIncludes{"<runtime/Error.h>"} = 1;
                 my $checkedArgument = "state->argument($argumentIndex)";
                 my $uncheckedArgument = "state->uncheckedArgument($argumentIndex)";
@@ -3759,12 +3759,13 @@ sub GenerateParametersCheck
                 push(@$outputArray, "    if (!$checkedArgument.isUndefinedOrNull()) {\n");
                 push(@$outputArray, "        $name = $nativeValue;\n");
                 if ($mayThrowException) {
-                    push(@$outputArray, "    if (UNLIKELY(state->hadException()))\n");
-                    push(@$outputArray, "        return JSValue::encode(jsUndefined());\n");
+                    push(@$outputArray, "        if (UNLIKELY(state->hadException()))\n");
+                    push(@$outputArray, "            return JSValue::encode(jsUndefined());\n");
                 }
                 push(@$outputArray, "        if (UNLIKELY(!$name))\n");
                 push(@$outputArray, "            return throwArgumentTypeError(*state, $argumentIndex, \"$name\", \"$visibleInterfaceName\", $quotedFunctionName, \"$type\");\n");
                 push(@$outputArray, "    }\n");
+                $value = "WTFMove($name)";
             } else {
                 if ($parameter->isOptional && defined($parameter->default) && !WillConvertUndefinedToDefaultParameterValue($type, $parameter->default)) {
                     my $defaultValue = $parameter->default;
@@ -4295,6 +4296,7 @@ my %nativeType = (
     "DOMTimeStamp" => "DOMTimeStamp",
     "Date" => "double",
     "Dictionary" => "Dictionary",
+    "EventListener" => "RefPtr<EventListener>",
     "SerializedScriptValue" => "RefPtr<SerializedScriptValue>",
     "XPathNSResolver" => "RefPtr<XPathNSResolver>",
     "any" => "JSC::JSValue",
index 3e7ef74..891efd8 100644 (file)
@@ -5028,7 +5028,12 @@ EncodedJSValue JSC_HOST_CALL jsTestObjPrototypeFunctionMethodWithOptionalNullabl
         return throwThisTypeError(*state, "TestObject", "methodWithOptionalNullableWrapper");
     ASSERT_GC_OBJECT_INHERITS(castedThis, JSTestObj::info());
     auto& impl = castedThis->wrapped();
-    auto obj = JSTestObj::toWrapped(state->argument(0));
+    TestObj* obj = nullptr;
+    if (!state->argument(0).isUndefinedOrNull()) {
+        obj = JSTestObj::toWrapped(state->uncheckedArgument(0));
+        if (UNLIKELY(!obj))
+            return throwArgumentTypeError(*state, 0, "obj", "TestObject", "methodWithOptionalNullableWrapper", "TestObj");
+    }
     impl.methodWithOptionalNullableWrapper(WTFMove(obj));
     return JSValue::encode(jsUndefined());
 }
@@ -5041,7 +5046,12 @@ EncodedJSValue JSC_HOST_CALL jsTestObjPrototypeFunctionMethodWithOptionalNullabl
         return throwThisTypeError(*state, "TestObject", "methodWithOptionalNullableWrapperIsNull");
     ASSERT_GC_OBJECT_INHERITS(castedThis, JSTestObj::info());
     auto& impl = castedThis->wrapped();
-    auto obj = JSTestObj::toWrapped(state->argument(0));
+    TestObj* obj = nullptr;
+    if (!state->argument(0).isUndefinedOrNull()) {
+        obj = JSTestObj::toWrapped(state->uncheckedArgument(0));
+        if (UNLIKELY(!obj))
+            return throwArgumentTypeError(*state, 0, "obj", "TestObject", "methodWithOptionalNullableWrapperIsNull", "TestObj");
+    }
     impl.methodWithOptionalNullableWrapperIsNull(WTFMove(obj));
     return JSValue::encode(jsUndefined());
 }
@@ -5054,9 +5064,14 @@ EncodedJSValue JSC_HOST_CALL jsTestObjPrototypeFunctionMethodWithOptionalXPathNS
         return throwThisTypeError(*state, "TestObject", "methodWithOptionalXPathNSResolver");
     ASSERT_GC_OBJECT_INHERITS(castedThis, JSTestObj::info());
     auto& impl = castedThis->wrapped();
-    auto resolver = JSXPathNSResolver::toWrapped(*state, state->argument(0));
-    if (UNLIKELY(state->hadException()))
-        return JSValue::encode(jsUndefined());
+    RefPtr<XPathNSResolver> resolver = nullptr;
+    if (!state->argument(0).isUndefinedOrNull()) {
+        resolver = JSXPathNSResolver::toWrapped(*state, state->uncheckedArgument(0));
+        if (UNLIKELY(state->hadException()))
+            return JSValue::encode(jsUndefined());
+        if (UNLIKELY(!resolver))
+            return throwArgumentTypeError(*state, 0, "resolver", "TestObject", "methodWithOptionalXPathNSResolver", "XPathNSResolver");
+    }
     impl.methodWithOptionalXPathNSResolver(WTFMove(resolver));
     return JSValue::encode(jsUndefined());
 }
@@ -5249,7 +5264,12 @@ static inline EncodedJSValue jsTestObjPrototypeFunctionOverloadedMethod1(ExecSta
     auto& impl = castedThis->wrapped();
     if (UNLIKELY(state->argumentCount() < 2))
         return throwVMError(state, createNotEnoughArgumentsError(state));
-    auto objArg = JSTestObj::toWrapped(state->argument(0));
+    TestObj* objArg = nullptr;
+    if (!state->argument(0).isUndefinedOrNull()) {
+        objArg = JSTestObj::toWrapped(state->uncheckedArgument(0));
+        if (UNLIKELY(!objArg))
+            return throwArgumentTypeError(*state, 0, "objArg", "TestObject", "overloadedMethod", "TestObj");
+    }
     auto strArg = state->argument(1).toWTFString(state);
     if (UNLIKELY(state->hadException()))
         return JSValue::encode(jsUndefined());
@@ -5267,7 +5287,12 @@ static inline EncodedJSValue jsTestObjPrototypeFunctionOverloadedMethod2(ExecSta
     auto& impl = castedThis->wrapped();
     if (UNLIKELY(state->argumentCount() < 1))
         return throwVMError(state, createNotEnoughArgumentsError(state));
-    auto objArg = JSTestObj::toWrapped(state->argument(0));
+    TestObj* objArg = nullptr;
+    if (!state->argument(0).isUndefinedOrNull()) {
+        objArg = JSTestObj::toWrapped(state->uncheckedArgument(0));
+        if (UNLIKELY(!objArg))
+            return throwArgumentTypeError(*state, 0, "objArg", "TestObject", "overloadedMethod", "TestObj");
+    }
     auto longArg = state->argument(1).isUndefined() ? Optional<int32_t>() : convert<int32_t>(*state, state->uncheckedArgument(1), NormalConversion);
     if (UNLIKELY(state->hadException()))
         return JSValue::encode(jsUndefined());
@@ -5336,9 +5361,14 @@ static inline EncodedJSValue jsTestObjPrototypeFunctionOverloadedMethod6(ExecSta
     auto& impl = castedThis->wrapped();
     if (UNLIKELY(state->argumentCount() < 1))
         return throwVMError(state, createNotEnoughArgumentsError(state));
-    auto listArg = JSDOMStringList::toWrapped(*state, state->argument(0));
-    if (UNLIKELY(state->hadException()))
-        return JSValue::encode(jsUndefined());
+    RefPtr<DOMStringList> listArg = nullptr;
+    if (!state->argument(0).isUndefinedOrNull()) {
+        listArg = JSDOMStringList::toWrapped(*state, state->uncheckedArgument(0));
+        if (UNLIKELY(state->hadException()))
+            return JSValue::encode(jsUndefined());
+        if (UNLIKELY(!listArg))
+            return throwArgumentTypeError(*state, 0, "listArg", "TestObject", "overloadedMethod", "DOMStringList");
+    }
     impl.overloadedMethod(WTFMove(listArg));
     return JSValue::encode(jsUndefined());
 }
@@ -5493,8 +5523,18 @@ static inline EncodedJSValue jsTestObjPrototypeFunctionOverloadedMethodWithOptio
     auto& impl = castedThis->wrapped();
     if (UNLIKELY(state->argumentCount() < 1))
         return throwVMError(state, createNotEnoughArgumentsError(state));
-    auto objArg1 = JSTestObj::toWrapped(state->argument(0));
-    auto objArg2 = JSTestObj::toWrapped(state->argument(1));
+    TestObj* objArg1 = nullptr;
+    if (!state->argument(0).isUndefinedOrNull()) {
+        objArg1 = JSTestObj::toWrapped(state->uncheckedArgument(0));
+        if (UNLIKELY(!objArg1))
+            return throwArgumentTypeError(*state, 0, "objArg1", "TestObject", "overloadedMethodWithOptionalParameter", "TestObj");
+    }
+    TestObj* objArg2 = nullptr;
+    if (!state->argument(1).isUndefinedOrNull()) {
+        objArg2 = JSTestObj::toWrapped(state->uncheckedArgument(1));
+        if (UNLIKELY(!objArg2))
+            return throwArgumentTypeError(*state, 1, "objArg2", "TestObject", "overloadedMethodWithOptionalParameter", "TestObj");
+    }
     impl.overloadedMethodWithOptionalParameter(WTFMove(objArg1), WTFMove(objArg2));
     return JSValue::encode(jsUndefined());
 }
@@ -5509,7 +5549,12 @@ static inline EncodedJSValue jsTestObjPrototypeFunctionOverloadedMethodWithOptio
     auto& impl = castedThis->wrapped();
     if (UNLIKELY(state->argumentCount() < 1))
         return throwVMError(state, createNotEnoughArgumentsError(state));
-    auto objArg = JSTestObj::toWrapped(state->argument(0));
+    TestObj* objArg = nullptr;
+    if (!state->argument(0).isUndefinedOrNull()) {
+        objArg = JSTestObj::toWrapped(state->uncheckedArgument(0));
+        if (UNLIKELY(!objArg))
+            return throwArgumentTypeError(*state, 0, "objArg", "TestObject", "overloadedMethodWithOptionalParameter", "TestObj");
+    }
     auto longArg = state->argument(1).isUndefined() ? Optional<int32_t>() : convert<int32_t>(*state, state->uncheckedArgument(1), NormalConversion);
     if (UNLIKELY(state->hadException()))
         return JSValue::encode(jsUndefined());
@@ -5800,7 +5845,12 @@ EncodedJSValue JSC_HOST_CALL jsTestObjPrototypeFunctionConvert2(ExecState* state
     auto& impl = castedThis->wrapped();
     if (UNLIKELY(state->argumentCount() < 1))
         return throwVMError(state, createNotEnoughArgumentsError(state));
-    auto value = JSTestNode::toWrapped(state->argument(0));
+    TestNode* value = nullptr;
+    if (!state->argument(0).isUndefinedOrNull()) {
+        value = JSTestNode::toWrapped(state->uncheckedArgument(0));
+        if (UNLIKELY(!value))
+            return throwArgumentTypeError(*state, 0, "value", "TestObject", "convert2", "TestNode");
+    }
     impl.convert2(WTFMove(value));
     return JSValue::encode(jsUndefined());
 }
@@ -5921,7 +5971,7 @@ EncodedJSValue JSC_HOST_CALL jsTestObjPrototypeFunctionStrictFunctionWithSequenc
     auto a = toNativeArray<uint32_t>(*state, state->argument(1));
     if (UNLIKELY(state->hadException()))
         return JSValue::encode(jsUndefined());
-    JSValue result = jsBoolean(impl.strictFunctionWithSequence(objArg, WTFMove(a), ec));
+    JSValue result = jsBoolean(impl.strictFunctionWithSequence(WTFMove(objArg), WTFMove(a), ec));
 
     setDOMException(state, ec);
     return JSValue::encode(result);