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) 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..a8f0e03b1b9c 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; }); }