Browse Source

Never throw literal (#23137)

* Never throw a literal

* never throw a literal
gero3 3 năm trước cách đây
mục cha
commit
cad5c542f7

+ 1 - 1
examples/jsm/animation/MMDPhysics.js

@@ -894,7 +894,7 @@ class RigidBody {
 					return new Ammo.btCapsuleShape( p.width, p.height );
 					return new Ammo.btCapsuleShape( p.width, p.height );
 
 
 				default:
 				default:
-					throw 'unknown shape type ' + p.shapeType;
+					throw new Error( 'unknown shape type ' + p.shapeType );
 
 
 			}
 			}
 
 

+ 1 - 1
examples/jsm/exporters/MMDExporter.js

@@ -186,7 +186,7 @@ function unicodeToShiftjis( str ) {
 
 
 		if ( value === undefined ) {
 		if ( value === undefined ) {
 
 
-			throw 'cannot convert charcode 0x' + code.toString( 16 );
+			throw new Error( 'cannot convert charcode 0x' + code.toString( 16 ) );
 
 
 		} else if ( value > 0xff ) {
 		} else if ( value > 0xff ) {
 
 

+ 19 - 18
examples/jsm/loaders/EXRLoader.js

@@ -230,7 +230,7 @@ class EXRLoader extends DataTextureLoader {
 
 
 					if ( p.value - inOffset.value > ni ) {
 					if ( p.value - inOffset.value > ni ) {
 
 
-						throw 'Something wrong with hufUnpackEncTable';
+						throw new Error( 'Something wrong with hufUnpackEncTable' );
 
 
 					}
 					}
 
 
@@ -242,7 +242,7 @@ class EXRLoader extends DataTextureLoader {
 
 
 					if ( im + zerun > iM + 1 ) {
 					if ( im + zerun > iM + 1 ) {
 
 
-						throw 'Something wrong with hufUnpackEncTable';
+						throw new Error( 'Something wrong with hufUnpackEncTable' );
 
 
 					}
 					}
 
 
@@ -256,7 +256,7 @@ class EXRLoader extends DataTextureLoader {
 
 
 					if ( im + zerun > iM + 1 ) {
 					if ( im + zerun > iM + 1 ) {
 
 
-						throw 'Something wrong with hufUnpackEncTable';
+						throw new Error( 'Something wrong with hufUnpackEncTable' );
 
 
 					}
 					}
 
 
@@ -293,7 +293,7 @@ class EXRLoader extends DataTextureLoader {
 
 
 				if ( c >> l ) {
 				if ( c >> l ) {
 
 
-					throw 'Invalid table entry';
+					throw new Error( 'Invalid table entry' );
 
 
 				}
 				}
 
 
@@ -303,7 +303,7 @@ class EXRLoader extends DataTextureLoader {
 
 
 					if ( pl.len ) {
 					if ( pl.len ) {
 
 
-						throw 'Invalid table entry';
+						throw new Error( 'Invalid table entry' );
 
 
 					}
 					}
 
 
@@ -338,7 +338,7 @@ class EXRLoader extends DataTextureLoader {
 
 
 						if ( pl.len || pl.p ) {
 						if ( pl.len || pl.p ) {
 
 
-							throw 'Invalid table entry';
+							throw new Error( 'Invalid table entry' );
 
 
 						}
 						}
 
 
@@ -626,7 +626,7 @@ class EXRLoader extends DataTextureLoader {
 
 
 						if ( ! pl.p ) {
 						if ( ! pl.p ) {
 
 
-							throw 'hufDecode issues';
+							throw new Error( 'hufDecode issues' );
 
 
 						}
 						}
 
 
@@ -666,7 +666,7 @@ class EXRLoader extends DataTextureLoader {
 
 
 						if ( j == pl.lit ) {
 						if ( j == pl.lit ) {
 
 
-							throw 'hufDecode issues';
+							throw new Error( 'hufDecode issues' );
 
 
 						}
 						}
 
 
@@ -696,7 +696,7 @@ class EXRLoader extends DataTextureLoader {
 
 
 				} else {
 				} else {
 
 
-					throw 'hufDecode issues';
+					throw new Error( 'hufDecode issues' );
 
 
 				}
 				}
 
 
@@ -722,7 +722,7 @@ class EXRLoader extends DataTextureLoader {
 
 
 			if ( im < 0 || im >= HUF_ENCSIZE || iM < 0 || iM >= HUF_ENCSIZE ) {
 			if ( im < 0 || im >= HUF_ENCSIZE || iM < 0 || iM >= HUF_ENCSIZE ) {
 
 
-				throw 'Something wrong with HUF_ENCSIZE';
+				throw new Error( 'Something wrong with HUF_ENCSIZE' );
 
 
 			}
 			}
 
 
@@ -737,7 +737,7 @@ class EXRLoader extends DataTextureLoader {
 
 
 			if ( nBits > 8 * ( nCompressed - ( inOffset.value - initialInOffset ) ) ) {
 			if ( nBits > 8 * ( nCompressed - ( inOffset.value - initialInOffset ) ) ) {
 
 
-				throw 'Something wrong with hufUncompress';
+				throw new Error( 'Something wrong with hufUncompress' );
 
 
 			}
 			}
 
 
@@ -1299,7 +1299,7 @@ class EXRLoader extends DataTextureLoader {
 
 
 			if ( maxNonZero >= BITMAP_SIZE ) {
 			if ( maxNonZero >= BITMAP_SIZE ) {
 
 
-				throw 'Something is wrong with PIZ_COMPRESSION BITMAP_SIZE';
+				throw new Error( 'Something is wrong with PIZ_COMPRESSION BITMAP_SIZE' );
 
 
 			}
 			}
 
 
@@ -1470,7 +1470,7 @@ class EXRLoader extends DataTextureLoader {
 			};
 			};
 
 
 			if ( dwaHeader.version < 2 )
 			if ( dwaHeader.version < 2 )
-				throw 'EXRLoader.parse: ' + EXRHeader.compression + ' version ' + dwaHeader.version + ' is unsupported';
+				throw new Error( 'EXRLoader.parse: ' + EXRHeader.compression + ' version ' + dwaHeader.version + ' is unsupported' );
 
 
 			// Read channel ruleset information
 			// Read channel ruleset information
 			var channelRules = new Array();
 			var channelRules = new Array();
@@ -1655,7 +1655,7 @@ class EXRLoader extends DataTextureLoader {
 					case LOSSY_DCT: // skip
 					case LOSSY_DCT: // skip
 
 
 					default:
 					default:
-						throw 'EXRLoader.parse: unsupported channel compression';
+						throw new Error( 'EXRLoader.parse: unsupported channel compression' );
 
 
 				}
 				}
 
 
@@ -1993,7 +1993,8 @@ class EXRLoader extends DataTextureLoader {
 			const EXRHeader = {};
 			const EXRHeader = {};
 
 
 			if ( dataView.getUint32( 0, true ) != 20000630 ) // magic
 			if ( dataView.getUint32( 0, true ) != 20000630 ) // magic
-				throw 'THREE.EXRLoader: provided file doesn\'t appear to be in OpenEXR format.';
+
+				throw new Error( 'THREE.EXRLoader: provided file doesn\'t appear to be in OpenEXR format.' );
 
 
 			EXRHeader.version = dataView.getUint8( 4, true );
 			EXRHeader.version = dataView.getUint8( 4, true );
 
 
@@ -2043,7 +2044,7 @@ class EXRLoader extends DataTextureLoader {
 			if ( spec != 0 ) {
 			if ( spec != 0 ) {
 
 
 				console.error( 'EXRHeader:', EXRHeader );
 				console.error( 'EXRHeader:', EXRHeader );
-				throw 'THREE.EXRLoader: provided file is currently unsupported.';
+				throw new Error( 'THREE.EXRLoader: provided file is currently unsupported.' );
 
 
 			}
 			}
 
 
@@ -2114,7 +2115,7 @@ class EXRLoader extends DataTextureLoader {
 					break;
 					break;
 
 
 				default:
 				default:
-					throw 'EXRLoader.parse: ' + EXRHeader.compression + ' is unsupported';
+					throw new Error( 'EXRLoader.parse: ' + EXRHeader.compression + ' is unsupported' );
 
 
 			}
 			}
 
 
@@ -2155,7 +2156,7 @@ class EXRLoader extends DataTextureLoader {
 
 
 			} else {
 			} else {
 
 
-				throw 'EXRLoader.parse: unsupported pixelType ' + EXRDecoder.type + ' for ' + EXRHeader.compression + '.';
+				throw new Error( 'EXRLoader.parse: unsupported pixelType ' + EXRDecoder.type + ' for ' + EXRHeader.compression + '.' );
 
 
 			}
 			}
 
 

+ 1 - 1
examples/jsm/loaders/RGBMLoader.js

@@ -328,7 +328,7 @@ UPNG.decode = function ( buff ) {
 	var fd, foff = 0;	// frames
 	var fd, foff = 0;	// frames
 
 
 	var mgck = [ 0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a ];
 	var mgck = [ 0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a ];
-	for ( var i = 0; i < 8; i ++ ) if ( data[ i ] != mgck[ i ] ) throw 'The input is not a PNG file!';
+	for ( var i = 0; i < 8; i ++ ) if ( data[ i ] != mgck[ i ] ) throw new Error( 'The input is not a PNG file!' );
 
 
 	while ( offset < data.length ) {
 	while ( offset < data.length ) {
 
 

+ 2 - 2
examples/jsm/misc/Volume.js

@@ -99,7 +99,7 @@ function Volume( xLength, yLength, zLength, type, arrayBuffer ) {
 			case 'unsigned long long int' :
 			case 'unsigned long long int' :
 			case 'uint64' :
 			case 'uint64' :
 			case 'uint64_t' :
 			case 'uint64_t' :
-				throw 'Error in Volume constructor : this type is not supported in JavaScript';
+				throw new Error( 'Error in Volume constructor : this type is not supported in JavaScript' );
 				break;
 				break;
 			case 'Float32' :
 			case 'Float32' :
 			case 'float32' :
 			case 'float32' :
@@ -118,7 +118,7 @@ function Volume( xLength, yLength, zLength, type, arrayBuffer ) {
 
 
 		if ( this.data.length !== this.xLength * this.yLength * this.zLength ) {
 		if ( this.data.length !== this.xLength * this.yLength * this.zLength ) {
 
 
-			throw 'Error in Volume constructor, lengths are not matching arrayBuffer size';
+			throw new Error( 'Error in Volume constructor, lengths are not matching arrayBuffer size' );
 
 
 		}
 		}
 
 

+ 1 - 1
examples/jsm/modifiers/EdgeSplitModifier.js

@@ -183,7 +183,7 @@ class EdgeSplitModifier {
 
 
 			if ( BufferGeometryUtils === undefined ) {
 			if ( BufferGeometryUtils === undefined ) {
 
 
-				throw 'THREE.EdgeSplitModifier relies on BufferGeometryUtils';
+				throw new Error( 'THREE.EdgeSplitModifier relies on BufferGeometryUtils' );
 
 
 			}
 			}
 
 

+ 1 - 1
examples/jsm/modifiers/SimplifyModifier.js

@@ -21,7 +21,7 @@ class SimplifyModifier {
 
 
 		if ( BufferGeometryUtils === undefined ) {
 		if ( BufferGeometryUtils === undefined ) {
 
 
-			throw 'THREE.SimplifyModifier relies on BufferGeometryUtils';
+			throw new Error( 'THREE.SimplifyModifier relies on BufferGeometryUtils' );
 
 
 		}
 		}
 
 

+ 1 - 1
examples/jsm/renderers/webgpu/WebGPUObjects.js

@@ -17,7 +17,7 @@ class WebGPUObjects {
 
 
 		if ( geometry.isBufferGeometry !== true ) {
 		if ( geometry.isBufferGeometry !== true ) {
 
 
-			throw 'THREE.WebGPURenderer: This renderer only supports THREE.BufferGeometry for geometries.';
+			throw new Error( 'THREE.WebGPURenderer: This renderer only supports THREE.BufferGeometry for geometries.' );
 
 
 		}
 		}
 
 

+ 2 - 2
examples/webgpu_compute.html

@@ -39,7 +39,7 @@
 			let camera, scene, renderer;
 			let camera, scene, renderer;
 			let pointer;
 			let pointer;
 			let scaleUniformBuffer;
 			let scaleUniformBuffer;
-			let scaleVector = new THREE.Vector3( 1, 1, 1 );
+			const scaleVector = new THREE.Vector3( 1, 1, 1 );
 
 
 			const computeParams = [];
 			const computeParams = [];
 
 
@@ -51,7 +51,7 @@
 
 
 					document.body.appendChild( WebGPU.getErrorMessage() );
 					document.body.appendChild( WebGPU.getErrorMessage() );
 
 
-					throw 'No WebGPU support';
+					throw new Error( 'No WebGPU support' );
 
 
 				}
 				}
 
 

+ 1 - 1
examples/webgpu_instance_uniform.html

@@ -75,7 +75,7 @@
 
 
 					document.body.appendChild( WebGPU.getErrorMessage() );
 					document.body.appendChild( WebGPU.getErrorMessage() );
 
 
-					throw 'No WebGPU support';
+					throw new Error( 'No WebGPU support' );
 
 
 				}
 				}
 
 

+ 1 - 1
examples/webgpu_lights_custom.html

@@ -43,7 +43,7 @@
 
 
 					document.body.appendChild( WebGPU.getErrorMessage() );
 					document.body.appendChild( WebGPU.getErrorMessage() );
 
 
-					throw 'No WebGPU support';
+					throw new Error( 'No WebGPU support' );
 
 
 				}
 				}
 
 

+ 1 - 1
examples/webgpu_lights_selective.html

@@ -51,7 +51,7 @@
 
 
 					document.body.appendChild( WebGPU.getErrorMessage() );
 					document.body.appendChild( WebGPU.getErrorMessage() );
 
 
-					throw 'No WebGPU support';
+					throw new Error( 'No WebGPU support' );
 
 
 				}
 				}
 
 

+ 1 - 1
examples/webgpu_materials.html

@@ -48,7 +48,7 @@
 
 
 					document.body.appendChild( WebGPU.getErrorMessage() );
 					document.body.appendChild( WebGPU.getErrorMessage() );
 
 
-					throw 'No WebGPU support';
+					throw new Error( 'No WebGPU support' );
 
 
 				}
 				}
 
 

+ 1 - 1
examples/webgpu_nodes_playground.html

@@ -76,7 +76,7 @@ flow {
 
 
 					document.body.appendChild( WebGPU.getErrorMessage() );
 					document.body.appendChild( WebGPU.getErrorMessage() );
 
 
-					throw 'No WebGPU support';
+					throw new Error( 'No WebGPU support' );
 
 
 				}
 				}
 
 

+ 1 - 1
examples/webgpu_rtt.html

@@ -46,7 +46,7 @@
 
 
 					document.body.appendChild( WebGPU.getErrorMessage() );
 					document.body.appendChild( WebGPU.getErrorMessage() );
 
 
-					throw 'No WebGPU support';
+					throw new Error( 'No WebGPU support' );
 
 
 				}
 				}
 
 

+ 2 - 2
examples/webgpu_sandbox.html

@@ -42,7 +42,7 @@
 
 
 					document.body.appendChild( WebGPU.getErrorMessage() );
 					document.body.appendChild( WebGPU.getErrorMessage() );
 
 
-					throw 'No WebGPU support';
+					throw new Error( 'No WebGPU support' );
 
 
 				}
 				}
 
 
@@ -82,7 +82,7 @@
 
 
 				const textureNode = new Nodes.TextureNode( texture, animateUV );
 				const textureNode = new Nodes.TextureNode( texture, animateUV );
 
 
-				materialBox.colorNode = new Nodes.MathNode( 'mix', textureNode, new Nodes.CheckerNode( animateUV ), new Nodes.FloatNode( .5) );
+				materialBox.colorNode = new Nodes.MathNode( 'mix', textureNode, new Nodes.CheckerNode( animateUV ), new Nodes.FloatNode( .5 ) );
 
 
 				// test uv 2
 				// test uv 2
 				//geometryBox.setAttribute( 'uv2', geometryBox.getAttribute( 'uv' ) );
 				//geometryBox.setAttribute( 'uv2', geometryBox.getAttribute( 'uv' ) );

+ 1 - 1
examples/webgpu_skinning.html

@@ -45,7 +45,7 @@
 
 
 					document.body.appendChild( WebGPU.getErrorMessage() );
 					document.body.appendChild( WebGPU.getErrorMessage() );
 
 
-					throw 'No WebGPU support';
+					throw new Error( 'No WebGPU support' );
 
 
 				}
 				}
 
 

+ 1 - 1
examples/webgpu_skinning_points.html

@@ -45,7 +45,7 @@
 
 
 					document.body.appendChild( WebGPU.getErrorMessage() );
 					document.body.appendChild( WebGPU.getErrorMessage() );
 
 
-					throw 'No WebGPU support';
+					throw new Error( 'No WebGPU support' );
 
 
 				}
 				}