Skip to content

feat(napi): support arraybuffer for de#2296

Merged
Brooooooklyn merged 6 commits into
napi-rs:mainfrom
richerfu:main
Oct 13, 2024
Merged

feat(napi): support arraybuffer for de#2296
Brooooooklyn merged 6 commits into
napi-rs:mainfrom
richerfu:main

Conversation

@richerfu

@richerfu richerfu commented Oct 8, 2024

Copy link
Copy Markdown
Contributor

For Buffer and ArrayBuffer, we need to handle it explicitly instead of using FromNapiValue.

Using FromNapiValue to convert value will get some error:

t.is(testSerdeBufferBytes({ code: new ArrayBuffer(10) }), 10n)
image

@Brooooooklyn

Copy link
Copy Markdown
Member

wasm test failed, seems like the emnapi napi_is_arraybuffer return false when value is new ArrayBuffer(10) /cc @toyobayashi

@toyobayashi

Copy link
Copy Markdown
Contributor

seems like the emnapi napi_is_arraybuffer return false when value is new ArrayBuffer(10)

After I comment out this two line test passed. Seems like the Uint8Array is converted in FromNapiValue for Array?

test('serde-buffer-bytes', (t) => {
  // t.is(testSerdeBufferBytes({ code: new Uint8Array([1, 2, 3]) }), 3n)
  // t.is(testSerdeBufferBytes({ code: new Uint8Array(0) }), 0n)

  t.is(testSerdeBufferBytes({ code: Buffer.from([1, 2, 3]) }), 3n)
  t.is(testSerdeBufferBytes({ code: Buffer.alloc(0) }), 0n)
  t.is(testSerdeBufferBytes({ code: new ArrayBuffer(10) }), 10n)
})

Comment thread crates/napi/src/js_values/de.rs
@Brooooooklyn Brooooooklyn merged commit 16fc9cb into napi-rs:main Oct 13, 2024
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

Successfully merging this pull request may close these issues.

3 participants