Make WordPress Core

Changeset 56095


Ignore:
Timestamp:
06/28/2023 05:24:36 PM (3 years ago)
Author:
westonruter
Message:

Emoji: Pass functions as arguments in loader to account for minification and worker script.

Amends [56074].
Fixes #58472.
Props joemcgill, westonruter, azaozz.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/js/_enqueues/lib/emoji-loader.js

    r56074 r56095  
    180180         * @param {CanvasRenderingContext2D} context 2D Context.
    181181         * @param {string} type Whether to test for support of "flag" or "emoji".
     182         * @param {Function} emojiSetsRenderIdentically Reference to emojiSetsRenderIdentically function, needed due to minification.
    182183         *
    183184         * @return {boolean} True if the browser can render emoji, false if it cannot.
    184185         */
    185         function browserSupportsEmoji( context, type ) {
     186        function browserSupportsEmoji( context, type, emojiSetsRenderIdentically ) {
    186187                var isIdentical;
    187188
     
    279280         *
    280281         * @param {string[]} tests Tests.
     282         * @param {Function} browserSupportsEmoji Reference to browserSupportsEmoji function, needed due to minification.
     283         * @param {Function} emojiSetsRenderIdentically Reference to emojiSetsRenderIdentically function, needed due to minification.
    281284         *
    282285         * @return {SupportTests} Support tests.
    283286         */
    284         function testEmojiSupports( tests ) {
     287        function testEmojiSupports( tests, browserSupportsEmoji, emojiSetsRenderIdentically ) {
    285288                var canvas;
    286289                if (
     
    305308                var supports = {};
    306309                tests.forEach( function ( test ) {
    307                         supports[ test ] = browserSupportsEmoji( context, test );
     310                        supports[ test ] = browserSupportsEmoji( context, test, emojiSetsRenderIdentically );
    308311                } );
    309312                return supports;
     
    350353                if ( supportsWorkerOffloading() ) {
    351354                        try {
    352                                 /*
    353                                  * Note that this string contains the real source code for the
    354                                  * copied functions, _not_ a string representation of them. This
    355                                  * is because it's not possible to transfer a Function across
    356                                  * threads. The lack of quotes is intentional. The function names
    357                                  * are copied to variable names since minification will munge the
    358                                  * function names, thus breaking the ability for the functions to
    359                                  * refer to each other.
    360                                  */
     355                                // Note that the functions are being passed as arguments due to minification.
    361356                                var workerScript =
    362                                         'var emojiSetsRenderIdentically = ' + emojiSetsRenderIdentically + ';' +
    363                                         'var browserSupportsEmoji = ' + browserSupportsEmoji + ';' +
    364                                         'var testEmojiSupports = ' + testEmojiSupports + ';' +
    365                                         'postMessage(testEmojiSupports(' + JSON.stringify(tests) + '));';
     357                                        'postMessage(' +
     358                                        testEmojiSupports.toString() +
     359                                        '(' +
     360                                        [
     361                                                JSON.stringify( tests ),
     362                                                browserSupportsEmoji.toString(),
     363                                                emojiSetsRenderIdentically.toString()
     364                                        ].join( ',' ) +
     365                                        '));';
    366366                                var blob = new Blob( [ workerScript ], {
    367367                                        type: 'text/javascript'
     
    377377                }
    378378
    379                 supportTests = testEmojiSupports( tests );
     379                supportTests = testEmojiSupports( tests, browserSupportsEmoji, emojiSetsRenderIdentically );
    380380                setSessionSupportTests( supportTests );
    381381                resolve( supportTests );
Note: See TracChangeset for help on using the changeset viewer.