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

runtime(js): fix useOptionalChain #1861

Merged
merged 1 commit into from
Mar 11, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions biome.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@
"rules": {
"recommended": true,
"complexity": {
"useArrowFunction": "off",
"useOptionalChain": "off"
"useArrowFunction": "off"
},
"correctness": {
"noInnerDeclarations": "off",
Expand Down
4 changes: 2 additions & 2 deletions runtime/js/compare.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ function caml_compare_val_tag(a) {
return 12520; // javascript string, like string_tag (252)
else if (a instanceof Number)
return 1000; // int_tag (we use it for all numbers)
else if (a && a.caml_custom)
else if (a?.caml_custom)
return 1255; // like custom_tag (255)
else if (a && a.compare)
else if (a?.compare)
return 1256; // like custom_tag (255)
else if (typeof a === "function")
return 1247; // like closure_tag (247)
Expand Down
2 changes: 1 addition & 1 deletion runtime/js/dynlink.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ function caml_dynlink_lookup_symbol(idx, fun_name) {
var name = caml_jsstring_of_string(fun_name);
console.log("Dynlink: looking for symbol", name);
var current_libs = get_current_libs();
if (current_libs[idx] && current_libs[idx][name])
if (current_libs[idx]?.[name])
return { name: name, symbol: current_libs[idx][name] };
return 0;
}
Expand Down
2 changes: 1 addition & 1 deletion runtime/js/effect.js
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@ function caml_resume(f, arg, stack, last) {
joo_direct: 1,
};
}
} while (res && res.joo_args);
} while (res?.joo_args);
return res;
} finally {
caml_stack_depth = saved_stack_depth;
Expand Down
2 changes: 1 addition & 1 deletion runtime/js/fs.js
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ function resolve_fs_device(name) {
}
if (!res && fs_node_supported()) {
var root = caml_get_root(name);
if (root && root.match(/^[a-zA-Z]:\/$/)) {
if (root?.match(/^[a-zA-Z]:\/$/)) {
var m = { path: root, device: new MlNodeDevice(root) };
jsoo_mount_point.push(m);
res = {
Expand Down
2 changes: 1 addition & 1 deletion runtime/js/fs_fake.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ class MlFakeDevice {
this.nm(name),
);
var parent = /^(.*)\/[^/]+/.exec(name);
parent = (parent && parent[1]) || "";
parent = parent?.[1] || "";
if (!this.exists(parent))
caml_raise_system_error(
raise_unix,
Expand Down
4 changes: 2 additions & 2 deletions runtime/js/hash.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ function caml_hash_univ_param(count, limit, obj) {
count--;
var p = caml_int64_to_bytes(caml_int64_bits_of_float(obj));
for (var i = 7; i >= 0; i--) hash_accu = (hash_accu * 19 + p[i]) | 0;
} else if (obj && obj.caml_custom) {
} else if (obj?.caml_custom) {
if (
caml_custom_ops[obj.caml_custom] &&
caml_custom_ops[obj.caml_custom].hash
Expand Down Expand Up @@ -216,7 +216,7 @@ function caml_hash(count, limit, seed, obj) {
wr = 1;
while (rd < wr && num > 0) {
v = queue[rd++];
if (v && v.caml_custom) {
if (v?.caml_custom) {
if (
caml_custom_ops[v.caml_custom] &&
caml_custom_ops[v.caml_custom].hash
Expand Down
4 changes: 2 additions & 2 deletions runtime/js/jslib.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ function caml_js_typeof(o) {
//Provides:caml_trampoline
function caml_trampoline(res) {
var c = 1;
while (res && res.joo_tramp) {
while (res?.joo_tramp) {
res = res.joo_tramp.apply(null, res.joo_args);
c++;
}
Expand Down Expand Up @@ -108,7 +108,7 @@ function caml_callback(f, args) {
caml_current_stack.x = caml_current_stack.x.t;
res = { joo_tramp: handler, joo_args: [caml_wrap_exception(e)] };
}
} while (res && res.joo_args);
} while (res?.joo_args);
} finally {
caml_stack_depth = saved_stack_depth;
caml_current_stack = saved_current_stack;
Expand Down
2 changes: 1 addition & 1 deletion runtime/js/obj.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ function caml_obj_tag(x) {
else if (caml_is_ml_bytes(x)) return 252;
else if (caml_is_ml_string(x)) return 252;
else if (x instanceof Function || typeof x === "function") return 247;
else if (x && x.caml_custom) return 255;
else if (x?.caml_custom) return 255;
else return 1000;
}

Expand Down
6 changes: 3 additions & 3 deletions runtime/js/sys.js
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ var caml_argv = (function () {
var main = "a.out";
var args = [];

if (process && process.argv && process.argv.length > 1) {
if (process?.argv?.length > 1) {
var argv = process.argv;
//nodejs
main = argv[1];
Expand Down Expand Up @@ -195,7 +195,7 @@ function caml_sys_system_command(cmd) {
var cmd = caml_jsstring_of_string(cmd);
if (typeof require !== "undefined") {
var child_process = require("node:child_process");
if (child_process && child_process.execSync)
if (child_process?.execSync)
try {
child_process.execSync(cmd, { stdio: "inherit" });
return 0;
Expand Down Expand Up @@ -374,7 +374,7 @@ function caml_sys_is_regular_file(name) {
//If: !wasm
function caml_setup_uncaught_exception_handler() {
var process = globalThis.process;
if (process && process.on) {
if (process?.on) {
process.on("uncaughtException", function (err, origin) {
caml_fatal_uncaught_exception(err);
process.exit(2);
Expand Down
2 changes: 1 addition & 1 deletion runtime/wasm/runtime.js
Original file line number Diff line number Diff line change
Expand Up @@ -631,7 +631,7 @@

start_fiber = make_promising(caml_start_fiber);
var _initialize = make_promising(_initialize);
if (globalThis.process && globalThis.process.on) {
if (globalThis.process?.on) {
globalThis.process.on("uncaughtException", (err, origin) =>
caml_handle_uncaught_exception(err),
);
Expand Down
Loading