diff --git a/compiler/tests-ocaml/lib-floatarray/floatarray.ml b/compiler/tests-ocaml/lib-floatarray/floatarray.ml index faafe9744f..654e15b646 100644 --- a/compiler/tests-ocaml/lib-floatarray/floatarray.ml +++ b/compiler/tests-ocaml/lib-floatarray/floatarray.ml @@ -107,9 +107,9 @@ module Test (A : S) : sig end = struct check_inval (fun i -> A.set a i 1.0) (-1); check_inval (fun i -> A.set a i 1.0) 1000; check_inval A.create (-1); - (* check_inval A.create (A.max_length + 1);*) + check_inval A.create (A.max_length + 1); check_inval (fun i -> A.make i 1.0) (-1); - (* check_inval (fun i -> A.make i 1.0) (A.max_length + 1); *) + check_inval (fun i -> A.make i 1.0) (A.max_length + 1); (* [length] *) let test_length l = assert (l = (A.length (A.create l))) in @@ -125,8 +125,7 @@ module Test (A : S) : sig end = struct let a = A.init 1000 Float.of_int in check_i a; check_inval (fun i -> A.init i Float.of_int) (-1); - (* check_inval (fun i -> A.init i Float.of_int) (A.max_length + 1); *) - + check_inval (fun i -> A.init i Float.of_int) (A.max_length + 1); (* [make_matrix] *) let check_make_matrix m n = @@ -641,8 +640,7 @@ module Test (A : S) : sig end = struct assert (compare value value' = 0) in let l = [0.; 0.25; -4.; 3.14159265; nan; infinity; neg_infinity; neg_zero] in - (* js_of_ocaml doesn't marshal floats *) - if false then test_structured_io (A.of_list l); + test_structured_io (A.of_list l); (* map_inplace *) let a = A.init 4 (fun i -> Float.of_int (i + 1)) in diff --git a/runtime/js/array.js b/runtime/js/array.js index 280abb5518..db467e2a4f 100644 --- a/runtime/js/array.js +++ b/runtime/js/array.js @@ -158,7 +158,7 @@ function caml_check_bound(array, index) { //Provides: caml_array_make const (const, mutable) //Requires: caml_array_bound_error function caml_array_make(len, init) { - if (len < 0) caml_array_bound_error(); + if (len < 0 || (len >= 0x7fffffff / 4) | 0) caml_array_bound_error(); var len = (len + 1) | 0; var b = new Array(len); b[0] = 0; @@ -175,7 +175,7 @@ function caml_make_vect(len, init) { //Provides: caml_make_float_vect const (const) //Requires: caml_array_bound_error function caml_make_float_vect(len) { - if (len < 0) caml_array_bound_error(); + if (len < 0 || (len >= 0x7fffffff / 8) | 0) caml_array_bound_error(); var len = (len + 1) | 0; var b = new Array(len); b[0] = 254; @@ -187,7 +187,7 @@ function caml_make_float_vect(len) { //Requires: caml_array_bound_error //Version: >= 5.3 function caml_array_create_float(len) { - if (len < 0) caml_array_bound_error(); + if (len < 0 || (len >= 0x7fffffff / 8) | 0) caml_array_bound_error(); var len = (len + 1) | 0; var b = new Array(len); b[0] = 254; @@ -197,7 +197,7 @@ function caml_array_create_float(len) { //Provides: caml_floatarray_create const (const) //Requires: caml_array_bound_error function caml_floatarray_create(len) { - if (len < 0) caml_array_bound_error(); + if (len < 0 || (len >= 0x7fffffff / 8) | 0) caml_array_bound_error(); var len = (len + 1) | 0; var b = new Array(len); b[0] = 254; @@ -206,17 +206,22 @@ function caml_floatarray_create(len) { } //Provides: caml_floatarray_make const (const) -//Requires: caml_array_make +//Requires: caml_array_bound_error //Version: >= 5.3 function caml_floatarray_make(len, init) { - return caml_array_make(len, init); + if (len < 0 || (len >= 0x7fffffff / 8) | 0) caml_array_bound_error(); + var len = (len + 1) | 0; + var b = new Array(len); + b[0] = 254; + for (var i = 1; i < len; i++) b[i] = init; + return b; } //Provides: caml_floatarray_make_unboxed const (const) -//Requires: caml_array_make +//Requires: caml_floatarray_make //Version: >= 5.3 function caml_floatarray_make_unboxed(len, init) { - return caml_array_make(len, init); + return caml_floatarray_make(len, init); } //Provides: caml_uniform_array_make const (const)