@mikrojs/firmware 0.8.0 → 0.10.0-pr-134.g9211761

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -133,7 +133,7 @@ include("${MIK_BYTECODE_CMAKE}")
133
133
 
134
134
  # Force linker to include self-registering native modules
135
135
  set(_MIK_MODULES cbor pin i2c spi http wifi rtc nvs_kv sntp sleep neopixel pwm uart)
136
- set(_MIK_BYTECODE_MODULES cbor env result schema fs http/helpers http/request i2c kv/nvs kv/rtc kv/shared neopixel observable observable/lazy observable/operators pin pwm reader sleep spi sntp stdio stream sys test uart udp wifi)
136
+ set(_MIK_BYTECODE_MODULES cbor env result schema fs http/helpers http/request i2c kv/nvs kv/rtc kv/shared module neopixel observable observable/lazy observable/operators pin pwm reader sleep spi sntp stdio stream sys test uart udp wifi)
137
137
  if(CONFIG_BT_ENABLED)
138
138
  list(APPEND _MIK_MODULES ble)
139
139
  list(APPEND _MIK_BYTECODE_MODULES ble)
@@ -5,6 +5,7 @@
5
5
  #include <esp_heap_caps.h>
6
6
  #include <esp_mac.h>
7
7
  #include <esp_random.h>
8
+ #include <esp_sleep.h>
8
9
  #include <esp_system.h>
9
10
  #include <esp_rtc_time.h>
10
11
  #include <esp_timer.h>
@@ -40,6 +41,16 @@ static void esp32_restart(void) {
40
41
  esp_restart();
41
42
  }
42
43
 
44
+ static void esp32_deep_sleep_us(uint64_t us) {
45
+ /* Flush + close the file log so buffered lines reach flash; deep sleep
46
+ * reboots the chip on wake, same as mik__sleep_deep does for the JS API. */
47
+ mik_logfile_close();
48
+ esp_sleep_disable_wakeup_source(ESP_SLEEP_WAKEUP_ALL);
49
+ esp_sleep_enable_timer_wakeup(us);
50
+ esp_deep_sleep_start();
51
+ /* Never reached */
52
+ }
53
+
43
54
  static void esp32_yield(void) {
44
55
  vTaskDelay(1);
45
56
  }
@@ -205,6 +216,7 @@ static const MIKPlatform esp32_platform = {
205
216
  .get_rtc_us = esp32_get_rtc_us,
206
217
  .random = esp32_random,
207
218
  .restart = esp32_restart,
219
+ .deep_sleep_us = esp32_deep_sleep_us,
208
220
  .yield = esp32_yield,
209
221
  .get_free_system_mem = esp32_get_free_system_mem,
210
222
  .get_min_free_system_mem = esp32_get_min_free_system_mem,
@@ -98,6 +98,52 @@ TEST_CASE("Module import.meta.main is true for entry module", "[modules]") {
98
98
  MIK_FreeRuntime(mik_rt);
99
99
  }
100
100
 
101
+ TEST_CASE("withUnload() unloads a module after the callback returns", "[modules]") {
102
+ const auto mik_rt = MIK_NewRuntime();
103
+ const auto ctx = MIK_GetJSContext(mik_rt);
104
+
105
+ /* Virtual leaf module with an eval counter: a second evaluation proves it
106
+ * was genuinely unloaded (re-import re-runs the body). Using a virtual
107
+ * module avoids depending on the LittleFS layout in the test. */
108
+ const char* leaf =
109
+ "globalThis.__leafEvals = (globalThis.__leafEvals || 0) + 1;\n"
110
+ "export const v = 99;\n";
111
+ MIK_RegisterVirtualModule(mik_rt, "/test/leaf.js", leaf, strlen(leaf));
112
+
113
+ /* Exercises the real shipped mikrojs/module withUnload() on device. */
114
+ const char* code =
115
+ "import {withUnload} from 'mikrojs/module';\n"
116
+ "globalThis.__first = await withUnload(import('./leaf.js'), (mod) => mod.v);\n"
117
+ "globalThis.__after = true;\n"
118
+ "const b = await import('./leaf.js');\n"
119
+ "globalThis.__second = b.v;\n";
120
+ JSValue ret = MIK_EvalModuleContent(ctx, "/test/main.js", code, strlen(code));
121
+ TEST_ASSERT_FALSE_MESSAGE(JS_IsException(ret), "disposable e2e module eval threw");
122
+ JS_FreeValue(ctx, ret);
123
+ mik__execute_jobs(ctx);
124
+
125
+ JSValue g = JS_GetGlobalObject(ctx);
126
+ JSValue first = JS_GetPropertyStr(ctx, g, "__first");
127
+ JSValue after = JS_GetPropertyStr(ctx, g, "__after");
128
+ JSValue second = JS_GetPropertyStr(ctx, g, "__second");
129
+ JSValue evals = JS_GetPropertyStr(ctx, g, "__leafEvals");
130
+ int32_t first_i = 0, second_i = 0, evals_i = 0;
131
+ JS_ToInt32(ctx, &first_i, first);
132
+ JS_ToInt32(ctx, &second_i, second);
133
+ JS_ToInt32(ctx, &evals_i, evals);
134
+ TEST_ASSERT_EQUAL(99, first_i);
135
+ TEST_ASSERT_EQUAL(1, JS_ToBool(ctx, after));
136
+ TEST_ASSERT_EQUAL(99, second_i);
137
+ TEST_ASSERT_EQUAL_MESSAGE(2, evals_i, "leaf should re-evaluate, proving real unload");
138
+ JS_FreeValue(ctx, first);
139
+ JS_FreeValue(ctx, after);
140
+ JS_FreeValue(ctx, second);
141
+ JS_FreeValue(ctx, evals);
142
+ JS_FreeValue(ctx, g);
143
+
144
+ MIK_FreeRuntime(mik_rt);
145
+ }
146
+
101
147
  TEST_CASE("Bytecode roundtrip: compile then load", "[modules]") {
102
148
  JSRuntime* rt = JS_NewRuntime();
103
149
  JSContext* ctx = JS_NewContext(rt);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mikrojs/firmware",
3
- "version": "0.8.0",
3
+ "version": "0.10.0-pr-134.g9211761",
4
4
  "description": "Mikro.js ESP32 firmware: ESP-IDF component, build tools, and project template",
5
5
  "keywords": [
6
6
  "esp-idf",
@@ -51,8 +51,8 @@
51
51
  },
52
52
  "dependencies": {
53
53
  "esbuild": "^0.28.0",
54
- "@mikrojs/quickjs": "0.8.0",
55
- "@mikrojs/native": "0.8.0"
54
+ "@mikrojs/native": "0.10.0-pr-134.g9211761",
55
+ "@mikrojs/quickjs": "0.10.0-pr-134.g9211761"
56
56
  },
57
57
  "engines": {
58
58
  "node": ">=24.0.0"
Binary file
Binary file
Binary file
Binary file
Binary file