Skip to content

Commit

Permalink
[embind] Simplify string.toWireType type check. NFC
Browse files Browse the repository at this point in the history
  • Loading branch information
sbc100 committed Jan 10, 2025
1 parent 7dc74dc commit ed99324
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 9 deletions.
3 changes: 2 additions & 1 deletion src/embind/embind.js
Original file line number Diff line number Diff line change
Expand Up @@ -547,7 +547,8 @@ var LibraryEmbind = {
var length;
var valueIsOfTypeString = (typeof value == 'string');

if (!(valueIsOfTypeString || value instanceof Uint8Array || value instanceof Uint8ClampedArray || value instanceof Int8Array)) {
// We accept `string` or array views with single byte elements
if (!(valueIsOfTypeString || (ArrayBuffer.isView(value) && value.BYTES_PER_ELEMENT == 1))) {
throwBindingError('Cannot pass non-string to std::string');
}
if (stdStringIsUTF8 && valueIsOfTypeString) {
Expand Down
8 changes: 4 additions & 4 deletions test/code_size/embind_hello_wasm.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"a.html": 552,
"a.html.gz": 380,
"a.js": 9879,
"a.js.gz": 4288,
"a.js": 9845,
"a.js.gz": 4303,
"a.wasm": 7348,
"a.wasm.gz": 3375,
"total": 17779,
"total_gz": 8043
"total": 17745,
"total_gz": 8058
}
8 changes: 4 additions & 4 deletions test/code_size/embind_val_wasm.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"a.html": 552,
"a.html.gz": 380,
"a.js": 7153,
"a.js.gz": 3042,
"a.js": 7119,
"a.js.gz": 3059,
"a.wasm": 9119,
"a.wasm.gz": 4701,
"total": 16824,
"total_gz": 8123
"total": 16790,
"total_gz": 8140
}

0 comments on commit ed99324

Please sign in to comment.