Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace isArray.js with native Array.isArray function #8526

Merged
merged 6 commits into from
Mar 2, 2020
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ Change Log

##### Deprecated :hourglass_flowing_sand:
* The property `Scene.sunColor` has been deprecated and will be removed in Cesium 1.69. Use `scene.light.color` and `scene.light.intensity` instead. [#8493](https://github.com/AnalyticalGraphicsInc/cesium/pull/8493)
* 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/AnalyticalGraphicsInc/cesium/pull/8526)

##### Additions :tada:

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;
fredj marked this conversation as resolved.
Show resolved Hide resolved
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 @@ -19,7 +19,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 WallGraphics from './WallGraphics.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 WallGraphics from './WallGraphics.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 WallGraphics from './WallGraphics.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 WallGraphics from './WallGraphics.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 WallGraphics from './WallGraphics.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 WallGraphics from './WallGraphics.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 WallGraphics from './WallGraphics.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 WallGraphics from './WallGraphics.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 WallGraphics from './WallGraphics.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 WallGraphics from './WallGraphics.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 @@ -2389,7 +2388,7 @@ import WallGraphics from './WallGraphics.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 @@ -3,14 +3,13 @@ import defined from '../Core/defined.js';
import defineProperties from '../Core/defineProperties.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 @@ -8,7 +8,6 @@ import defined from '../Core/defined.js';
import defineProperties from '../Core/defineProperties.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 @@ -949,7 +948,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 @@ -1206,7 +1205,7 @@ import ScaledPositionProperty from './ScaledPositionProperty.js';
}

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

Expand Down
5 changes: 2 additions & 3 deletions Source/Scene/ClassificationPrimitive.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import defineProperties from '../Core/defineProperties.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 @@ -173,7 +172,7 @@ import StencilOperation from './StencilOperation.js';
this.appearance = options.appearance;

var readOnlyAttributes;
if (defined(geometryInstances) && isArray(geometryInstances) && geometryInstances.length > 1) {
if (defined(geometryInstances) && Array.isArray(geometryInstances) && geometryInstances.length > 1) {
readOnlyAttributes = ClassificationPrimitiveReadOnlyInstanceAttributes;
}

Expand Down Expand Up @@ -1002,7 +1001,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 @@ -6,7 +6,6 @@ import Color from '../Core/Color.js';
import defined from '../Core/defined.js';
import defineProperties from '../Core/defineProperties.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 @@ -1569,7 +1568,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 @@ -1585,7 +1584,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 @@ -8,7 +8,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 @@ -596,7 +595,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 @@ -9,7 +9,6 @@ import defineProperties from '../Core/defineProperties.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 @@ -119,7 +118,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 @@ -619,7 +618,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 @@ -8,7 +8,6 @@ import defined from '../Core/defined.js';
import defineProperties from '../Core/defineProperties.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 @@ -993,7 +992,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 @@ -20,7 +20,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