Skip to content

Commit 0d6bf75

Browse files
committed
refactor: resolve error constructor and add todos
1 parent ecff289 commit 0d6bf75

File tree

6 files changed

+12
-71
lines changed

6 files changed

+12
-71
lines changed

lib/node_modules/@stdlib/ndarray/fancy/lib/error_constructor.js

Lines changed: 0 additions & 53 deletions
This file was deleted.

lib/node_modules/@stdlib/ndarray/fancy/lib/get_slice.js

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222

2323
var slice = require( '@stdlib/ndarray/base/slice' );
2424
var errMessage = require( './error_message.js' );
25-
var errConstructor = require( './error_constructor.js' );
2625

2726

2827
// MAIN //
@@ -39,18 +38,16 @@ var errConstructor = require( './error_constructor.js' );
3938
* @throws {RangeError} number of slice dimensions must match the number of array dimensions
4039
* @returns {FancyArray} result
4140
*/
42-
function getSlice( target, property, receiver, prop2slice ) { // eslint-disable-line stdlib/jsdoc-require-throws-tags
41+
function getSlice( target, property, receiver, prop2slice ) {
4342
var strict;
44-
var E;
4543
var s;
4644

4745
strict = false; // TODO: support strict mode
4846
s = prop2slice( target, property, strict );
4947
try {
5048
return slice( receiver, s, strict, false );
5149
} catch ( err ) {
52-
E = errConstructor( err );
53-
throw new E( errMessage( err.message ) );
50+
throw new err.constructor( errMessage( err.message ) );
5451
}
5552
}
5653

lib/node_modules/@stdlib/ndarray/fancy/lib/prop2slice.0d.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ function prop2slice( target, property ) {
5858
// Case: slice
5959
if ( ch === 'S' ) {
6060
// Convert the string to a slice object:
61-
s = str2slice( property );
61+
s = str2slice( prop );
6262
if ( s === null ) {
6363
throw new Error( format( 'invalid operation. Unsupported slice operation. Value: `%s`.', property ) );
6464
}
@@ -104,7 +104,7 @@ function prop2slice( target, property ) {
104104
s = new MultiSlice();
105105
}
106106
// Case: non-empty string
107-
else {
107+
else { // FIXME: need to gracefully handle non-existent properties
108108
throw new Error( format( 'invalid operation. Unsupported slice operation. Value: `%s`.', property ) );
109109
}
110110
return s;

lib/node_modules/@stdlib/ndarray/fancy/lib/prop2slice.1d.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ function prop2slice( target, property, strict ) {
5757
// Case: slice
5858
if ( ch === 'S' ) {
5959
// Convert the string to a slice object:
60-
s = str2slice( property );
60+
s = str2slice( prop );
6161
if ( s === null ) {
6262
throw new Error( format( 'invalid operation. Unsupported slice operation. Value: `%s`.', property ) );
6363
}
@@ -81,7 +81,7 @@ function prop2slice( target, property, strict ) {
8181
s = new MultiSlice( s );
8282
}
8383
// Case: subsequence string
84-
else if ( prop.length > 0 ) {
84+
else if ( prop.length > 0 ) { // FIXME: need to gracefully handle non-existent properties
8585
shape = target.shape;
8686
s = seq2multislice( prop, shape, true );
8787
if ( s.code ) {

lib/node_modules/@stdlib/ndarray/fancy/lib/prop2slice.nd.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ function prop2slice( target, property, strict ) {
8686
// Case: array syntax (e.g., [ Slice(0,10,1), null, Slice(4,null,-1) ]) or Slice or integer or arbitrary string (where the latter three are not valid for >2d arrays)
8787
else {
8888
s = sargs2multislice( prop );
89-
if ( s === null ) {
89+
if ( s === null ) { // FIXME: need to gracefully handle non-existent properties
9090
throw new Error( format( 'invalid operation. Unsupported slice operation. Value: `%s`.', property ) );
9191
}
9292
}

lib/node_modules/@stdlib/ndarray/fancy/lib/set_slice.js

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ var complexDataType = require( '@stdlib/complex/dtype' );
3838
var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' );
3939
var format = require( '@stdlib/string/format' );
4040
var errMessage = require( './error_message.js' );
41-
var errConstructor = require( './error_constructor.js' );
4241

4342

4443
// FUNCTIONS //
@@ -75,11 +74,10 @@ function options( dtype ) {
7574
* @throws {TypeError} target array must have a supported data type
7675
* @returns {boolean} boolean indicating whether assignment succeeded
7776
*/
78-
function setSlice( target, property, value, receiver, prop2slice ) { // eslint-disable-line stdlib/jsdoc-require-throws-tags
77+
function setSlice( target, property, value, receiver, prop2slice ) {
7978
var strict;
8079
var vdt;
8180
var dt;
82-
var E;
8381
var s;
8482

8583
if ( !isndarrayLike( value ) ) {
@@ -89,15 +87,15 @@ function setSlice( target, property, value, receiver, prop2slice ) { // eslint-d
8987
if ( dt === 'generic' ) {
9088
value = scalar2ndarray( value, options( dt ) );
9189
}
92-
// If the input value is real-valued number, we need to inspect the value to determine whether we can safely cast the value to the target array data type...
90+
// If the input value is a real-valued number, we need to inspect the value to determine whether we can safely cast the value to the target array data type...
9391
else if ( isNumber( value ) ) {
94-
// If the target array has a floating-point data type, we can just go ahead and cast the input scalar to the target array data type...
92+
// If the target array has a floating-point data type, we can just go ahead and cast the input scalar to the target array data type, as number literals are, by default, double-precision floating-point values and casting to lower-precision floating-point is allowed...
9593
if ( isFloatingDataType( dt ) ) {
9694
value = scalar2ndarray( value, options( dt ) );
9795
}
9896
// If the target array has an unsigned integer data type, then the assigned value must be a compatible nonnegative integer value...
9997
else if ( isUnsignedIntegerDataType( dt ) ) {
100-
vdt = minDataType( value );
98+
vdt = minDataType( value ); // note: we rely on data type resolution to handle the case where `value` is a non-integer value. In that case, `vdt` will resolve to a floating-point data type and `isSafeCast` will evaluate to `false`
10199
if ( isSafeCast( vdt, dt ) ) {
102100
value = scalar2ndarray( value, options( dt ) );
103101
} else {
@@ -160,8 +158,7 @@ function setSlice( target, property, value, receiver, prop2slice ) { // eslint-d
160158
sliceAssign( value, receiver, s, strict );
161159
return true;
162160
} catch ( err ) {
163-
E = errConstructor( err );
164-
throw new E( errMessage( err.message ) );
161+
throw new err.constructor( errMessage( err.message ) );
165162
}
166163
}
167164

0 commit comments

Comments
 (0)