Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

contents of Map don't survive 2nd snapshot / restore #488

Closed
dckc opened this issue Oct 27, 2020 · 2 comments
Closed

contents of Map don't survive 2nd snapshot / restore #488

dckc opened this issue Oct 27, 2020 · 2 comments
Labels
confirmed issue reported has been reproduced fixed - please verify Issue has been fixed. Please verify and close.

Comments

@dckc
Copy link
Contributor

dckc commented Oct 27, 2020

Steps to Reproduce

in maptest.js:

const progress = [];
const mapTest = new Map();

function proceed() {
  progress.push('moar!');
  mapTest.set(progress.length, 'thing');
  print(progress.length);
  print(progress);
  print(mapTest.size);
  print([...mapTest.entries()]);
}

globalThis.proceed = proceed;

proceed();

in mapcont.js:

proceed();

Then invoke...

$ xsnap -m maptest.js -w s1.xsnap
1
moar!
1
1,thing
$ xsnap -m mapcont.js -r s1.xsnap -w s2.xsnap
2
moar!,moar!
2
1,thing,2,thing
$ xsnap -m mapcont.js -r s2.xsnap -w s3.xsnap
3
moar!,moar!,moar!
1
3,thing

Expected behavior

as above but for the last 2 lines:

3
1,thing,2,thing,3,thing

Build environment: Linux
Target device: xsnap
sdk version 748fda9
xsnap version e8199b1012981d627a77235bb6737f9deef07103

cc @warner @erights @phoddie

@phoddie
Copy link
Collaborator

phoddie commented Oct 28, 2020

There is a bug in the loading of Maps. The fix is small, so I'll post it here ahead of us updating this repository. Replace these lines:

slot = the->firstHeap;
slot->value.reference = the->freeHeap;
slot++;

With:

slot = the->firstHeap + 1;

The test isn't quite right though. The second step loads mapcont.js so the third step does nothing as that module is already loaded. mapcont.js is already loaded so nothing happens.

$ xsnap -m maptest.js -w s1.xsnap
1
moar!
1
1,thing
$ xsnap -m mapcont.js -r s1.xsnap -w s2.xsnap
2
moar!,moar!
2
1,thing,2,thing
$ xsnap -m mapcont.js -r s2.xsnap -w s3.xsnap

You need a separate module, such as mapcont2.js:

proceed();

Then the output is as you expect:

$ xsnap -m mapcont2.js -r s2.xsnap -w s3.xsnap
3
moar!,moar!,moar!
3
1,thing,2,thing,3,thing

@phoddie phoddie added confirmed issue reported has been reproduced fixed - please verify Issue has been fixed. Please verify and close. labels Oct 28, 2020
@dckc
Copy link
Contributor Author

dckc commented Oct 28, 2020

confirmed. thanks!

(committed locally / temporarily as fb0141f3)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
confirmed issue reported has been reproduced fixed - please verify Issue has been fixed. Please verify and close.
Projects
None yet
Development

No branches or pull requests

2 participants