RESOLVED FIXED 130775
[Bindings] constants are always typed to 'int'
https://bugs.webkit.org/show_bug.cgi?id=130775
Summary [Bindings] constants are always typed to 'int'
Antonio Gomes
Reported 2014-03-26 08:02:09 PDT
that makes the following IDL return -1 (overflow) instead of the actual result. ] interface NodeFilter { ... // Constants for whatToShow const unsigned long SHOW_ALL = 0xFFFFFFFF; ... } Generated code from this IDL looks like: JSValue jsNodeFilterSHOW_ALL(ExecState* exec, JSValue, PropertyName) { UNUSED_PARAM(exec); return jsNumber(static_cast<int>(0xFFFFFFFF)); <--- OVERFLOW } Firefox, for instance, returns 4294967295 as expected.
Attachments
patch - for EWS (10.38 KB, patch)
2014-03-26 14:30 PDT, Antonio Gomes
buildbot: commit-queue-
Archive of layout-test-results from webkit-ews-15 for mac-mountainlion-wk2 (463.44 KB, application/zip)
2014-03-26 15:39 PDT, Build Bot
no flags
Archive of layout-test-results from webkit-ews-03 for mac-mountainlion (550.11 KB, application/zip)
2014-03-26 16:39 PDT, Build Bot
no flags
Archive of layout-test-results from webkit-ews-16 for mac-mountainlion-wk2 (464.79 KB, application/zip)
2014-03-26 16:47 PDT, Build Bot
no flags
Archive of layout-test-results from webkit-ews-06 for mac-mountainlion (489.17 KB, application/zip)
2014-03-26 18:06 PDT, Build Bot
no flags
patch - for review (11.81 KB, patch)
2014-03-26 21:32 PDT, Antonio Gomes
darin: review-
buildbot: commit-queue-
Archive of layout-test-results from webkit-ews-16 for mac-mountainlion-wk2 (568.37 KB, application/zip)
2014-03-26 23:44 PDT, Build Bot
no flags
patch - as per Darin's review (12.47 KB, patch)
2014-03-27 15:46 PDT, Antonio Gomes
no flags
(actual) patch - as per Darin's review (12.93 KB, patch)
2014-03-27 15:52 PDT, Antonio Gomes
darin: review+
Darin Adler
Comment 1 2014-03-26 08:50:39 PDT
We should try just removing "static_cast<int>" from the generated code. I don’t think that cast is doing us any good. Actually parsing the type of the constant (“unsigned long”) would be OK, but likely is not needed. I suggest we make tests for all these enum values. They would be very easy to write: shouldBe("NodeFilter.SHOW_ALL", "0xFFFFFFFF");
Antonio Gomes
Comment 2 2014-03-26 09:41:31 PDT
(In reply to comment #1) > We should try just removing "static_cast<int>" from the generated code. I don’t think that cast is doing us any good. It might be important to static_cast it, so the proper jsNumber constructor can be called? > Actually parsing the type of the constant (“unsigned long”) would be OK, but likely is not needed. We already here this information: - push(@implContent, " return JSValue::encode(jsNumber(static_cast<int>(" . $constant->value . ")));\n"); + push(@implContent, " return JSValue::encode(jsNumber(static_cast<" . $constant->type . ">(" . $constant->value . ")));\n"); > I suggest we make tests for all these enum values. They would be very easy to write: > > shouldBe("NodeFilter.SHOW_ALL", "0xFFFFFFFF"); Sounds good. There are actually compile-times tests dumped into the generated C++ code, but an IDL might have a "DoNotCheckConstants" extended attribute entry, that bypasses it.
Darin Adler
Comment 3 2014-03-26 10:07:54 PDT
(In reply to comment #2) > (In reply to comment #1) > > We should try just removing "static_cast<int>" from the generated code. I don’t think that cast is doing us any good. > > It might be important to static_cast it, so the proper jsNumber constructor can be called? No, I don’t believe it is important. Generally speaking, the jsNumber constructor should correctly convert a number passed in of most any C++ type. It’s overloaded for the various types. But of course we need to test to make sure it works. > > Actually parsing the type of the constant (“unsigned long”) would be OK, but likely is not needed. > > We already here this information: > > - push(@implContent, " return JSValue::encode(jsNumber(static_cast<int>(" . $constant->value . ")));\n"); > + push(@implContent, " return JSValue::encode(jsNumber(static_cast<" . $constant->type . ">(" . $constant->value . ")));\n"); If $constant->type is going to be “unsigned long” then the code above is going to be incorrect. The type “unsigned long” in IDL needs to turn into “unsigned” in C++. That’s one of the reasons I made my suggestion above. Casting to unsigned long will convert to 64-bit on a 64-bit system, which is something we don’t want to do. > There are actually compile-times tests dumped into the generated C++ code, but an IDL might have a "DoNotCheckConstants" extended attribute entry, that bypasses it. Tests in C++ code would not be sufficient. We need to test this in JavaScript, since it’s a JavaScript binding we are testing.
Antonio Gomes
Comment 4 2014-03-26 14:30:15 PDT
Created attachment 227885 [details] patch - for EWS
Build Bot
Comment 5 2014-03-26 15:38:59 PDT
Comment on attachment 227885 [details] patch - for EWS Attachment 227885 [details] did not pass mac-wk2-ews (mac-wk2): Output: http://webkit-queues.appspot.com/results/6078183057129472 New failing tests: fast/dom/constants.html
Build Bot
Comment 6 2014-03-26 15:39:03 PDT
Created attachment 227893 [details] Archive of layout-test-results from webkit-ews-15 for mac-mountainlion-wk2 The attached test failures were seen while running run-webkit-tests on the mac-wk2-ews. Bot: webkit-ews-15 Port: mac-mountainlion-wk2 Platform: Mac OS X 10.8.5
Build Bot
Comment 7 2014-03-26 16:39:13 PDT
Comment on attachment 227885 [details] patch - for EWS Attachment 227885 [details] did not pass mac-ews (mac): Output: http://webkit-queues.appspot.com/results/5987782585483264 New failing tests: fast/dom/constants.html
Build Bot
Comment 8 2014-03-26 16:39:19 PDT
Created attachment 227897 [details] Archive of layout-test-results from webkit-ews-03 for mac-mountainlion The attached test failures were seen while running run-webkit-tests on the mac-ews. Bot: webkit-ews-03 Port: mac-mountainlion Platform: Mac OS X 10.8.5
Build Bot
Comment 9 2014-03-26 16:47:11 PDT
Comment on attachment 227885 [details] patch - for EWS Attachment 227885 [details] did not pass mac-wk2-ews (mac-wk2): Output: http://webkit-queues.appspot.com/results/4716566755147776 New failing tests: fast/dom/constants.html
Build Bot
Comment 10 2014-03-26 16:47:17 PDT
Created attachment 227899 [details] Archive of layout-test-results from webkit-ews-16 for mac-mountainlion-wk2 The attached test failures were seen while running run-webkit-tests on the mac-wk2-ews. Bot: webkit-ews-16 Port: mac-mountainlion-wk2 Platform: Mac OS X 10.8.5
Build Bot
Comment 11 2014-03-26 18:06:17 PDT
Comment on attachment 227885 [details] patch - for EWS Attachment 227885 [details] did not pass mac-ews (mac): Output: http://webkit-queues.appspot.com/results/4573937333698560 New failing tests: fast/dom/constants.html
Build Bot
Comment 12 2014-03-26 18:06:24 PDT
Created attachment 227901 [details] Archive of layout-test-results from webkit-ews-06 for mac-mountainlion The attached test failures were seen while running run-webkit-tests on the mac-ews. Bot: webkit-ews-06 Port: mac-mountainlion Platform: Mac OS X 10.8.5
Antonio Gomes
Comment 13 2014-03-26 21:32:49 PDT
Created attachment 227918 [details] patch - for review
Build Bot
Comment 14 2014-03-26 23:44:24 PDT
Comment on attachment 227918 [details] patch - for review Attachment 227918 [details] did not pass mac-wk2-ews (mac-wk2): Output: http://webkit-queues.appspot.com/results/5823585985757184 New failing tests: media/W3C/audio/canPlayType/canPlayType_application_octet_stream_with_codecs_1.html
Build Bot
Comment 15 2014-03-26 23:44:28 PDT
Created attachment 227927 [details] Archive of layout-test-results from webkit-ews-16 for mac-mountainlion-wk2 The attached test failures were seen while running run-webkit-tests on the mac-wk2-ews. Bot: webkit-ews-16 Port: mac-mountainlion-wk2 Platform: Mac OS X 10.8.5
Antonio Gomes
Comment 16 2014-03-27 12:48:30 PDT
Darin, could you review the patch?
Darin Adler
Comment 17 2014-03-27 15:31:28 PDT
Comment on attachment 227918 [details] patch - for review View in context: https://bugs.webkit.org/attachment.cgi?id=227918&action=review Fix is good, but LayoutTests part of patch is wrong. > LayoutTests/fast/dom/constants-expected.txt:30 > -PASS: nodeFilter.SHOW_ALL should be -1 and is. > +FAIL: nodeFilter.SHOW_ALL should be -1 but instead is 4294967295. This is wrong. We should fix the fast/dom/constants.html test itself, which we now believe was expecting the wrong thing. We should not instead update the expected results to show failure! > Source/WebCore/ChangeLog:16 > + NodeFilter.SHOW_ALL (0xFFFFFF). Should have 8 Fs there, not 6.
Antonio Gomes
Comment 18 2014-03-27 15:46:25 PDT
Created attachment 227998 [details] patch - as per Darin's review
Antonio Gomes
Comment 19 2014-03-27 15:52:12 PDT
Created attachment 227999 [details] (actual) patch - as per Darin's review
Darin Adler
Comment 20 2014-03-27 17:10:02 PDT
Comment on attachment 227999 [details] (actual) patch - as per Darin's review View in context: https://bugs.webkit.org/attachment.cgi?id=227999&action=review > LayoutTests/fast/dom/constants.html:83 > + shouldBe("nodeFilter.SHOW_ALL", 4294967295); I would have written this as 0xFFFFFFFF. > LayoutTests/fast/dom/constants.html:100 > + shouldBe("window.NodeFilter.SHOW_ALL", 4294967295); Ditto.
Antonio Gomes
Comment 21 2014-03-28 10:53:31 PDT
(In reply to comment #20) > (From update of attachment 227999 [details]) > View in context: https://bugs.webkit.org/attachment.cgi?id=227999&action=review > > > LayoutTests/fast/dom/constants.html:83 > > + shouldBe("nodeFilter.SHOW_ALL", 4294967295); > > I would have written this as 0xFFFFFFFF. > > > LayoutTests/fast/dom/constants.html:100 > > + shouldBe("window.NodeFilter.SHOW_ALL", 4294967295); > > Ditto. Done: <https://trac.webkit.org/r166413>
Note You need to log in before you can comment on or make changes to this bug.