RESOLVED FIXED Bug 55343
[ES5] Global Math object should be configurable but isn't
https://bugs.webkit.org/show_bug.cgi?id=55343
Summary [ES5] Global Math object should be configurable but isn't
Mark S. Miller
Reported 2011-02-27 20:14:05 PST
They are both still writable as they should be, so this isn't a big deal -- hence the classification as trivial. If you close this out as a wont-fix, please tag this with DeliberateSpecViolation (a new v8 tag introduced for this purpose) or some such so we can track these.
Attachments
Fix for JSON object (3.51 KB, patch)
2012-01-02 15:41 PST, Gavin Barraclough
no flags
Fix Math object. (3.73 KB, patch)
2012-09-21 10:26 PDT, Gavin Barraclough
oliver: review+
Gavin Barraclough
Comment 1 2011-06-17 00:56:31 PDT
*** Bug 55034 has been marked as a duplicate of this bug. ***
Gavin Barraclough
Comment 2 2012-01-02 15:41:25 PST
Created attachment 120897 [details] Fix for JSON object Our current handling of Math & JSON (treating them as non-configurable vars) allows slightly faster access. This is probably not significant for typical JSON loads, since in real world usage the overhead of one property access from the global object is nothing compared to the cost of loading JSON data over the network, the host call to the parse function, and running the parser over the JSON data. Fast access to the Math object is more important since it is used for very small, fast intrinsic functions that will be inlined by the JIT, e.g. abs. We should fix this bug for the Math object too, but there we will need to pay more concern to avoiding any performance penalty – in the case of the JSON object there is no real justification to retain our current incorrect behavior.
Gavin Barraclough
Comment 3 2012-01-02 18:37:31 PST
Fixed for JSON object in r103921, updating title to reflect this.
Mark S. Miller
Comment 4 2012-01-03 04:31:45 PST
(In reply to comment #2) > Created an attachment (id=120897) [details] > Fix for JSON object > > [...] Math [...] slightly faster access. [..] Fast access to the Math object is more important since it is used for very small, fast intrinsic functions that will be inlined by the JIT, e.g. abs. We should fix this bug for the Math object too, but there we will need to pay more concern to avoiding any performance penalty [...] I just tested on WebKit Nightly r103874, and as I expected the properties on the Math object are correctly writable and configurable. Thus, you have to worry about cache invalidation for of calls to these Math functions anyway. Given that, is it still more expensive to have assignment to Math also invalidate these same caches? > Math.abs = function(x){return x;} > Math.abs(-7) -7
Gavin Barraclough
Comment 5 2012-01-03 10:45:38 PST
(In reply to comment #4) > Given that, is it still more expensive to have assignment to Math also invalidate these same caches? Hi Mark, The way our engine works, if we store Math in a regular property on the global object the calling abs will require 3 independent checks: 1) Check the shape of the global object, ensure there is still a 'Math' property at the expected offset. 2) Load the 'Math' property from a fixed offset in the global object's storage. 3) Check the shape of the Math object, ensure there is still a 'abs' property at the expected offset. 2) Load the 'abs' property from a fixed offset in the Math object's storage. 5) Check the abs function is callable (or is the expected value, or check that it is the abs intrinsic, depending on optimizations). If 'Math' is a var on the global object instead of a property, and as such non-configurable, we can skip step 1 (Math will always be present at the same offset into the var storage). We should be able to better optimize the process of access to variables like this – of course the fact we have incorrectly been treating 'Math' as a var has been artificially taking away a key incentive to do so! cheers, G.
Eric Seidel (no email)
Comment 6 2012-03-27 12:33:34 PDT
Attachment 120897 [details] was posted by a committer and has review+, assigning to Gavin Barraclough for commit.
Gavin Barraclough
Comment 7 2012-03-27 12:38:23 PDT
Comment on attachment 120897 [details] Fix for JSON object Clearing review flag, this was landed in r103921.
Gavin Barraclough
Comment 8 2012-09-21 10:26:44 PDT
Created attachment 165153 [details] Fix Math object. This no longer has any bearing on performance.
Eric Seidel (no email)
Comment 9 2012-09-21 11:05:59 PDT
Comment on attachment 165153 [details] Fix Math object. I'm surprised we don't have a more centralized test for what global objects are deletable or not. :) LGTM too.
Gavin Barraclough
Comment 10 2012-09-21 11:08:55 PDT
Fixed in r129241
Gavin Barraclough
Comment 11 2012-09-21 12:03:46 PDT
(In reply to comment #9) > (From update of attachment 165153 [details]) > I'm surprised we don't have a more centralized test for what global objects are deletable or not. :) LGTM too. Funnily enough, this isn't covered by the Test262 suite. Ideally I think a test should be added there and then we should find a way to start running that, though I think if I import the full Test262 suite into LayoutTests people are going to not like me for the runtime. :-)
Note You need to log in before you can comment on or make changes to this bug.