Skip to content

Commit 69aa4cd

Browse files
authored
JS: Fix merge of 3963 and 3961 (#3980)
* toString() was moved, not duplicated * These had gotten lost * This is now implemented * Add missing version doctags
1 parent f4887ed commit 69aa4cd

File tree

4 files changed

+61
-16
lines changed

4 files changed

+61
-16
lines changed

applications/system/js_app/js_thread.c

-11
Original file line numberDiff line numberDiff line change
@@ -217,16 +217,6 @@ static void js_parse_int(struct mjs* mjs) {
217217
mjs_return(mjs, mjs_mk_number(mjs, num));
218218
}
219219

220-
static void js_global_to_string(struct mjs* mjs) {
221-
int base = 10;
222-
if(mjs_nargs(mjs) > 1) base = mjs_get_int(mjs, mjs_arg(mjs, 1));
223-
double num = mjs_get_int(mjs, mjs_arg(mjs, 0));
224-
char tmp_str[] = "-2147483648";
225-
itoa(num, tmp_str, base);
226-
mjs_val_t ret = mjs_mk_string(mjs, tmp_str, ~0, true);
227-
mjs_return(mjs, ret);
228-
}
229-
230220
#ifdef JS_DEBUG
231221
static void js_dump_write_callback(void* ctx, const char* format, ...) {
232222
File* file = ctx;
@@ -278,7 +268,6 @@ static int32_t js_thread(void* arg) {
278268
JS_ASSIGN_MULTI(mjs, global) {
279269
JS_FIELD("print", MJS_MK_FN(js_print));
280270
JS_FIELD("delay", MJS_MK_FN(js_delay));
281-
JS_FIELD("toString", MJS_MK_FN(js_global_to_string));
282271
JS_FIELD("parseInt", MJS_MK_FN(js_parse_int));
283272
JS_FIELD("ffi_address", MJS_MK_FN(js_ffi_address));
284273
JS_FIELD("require", MJS_MK_FN(js_require));

applications/system/js_app/packages/fz-sdk/global.d.ts

+39-4
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ declare function checkSdkCompatibility(expectedMajor: number, expectedMinor: num
120120
* recognized as a baseline feature. For more info, consult the module
121121
* documentation.
122122
* @param features Array of named features to query
123+
* @version Added in JS SDK 0.1
123124
*/
124125
declare function doesSdkSupport(features: string[]): boolean;
125126

@@ -131,6 +132,7 @@ declare function doesSdkSupport(features: string[]): boolean;
131132
* features that are now recognized as baseline features. For more
132133
* info, consult the module documentation.
133134
* @param features Array of named features to query
135+
* @version Added in JS SDK 0.1
134136
*/
135137
declare function checkSdkFeatures(features: string[]): void | never;
136138

@@ -150,15 +152,48 @@ declare function delay(ms: number): void;
150152
declare function print(...args: any[]): void;
151153

152154
/**
153-
* @brief Reads a JS value from a file
155+
* @brief Converts a string to a number
156+
* @param text The string to convert to a number
157+
* @param base Integer base (`2`...`16`), default: 10
158+
* @version Added in JS SDK 0.1
159+
*/
160+
declare function parseInt(text: string, base?: number): number;
161+
162+
/**
163+
* @brief Path to the directory containing the current script
164+
* @version Added in JS SDK 0.1
165+
*/
166+
declare const __dirname: string;
167+
168+
/**
169+
* @brief Path to the current script file
170+
* @version Added in JS SDK 0.1
171+
*/
172+
declare const __filename: string;
173+
174+
/**
175+
* @brief Runs a JS file and returns value from it
154176
*
155-
* Reads a file at the specified path, interprets it as a JS value and returns
156-
* said value.
177+
* Reads a file at the specified path and runs it as JS, returning the last evaluated value.
178+
*
179+
* The result is cached and this filepath will not re-evaluated on future
180+
* load() calls for this session.
157181
*
158182
* @param path The path to the file
183+
* @param scope An object to use as global scope while running this file
184+
* @version Added in JS SDK 0.1
185+
*/
186+
declare function load(path: string, scope?: object): any;
187+
188+
/**
189+
* @brief Return 1-byte string whose ASCII code is the integer `n`
190+
*
191+
* If `n` is not numeric or outside of `0-255` range, `null` is returned
192+
*
193+
* @param n The ASCII code to convert to string
159194
* @version Added in JS SDK 0.1
160195
*/
161-
declare function load(path: string): any;
196+
declare function chr(n: number): string | null;
162197

163198
/**
164199
* @brief Loads a natively implemented module

applications/system/js_app/packages/fz-sdk/gui/index.d.ts

+21-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
* |----------------------|------------------|
3131
* | `button_menu` | ❌ |
3232
* | `button_panel` | ❌ |
33-
* | `byte_input` | |
33+
* | `byte_input` | |
3434
* | `dialog_ex` | ✅ (as `dialog`) |
3535
* | `empty_screen` | ✅ |
3636
* | `file_browser` | ❌ |
@@ -122,11 +122,26 @@ import type { Contract } from "../event_loop";
122122
type Properties = { [K: string]: any };
123123

124124
export declare class View<Props extends Properties> {
125+
/**
126+
* Assign value to property by name
127+
* @param property Name of the property
128+
* @param value Value to assign
129+
* @version Added in JS SDK 0.1
130+
*/
125131
set<P extends keyof Props>(property: P, value: Props[P]): void;
126132
}
127133

128134
export declare class ViewFactory<Props extends Properties, V extends View<Props>> {
135+
/**
136+
* Create view instance with default values, can be changed later with set()
137+
* @version Added in JS SDK 0.1
138+
*/
129139
make(): V;
140+
/**
141+
* Create view instance with custom values, can be changed later with set()
142+
* @param initial Dictionary of property names to values
143+
* @version Added in JS SDK 0.1
144+
*/
130145
makeWith(initial: Partial<Props>): V;
131146
}
132147

@@ -144,6 +159,11 @@ declare class ViewDispatcher {
144159
* @version Added in JS SDK 0.1
145160
*/
146161
navigation: Contract;
162+
/**
163+
* View object currently shown
164+
* @version Added in JS SDK 0.1
165+
*/
166+
currentView: View<any>;
147167
/**
148168
* Sends a number to the custom event handler
149169
* @param event number to send

applications/system/js_app/packages/fz-sdk/notification/index.d.ts

+1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ export declare function success(): void;
1414
/**
1515
* @brief Signals failure to the user via the color LED, speaker and vibration
1616
* motor
17+
* @version Added in JS SDK 0.1
1718
*/
1819
export declare function error(): void;
1920

0 commit comments

Comments
 (0)