Skip to content

Commit f2aebc9

Browse files
committed
fix(cpp.js): pass embind-object arrays across the worker boundary.
1 parent 9dcf85f commit f2aebc9

4 files changed

Lines changed: 45 additions & 2 deletions

File tree

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MIT License
22

3-
Copyright (c) 2026 Buğra Sarı
3+
Copyright (c) 2026 Buğra Sarı and cpp.js contributors
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

cppjs-core/cpp.js/LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2026 Buğra Sarı and cpp.js contributors
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

cppjs-core/cpp.js/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "cpp.js",
3-
"version": "2.0.0-beta.24",
3+
"version": "2.0.0-beta.25",
44
"license": "MIT",
55
"homepage": "https://cpp.js.org",
66
"repository": "https://github.com/bugra9/cpp.js.git",

cppjs-core/cpp.js/src/assets/js-runtime/adapters/worker-comlink.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,28 @@ Comlink.transferHandlers.set('embindObject', {
132132
},
133133
});
134134

135+
// 6. embindProxyArray: a plain JS array that contains proxied embind objects
136+
// can't be structured-cloned across the
137+
// worker boundary, because the element proxies are functions. Resolve each
138+
// registered proxy element back to its worker-side original, the same way the
139+
// embindProxy handler does for a single argument.
140+
Comlink.transferHandlers.set('embindProxyArray', {
141+
canHandle(obj) {
142+
return Array.isArray(obj) && obj.some((e) => embindProxyIds.has(e));
143+
},
144+
serialize(arr) {
145+
return [
146+
arr.map((e) => (embindProxyIds.has(e) ? { __embindRef: embindProxyIds.get(e) } : e)),
147+
[],
148+
];
149+
},
150+
deserialize(arr) {
151+
return arr.map((e) => (e != null && typeof e === 'object' && '__embindRef' in e
152+
? embindRegistry.get(e.__embindRef)
153+
: e));
154+
},
155+
});
156+
135157
let _worker = null;
136158

137159
function resolveScriptUrl(config) {

0 commit comments

Comments
 (0)