Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorrect constructor functions for typed arrays #48

Closed
sockmaster27 opened this issue Mar 6, 2024 · 2 comments
Closed

Incorrect constructor functions for typed arrays #48

sockmaster27 opened this issue Mar 6, 2024 · 2 comments

Comments

@sockmaster27
Copy link

When returning a typed array, like JsInt16Array for example, the following JavaScript expression will evaluate to false:

x instanceof Int16Array

Using Jest, this assertion

expect(arr).toBeInstanceOf(Int16Array)

fails and reports the following:

Expected constructor: Int16Array
Received constructor: Int16Array

This makes me suspect that Neon is using a constructor function with an identical name, but different equality identity.

@kjvalencik
Copy link
Member

kjvalencik commented Mar 6, 2024

@sockmaster27 are you using any transpilers that could be polyfilling or transforming typed arrays?

I am not ables to reproduce with a simple test:

use neon::prelude::*;

#[neon::main]
fn main(mut cx: ModuleContext) -> NeonResult<()> {
    cx.export_function("array", |mut cx| {
        JsInt16Array::from_slice(&mut cx, &[0, 1, 2, 3])
    })?;

    Ok(())
}
npm install
node -e 'console.log(require(".").array() instanceof Int16Array)'
# true

Internally, Neon is calling napi_create_typed_array.

@sockmaster27
Copy link
Author

sockmaster27 commented Mar 6, 2024

It appears to be a problem with Jest.
Sorry for the inconvenience.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants