Skip to content

Commit

Permalink
Merge pull request #8526 from fredj/Array.isArray
Browse files Browse the repository at this point in the history
Replace isArray.js with native Array.isArray function
  • Loading branch information
mramato authored Mar 2, 2020
2 parents dbba447 + ff06f99 commit 0642d46
Show file tree
Hide file tree
Showing 23 changed files with 56 additions and 65 deletions.
2 changes: 1 addition & 1 deletion Apps/Sandcastle/gallery/Clustering.html
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@
var pickedLabel = viewer.scene.pick(movement.position);
if (Cesium.defined(pickedLabel)) {
var ids = pickedLabel.id;
if (Cesium.isArray(ids)) {
if (Array.isArray(ids)) {
for (var i = 0; i < ids.length; ++i) {
ids[i].billboard.color = Cesium.Color.RED;
}
Expand Down
3 changes: 3 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ Change Log
* Fixed a bug where applying a new 3D Tiles style during a flight would not update all existing tiles. [#8622](https://github.com/CesiumGS/cesium/pull/8622)
* Fixed a bug where Cartesian vectors could not be packed to typed arrays [#8568](https://github.com/AnalyticalGraphicsInc/cesium/pull/8568)

##### Deprecated :hourglass_flowing_sand:
* The `isArray` function has been deprecated and will be removed in Cesium 1.69. Use the native `Array.isArray` function instead. [#8526](https://github.com/CesiumGS/cesium/pull/8526)

### 1.66.0 - 2020-02-03

##### Deprecated :hourglass_flowing_sand:
Expand Down
5 changes: 2 additions & 3 deletions Source/Core/PolylinePipeline.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import Ellipsoid from './Ellipsoid.js';
import EllipsoidGeodesic from './EllipsoidGeodesic.js';
import EllipsoidRhumbLine from './EllipsoidRhumbLine.js';
import IntersectionTests from './IntersectionTests.js';
import isArray from './isArray.js';
import CesiumMath from './Math.js';
import Matrix4 from './Matrix4.js';
import Plane from './Plane.js';
Expand Down Expand Up @@ -260,7 +259,7 @@ import Plane from './Plane.js';
var length = positions.length;
var ellipsoid = defaultValue(options.ellipsoid, Ellipsoid.WGS84);
var height = defaultValue(options.height, 0);
var hasHeightArray = isArray(height);
var hasHeightArray = Array.isArray(height);

if (length < 1) {
return [];
Expand Down Expand Up @@ -351,7 +350,7 @@ import Plane from './Plane.js';
var length = positions.length;
var ellipsoid = defaultValue(options.ellipsoid, Ellipsoid.WGS84);
var height = defaultValue(options.height, 0);
var hasHeightArray = isArray(height);
var hasHeightArray = Array.isArray(height);

if (length < 1) {
return [];
Expand Down
10 changes: 9 additions & 1 deletion Source/Core/isArray.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,24 @@
import defined from './defined.js';
import deprecationWarning from './deprecationWarning.js';

/**
* Tests an object to see if it is an array.
* @exports isArray
*
* @param {*} value The value to test.
* @returns {Boolean} true if the value is an array, false otherwise.
* @deprecated See https://github.com/AnalyticalGraphicsInc/cesium/issues/8526.
* Use `Array.isArray` instead
*/
var isArray = Array.isArray;
if (!defined(isArray)) {
isArray = function(value) {
return Object.prototype.toString.call(value) === '[object Array]';
};
}
export default isArray;

function isArrayFunction(value) {
deprecationWarning('isArray', 'isArray will be removed in Cesium 1.69. Use the native `Array.isArray` function instead.');
return isArray(value);
}
export default isArrayFunction;
3 changes: 1 addition & 2 deletions Source/Core/objectToQuery.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import defined from './defined.js';
import DeveloperError from './DeveloperError.js';
import isArray from './isArray.js';

/**
* Converts an object representing a set of name/value pairs into a query string,
Expand Down Expand Up @@ -36,7 +35,7 @@ import isArray from './isArray.js';
var value = obj[propName];

var part = encodeURIComponent(propName) + '=';
if (isArray(value)) {
if (Array.isArray(value)) {
for (var i = 0, len = value.length; i < len; ++i) {
result += part + encodeURIComponent(value[i]) + '&';
}
Expand Down
3 changes: 1 addition & 2 deletions Source/Core/queryToObject.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import defined from './defined.js';
import DeveloperError from './DeveloperError.js';
import isArray from './isArray.js';

/**
* Parses a query string into an object, where the keys and values of the object are the
Expand Down Expand Up @@ -50,7 +49,7 @@ import isArray from './isArray.js';
if (typeof resultValue === 'string') {
// expand the single value to an array
result[name] = [resultValue, value];
} else if (isArray(resultValue)) {
} else if (Array.isArray(resultValue)) {
resultValue.push(value);
} else {
result[name] = value;
Expand Down
23 changes: 11 additions & 12 deletions Source/DataSources/CzmlDataSource.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import Event from '../Core/Event.js';
import ExtrapolationType from '../Core/ExtrapolationType.js';
import getFilenameFromUri from '../Core/getFilenameFromUri.js';
import HermitePolynomialApproximation from '../Core/HermitePolynomialApproximation.js';
import isArray from '../Core/isArray.js';
import Iso8601 from '../Core/Iso8601.js';
import JulianDate from '../Core/JulianDate.js';
import LagrangePolynomialApproximation from '../Core/LagrangePolynomialApproximation.js';
Expand Down Expand Up @@ -776,7 +775,7 @@ import Cesium3DTilesetGraphics from './Cesium3DTilesetGraphics.js';
return;
}

if (isArray(packetData)) {
if (Array.isArray(packetData)) {
for (var i = 0, len = packetData.length; i < len; ++i) {
processProperty(type, object, propertyName, packetData[i], interval, sourceUri, entityCollection);
}
Expand Down Expand Up @@ -950,7 +949,7 @@ import Cesium3DTilesetGraphics from './Cesium3DTilesetGraphics.js';
return;
}

if (isArray(packetData)) {
if (Array.isArray(packetData)) {
for (var i = 0, len = packetData.length; i < len; ++i) {
processPositionProperty(object, propertyName, packetData[i], interval, sourceUri, entityCollection);
}
Expand Down Expand Up @@ -1086,7 +1085,7 @@ import Cesium3DTilesetGraphics from './Cesium3DTilesetGraphics.js';
return;
}

if (isArray(packetData)) {
if (Array.isArray(packetData)) {
for (var i = 0, len = packetData.length; i < len; ++i) {
processMaterialProperty(object, propertyName, packetData[i], interval, sourceUri, entityCollection);
}
Expand Down Expand Up @@ -1148,7 +1147,7 @@ import Cesium3DTilesetGraphics from './Cesium3DTilesetGraphics.js';
}

var propertyData = propertiesData[key];
if (isArray(propertyData)) {
if (Array.isArray(propertyData)) {
for (var i = 0, len = propertyData.length; i < len; ++i) {
processProperty(getPropertyType(propertyData[i]), entity.properties, key, propertyData[i], undefined, sourceUri, entityCollection);
}
Expand Down Expand Up @@ -1200,7 +1199,7 @@ import Cesium3DTilesetGraphics from './Cesium3DTilesetGraphics.js';
return;
}

if (isArray(packetData)) {
if (Array.isArray(packetData)) {
for (var i = 0, length = packetData.length; i < length; ++i) {
processArrayPacketData(object, propertyName, packetData[i], entityCollection);
}
Expand Down Expand Up @@ -1233,7 +1232,7 @@ import Cesium3DTilesetGraphics from './Cesium3DTilesetGraphics.js';
return;
}

if (isArray(packetData)) {
if (Array.isArray(packetData)) {
for (var i = 0, length = packetData.length; i < length; ++i) {
processPositionArrayPacketData(object, propertyName, packetData[i], entityCollection);
}
Expand Down Expand Up @@ -1283,7 +1282,7 @@ import Cesium3DTilesetGraphics from './Cesium3DTilesetGraphics.js';
return;
}

if (isArray(packetData)) {
if (Array.isArray(packetData)) {
for (var i = 0, length = packetData.length; i < length; ++i) {
processPositionArrayOfArraysPacketData(object, propertyName, packetData[i], entityCollection);
}
Expand All @@ -1299,7 +1298,7 @@ import Cesium3DTilesetGraphics from './Cesium3DTilesetGraphics.js';
}

var intervals;
if (isArray(packetData)) {
if (Array.isArray(packetData)) {
for (var i = 0, len = packetData.length; i < len; ++i) {
if (!defined(intervals)) {
intervals = new TimeIntervalCollection();
Expand Down Expand Up @@ -1617,7 +1616,7 @@ import Cesium3DTilesetGraphics from './Cesium3DTilesetGraphics.js';
var i, len;
var nodeTransformationsData = modelData.nodeTransformations;
if (defined(nodeTransformationsData)) {
if (isArray(nodeTransformationsData)) {
if (Array.isArray(nodeTransformationsData)) {
for (i = 0, len = nodeTransformationsData.length; i < len; ++i) {
processNodeTransformations(model, nodeTransformationsData[i], interval, sourceUri, entityCollection);
}
Expand All @@ -1628,7 +1627,7 @@ import Cesium3DTilesetGraphics from './Cesium3DTilesetGraphics.js';

var articulationsData = modelData.articulations;
if (defined(articulationsData)) {
if (isArray(articulationsData)) {
if (Array.isArray(articulationsData)) {
for (i = 0, len = articulationsData.length; i < len; ++i) {
processArticulations(model, articulationsData[i], interval, sourceUri, entityCollection);
}
Expand Down Expand Up @@ -2407,7 +2406,7 @@ import Cesium3DTilesetGraphics from './Cesium3DTilesetGraphics.js';
CzmlDataSource._processCzml = function(czml, entityCollection, sourceUri, updaterFunctions, dataSource) {
updaterFunctions = defaultValue(updaterFunctions, CzmlDataSource.updaters);

if (isArray(czml)) {
if (Array.isArray(czml)) {
for (var i = 0, len = czml.length; i < len; ++i) {
processCzmlPacket(czml[i], entityCollection, updaterFunctions, sourceUri, dataSource);
}
Expand Down
3 changes: 1 addition & 2 deletions Source/DataSources/PolygonGraphics.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,13 @@ import defaultValue from '../Core/defaultValue.js';
import defined from '../Core/defined.js';
import DeveloperError from '../Core/DeveloperError.js';
import Event from '../Core/Event.js';
import isArray from '../Core/isArray.js';
import PolygonHierarchy from '../Core/PolygonHierarchy.js';
import ConstantProperty from './ConstantProperty.js';
import createMaterialPropertyDescriptor from './createMaterialPropertyDescriptor.js';
import createPropertyDescriptor from './createPropertyDescriptor.js';

function createPolygonHierarchyProperty(value) {
if (isArray(value)) {
if (Array.isArray(value)) {
// convert array of positions to PolygonHierarchy object
value = new PolygonHierarchy(value);
}
Expand Down
5 changes: 2 additions & 3 deletions Source/DataSources/exportKml.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import defaultValue from '../Core/defaultValue.js';
import defined from '../Core/defined.js';
import DeveloperError from '../Core/DeveloperError.js';
import Ellipsoid from '../Core/Ellipsoid.js';
import isArray from '../Core/isArray.js';
import Iso8601 from '../Core/Iso8601.js';
import JulianDate from '../Core/JulianDate.js';
import CesiumMath from '../Core/Math.js';
Expand Down Expand Up @@ -948,7 +947,7 @@ import ScaledPositionProperty from './ScaledPositionProperty.js';
var hierarchy = valueGetter.get(hierarchyProperty);

// Polygon hierarchy can sometimes just be an array of positions
var positions = isArray(hierarchy) ? hierarchy : hierarchy.positions;
var positions = Array.isArray(hierarchy) ? hierarchy : hierarchy.positions;

// Polygon boundaries
var outerBoundaryIs = kmlDoc.createElement('outerBoundaryIs');
Expand Down Expand Up @@ -1205,7 +1204,7 @@ import ScaledPositionProperty from './ScaledPositionProperty.js';
}

function getCoordinates(coordinates, ellipsoid) {
if (!isArray(coordinates)) {
if (!Array.isArray(coordinates)) {
coordinates = [coordinates];
}

Expand Down
3 changes: 1 addition & 2 deletions Source/Scene/ClassificationPrimitive.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import defined from '../Core/defined.js';
import destroyObject from '../Core/destroyObject.js';
import DeveloperError from '../Core/DeveloperError.js';
import GeometryInstance from '../Core/GeometryInstance.js';
import isArray from '../Core/isArray.js';
import DrawCommand from '../Renderer/DrawCommand.js';
import Pass from '../Renderer/Pass.js';
import RenderState from '../Renderer/RenderState.js';
Expand Down Expand Up @@ -988,7 +987,7 @@ import StencilOperation from './StencilOperation.js';
var primitiveOptions = this._primitiveOptions;

if (!defined(this._primitive)) {
var instances = isArray(this.geometryInstances) ? this.geometryInstances : [this.geometryInstances];
var instances = Array.isArray(this.geometryInstances) ? this.geometryInstances : [this.geometryInstances];
var length = instances.length;

var i;
Expand Down
5 changes: 2 additions & 3 deletions Source/Scene/Expression.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import Check from '../Core/Check.js';
import Color from '../Core/Color.js';
import defined from '../Core/defined.js';
import DeveloperError from '../Core/DeveloperError.js';
import isArray from '../Core/isArray.js';
import CesiumMath from '../Core/Math.js';
import RuntimeError from '../Core/RuntimeError.js';
import jsep from '../ThirdParty/jsep.js';
Expand Down Expand Up @@ -1570,7 +1569,7 @@ import ExpressionNodeType from './ExpressionNodeType.js';
var value = this._value;

if (defined(this._left)) {
if (isArray(this._left)) {
if (Array.isArray(this._left)) {
// Left can be an array if the type is LITERAL_COLOR or LITERAL_VECTOR
left = getExpressionArray(this._left, attributePrefix, shaderState, this);
} else {
Expand All @@ -1586,7 +1585,7 @@ import ExpressionNodeType from './ExpressionNodeType.js';
test = this._test.getShaderExpression(attributePrefix, shaderState, this);
}

if (isArray(this._value)) {
if (Array.isArray(this._value)) {
// For ARRAY type
value = getExpressionArray(this._value, attributePrefix, shaderState, this);
}
Expand Down
3 changes: 1 addition & 2 deletions Source/Scene/GroundPolylinePrimitive.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import DeveloperError from '../Core/DeveloperError.js';
import GeometryInstance from '../Core/GeometryInstance.js';
import GeometryInstanceAttribute from '../Core/GeometryInstanceAttribute.js';
import GroundPolylineGeometry from '../Core/GroundPolylineGeometry.js';
import isArray from '../Core/isArray.js';
import DrawCommand from '../Renderer/DrawCommand.js';
import Pass from '../Renderer/Pass.js';
import RenderState from '../Renderer/RenderState.js';
Expand Down Expand Up @@ -591,7 +590,7 @@ import StencilOperation from './StencilOperation.js';
var that = this;
var primitiveOptions = this._primitiveOptions;
if (!defined(this._primitive)) {
var geometryInstances = isArray(this.geometryInstances) ? this.geometryInstances : [this.geometryInstances];
var geometryInstances = Array.isArray(this.geometryInstances) ? this.geometryInstances : [this.geometryInstances];
var geometryInstancesLength = geometryInstances.length;
var groundInstances = new Array(geometryInstancesLength);

Expand Down
5 changes: 2 additions & 3 deletions Source/Scene/GroundPrimitive.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import defined from '../Core/defined.js';
import destroyObject from '../Core/destroyObject.js';
import DeveloperError from '../Core/DeveloperError.js';
import GeometryInstance from '../Core/GeometryInstance.js';
import isArray from '../Core/isArray.js';
import OrientedBoundingBox from '../Core/OrientedBoundingBox.js';
import Rectangle from '../Core/Rectangle.js';
import when from '../ThirdParty/when.js';
Expand Down Expand Up @@ -118,7 +117,7 @@ import ShadowVolumeAppearance from './ShadowVolumeAppearance.js';
var appearance = options.appearance;
var geometryInstances = options.geometryInstances;
if (!defined(appearance) && defined(geometryInstances)) {
var geometryInstancesArray = isArray(geometryInstances) ? geometryInstances : [geometryInstances];
var geometryInstancesArray = Array.isArray(geometryInstances) ? geometryInstances : [geometryInstances];
var geometryInstanceCount = geometryInstancesArray.length;
for (var i = 0; i < geometryInstanceCount; i++) {
var attributes = geometryInstancesArray[i].attributes;
Expand Down Expand Up @@ -618,7 +617,7 @@ import ShadowVolumeAppearance from './ShadowVolumeAppearance.js';
var geometry;
var instanceType;

var instances = isArray(this.geometryInstances) ? this.geometryInstances : [this.geometryInstances];
var instances = Array.isArray(this.geometryInstances) ? this.geometryInstances : [this.geometryInstances];
var length = instances.length;
var groundInstances = new Array(length);

Expand Down
3 changes: 1 addition & 2 deletions Source/Scene/Material.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import defaultValue from '../Core/defaultValue.js';
import defined from '../Core/defined.js';
import destroyObject from '../Core/destroyObject.js';
import DeveloperError from '../Core/DeveloperError.js';
import isArray from '../Core/isArray.js';
import loadCRN from '../Core/loadCRN.js';
import loadKTX from '../Core/loadKTX.js';
import Matrix2 from '../Core/Matrix2.js';
Expand Down Expand Up @@ -992,7 +991,7 @@ import when from '../ThirdParty/when.js';
uniformType = 'sampler2D';
}
} else if (type === 'object') {
if (isArray(uniformValue)) {
if (Array.isArray(uniformValue)) {
if (uniformValue.length === 4 || uniformValue.length === 9 || uniformValue.length === 16) {
uniformType = 'mat' + Math.sqrt(uniformValue.length);
}
Expand Down
3 changes: 1 addition & 2 deletions Source/Scene/Model.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import getAbsoluteUri from '../Core/getAbsoluteUri.js';
import getMagic from '../Core/getMagic.js';
import getStringFromTypedArray from '../Core/getStringFromTypedArray.js';
import IndexDatatype from '../Core/IndexDatatype.js';
import isArray from '../Core/isArray.js';
import loadCRN from '../Core/loadCRN.js';
import loadImageFromTypedArray from '../Core/loadImageFromTypedArray.js';
import loadKTX from '../Core/loadKTX.js';
Expand Down Expand Up @@ -1141,7 +1140,7 @@ import ShadowMode from './ShadowMode.js';
},
set : function(value) {
//>>includeStart('debug', pragmas.debug);
if (defined(value) && (!isArray(value) || value.length !== 9)) {
if (defined(value) && (!Array.isArray(value) || value.length !== 9)) {
throw new DeveloperError('sphericalHarmonicCoefficients must be an array of 9 Cartesian3 values.');
}
//>>includeEnd('debug');
Expand Down
Loading

0 comments on commit 0642d46

Please sign in to comment.