Repository navigation
Commit faa8a05
authored
fix: uneval loses a repeated typed array/DataView referenced inside a cycle (#163)
* fix: emit uneval reconstructions before the statements that reference them
A typed array, DataView or ArrayBuffer that is referenced more than once
is hoisted into the IIFE preamble as a placeholder (`{}`) and rebuilt with
a reassignment (`b = new Uint8Array(...)`). That reassignment was pushed
onto the same ordered `statements` list as the property fills, so when a
referencing container came first, it captured the `{}` placeholder:
const view = new Uint8Array([1, 2, 3]);
const obj = { a: view, b: view };
obj.self = obj; // make `obj` a named, cyclic value
uneval(obj);
// (function(a,b){a.self=a;a.a=b;a.b=b;b=new Uint8Array([1,2,3]);return a}({},{}))
// ^^^^^^^ captured the {} placeholder, not the view
Emit these reassignments first. They only depend on IIFE arguments (a
typed array's buffer is always passed as an argument, never reassigned),
never on each other or on the containers, so running them before the
property fills is safe and makes the references resolve to the real value.
* chore: add changeset1 parent 3770846 commit faa8a05
3 files changed
Lines changed: 29 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
361 | 361 | | |
362 | 362 | | |
363 | 363 | | |
| 364 | + | |
| 365 | + | |
| 366 | + | |
| 367 | + | |
| 368 | + | |
| 369 | + | |
| 370 | + | |
364 | 371 | | |
365 | 372 | | |
366 | 373 | | |
| |||
457 | 464 | | |
458 | 465 | | |
459 | 466 | | |
460 | | - | |
| 467 | + | |
461 | 468 | | |
462 | 469 | | |
463 | 470 | | |
| |||
478 | 485 | | |
479 | 486 | | |
480 | 487 | | |
481 | | - | |
| 488 | + | |
482 | 489 | | |
483 | 490 | | |
484 | 491 | | |
| |||
507 | 514 | | |
508 | 515 | | |
509 | 516 | | |
510 | | - | |
| 517 | + | |
| 518 | + | |
511 | 519 | | |
512 | 520 | | |
513 | 521 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1493 | 1493 | | |
1494 | 1494 | | |
1495 | 1495 | | |
| 1496 | + | |
| 1497 | + | |
| 1498 | + | |
| 1499 | + | |
| 1500 | + | |
| 1501 | + | |
| 1502 | + | |
| 1503 | + | |
| 1504 | + | |
| 1505 | + | |
| 1506 | + | |
| 1507 | + | |
| 1508 | + | |
1496 | 1509 | | |
1497 | 1510 | | |
1498 | 1511 | | |
| |||
0 commit comments