From 83080f8e438ff2b0742cc9a64bc4f4e4251ce66e Mon Sep 17 00:00:00 2001 From: Gary Pendergast Date: Thu, 17 Mar 2016 04:53:49 +0000 Subject: [PATCH] Emoji: Fix the diversity emoji check in Safari. When the browser test for diversity emoji was added in [36160], it included a workaround for Chrome not being able to compare `Uint8ClampedArray` objects directly, by converting them to a string. Unfortunately, Safari doesn't support the `Uint8ClampedArray.toString()` method correctly, so the test was incorrectly failing in Safari. Fixes #36266 for trunk. git-svn-id: https://develop.svn.wordpress.org/trunk@37028 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-includes/js/wp-emoji-loader.js | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/wp-includes/js/wp-emoji-loader.js b/src/wp-includes/js/wp-emoji-loader.js index 015ebc9125..ea8ad8209a 100755 --- a/src/wp-includes/js/wp-emoji-loader.js +++ b/src/wp-includes/js/wp-emoji-loader.js @@ -14,7 +14,7 @@ var canvas = document.createElement( 'canvas' ), context = canvas.getContext && canvas.getContext( '2d' ), stringFromCharCode = String.fromCharCode, - tone; + tonedata, tone, tone2; if ( ! context || ! context.fillText ) { return false; @@ -48,10 +48,15 @@ * compares if the emoji rendering has changed. */ context.fillText( stringFromCharCode( 55356, 57221 ), 0, 0 ); - tone = context.getImageData( 16, 16, 1, 1 ).data.toString(); + tonedata = context.getImageData( 16, 16, 1, 1 ).data; + context.fillText( stringFromCharCode( 55356, 57221, 55356, 57343 ), 0, 0 ); - // Chrome has issues comparing arrays, so we compare it as a string, instead. - return tone !== context.getImageData( 16, 16, 1, 1 ).data.toString(); + // Chrome has issues comparing arrays, and Safari has issues converting arrays to strings. + // So, we create our own string and compare that, instead. + tonedata = context.getImageData( 16, 16, 1, 1 ).data; + tone2 = tonedata[0] + ',' + tonedata[1] + ',' + tonedata[2] + ',' + tonedata[3]; + + return tone !== tone2; case 'simple': /* * This creates a smiling emoji, and checks to see if there is any image data in the