From c999806024cfc2c4d7951ea3f73545eb2c94740b Mon Sep 17 00:00:00 2001 From: Matthew Amato Date: Fri, 30 Mar 2018 20:58:51 -0400 Subject: [PATCH 1/3] Fix JavaScript parsing error in IE 10 and earlier While Cesium doesn't work in IE10, we need to allow the JS to parse so that an app can still function without Cesium. In this case, Uint8ClampedArray isn't supported in IE 10, so the arraySlice polyfill was throwing on load. I cleaned up `arraySlide` and deduplicated rom TypedArray code into FeatureDetection. To Test, load Viewer in IE11 with the debugger open and set to IE10 compatibility mode. --- Source/Core/FeatureDetection.js | 17 ++++++++- Source/Core/arraySlice.js | 68 +++++++++++---------------------- Specs/equals.js | 18 +-------- 3 files changed, 40 insertions(+), 63 deletions(-) diff --git a/Source/Core/FeatureDetection.js b/Source/Core/FeatureDetection.js index 772b744ea697..1d9ee2a17224 100644 --- a/Source/Core/FeatureDetection.js +++ b/Source/Core/FeatureDetection.js @@ -7,6 +7,7 @@ define([ defined, Fullscreen) { 'use strict'; + /*global CanvasPixelArray*/ var theNavigator; if (typeof navigator !== 'undefined') { @@ -196,6 +197,19 @@ define([ return supportsImageRenderingPixelated() ? imageRenderingValueResult : undefined; } + var typedArrayTypes = []; + if (typeof ArrayBuffer !== 'undefined') { + typedArrayTypes.push(Int8Array, Uint8Array, Int16Array, Uint16Array, Int32Array, Uint32Array, Float32Array, Float64Array); + + if (typeof Uint8ClampedArray !== 'undefined') { + typedArrayTypes.push(Uint8ClampedArray); + } + + if (typeof CanvasPixelArray !== 'undefined') { + typedArrayTypes.push(CanvasPixelArray); + } + } + /** * A set of functions to detect whether the current browser supports * various features. @@ -219,7 +233,8 @@ define([ hardwareConcurrency : defaultValue(theNavigator.hardwareConcurrency, 3), supportsPointerEvents : supportsPointerEvents, supportsImageRenderingPixelated: supportsImageRenderingPixelated, - imageRenderingValue: imageRenderingValue + imageRenderingValue: imageRenderingValue, + typedArrayTypes: typedArrayTypes }; /** diff --git a/Source/Core/arraySlice.js b/Source/Core/arraySlice.js index deb9aa766eeb..16c8955ece3f 100644 --- a/Source/Core/arraySlice.js +++ b/Source/Core/arraySlice.js @@ -10,7 +10,17 @@ define([ FeatureDetection) { 'use strict'; - var slice = function(array, begin, end) { + /** + * Create a shallow copy of an array from begin to end. + * + * @param {Array} array The array to fill. + * @param {Number} [begin=0] The index to start at. + * @param {Number} [end=array.length] The index to end at which is not included. + * + * @returns {Array} The resulting array. + * @private + */ + function arraySlice(array, begin, end) { //>>includeStart('debug', pragmas.debug); Check.defined('array', array); if (defined(begin)) { @@ -20,54 +30,22 @@ define([ Check.typeOf.number('end', end); } //>>includeEnd('debug'); - return array.slice(begin, end); - }; - - if (FeatureDetection.supportsTypedArrays()) { - var tempArray = new Uint8Array(1); - if (typeof tempArray.slice !== 'function') { - var typedArrayTypes = [Int8Array, Uint8Array, Uint8ClampedArray, Int16Array, Uint16Array, Int32Array, Uint32Array, Float32Array, Float64Array]; - slice = function(array, begin, end) { - //>>includeStart('debug', pragmas.debug); - Check.defined('array', array); - if (defined(begin)) { - Check.typeOf.number('begin', begin); - } - if (defined(end)) { - Check.typeOf.number('end', end); - } - //>>includeEnd('debug'); - - if (typeof array.slice === 'function') { - return array.slice(begin, end); - } - var copy = Array.prototype.slice.call(array, begin, end); - var length = typedArrayTypes.length; - for (var i = 0; i < length; ++i) { - if (array instanceof typedArrayTypes[i]) { - copy = new typedArrayTypes[i](copy); - break; - } - } + if (typeof array.slice === 'function') { + return array.slice(begin, end); + } - return copy; - }; + var copy = Array.prototype.slice.call(array, begin, end); + var typedArrayTypes = FeatureDetection.typedarrayTypes; + var length = typedArrayTypes.length; + for (var i = 0; i < length; ++i) { + if (array instanceof typedArrayTypes[i]) { + copy = new typedArrayTypes[i](copy); + break; + } } - } - /** - * Create a shallow copy of an array from begin to end. - * - * @param {Array} array The array to fill. - * @param {Number} [begin=0] The index to start at. - * @param {Number} [end=array.length] The index to end at which is not included. - * - * @returns {Array} The resulting array. - * @private - */ - function arraySlice(array, begin, end) { - return slice(array, begin, end); + return copy; } return arraySlice; diff --git a/Specs/equals.js b/Specs/equals.js index caeb2a650d39..6d47c07f9016 100644 --- a/Specs/equals.js +++ b/Specs/equals.js @@ -3,25 +3,9 @@ define([ ], function( FeatureDetection) { 'use strict'; - /*global CanvasPixelArray*/ - - var typedArrayTypes = []; - - // Earlier versions of IE do not support typed arrays - if (FeatureDetection.supportsTypedArrays()) { - typedArrayTypes.push(Int8Array, Uint8Array, Int16Array, Uint16Array, Int32Array, Uint32Array, Float32Array, Float64Array); - - if (typeof Uint8ClampedArray !== 'undefined') { - typedArrayTypes.push(Uint8ClampedArray); - } - - if (typeof CanvasPixelArray !== 'undefined') { - typedArrayTypes.push(CanvasPixelArray); - } - } function isTypedArray(o) { - return typedArrayTypes.some(function(type) { + return FeatureDetection.typedArrayTypes.some(function(type) { return o instanceof type; }); } From f3cae02814132ed2cef11f016376ad04851aab94 Mon Sep 17 00:00:00 2001 From: Matthew Amato Date: Mon, 9 Apr 2018 15:17:29 -0400 Subject: [PATCH 2/3] Fix typo. --- Source/Core/arraySlice.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/Core/arraySlice.js b/Source/Core/arraySlice.js index 16c8955ece3f..a8f0e03b1b9c 100644 --- a/Source/Core/arraySlice.js +++ b/Source/Core/arraySlice.js @@ -36,7 +36,7 @@ define([ } var copy = Array.prototype.slice.call(array, begin, end); - var typedArrayTypes = FeatureDetection.typedarrayTypes; + var typedArrayTypes = FeatureDetection.typedArrayTypes; var length = typedArrayTypes.length; for (var i = 0; i < length; ++i) { if (array instanceof typedArrayTypes[i]) { From 44d679be3df59dcb3a74cd1d05272fae230042f3 Mon Sep 17 00:00:00 2001 From: Matthew Amato Date: Mon, 9 Apr 2018 15:20:03 -0400 Subject: [PATCH 3/3] Update CHANGES --- CHANGES.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGES.md b/CHANGES.md index dc89a88e91b9..43e04b9b137b 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -9,6 +9,7 @@ Change Log * Fixed glTF support to handle skinned meshes when no skin is supplied. [#6061](https://github.com/AnalyticalGraphicsInc/cesium/issues/6061) * Allow loadWithXhr to work with string URLs in a web worker. * Fix Firefox WebGL console warnings. [#5912](https://github.com/AnalyticalGraphicsInc/cesium/issues/5912) +* Fix parsing Cesium.js in older browsers that do not support all TypedArray types. [#6396](https://github.com/AnalyticalGraphicsInc/cesium/pull/6396) ##### Additions :tada: * Improved `MapboxImageryProvider` performance by 300% via `tiles.mapbox.com` subdomain switching. [#6426](https://github.com/AnalyticalGraphicsInc/cesium/issues/6426)