Skip to content

Commit f7f979d

Browse files
committed
Fix references to function names in parent scope
This commit addresses bugs introduce after minification (and mangling). Because the function references occur in evaluated strings, several bugs can be encountered. For example, the minification engine may decide to eliminate what it considers unused code/variables. Next, a minification engine may rename the variables, thus introducing a discrepancy in the evaluated string which relies on the source variable names. The workaround used in this commit is to bind the functions directly to the evaluated function, where property names are less likely to be mangled.
1 parent ab76efc commit f7f979d

File tree

2 files changed

+18
-10
lines changed

2 files changed

+18
-10
lines changed

lib/node_modules/@stdlib/ndarray/ctor/lib/compile_get.js

+9-5
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@
2020

2121
// MODULES //
2222

23-
var isInteger = require( '@stdlib/assert/is-integer' ).isPrimitive; // eslint-disable-line no-unused-vars
24-
var getIndex = require( '@stdlib/ndarray/base/ind' ); // eslint-disable-line no-unused-vars
23+
var isInteger = require( '@stdlib/assert/is-integer' ).isPrimitive;
24+
var getIndex = require( '@stdlib/ndarray/base/ind' );
2525

2626

2727
// MAIN //
@@ -65,14 +65,14 @@ function get( ndims, mode ) {
6565
* > if ( !isInteger( i0 ) ) { throw new TypeError( ... ) }
6666
*/
6767
for ( i = 0; i < ndims; i++ ) {
68-
f += 'if(!isInteger(i'+i+')){throw new TypeError(\'invalid input argument. Indices must be integer valued. Argument: '+i+'. Value: `\'+i'+i+'+\'`.\');}';
68+
f += 'if(!f.__isint__(i'+i+')){throw new TypeError(\'invalid input argument. Indices must be integer valued. Argument: '+i+'. Value: `\'+i'+i+'+\'`.\');}';
6969
}
7070
/*
7171
* Resolve indices based on the index mode.
7272
* > i0 = getIndex( i0, shape[0]-1, mode );
7373
*/
7474
for ( i = 0; i < ndims; i++ ) {
75-
f += 'i'+i+'=getIndex(i'+i+',this._shape['+i+']-1,\''+mode[i%mode.length]+'\');';
75+
f += 'i'+i+'=f.__get_index__(i'+i+',this._shape['+i+']-1,\''+mode[i%mode.length]+'\');';
7676
}
7777
/*
7878
* Index into the array according to the offset and strides...
@@ -97,7 +97,11 @@ function get( ndims, mode ) {
9797
f += '//# sourceURL=ndarray.ctor.get.js';
9898

9999
// Create the function in the current scope to allow access to required modules:
100-
return eval( f ); // eslint-disable-line no-eval
100+
f = eval( f ); // eslint-disable-line no-eval
101+
f.__isint__ = isInteger; // eslint-disable-line no-underscore-dangle
102+
f.__get_index__ = getIndex; // eslint-disable-line no-underscore-dangle
103+
104+
return f;
101105

102106
/*
103107
* e.g.,

lib/node_modules/@stdlib/ndarray/ctor/lib/compile_set.js

+9-5
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@
2020

2121
// MODULES //
2222

23-
var isInteger = require( '@stdlib/assert/is-integer' ).isPrimitive; // eslint-disable-line no-unused-vars
24-
var getIndex = require( '@stdlib/ndarray/base/ind' ); // eslint-disable-line no-unused-vars
23+
var isInteger = require( '@stdlib/assert/is-integer' ).isPrimitive;
24+
var getIndex = require( '@stdlib/ndarray/base/ind' );
2525

2626

2727
// MAIN //
@@ -62,14 +62,14 @@ function set( ndims, mode ) {
6262
* > if ( !isInteger( i0 ) ) { throw new TypeError( ... ) }
6363
*/
6464
for ( i = 0; i < ndims; i++ ) {
65-
f += 'if(!isInteger(i'+i+')){throw new TypeError(\'invalid input argument. Indices must be integer valued. Argument: '+i+'. Value: `\'+i'+i+'+\'`.\');}';
65+
f += 'if(!f.__isint__(i'+i+')){throw new TypeError(\'invalid input argument. Indices must be integer valued. Argument: '+i+'. Value: `\'+i'+i+'+\'`.\');}';
6666
}
6767
/*
6868
* Resolve indices based on the index mode.
6969
* > i0 = getIndex( i0, shape[0]-1, mode );
7070
*/
7171
for ( i = 0; i < ndims; i++ ) {
72-
f += 'i'+i+'=getIndex(i'+i+',this._shape['+i+']-1,\''+mode[i%mode.length]+'\');';
72+
f += 'i'+i+'=f.__get_index__(i'+i+',this._shape['+i+']-1,\''+mode[i%mode.length]+'\');';
7373
}
7474
/*
7575
* Index into the array according to the offset and strides...
@@ -97,7 +97,11 @@ function set( ndims, mode ) {
9797
f += '//# sourceURL=ndarray.ctor.set.js';
9898

9999
// Create the function in the current scope to allow access to required modules:
100-
return eval( f ); // eslint-disable-line no-eval
100+
f = eval( f ); // eslint-disable-line no-eval
101+
f.__isint__ = isInteger; // eslint-disable-line no-underscore-dangle
102+
f.__get_index__ = getIndex; // eslint-disable-line no-underscore-dangle
103+
104+
return f;
101105

102106
/*
103107
* e.g.,

0 commit comments

Comments
 (0)