@@ -216,10 +216,16 @@ impl ResourceIntrinsic {
216216 function {resource_transfer_borrow_fn}(handle, fromTid, toTid) {{
217217 const fromTable = {handle_tables}[fromTid];
218218 const fromHandle = fromTable[(handle << 1) + 1];
219- const toTable = {handle_tables}[toTid] || ({handle_tables}[toTid] = [T_FLAG, 0]);
220219 const isOwn = (fromHandle & T_FLAG) !== 0;
221220 const rep = isOwn ? fromHandle & ~T_FLAG : {rsc_table_remove}(fromTable, fromHandle).rep;
222221
222+ let toTable = {handle_tables}[toTid];
223+ if (!toTable) {{
224+ {handle_tables}[toTid] = [T_FLAG, 0];
225+ toTable = {handle_tables}[toTid];
226+ toTable._createdReps = new Set();
227+ }}
228+
223229 if (toTable._createdReps.has(rep)) {{
224230 return rep;
225231 }}
@@ -240,15 +246,20 @@ impl ResourceIntrinsic {
240246 output. push_str ( & format ! ( r#"
241247 function resourceTransferBorrowValidLifting(handle, fromTid, toTid) {{
242248 const fromTable = {handle_tables}[fromTid];
243- const toTable = {handle_tables}[toTid];
244249 const isOwn = (fromTable[(handle << 1) + 1] & T_FLAG) !== 0;
245250 const rep = isOwn ? fromTable[(handle << 1) + 1] & ~T_FLAG : {rsc_table_remove}(fromTable, handle).rep;
246251
252+ let toTable = {handle_tables}[toTid];
253+ if (!toTable) {{
254+ {handle_tables}[toTid] = [T_FLAG, 0];
255+ toTable = {handle_tables}[toTid];
256+ toTable._createdReps = new Set();
257+ }}
258+
247259 if (toTable._createdReps.has(rep)) {{
248260 return rep;
249261 }}
250262
251- const toTable = {handle_tables}[toTid] || ({handle_tables}[toTid] = [T_FLAG, 0]);
252263 return {rsc_table_create_borrow}(toTable, rep, {scope_id});
253264 }}
254265 "# ) ) ;
@@ -258,14 +269,23 @@ impl ResourceIntrinsic {
258269 let handle_tables = Intrinsic :: HandleTables . name ( ) ;
259270 let rsc_table_remove = Self :: ResourceTableRemove . name ( ) ;
260271 let rsc_table_create_own = Self :: ResourceTableCreateOwn . name ( ) ;
261- output. push_str ( & format ! ( r#"
272+ output. push_str ( & format ! (
273+ r#"
262274 function resourceTransferOwn(handle, fromTid, toTid) {{
263275 const {{ rep }} = {rsc_table_remove}({handle_tables}[fromTid], handle);
264- const toTable = {handle_tables}[toTid] || ({handle_tables}[toTid] = [T_FLAG, 0]);
276+
277+ let toTable = {handle_tables}[toTid];
278+ if (!toTable) {{
279+ {handle_tables}[toTid] = [T_FLAG, 0];
280+ toTable = {handle_tables}[toTid];
281+ toTable._createdReps = new Set();
282+ }}
283+
265284 const newHandle = {rsc_table_create_own}(toTable, rep);
266285 return newHandle;
267286 }}
268- "# ) ) ;
287+ "#
288+ ) ) ;
269289 }
270290
271291 Self :: ResourceCallBorrows => {
0 commit comments