Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/**
* @license Apache-2.0
*
* Copyright (c) 2026 The Stdlib Authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

'use strict';

// MODULES //

var bench = require( '@stdlib/bench' );
var format = require( '@stdlib/string/format' );
var pkg = require( './../package.json' ).name;
var Fcn = require( './../lib' );


// MAIN //

bench( format( '%s:apply', pkg ), function benchmark( b ) {
var args;
var f;
var v;
var i;

f = new Fcn( 'x', 'y', 'return x + y' );
args = [ 0, 1 ];

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
args[ 0 ] = i;
v = f.apply( null, args );
if ( v !== v ) {
b.fail( 'should not return NaN' );
}
}
b.toc();
if ( v !== v ) {
b.fail( 'should not return NaN' );
}
b.pass( 'benchmark finished' );
b.end();
});
52 changes: 52 additions & 0 deletions lib/node_modules/@stdlib/function/ctor/benchmark/benchmark.bind.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/**
* @license Apache-2.0
*
* Copyright (c) 2026 The Stdlib Authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

'use strict';

// MODULES //

var bench = require( '@stdlib/bench' );
var format = require( '@stdlib/string/format' );
var isFunction = require( '@stdlib/assert/is-function' );
var pkg = require( './../package.json' ).name;
var Fcn = require( './../lib' );


// MAIN //

bench( format( '%s:bind', pkg ), function benchmark( b ) {
var f;
var g;
var i;

f = new Fcn( 'x', 'y', 'return x + y' );

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
g = f.bind( null, i );
if ( typeof g !== 'function' ) {
b.fail( 'should return a function' );
}
}
b.toc();
if ( !isFunction( g ) ) {
b.fail( 'should return a function' );
}
b.pass( 'benchmark finished' );
b.end();
});
51 changes: 51 additions & 0 deletions lib/node_modules/@stdlib/function/ctor/benchmark/benchmark.call.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/**
* @license Apache-2.0
*
* Copyright (c) 2026 The Stdlib Authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

'use strict';

// MODULES //

var bench = require( '@stdlib/bench' );
var format = require( '@stdlib/string/format' );
var pkg = require( './../package.json' ).name;
var Fcn = require( './../lib' );


// MAIN //

bench( format( '%s:call', pkg ), function benchmark( b ) {
var f;
var v;
var i;

f = new Fcn( 'x', 'y', 'return x + y' );

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
v = f.call( null, i, i + 1 ); // eslint-disable-line no-useless-call
if ( v !== v ) {
b.fail( 'should not return NaN' );
}
}
b.toc();
if ( v !== v ) {
b.fail( 'should not return NaN' );
}
b.pass( 'benchmark finished' );
b.end();
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
/**
* @license Apache-2.0
*
* Copyright (c) 2026 The Stdlib Authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

'use strict';

// MODULES //

var bench = require( '@stdlib/bench' );
var format = require( '@stdlib/string/format' );
var isNonNegativeInteger = require( '@stdlib/assert/is-nonnegative-integer' ).isPrimitive;
var pkg = require( './../package.json' ).name;
var Fcn = require( './../lib' );


// MAIN //

bench( format( '%s::get:length', pkg ), function benchmark( b ) {
var f;
var v;
var i;

f = new Fcn( 'x', 'y', 'return x + y' );

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
// Note: the following may be optimized away due to loop invariant code motion and/or other compiler optimizations, rendering this benchmark meaningless...
v = f.length;
if ( v !== v ) {
b.fail( 'should not return NaN' );
}
}
b.toc();
if ( !isNonNegativeInteger( v ) ) {
b.fail( 'should return a nonnegative integer' );
}
b.pass( 'benchmark finished' );
b.end();
});

bench( format( '%s::get:name', pkg ), function benchmark( b ) {
var f;
var v;
var i;

f = new Fcn( 'x', 'y', 'return x + y' );

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
// Note: the following may be optimized away due to loop invariant code motion and/or other compiler optimizations, rendering this benchmark meaningless...
v = f.name;
if ( typeof v !== 'string' ) {
b.fail( 'should return a string' );
}
}
b.toc();
if ( typeof v !== 'string' ) {
b.fail( 'should return a string' );
}
b.pass( 'benchmark finished' );
b.end();
});

bench( format( '%s::get:prototype', pkg ), function benchmark( b ) {
var f;
var v;
var i;

f = new Fcn( 'x', 'y', 'return x + y' );

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
// Note: the following may be optimized away due to loop invariant code motion and/or other compiler optimizations, rendering this benchmark meaningless...
v = f.prototype;
if ( typeof v !== 'object' ) {
b.fail( 'should return an object' );
}
}
b.toc();
if ( typeof v !== 'object' ) {
b.fail( 'should return an object' );
}
b.pass( 'benchmark finished' );
b.end();
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/**
* @license Apache-2.0
*
* Copyright (c) 2026 The Stdlib Authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

'use strict';

// MODULES //

var bench = require( '@stdlib/bench' );
var format = require( '@stdlib/string/format' );
var pkg = require( './../package.json' ).name;
var Fcn = require( './../lib' );


// MAIN //

bench( format( '%s:toString', pkg ), function benchmark( b ) {
var out;
var f;
var i;

f = new Fcn( 'x', 'y', 'return x + y' );

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
out = f.toString();
if ( typeof out !== 'string' ) {
b.fail( 'should return a string' );
}
}
b.toc();
if ( typeof out !== 'string' ) {
b.fail( 'should return a string' );
}
b.pass( 'benchmark finished' );
b.end();
});
11 changes: 6 additions & 5 deletions lib/node_modules/@stdlib/function/ctor/docs/repl.txt
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
> f.apply( null, [ 1, 2 ] )
3


{{alias}}.prototype.call( thisArg, ...args )
Calls a function with a given `this` value and arguments provided
individually.
Expand All @@ -72,6 +73,7 @@
> f.call( null, 1, 2 )
3


{{alias}}.prototype.bind( thisArg, ...args )
Creates a new function which, when called, has its `this` keyword set to the
provided value, with a given sequence of arguments preceding any provided
Expand All @@ -97,14 +99,16 @@
> g( 2 )
3


{{alias}}.prototype.toString()
Returns a string representation of the function.

Examples
--------
> var f = new {{alias}}( 'x', 'y', 'return x + y' );
> f.toString()
'function anonymous( x, y ) { return x + y; }'
'function anonymous(x,y\n) {\nreturn x + y\n}'


{{alias}}.prototype.length
The number of arguments expected by the function.
Expand All @@ -115,6 +119,7 @@
> f.length
2


{{alias}}.prototype.name
The name of the function.

Expand All @@ -124,10 +129,6 @@
> f.name
'anonymous'

> var f = new {{alias}}( 'x', 'y', 'return x + y' );
> f.name = 'add';
> f.name
'add'

{{alias}}.prototype.prototype
The prototype of the function.
Expand Down
Loading