From d634569b5eb04353941bf056c60f74e39bf0d8e0 Mon Sep 17 00:00:00 2001 From: Sora Morimoto Date: Sat, 14 Sep 2024 01:06:47 +0900 Subject: [PATCH] runtime: use `Array.isArray()` instead of `instanceof Array` Signed-off-by: Sora Morimoto --- runtime/bigarray.js | 4 ++-- runtime/compare.js | 2 +- runtime/fs_fake.js | 2 +- runtime/hash.js | 4 ++-- runtime/jslib.js | 2 +- runtime/marshal.js | 2 +- runtime/obj.js | 6 +++--- runtime/parsing.js | 4 ++-- runtime/sys.js | 2 +- runtime/weak.js | 2 +- 10 files changed, 15 insertions(+), 15 deletions(-) diff --git a/runtime/bigarray.js b/runtime/bigarray.js index 9f97256217..e23a17c37f 100644 --- a/runtime/bigarray.js +++ b/runtime/bigarray.js @@ -99,7 +99,7 @@ Ml_Bigarray.prototype.caml_custom = caml_ba_custom_name; Ml_Bigarray.prototype.offset = function (arg) { var ofs = 0; if(typeof arg === "number") arg = [arg]; - if (! (arg instanceof Array)) caml_invalid_argument("bigarray.js: invalid offset"); + if (! (Array.isArray(arg))) caml_invalid_argument("bigarray.js: invalid offset"); if (this.dims.length != arg.length) caml_invalid_argument("Bigarray.get/set: bad number of dimensions"); if(this.layout == 0 /* c_layout */) { @@ -269,7 +269,7 @@ function Ml_Bigarray_c_1_1(kind, layout, dims, buffer) { Ml_Bigarray_c_1_1.prototype = new Ml_Bigarray() Ml_Bigarray_c_1_1.prototype.offset = function (arg) { if(typeof arg !== "number"){ - if((arg instanceof Array) && arg.length == 1) + if((Array.isArray(arg)) && arg.length == 1) arg = arg[0]; else caml_invalid_argument("Ml_Bigarray_c_1_1.offset"); } diff --git a/runtime/compare.js b/runtime/compare.js index bea052f414..38d76ae4fe 100644 --- a/runtime/compare.js +++ b/runtime/compare.js @@ -21,7 +21,7 @@ function caml_compare_val_tag(a){ if (typeof a === "number") return 1000; // int_tag (we use it for all numbers) else if (caml_is_ml_bytes(a)) return 252; // string_tag else if (caml_is_ml_string(a)) return 1252; // ocaml string (if different from bytes) - else if (a instanceof Array && a[0] === (a[0]>>>0) && a[0] <= 255) { + else if (Array.isArray(a) && a[0] === (a[0]>>>0) && a[0] <= 255) { // Look like an ocaml block var tag = a[0] | 0; // ignore double_array_tag because we cannot accurately set diff --git a/runtime/fs_fake.js b/runtime/fs_fake.js index c4d7006a99..4030f4a1b4 100644 --- a/runtime/fs_fake.js +++ b/runtime/fs_fake.js @@ -245,7 +245,7 @@ MlFakeDevice.prototype.register= function (name,content){ file = new MlFakeFile(content); if(caml_is_ml_string(content)) file = new MlFakeFile(caml_bytes_of_string(content)); - else if(content instanceof Array) + else if(Array.isArray(content)) file = new MlFakeFile(caml_bytes_of_array(content)); else if(typeof content === "string") file = new MlFakeFile(caml_bytes_of_jsbytes(content)); diff --git a/runtime/hash.js b/runtime/hash.js index 818feb2e1b..fca874c754 100644 --- a/runtime/hash.js +++ b/runtime/hash.js @@ -29,7 +29,7 @@ function caml_hash_univ_param (count, limit, obj) { function hash_aux (obj) { limit --; if (count < 0 || limit < 0) return; - if (obj instanceof Array && obj[0] === (obj[0]|0)) { + if (Array.isArray(obj) && obj[0] === (obj[0]|0)) { switch (obj[0]) { case 248: // Object @@ -206,7 +206,7 @@ function caml_hash (count, limit, seed, obj) { num --; } } - else if (v instanceof Array && v[0] === (v[0]|0)) { + else if (Array.isArray(v) && v[0] === (v[0]|0)) { switch (v[0]) { case 248: // Object diff --git a/runtime/jslib.js b/runtime/jslib.js index 23e5a1a994..8212344a55 100644 --- a/runtime/jslib.js +++ b/runtime/jslib.js @@ -131,7 +131,7 @@ function caml_jsoo_flags_effects(unit){ //Requires: caml_global_data,caml_string_of_jsstring,caml_named_value function caml_wrap_exception(e) { if (FLAG("excwrap")) { - if(e instanceof Array) return e; + if(Array.isArray(e)) return e; var exn; //Stack_overflow: chrome, safari if(globalThis.RangeError diff --git a/runtime/marshal.js b/runtime/marshal.js index cb654f2ff8..5929e3df4e 100644 --- a/runtime/marshal.js +++ b/runtime/marshal.js @@ -687,7 +687,7 @@ var caml_output_val = function (){ writer.size_32 += 2 + ((sz_32_64[0] + 3) >> 2); writer.size_64 += 2 + ((sz_32_64[1] + 7) >> 3); } - else if (v instanceof Array && v[0] === (v[0]|0)) { + else if (Array.isArray(v) && v[0] === (v[0]|0)) { if (v[0] == 251) { caml_failwith("output_value: abstract value (Abstract)"); } diff --git a/runtime/obj.js b/runtime/obj.js index 7d3bfee3c9..db7ed9cbc3 100644 --- a/runtime/obj.js +++ b/runtime/obj.js @@ -29,13 +29,13 @@ function caml_alloc_dummy_infix () { } //Provides: caml_obj_is_block const (const) -function caml_obj_is_block (x) { return +(x instanceof Array); } +function caml_obj_is_block (x) { return +(Array.isArray(x)); } //Provides: caml_obj_tag //Requires: caml_is_ml_bytes, caml_is_ml_string function caml_obj_tag (x) { - if ((x instanceof Array) && x[0] == (x[0] >>> 0)) + if ((Array.isArray(x)) && x[0] == (x[0] >>> 0)) return x[0] else if (caml_is_ml_bytes(x)) return 252 @@ -173,7 +173,7 @@ function caml_obj_update_tag(b,o,n) { //Provides: caml_lazy_update_to_forcing //Requires: caml_obj_update_tag function caml_lazy_update_to_forcing(o) { - if ((o instanceof Array) && o[0] == (o[0] >>> 0) && + if ((Array.isArray(o)) && o[0] == (o[0] >>> 0) && caml_obj_update_tag(o, 246, 244)) { return 0; } else { diff --git a/runtime/parsing.js b/runtime/parsing.js index 406f7c8498..9a3808e4f4 100644 --- a/runtime/parsing.js +++ b/runtime/parsing.js @@ -98,7 +98,7 @@ function caml_parse_engine(tables, env, cmd, arg) function print_token(state, tok) { var token, kind; - if (tok instanceof Array) { + if (Array.isArray(tok)) { token = token_name(tables[tbl_names_block], tok[0]); if (typeof tok[1] == "number") kind = "" + tok[1]; @@ -150,7 +150,7 @@ function caml_parse_engine(tables, env, cmd, arg) /* The ML code calls the lexer and updates */ /* symb_start and symb_end */ case 1://TOKEN_READ: - if (arg instanceof Array) { + if (Array.isArray(arg)) { env[env_curr_char] = tables[tbl_transl_block][arg[0] + 1]; env[env_lval] = arg[1]; } else { diff --git a/runtime/sys.js b/runtime/sys.js index 92c402bbd7..7107cd6852 100644 --- a/runtime/sys.js +++ b/runtime/sys.js @@ -83,7 +83,7 @@ function caml_format_exception(exn){ //Provides: caml_fatal_uncaught_exception //Requires: caml_named_value, caml_format_exception, caml_callback function caml_fatal_uncaught_exception(err){ - if(err instanceof Array && (err[0] == 0 || err[0] == 248)) { + if(Array.isArray(err) && (err[0] == 0 || err[0] == 248)) { var handler = caml_named_value("Printexc.handle_uncaught_exception"); if(handler) caml_callback(handler, [err,false]); else { diff --git a/runtime/weak.js b/runtime/weak.js index 025aefd23b..3da6511000 100644 --- a/runtime/weak.js +++ b/runtime/weak.js @@ -106,7 +106,7 @@ function caml_ephe_get_key_copy(x, i) { var y = caml_ephe_get_key(x, i); if (y === 0) return y; var z = y[1]; - if (z instanceof Array) return [0, caml_obj_dup(z)]; + if (Array.isArray(z)) return [0, caml_obj_dup(z)]; return y; }