simon-git: puzzles (main): Ben Harris

Commits to Tartarus hosted VCS tartarus-commits at lists.tartarus.org
Sat Jun 3 17:10:59 BST 2023


TL;DR:
  6a41c0b js: handle exceptions when accessing localStorage
  5acce15 js: pass preferences file from JS to C on the heap, not the stack

Repository:     https://git.tartarus.org/simon/puzzles.git
On the web:     https://git.tartarus.org/?p=simon/puzzles.git
Branch updated: main
Committer:      Ben Harris <bjh21 at bjh21.me.uk>
Date:           2023-06-03 17:10:59

commit 6a41c0b7a0c0f8299a86e5d33e7008ced3911924
web diff https://git.tartarus.org/?p=simon/puzzles.git;a=commitdiff;h=6a41c0b7a0c0f8299a86e5d33e7008ced3911924;hp=b6c842a28cf6597df063fcff35079c3e3982381e
Author: Ben Harris <bjh21 at bjh21.me.uk>
Date:   Tue May 30 15:07:41 2023 +0200

    js: handle exceptions when accessing localStorage
    
    Trying to access window.localStorage will generate an exception if the
    local storage is for some reason inaccessible.  This can be
    demonstrated in Firefox by configuring it to block a site from using
    site data.  Writing to local storage might also cause an exception if,
    for instance, the quota of data for a site is exceeded.
    
    If an exception is raised while loading preferences we log the fact
    but don't make any report to the user, behaving as if no preferences
    were found.  This avoids annoying the user on every visit to a puzzle
    page if they're not trying to use preferences.
    
    If something goes wrong when saving, we do currently report that to
    the user in an alert box.  This seems reasonable since it's in
    response to an explicit user action.

 emcclib.js | 21 +++++++++++++++++----
 1 file changed, 17 insertions(+), 4 deletions(-)

commit 5acce15ed907d29a5575668a09e7d94cf7a36b3f
web diff https://git.tartarus.org/?p=simon/puzzles.git;a=commitdiff;h=5acce15ed907d29a5575668a09e7d94cf7a36b3f;hp=6a41c0b7a0c0f8299a86e5d33e7008ced3911924
Author: Ben Harris <bjh21 at bjh21.me.uk>
Date:   Tue May 30 16:55:22 2023 +0200

    js: pass preferences file from JS to C on the heap, not the stack
    
    The C stack used by Emscripten is quite small, so passing more than a
    few klilobytes of data on it tends to cause an overflow.  Current
    versions of puzzles will only generate tiny preferences files, but this
    might change in future and in any case Puzzles shouldn't crash just
    because the preferences in local storage have got corrupted.
    
    To fix this, we now have JavaScript allocate a suitable amount of C heap
    memory using malloc() and stick the preferences file in there.
    
    This could plausibly fail if the preferences file were really big, but
    that's unlikely since browsers generally limit an origin to about 5 MB
    of local storage.  In any case, if malloc() does fail, we'll just ignore
    the preferences file, which is probably the right thing to do.

 cmake/platforms/emscripten.cmake | 3 +++
 emcclib.js                       | 8 +++++++-
 emccpre.js                       | 2 +-
 3 files changed, 11 insertions(+), 2 deletions(-)



More information about the tartarus-commits mailing list