Skip to content

Commit

Permalink
Auto-generated commit
Browse files Browse the repository at this point in the history
  • Loading branch information
stdlib-bot committed Sep 16, 2024
1 parent 109d75d commit 58ee818
Showing 13 changed files with 633 additions and 2 deletions.
27 changes: 26 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -4,7 +4,7 @@
<section class="release" id="unreleased">

## Unreleased (2024-09-15)
## Unreleased (2024-09-16)

<section class="packages">

@@ -20,6 +20,7 @@

##### Features

- [`5279713`](https://github.com/stdlib-js/stdlib/commit/527971383e70a0e92dbca647dabfef27f294f149) - add `isWebAssemblyMemory` to namespace
- [`e97215f`](https://github.com/stdlib-js/stdlib/commit/e97215fbf9f4d1ec8548086f78ed04a0ec80a43f) - add `hasBtoaSupport` to namespace
- [`80b8061`](https://github.com/stdlib-js/stdlib/commit/80b8061c5888d04dcaa48f0363669ba2606856df) - add `hasAtobSupport` to namespace
- [`1123204`](https://github.com/stdlib-js/stdlib/commit/11232044680f87bb3b53b447dab24e4e54b659ef) - add `isEqualArray` to namespace
@@ -167,6 +168,28 @@

<!-- /.package -->

<section class="package" id="assert-is-wasm-memory-unreleased">

#### [@stdlib/assert/is-wasm-memory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/assert/is-wasm-memory)

<details>

<section class="features">

##### Features

- [`718ba36`](https://github.com/stdlib-js/stdlib/commit/718ba365fd18e0e35582433c22f6878a0e744675) - add `assert/is-wasm-memory`

</section>

<!-- /.features -->

</details>

</section>

<!-- /.package -->

</section>

<!-- /.packages -->
@@ -193,6 +216,8 @@ A total of 5 people contributed to this release. Thank you to the following cont

<details>

- [`5279713`](https://github.com/stdlib-js/stdlib/commit/527971383e70a0e92dbca647dabfef27f294f149) - **feat:** add `isWebAssemblyMemory` to namespace _(by Athan Reines)_
- [`718ba36`](https://github.com/stdlib-js/stdlib/commit/718ba365fd18e0e35582433c22f6878a0e744675) - **feat:** add `assert/is-wasm-memory` _(by Athan Reines)_
- [`15e6c71`](https://github.com/stdlib-js/stdlib/commit/15e6c71cac991fadbb8f804a7811650daa0d5e87) - **feat:** add `assert/is-same-array-like-object` _(by yaswanth, Philipp Burckhardt)_
- [`7bb8e20`](https://github.com/stdlib-js/stdlib/commit/7bb8e2020d334d9f9a838291e78d2f7442b24a67) - **feat:** add `@stdlib/assert/is-same-accessor-array` _(by Aayush Khanna, Philipp Burckhardt)_
- [`1f6fc8b`](https://github.com/stdlib-js/stdlib/commit/1f6fc8b5b99837f9d8b378413298f7544f1cb38e) - **bench:** update benchmarks to measure affirmative/negative test values _(by Soumajit Chatterjee, Philipp Burckhardt)_
96 changes: 96 additions & 0 deletions is-wasm-memory/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
<!--
@license Apache-2.0
Copyright (c) 2024 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.
-->

# isWebAssemblyMemory

> Test if a value is a WebAssembly [memory][@stdlib/wasm/memory] instance.
<section class="usage">

## Usage

```javascript
var isWebAssemblyMemory = require( '@stdlib/assert/is-wasm-memory' );
```

#### isWebAssemblyMemory( value )

Tests if a value is a WebAssembly [memory][@stdlib/wasm/memory] instance.

```javascript
var Memory = require( '@stdlib/wasm/memory' );

var mem = new Memory({
'initial': 0
});
var bool = isWebAssemblyMemory( mem );
// returns true
```

</section>

<!-- /.usage -->

<section class="examples">

## Examples

<!-- eslint no-undef: "error" -->

```javascript
var Uint8Array = require( '@stdlib/array/uint8' );
var ArrayBuffer = require( '@stdlib/array/buffer' );
var Memory = require( '@stdlib/wasm/memory' );
var isWebAssemblyMemory = require( '@stdlib/assert/is-wasm-memory' );

var mem = new Memory({
'initial': 0
});
var bool = isWebAssemblyMemory( mem );
// returns true

bool = isWebAssemblyMemory( new Uint8Array( 10 ) );
// returns false

bool = isWebAssemblyMemory( new ArrayBuffer( 10 ) );
// returns false
```

</section>

<!-- /.examples -->

<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. -->

<section class="related">

</section>

<!-- /.related -->

<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->

<section class="links">

[@stdlib/wasm/memory]: https://github.com/stdlib-js/wasm-memory

</section>

<!-- /.links -->
95 changes: 95 additions & 0 deletions is-wasm-memory/benchmark/benchmark.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
/**
* @license Apache-2.0
*
* Copyright (c) 2024 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 Uint8Array = require( '@stdlib/array/uint8' );
var ArrayBuffer = require( '@stdlib/array/buffer' );
var Memory = require( '@stdlib/wasm/memory' );
var hasWebAssemblySupport = require( './../../has-wasm-support' );
var isBoolean = require( './../../is-boolean' ).isPrimitive;
var pkg = require( './../package.json' ).name;
var isWebAssemblyMemory = require( './../lib' );


// VARIABLES //

var opts = {
'skip': !hasWebAssemblySupport()
};


// MAIN //

bench( pkg+'::true', opts, function benchmark( b ) {
var values;
var bool;
var o;
var i;

o = {
'initial': 0
};

values = [
new Memory( o ),
new Memory( o )
];

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
bool = isWebAssemblyMemory( values[ i%values.length ] );
if ( typeof bool !== 'boolean' ) {
b.fail( 'should return a boolean' );
}
}
b.toc();
if ( !isBoolean( bool ) ) {
b.fail( 'should return a boolean' );
}
b.pass( 'benchmark finished' );
b.end();
});

bench( pkg+'::false', function benchmark( b ) {
var values;
var bool;
var i;

values = [
new Uint8Array( 10 ),
new ArrayBuffer( 10 )
];

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
bool = isWebAssemblyMemory( values[ i%values.length ] );
if ( typeof bool !== 'boolean' ) {
b.fail( 'should return a boolean' );
}
}
b.toc();
if ( !isBoolean( bool ) ) {
b.fail( 'should return a boolean' );
}
b.pass( 'benchmark finished' );
b.end();
});
22 changes: 22 additions & 0 deletions is-wasm-memory/docs/repl.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@

{{alias}}( value )
Tests if a value is a WebAssembly memory instance.

Parameters
----------
value: any
Value to test.

Returns
-------
bool: boolean
Boolean indicating whether value is a WebAssembly memory instance.

Examples
--------
> var bool = {{alias}}( {} )
false

See Also
--------

45 changes: 45 additions & 0 deletions is-wasm-memory/docs/types/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*
* @license Apache-2.0
*
* Copyright (c) 2024 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.
*/

// TypeScript Version: 4.1

/**
* Tests if a value is a WebAssembly memory instance.
*
* @param value - value to test
* @returns boolean indicating whether value is a WebAssembly memory instance
*
* @example
* var Memory = require( '@stdlib/wasm/memory' );
*
* var mem = new Memory({
* 'initial': 0
* });
* var bool = isWebAssemblyMemory( mem );
* // returns true
*
* @example
* var bool = isWebAssemblyMemory( [] );
* // returns false
*/
declare function isWebAssemblyMemory( value: any ): boolean; // Note: WebAssembly.Memory is not available in older JavaScript environments


// EXPORTS //

export = isWebAssemblyMemory;
33 changes: 33 additions & 0 deletions is-wasm-memory/docs/types/test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
* @license Apache-2.0
*
* Copyright (c) 2024 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.
*/

import isWebAssemblyMemory = require( './index' );


// TESTS //

// The function returns a boolean...
{
isWebAssemblyMemory( [] ); // $ExpectType boolean
}

// The compiler throws an error if the function is provided an unsupported number of arguments...
{
isWebAssemblyMemory(); // $ExpectError
isWebAssemblyMemory( [], 123 ); // $ExpectError
}
41 changes: 41 additions & 0 deletions is-wasm-memory/examples/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/**
* @license Apache-2.0
*
* Copyright (c) 2024 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';

var hasWebAssemblySupport = require( './../../has-wasm-support' );
var Uint8Array = require( '@stdlib/array/uint8' );
var ArrayBuffer = require( '@stdlib/array/buffer' );
var Memory = require( '@stdlib/wasm/memory' );
var isWebAssemblyMemory = require( './../lib' );

var bool = isWebAssemblyMemory( new Uint8Array( 10 ) );
console.error( bool );
// => false

bool = isWebAssemblyMemory( new ArrayBuffer( 10 ) );
console.error( bool );
// => false

if ( hasWebAssemblySupport() ) {
bool = isWebAssemblyMemory( new Memory({
'initial': 0
}));
console.log( bool );
// => true
}
Loading

0 comments on commit 58ee818

Please sign in to comment.