From 10c6e2e0e880fd7d7f8ee0589c2186f6630e3a53 Mon Sep 17 00:00:00 2001 From: Weston Ruter Date: Wed, 28 Jun 2023 17:26:26 +0000 Subject: [PATCH] Emoji: Pass functions as arguments in loader to account for minification and worker script. Amends [56074]. Fixes #58472. Props joemcgill, westonruter, azaozz. Built from https://develop.svn.wordpress.org/trunk@56095 git-svn-id: http://core.svn.wordpress.org/trunk@55607 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/js/wp-emoji-loader.js | 34 +++++++++++++-------------- wp-includes/js/wp-emoji-loader.min.js | 2 +- wp-includes/version.php | 2 +- 3 files changed, 19 insertions(+), 19 deletions(-) diff --git a/wp-includes/js/wp-emoji-loader.js b/wp-includes/js/wp-emoji-loader.js index f32fbaa384..2dce4e2637 100644 --- a/wp-includes/js/wp-emoji-loader.js +++ b/wp-includes/js/wp-emoji-loader.js @@ -179,10 +179,11 @@ * * @param {CanvasRenderingContext2D} context 2D Context. * @param {string} type Whether to test for support of "flag" or "emoji". + * @param {Function} emojiSetsRenderIdentically Reference to emojiSetsRenderIdentically function, needed due to minification. * * @return {boolean} True if the browser can render emoji, false if it cannot. */ - function browserSupportsEmoji( context, type ) { + function browserSupportsEmoji( context, type, emojiSetsRenderIdentically ) { var isIdentical; switch ( type ) { @@ -278,10 +279,12 @@ * @private * * @param {string[]} tests Tests. + * @param {Function} browserSupportsEmoji Reference to browserSupportsEmoji function, needed due to minification. + * @param {Function} emojiSetsRenderIdentically Reference to emojiSetsRenderIdentically function, needed due to minification. * * @return {SupportTests} Support tests. */ - function testEmojiSupports( tests ) { + function testEmojiSupports( tests, browserSupportsEmoji, emojiSetsRenderIdentically ) { var canvas; if ( typeof WorkerGlobalScope !== 'undefined' && @@ -304,7 +307,7 @@ var supports = {}; tests.forEach( function ( test ) { - supports[ test ] = browserSupportsEmoji( context, test ); + supports[ test ] = browserSupportsEmoji( context, test, emojiSetsRenderIdentically ); } ); return supports; } @@ -349,20 +352,17 @@ if ( supportsWorkerOffloading() ) { try { - /* - * Note that this string contains the real source code for the - * copied functions, _not_ a string representation of them. This - * is because it's not possible to transfer a Function across - * threads. The lack of quotes is intentional. The function names - * are copied to variable names since minification will munge the - * function names, thus breaking the ability for the functions to - * refer to each other. - */ + // Note that the functions are being passed as arguments due to minification. var workerScript = - 'var emojiSetsRenderIdentically = ' + emojiSetsRenderIdentically + ';' + - 'var browserSupportsEmoji = ' + browserSupportsEmoji + ';' + - 'var testEmojiSupports = ' + testEmojiSupports + ';' + - 'postMessage(testEmojiSupports(' + JSON.stringify(tests) + '));'; + 'postMessage(' + + testEmojiSupports.toString() + + '(' + + [ + JSON.stringify( tests ), + browserSupportsEmoji.toString(), + emojiSetsRenderIdentically.toString() + ].join( ',' ) + + '));'; var blob = new Blob( [ workerScript ], { type: 'text/javascript' } ); @@ -376,7 +376,7 @@ } catch ( e ) {} } - supportTests = testEmojiSupports( tests ); + supportTests = testEmojiSupports( tests, browserSupportsEmoji, emojiSetsRenderIdentically ); setSessionSupportTests( supportTests ); resolve( supportTests ); } ) diff --git a/wp-includes/js/wp-emoji-loader.min.js b/wp-includes/js/wp-emoji-loader.min.js index 60629920e1..38f33b869f 100644 --- a/wp-includes/js/wp-emoji-loader.min.js +++ b/wp-includes/js/wp-emoji-loader.min.js @@ -1,2 +1,2 @@ /*! This file is auto-generated */ -!function(a,n){var o,s,e;function i(e){if("undefined"!=typeof sessionStorage)try{var t={supportTests:e,timestamp:(new Date).valueOf()};sessionStorage.setItem(o,JSON.stringify(t))}catch(e){}}function p(e,t,n){e.clearRect(0,0,e.canvas.width,e.canvas.height),e.fillText(t,0,0);var t=new Uint32Array(e.getImageData(0,0,e.canvas.width,e.canvas.height).data),r=(e.clearRect(0,0,e.canvas.width,e.canvas.height),e.fillText(n,0,0),new Uint32Array(e.getImageData(0,0,e.canvas.width,e.canvas.height).data));return t.every(function(e,t){return e===r[t]})}function c(e,t){switch(t){case"flag":return p(e,"\ud83c\udff3\ufe0f\u200d\u26a7\ufe0f","\ud83c\udff3\ufe0f\u200b\u26a7\ufe0f")?!1:!p(e,"\ud83c\uddfa\ud83c\uddf3","\ud83c\uddfa\u200b\ud83c\uddf3")&&!p(e,"\ud83c\udff4\udb40\udc67\udb40\udc62\udb40\udc65\udb40\udc6e\udb40\udc67\udb40\udc7f","\ud83c\udff4\u200b\udb40\udc67\u200b\udb40\udc62\u200b\udb40\udc65\u200b\udb40\udc6e\u200b\udb40\udc67\u200b\udb40\udc7f");case"emoji":return!p(e,"\ud83e\udef1\ud83c\udffb\u200d\ud83e\udef2\ud83c\udfff","\ud83e\udef1\ud83c\udffb\u200b\ud83e\udef2\ud83c\udfff")}return!1}function f(e){var t="undefined"!=typeof WorkerGlobalScope&&self instanceof WorkerGlobalScope?new OffscreenCanvas(300,150):a.createElement("canvas"),n=t.getContext("2d",{willReadFrequently:!0}),r=(n.textBaseline="top",n.font="600 32px Arial",{});return e.forEach(function(e){r[e]=c(n,e)}),r}function t(e){var t=a.createElement("script");t.src=e,t.defer=!0,a.head.appendChild(t)}"undefined"!=typeof Promise&&(o="wpEmojiSettingsSupports",s=["flag","emoji"],n.supports={everything:!0,everythingExceptFlag:!0},e=new Promise(function(e){a.addEventListener("DOMContentLoaded",e,{once:!0})}),new Promise(function(t){var n=function(){if("undefined"!=typeof sessionStorage&&o in sessionStorage)try{var e=JSON.parse(sessionStorage.getItem(o));if("object"==typeof e&&"number"==typeof e.timestamp&&(new Date).valueOf()