| 1531 | // the host, so create -> flush -> ... -> read stay correctly ordered; the one |
| 1532 | // read (getRGB) is the only round-trip and the only thing that waits. |
| 1533 | function cn1SurfacePost(symbol, arg) { |
| 1534 | arg.__cn1_no_response = true; |
| 1535 | var msg = { type: "host-call", symbol: symbol, args: [arg], id: 0 }; |
| 1536 | // Route through the runtime's emitVmMessage (same path the scheduler uses for |
| 1537 | // every other worker->host message) so the payload goes through |
| 1538 | // sanitizeMessagePayload -- a raw self.postMessage THROWS on any non-cloneable |
| 1539 | // value (cycle / stray function) and the flush is silently lost, leaving the |
| 1540 | // surface unpopulated (the intermittent "Failed to encode" / stall). Sanitize |
| 1541 | // never throws; at worst it drops a bad field. |
| 1542 | if (typeof self.emitVmMessage === "function") { |
| 1543 | self.emitVmMessage(msg); |
| 1544 | } else { |
| 1545 | self.postMessage(msg); |
| 1546 | } |
| 1547 | } |
| 1548 | |
| 1549 | // Sanitize a worker-side host-ref (a live JSObject whose interface methods are |
| 1550 | // FUNCTION-valued and thus not structured-cloneable) into a clean transferable |