Title: [200393] trunk/Source/WebCore
Revision
200393
Author
[email protected]
Date
2016-05-03 16:25:30 -0700 (Tue, 03 May 2016)

Log Message

Optimize [StrictTypeChecking] on IDL attributes
https://bugs.webkit.org/show_bug.cgi?id=157321

Reviewed by Geoffrey Garen.

Optimize [StrictTypeChecking] on IDL attributes:
- Only generate extra code for nullable attributes because for non-nullable
  attributes, JSXXX::toWrapped() will return null in case of a bad input
  type. We will then throw a TypeError when null-checking it already.
- After the JSValue::isNullOrUndefined() check, avoid calling
  JSXXX::toWrapped() and set nativeValue to nullptr directly.
- Drop the check for JSValue::inherits(JSXXX::info()) and just do a null
  check on the value returned by JSXXX::toWrapped(). toWrapped() already
  does a JSValue::inherits(JSXXX::info() check. Since we only call
  toWrapped() if the JSValue is not null/undefined, a null return value
  always indicates a bad input type.

* bindings/scripts/CodeGeneratorJS.pm:
(GenerateImplementation):
* bindings/scripts/test/GObject/WebKitDOMTestObj.cpp:
(webkit_dom_test_obj_set_strict_type_checking_attribute):
* bindings/scripts/test/JS/JSTestObj.cpp:
(WebCore::setJSTestObjStrictTypeCheckingAttribute):
* bindings/scripts/test/ObjC/DOMTestObj.mm:
(-[DOMTestObj setStrictTypeCheckingAttribute:]):
* bindings/scripts/test/TestObj.idl:

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (200392 => 200393)


--- trunk/Source/WebCore/ChangeLog	2016-05-03 23:01:46 UTC (rev 200392)
+++ trunk/Source/WebCore/ChangeLog	2016-05-03 23:25:30 UTC (rev 200393)
@@ -1,5 +1,34 @@
 2016-05-03  Chris Dumez  <[email protected]>
 
+        Optimize [StrictTypeChecking] on IDL attributes
+        https://bugs.webkit.org/show_bug.cgi?id=157321
+
+        Reviewed by Geoffrey Garen.
+
+        Optimize [StrictTypeChecking] on IDL attributes:
+        - Only generate extra code for nullable attributes because for non-nullable
+          attributes, JSXXX::toWrapped() will return null in case of a bad input
+          type. We will then throw a TypeError when null-checking it already.
+        - After the JSValue::isNullOrUndefined() check, avoid calling
+          JSXXX::toWrapped() and set nativeValue to nullptr directly.
+        - Drop the check for JSValue::inherits(JSXXX::info()) and just do a null
+          check on the value returned by JSXXX::toWrapped(). toWrapped() already
+          does a JSValue::inherits(JSXXX::info() check. Since we only call
+          toWrapped() if the JSValue is not null/undefined, a null return value
+          always indicates a bad input type.
+
+        * bindings/scripts/CodeGeneratorJS.pm:
+        (GenerateImplementation):
+        * bindings/scripts/test/GObject/WebKitDOMTestObj.cpp:
+        (webkit_dom_test_obj_set_strict_type_checking_attribute):
+        * bindings/scripts/test/JS/JSTestObj.cpp:
+        (WebCore::setJSTestObjStrictTypeCheckingAttribute):
+        * bindings/scripts/test/ObjC/DOMTestObj.mm:
+        (-[DOMTestObj setStrictTypeCheckingAttribute:]):
+        * bindings/scripts/test/TestObj.idl:
+
+2016-05-03  Chris Dumez  <[email protected]>
+
         Unreviewed, rolling out r199259 and r200161.
 
         Seems to have caused a ~1.2% PLT regression on iOS

Modified: trunk/Source/WebCore/bindings/scripts/CodeGeneratorJS.pm (200392 => 200393)


--- trunk/Source/WebCore/bindings/scripts/CodeGeneratorJS.pm	2016-05-03 23:01:46 UTC (rev 200392)
+++ trunk/Source/WebCore/bindings/scripts/CodeGeneratorJS.pm	2016-05-03 23:25:30 UTC (rev 200393)
@@ -2855,21 +2855,29 @@
                 # is thrown rather than silently passing NULL to the C++ code.
                 # Per the Web IDL and ECMAScript specifications, incoming values can always be converted to
                 # both strings and numbers, so do not throw TypeError if the attribute is of these types.
-                if ($codeGenerator->IsWrapperType($type) && $attribute->signature->extendedAttributes->{"StrictTypeChecking"}) {
+                my ($nativeValue, $mayThrowException) = JSValueToNative($interface, $attribute->signature, "value", $attribute->signature->extendedAttributes->{"Conditional"});
+                if ($codeGenerator->IsWrapperType($type) && $attribute->signature->extendedAttributes->{"StrictTypeChecking"} && $attribute->signature->isNullable) {
                     $implIncludes{"<runtime/Error.h>"} = 1;
-                    push(@implContent, "    if (UNLIKELY(!value.isUndefinedOrNull() && !value.inherits(JS${type}::info()))) {\n");
-                    push(@implContent, "        throwAttributeTypeError(*state, \"$interfaceName\", \"$name\", \"$type\");\n");
-                    push(@implContent, "        return false;\n");
-                    push(@implContent, "    };\n");
+                    push(@implContent, "    " . GetNativeTypeFromSignature($attribute->signature) . " nativeValue = nullptr;\n");
+                    push(@implContent, "    if (!value.isUndefinedOrNull()) {\n");
+                    push(@implContent, "        nativeValue = $nativeValue;\n");
+                    if ($mayThrowException) {
+                        push(@implContent, "    if (UNLIKELY(state->hadException()))\n");
+                        push(@implContent, "        return false;\n");
+                    }
+                    push(@implContent, "        if (UNLIKELY(!nativeValue)) {\n");
+                    push(@implContent, "            throwAttributeTypeError(*state, \"$interfaceName\", \"$name\", \"$type\");\n");
+                    push(@implContent, "            return false;\n");
+                    push(@implContent, "        }\n");
+                    push(@implContent, "    }\n");
+                } else {
+                    push(@implContent, "    " . GetNativeTypeFromSignature($attribute->signature) . " nativeValue = $nativeValue;\n");
+                    if ($mayThrowException) {
+                        push(@implContent, "    if (UNLIKELY(state->hadException()))\n");
+                        push(@implContent, "        return false;\n");
+                    }
                 }
 
-                my ($nativeValue, $mayThrowException) = JSValueToNative($interface, $attribute->signature, "value", $attribute->signature->extendedAttributes->{"Conditional"});
-                push(@implContent, "    " . GetNativeTypeFromSignature($attribute->signature) . " nativeValue = $nativeValue;\n");
-                if ($mayThrowException) {
-                    push(@implContent, "    if (UNLIKELY(state->hadException()))\n");
-                    push(@implContent, "        return false;\n");
-                }
-
                 if ($codeGenerator->IsEnumType($type)) {
                     push (@implContent, "    if (UNLIKELY(!nativeValue))\n");
                     push (@implContent, "        return false;\n");

Modified: trunk/Source/WebCore/bindings/scripts/test/GObject/WebKitDOMTestObj.cpp (200392 => 200393)


--- trunk/Source/WebCore/bindings/scripts/test/GObject/WebKitDOMTestObj.cpp	2016-05-03 23:01:46 UTC (rev 200392)
+++ trunk/Source/WebCore/bindings/scripts/test/GObject/WebKitDOMTestObj.cpp	2016-05-03 23:25:30 UTC (rev 200393)
@@ -2655,7 +2655,7 @@
     g_return_if_fail(WEBKIT_DOM_IS_TEST_OBJ(value));
     WebCore::TestObj* item = WebKit::core(self);
     WebCore::TestObj* convertedValue = WebKit::core(value);
-    item->setStrictTypeCheckingAttribute(*convertedValue);
+    item->setStrictTypeCheckingAttribute(convertedValue);
 }
 
 glong webkit_dom_test_obj_get_with_script_state_attribute(WebKitDOMTestObj* self)

Modified: trunk/Source/WebCore/bindings/scripts/test/JS/JSTestObj.cpp (200392 => 200393)


--- trunk/Source/WebCore/bindings/scripts/test/JS/JSTestObj.cpp	2016-05-03 23:01:46 UTC (rev 200392)
+++ trunk/Source/WebCore/bindings/scripts/test/JS/JSTestObj.cpp	2016-05-03 23:25:30 UTC (rev 200393)
@@ -3090,16 +3090,15 @@
         return throwSetterTypeError(*state, "TestObj", "strictTypeCheckingAttribute");
     }
     auto& impl = castedThis->wrapped();
-    if (UNLIKELY(!value.isUndefinedOrNull() && !value.inherits(JSTestObj::info()))) {
-        throwAttributeTypeError(*state, "TestObj", "strictTypeCheckingAttribute", "TestObj");
-        return false;
-    };
-    TestObj* nativeValue = JSTestObj::toWrapped(value);
-    if (UNLIKELY(!nativeValue)) {
-        throwVMTypeError(state);
-        return false;
+    TestObj* nativeValue = nullptr;
+    if (!value.isUndefinedOrNull()) {
+        nativeValue = JSTestObj::toWrapped(value);
+        if (UNLIKELY(!nativeValue)) {
+            throwAttributeTypeError(*state, "TestObj", "strictTypeCheckingAttribute", "TestObj");
+            return false;
+        }
     }
-    impl.setStrictTypeCheckingAttribute(*nativeValue);
+    impl.setStrictTypeCheckingAttribute(nativeValue);
     return true;
 }
 

Modified: trunk/Source/WebCore/bindings/scripts/test/ObjC/DOMTestObj.mm (200392 => 200393)


--- trunk/Source/WebCore/bindings/scripts/test/ObjC/DOMTestObj.mm	2016-05-03 23:01:46 UTC (rev 200392)
+++ trunk/Source/WebCore/bindings/scripts/test/ObjC/DOMTestObj.mm	2016-05-03 23:25:30 UTC (rev 200393)
@@ -544,9 +544,7 @@
     WebCore::JSMainThreadNullState state;
     ASSERT(newStrictTypeCheckingAttribute);
 
-    if (!core(newStrictTypeCheckingAttribute))
-        WebCore::raiseTypeErrorException();
-    IMPL->setStrictTypeCheckingAttribute(*core(newStrictTypeCheckingAttribute));
+    IMPL->setStrictTypeCheckingAttribute(core(newStrictTypeCheckingAttribute));
 }
 
 - (int)customAttr

Modified: trunk/Source/WebCore/bindings/scripts/test/TestObj.idl (200392 => 200393)


--- trunk/Source/WebCore/bindings/scripts/test/TestObj.idl	2016-05-03 23:01:46 UTC (rev 200392)
+++ trunk/Source/WebCore/bindings/scripts/test/TestObj.idl	2016-05-03 23:25:30 UTC (rev 200393)
@@ -137,7 +137,7 @@
     [SetterRaisesException] attribute DOMString stringAttrWithSetterException;
 
     // Strict type checking.
-    [StrictTypeChecking] attribute TestObj strictTypeCheckingAttribute;
+    [StrictTypeChecking] attribute TestObj? strictTypeCheckingAttribute;
 
     // 'Custom' extended attribute
     [Custom] attribute long            customAttr;
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to