webassembly: Implement MICROPY_PY_RANDOM_SEED_INIT_FUNC.

Signed-off-by: Damien George <damien@micropython.org>
pull/13583/head
Damien George 2023-12-13 13:10:03 +11:00
rodzic 8282bd93a2
commit 76898cbfa1
3 zmienionych plików z 12 dodań i 0 usunięć

Wyświetl plik

@ -29,3 +29,4 @@
extern void mp_js_write(const char *str, mp_uint_t len);
extern int mp_js_ticks_ms(void);
extern void mp_js_hook(void);
extern uint32_t mp_js_random_u32(void);

Wyświetl plik

@ -63,4 +63,11 @@ mergeInto(LibraryManager.library, {
}
}
},
// Node prior to v19 did not expose "crypto" as a global, so make sure it exists.
mp_js_random_u32__postset:
"if (globalThis.crypto === undefined) { globalThis.crypto = require('crypto'); }",
mp_js_random_u32: () =>
globalThis.crypto.getRandomValues(new Uint32Array(1))[0],
});

Wyświetl plik

@ -49,6 +49,8 @@
#define MICROPY_FLOAT_IMPL (MICROPY_FLOAT_IMPL_DOUBLE)
#define MICROPY_USE_INTERNAL_ERRNO (1)
#define MICROPY_USE_INTERNAL_PRINTF (0)
#define MICROPY_PY_RANDOM_SEED_INIT_FUNC (mp_js_random_u32())
#ifndef MICROPY_VFS
#define MICROPY_VFS (1)
#endif
@ -95,3 +97,5 @@ typedef long mp_off_t;
// _GNU_SOURCE must be defined to get definitions of DT_xxx symbols from dirent.h.
#define _GNU_SOURCE
#endif
uint32_t mp_js_random_u32(void);