Rename Number.prototype.clz to Math.clz

Jason Orendorff jason.orendorff at gmail.com
Thu Jan 16 06:50:56 PST 2014


On Wed, Jan 15, 2014 at 1:26 PM, Allen Wirfs-Brock
<allen at wirfs-brock.com> wrote:
> So we discussed all that when we made that decision.  I understand that you disagree but is there any new data that should cause us to reopen an issue that was already discussed and decided at a TC39 meeting?

Well, here's one data point. This function, like most Math functions,
is particularly useful for systems that compile to JS, like
Emscripten. See <https://bugzilla.mozilla.org/show_bug.cgi?id=925123>.

Emscripten emits code (roughly) like this:

    function program() {
        var sin = Math.sin;
        ... lots of functions that call sin() ...
        return main;
    }

This kind of code has nice tamper-resistant semantics and (not
coincidentally) it will scream on existing JS engines.

If clz is a Math function, Emscripten can just

    var clz = Math.clz;

If it's a method, it would have to emit something like:

    var clz = Function.prototype.call.bind(Number.prototype.clz);

and hope the JS engines all optimize away the bound method call.

-j


More information about the es-discuss mailing list