Skip to content

Commit

Permalink
Runtime: use Array.isArray() instead of instanceof Array (#1671)
Browse files Browse the repository at this point in the history
Signed-off-by: Sora Morimoto <[email protected]>
  • Loading branch information
smorimoto authored Sep 13, 2024
1 parent 818dcd6 commit c76f8cc
Show file tree
Hide file tree
Showing 10 changed files with 15 additions and 15 deletions.
4 changes: 2 additions & 2 deletions runtime/bigarray.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 */) {
Expand Down Expand Up @@ -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");
}
Expand Down
2 changes: 1 addition & 1 deletion runtime/compare.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion runtime/fs_fake.js
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
4 changes: 2 additions & 2 deletions runtime/hash.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion runtime/jslib.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion runtime/marshal.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)");
}
Expand Down
6 changes: 3 additions & 3 deletions runtime/obj.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions runtime/parsing.js
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion runtime/sys.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion runtime/weak.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down

0 comments on commit c76f8cc

Please sign in to comment.