<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[200393] trunk/Source/WebCore</title>
</head>
<body>
<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; }
#msg dl a { font-weight: bold}
#msg dl a:link { color:#fc3; }
#msg dl a:active { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://trac.webkit.org/projects/webkit/changeset/200393">200393</a></dd>
<dt>Author</dt> <dd>cdumez@apple.com</dd>
<dt>Date</dt> <dd>2016-05-03 16:25:30 -0700 (Tue, 03 May 2016)</dd>
</dl>
<h3>Log Message</h3>
<pre>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:</pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkSourceWebCoreChangeLog">trunk/Source/WebCore/ChangeLog</a></li>
<li><a href="#trunkSourceWebCorebindingsscriptsCodeGeneratorJSpm">trunk/Source/WebCore/bindings/scripts/CodeGeneratorJS.pm</a></li>
<li><a href="#trunkSourceWebCorebindingsscriptstestGObjectWebKitDOMTestObjcpp">trunk/Source/WebCore/bindings/scripts/test/GObject/WebKitDOMTestObj.cpp</a></li>
<li><a href="#trunkSourceWebCorebindingsscriptstestJSJSTestObjcpp">trunk/Source/WebCore/bindings/scripts/test/JS/JSTestObj.cpp</a></li>
<li><a href="#trunkSourceWebCorebindingsscriptstestObjCDOMTestObjmm">trunk/Source/WebCore/bindings/scripts/test/ObjC/DOMTestObj.mm</a></li>
<li><a href="#trunkSourceWebCorebindingsscriptstestTestObjidl">trunk/Source/WebCore/bindings/scripts/test/TestObj.idl</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkSourceWebCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/ChangeLog (200392 => 200393)</h4>
<pre class="diff"><span>
<span class="info">--- 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)
</span><span class="lines">@@ -1,5 +1,34 @@
</span><span class="cx"> 2016-05-03 Chris Dumez <cdumez@apple.com>
</span><span class="cx">
</span><ins>+ 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 <cdumez@apple.com>
+
</ins><span class="cx"> Unreviewed, rolling out r199259 and r200161.
</span><span class="cx">
</span><span class="cx"> Seems to have caused a ~1.2% PLT regression on iOS
</span></span></pre></div>
<a id="trunkSourceWebCorebindingsscriptsCodeGeneratorJSpm"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/bindings/scripts/CodeGeneratorJS.pm (200392 => 200393)</h4>
<pre class="diff"><span>
<span class="info">--- 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)
</span><span class="lines">@@ -2855,21 +2855,29 @@
</span><span class="cx"> # is thrown rather than silently passing NULL to the C++ code.
</span><span class="cx"> # Per the Web IDL and ECMAScript specifications, incoming values can always be converted to
</span><span class="cx"> # both strings and numbers, so do not throw TypeError if the attribute is of these types.
</span><del>- if ($codeGenerator->IsWrapperType($type) && $attribute->signature->extendedAttributes->{"StrictTypeChecking"}) {
</del><ins>+ my ($nativeValue, $mayThrowException) = JSValueToNative($interface, $attribute->signature, "value", $attribute->signature->extendedAttributes->{"Conditional"});
+ if ($codeGenerator->IsWrapperType($type) && $attribute->signature->extendedAttributes->{"StrictTypeChecking"} && $attribute->signature->isNullable) {
</ins><span class="cx"> $implIncludes{"<runtime/Error.h>"} = 1;
</span><del>- 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");
</del><ins>+ 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");
+ }
</ins><span class="cx"> }
</span><span class="cx">
</span><del>- 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");
- }
-
</del><span class="cx"> if ($codeGenerator->IsEnumType($type)) {
</span><span class="cx"> push (@implContent, " if (UNLIKELY(!nativeValue))\n");
</span><span class="cx"> push (@implContent, " return false;\n");
</span></span></pre></div>
<a id="trunkSourceWebCorebindingsscriptstestGObjectWebKitDOMTestObjcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/bindings/scripts/test/GObject/WebKitDOMTestObj.cpp (200392 => 200393)</h4>
<pre class="diff"><span>
<span class="info">--- 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)
</span><span class="lines">@@ -2655,7 +2655,7 @@
</span><span class="cx"> g_return_if_fail(WEBKIT_DOM_IS_TEST_OBJ(value));
</span><span class="cx"> WebCore::TestObj* item = WebKit::core(self);
</span><span class="cx"> WebCore::TestObj* convertedValue = WebKit::core(value);
</span><del>- item->setStrictTypeCheckingAttribute(*convertedValue);
</del><ins>+ item->setStrictTypeCheckingAttribute(convertedValue);
</ins><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> glong webkit_dom_test_obj_get_with_script_state_attribute(WebKitDOMTestObj* self)
</span></span></pre></div>
<a id="trunkSourceWebCorebindingsscriptstestJSJSTestObjcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/bindings/scripts/test/JS/JSTestObj.cpp (200392 => 200393)</h4>
<pre class="diff"><span>
<span class="info">--- 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)
</span><span class="lines">@@ -3090,16 +3090,15 @@
</span><span class="cx"> return throwSetterTypeError(*state, "TestObj", "strictTypeCheckingAttribute");
</span><span class="cx"> }
</span><span class="cx"> auto& impl = castedThis->wrapped();
</span><del>- 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;
</del><ins>+ TestObj* nativeValue = nullptr;
+ if (!value.isUndefinedOrNull()) {
+ nativeValue = JSTestObj::toWrapped(value);
+ if (UNLIKELY(!nativeValue)) {
+ throwAttributeTypeError(*state, "TestObj", "strictTypeCheckingAttribute", "TestObj");
+ return false;
+ }
</ins><span class="cx"> }
</span><del>- impl.setStrictTypeCheckingAttribute(*nativeValue);
</del><ins>+ impl.setStrictTypeCheckingAttribute(nativeValue);
</ins><span class="cx"> return true;
</span><span class="cx"> }
</span><span class="cx">
</span></span></pre></div>
<a id="trunkSourceWebCorebindingsscriptstestObjCDOMTestObjmm"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/bindings/scripts/test/ObjC/DOMTestObj.mm (200392 => 200393)</h4>
<pre class="diff"><span>
<span class="info">--- 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)
</span><span class="lines">@@ -544,9 +544,7 @@
</span><span class="cx"> WebCore::JSMainThreadNullState state;
</span><span class="cx"> ASSERT(newStrictTypeCheckingAttribute);
</span><span class="cx">
</span><del>- if (!core(newStrictTypeCheckingAttribute))
- WebCore::raiseTypeErrorException();
- IMPL->setStrictTypeCheckingAttribute(*core(newStrictTypeCheckingAttribute));
</del><ins>+ IMPL->setStrictTypeCheckingAttribute(core(newStrictTypeCheckingAttribute));
</ins><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> - (int)customAttr
</span></span></pre></div>
<a id="trunkSourceWebCorebindingsscriptstestTestObjidl"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/bindings/scripts/test/TestObj.idl (200392 => 200393)</h4>
<pre class="diff"><span>
<span class="info">--- 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)
</span><span class="lines">@@ -137,7 +137,7 @@
</span><span class="cx"> [SetterRaisesException] attribute DOMString stringAttrWithSetterException;
</span><span class="cx">
</span><span class="cx"> // Strict type checking.
</span><del>- [StrictTypeChecking] attribute TestObj strictTypeCheckingAttribute;
</del><ins>+ [StrictTypeChecking] attribute TestObj? strictTypeCheckingAttribute;
</ins><span class="cx">
</span><span class="cx"> // 'Custom' extended attribute
</span><span class="cx"> [Custom] attribute long customAttr;
</span></span></pre>
</div>
</div>
</body>
</html>