rounDOM INT32 MAX Fork

    @@ -1,119 +1,53 @@ /* - * @title v - * @description dumb jump to bottom of page; [Ctrl +] End alternatives + * @title rounDOM 2147483647 + * @description get Signed INT32 max value w/ DOM API * @include http://* * @include https://* - * @license MIT License https://opensource.org/licenses/MIT + * @contributor noromanba http://let.hatelabo.jp/noromanba/let/hLHUs7CEkec6 + * @contributor noromanba http://let.hatelabo.jp/noromanba/let/hLHVmL_ErMVx + * @contributor noromanba http://let.hatelabo.jp/noromanba/let/hLHVmL_RgoIK + * @license MIT License https://opensource.org/licenses/MIT * @javascript_url */ - // via - // https://hail2u.net/blog/coding/window-scrollto-infinity-infinity.html - - // TBD simulate End key press - - /* for mobile and legacy browsers - javascript:window.scrollTo(0,Math.max.apply(null,[document.documentElement.scrollHeight,document.documentElement.clientHeight,document.body.scrollHeight,document.body.clientHeight])) - javascript:window.scrollTo(0,Number.MAX_SAFE_INTEGER) - javascript:window.scrollTo(0,Number.MAX_VALUE) - */ - - // avoid Magic Number e.g. - // 99999..., 10000... and 1e100... (() => { 'use strict'; - //*/ boring... - window.scrollTo(0, Math.max(...[ - document.documentElement.scrollHeight, - document.documentElement.clientHeight, - document.body.scrollHeight, - document.body.clientHeight, - ])); - /*/ - window.scrollTo(0, Number.MAX_SAFE_INTEGER || Infinity); - // XXX `Infinity` is fallback/workaround for IE (might be fixed) c.f. - // https://hail2u.net/blog/coding/window-scrollto-infinity-infinity.html - // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/MAX_SAFE_INTEGER - // - // You can use `Number.MAX_VALUE` BUT exponential; - // so hard to try decimalization before truncate c.f. - // https://stackoverflow.com/questions/18719775/parsing-and-converting-exponential-values-to-decimal-in-javascript - // - // FIXME `Number.MAX_SAFE_INTEGER` methods do not working on Firefox 58.0.2 Desktop - // expected scroll to bottom, but actual scroll to top; like this - // window.scrollTo(0, 0) - // perhaps Fx treated like a "finite values", `NaN` and +/-`Infinity` c.f. - // https://www.w3.org/TR/cssom-view/#dom-window-scroll - // https://www.w3.org/TR/cssom-view/#normalize-non-finite-values - // https://www.w3.org/TR/cssom-view/#webidl-values - // - // scrollTo restricted from 32-bit limit? - // - // Firefox 58.0.2 mobile works fine - // `Number.MAX_SAFE_INTEGER`, `Number.MAX_VALUE` and `1e100` (!) - //*/ + const wall = document.head || document.body || document.documentElement; + const sandbox = wall.appendChild(document.createElement('iframe')); + + // [^1] DOM w/ IEEE_754 details c.f. + // http://let.hatelabo.jp/noromanba/let/hLHUs7CEkec6 + // Firefox Desktop ignoring >Signed INT32 + // so you can't use `Number.MAX_SAFE_INTEGER` + let rounder = sandbox.contentWindow.document.body; + // needs get after set + rounder.style.zIndex = Number.MAX_SAFE_INTEGER; + const MAX_SAFE_SIGNED_INT32 = Number(rounder.style.zIndex); + + if (!console || !console.assert) { + window.prompt('Signed +INT32: 2147483647?', MAX_SAFE_SIGNED_INT32); + return; + } + console.assert([ + 0x7FFFFFFF, + -1 >>> 1, + 2 ** (32 - 1) - 1, + MAX_SAFE_SIGNED_INT32, + ].every(v => v === 2147483647)); })(); - // DBG - // window.scrollTo() w/ constants X-Browser + // DEV // - // - Chromium 64.0.3282.167 32-bit arch - // - Firefox 58.0.2 32-bit arch - // - Edge mobile 1.0.0.1656 Blink 64-bit arch - // - Firefox mobile 58.0.2 64-bit arch - // - // - // Browser Compatibility Table - // - // [x] works - // [ ] like a finite, treated to `0` - // [-] not check yet - // - // | Browser | height | MAX_SAFE_INTEGER | MAX_VALUE | exponential | hex | - // |--------------|--------|------------------|-----------|-------------|-----| - // | Chromium | [x] | [x] | [ ] | [ ] | [x] | - // | Firefox | [x] | [ ] | [ ] | [ ] | [x] | - // | Edge mobi | [x] | [x] | [ ] | [ ] | [-] | - // | Firefox mobi | [x] | [x] | [x] | [x] | [-] | - // - // exponential: 1e100 - // hex: 0xFFFFFFF (< signed 32-bit limit) - // - // - // IEEE 754[-2008] c.f. - // https://en.wikipedia.org/wiki/IEEE_754 - // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/isSafeInteger - // - // Number.MAX_SAFE_INTEGER // 9007199254740991 - // Number.MAX_SAFE_INTEGER - // .toPrecision(16) // 9007199254740991 - // 2 ** 53 - 1 // 9007199254740991 - // Number.MAX_VALUE // 1.7976931348623157e+308 - // - // - // MAX_VALUE truncates - // - // bitwise op 32-bit signed number c.f. - // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Bitwise_Operators#Signed_32-bit_integers - // Math.pow(2, 32 -1) // 2147483648 - // - // Number.MAX_VALUE | 0 // 0 - // ~~Number.MAX_VALUE // 0 - // parseInt(Number.MAX_VALUE, 10) // 1 - // Math.trunc(Number.MAX_VALUE) // 1.7976931348623157e+308 - // - // - // Hex playing - // - // Number(0xFFFFFFFFFFFFFFFFF) // 295147905179352830000 - // Number(0xFFFFFFFFFFFFFFFFF0) // 4.722366482869645e+21 - // - // Chromium works - // window.scroll(0, '0x'.padEnd(Number.MAX_SAFE_INTEGER.toString().length, 'F')) - // - // Firefox works limit - // window.scrollTo(0, 0xFFFFFFF) // 268435455 - // 2 ** 32 - 1 // 2147483648 - // window.scrollTo(0, 0xFFFFFFF0) // 4294967280 + // [1]: + // Signed INT32 + // https://en.wikipedia.org/wiki/IEEE_754 + // https://en.wikipedia.org/wiki/Single-precision_floating-point_format + // specs + // https://www.w3.org/TR/CSS2/visuren.html#propdef-z-index + // TODO CSS3 spec + // https://www.w3.org/Style/CSS/ + // same as `window.scroll*()`, X-Browsers reports + // http://let.hatelabo.jp/noromanba/let/hLHVmL_RgoIK + // https://www.w3.org/TR/cssom-view/#webidl-values
  • /*
     * @title rounDOM 2147483647
     * @description get Signed INT32 max value w/ DOM API
     * @include http://*
     * @include https://*
     * @contributor noromanba   http://let.hatelabo.jp/noromanba/let/hLHUs7CEkec6
     * @contributor noromanba   http://let.hatelabo.jp/noromanba/let/hLHVmL_ErMVx
     * @contributor noromanba   http://let.hatelabo.jp/noromanba/let/hLHVmL_RgoIK
     * @license     MIT License https://opensource.org/licenses/MIT
     * @javascript_url
     */
    
    (() => {
        'use strict';
    
        const wall = document.head || document.body || document.documentElement;
        const sandbox = wall.appendChild(document.createElement('iframe'));
    
        // [^1] DOM w/ IEEE_754 details c.f.
        //       http://let.hatelabo.jp/noromanba/let/hLHUs7CEkec6
        //      Firefox Desktop ignoring >Signed INT32
        //      so you can't use `Number.MAX_SAFE_INTEGER`
        let rounder = sandbox.contentWindow.document.body;
        // needs get after set
        rounder.style.zIndex = Number.MAX_SAFE_INTEGER;
        const MAX_SAFE_SIGNED_INT32 = Number(rounder.style.zIndex);
    
        if (!console || !console.assert) {
            window.prompt('Signed +INT32: 2147483647?', MAX_SAFE_SIGNED_INT32);
            return;
        }
        console.assert([
            0x7FFFFFFF,
            -1 >>> 1,
            2 ** (32 - 1) - 1,
            MAX_SAFE_SIGNED_INT32,
        ].every(v => v === 2147483647));
    })();
    
    // DEV
    //
    // [1]:
    // Signed INT32
    //  https://en.wikipedia.org/wiki/IEEE_754
    //  https://en.wikipedia.org/wiki/Single-precision_floating-point_format
    // specs
    //  https://www.w3.org/TR/CSS2/visuren.html#propdef-z-index
    //  TODO CSS3 spec
    //   https://www.w3.org/Style/CSS/
    // same as `window.scroll*()`, X-Browsers reports
    //  http://let.hatelabo.jp/noromanba/let/hLHVmL_RgoIK
    //   https://www.w3.org/TR/cssom-view/#webidl-values
    
    
  • Permalink
    このページへの個別リンクです。
    RAW
    書かれたコードへの直接のリンクです。
    Packed
    文字列が圧縮された書かれたコードへのリンクです。
    Userscript
    Greasemonkey 等で利用する場合の .user.js へのリンクです。
    Loader
    @require やソースコードが長い場合に多段ロードする Loader コミのコードへのリンクです。
    Metadata
    コード中にコメントで @xxx と書かれたメタデータの JSON です。