Skip to content

Commit dffd241

Browse files
authored
Merge pull request rescript-lang#2128 from BuckleScript/gpr_2126
fix rescript-lang#2126
2 parents 4cb876d + 6f28810 commit dffd241

File tree

5 files changed

+20
-6
lines changed

5 files changed

+20
-6
lines changed

jscomp/runtime/caml_sys.ml

+3-1
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,9 @@ let caml_sys_get_argv () : string * string array =
9191
match [%external process] with
9292
| None -> ("",[|""|])
9393
| Some process
94-
-> Array.unsafe_get process##argv 0, process##argv
94+
->
95+
if Js.testAny process##argv then ("",[|""|])
96+
else Array.unsafe_get process##argv 0, process##argv
9597

9698
(** {!Pervasives.sys_exit} *)
9799
let caml_sys_exit exit_code =

jscomp/runtime/js.ml

+1
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ type + 'a null_undefined = 'a nullable
6363

6464
external toOption : 'a nullable -> 'a option = "#null_undefined_to_opt"
6565
external test : 'a nullable -> bool = "#is_nil_undef"
66+
external testAny : 'a -> bool = "#is_nil_undef"
6667

6768
type boolean
6869
(** The JS boolean type, can be [Js.true_] or [Js.false_] *)

jscomp/runtime/js.mli

+3
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,9 @@ type + 'a null_undefined = 'a nullable
7676
external toOption : 'a nullable -> 'a option = "#null_undefined_to_opt"
7777
external test : 'a nullable -> bool = "#is_nil_undef"
7878

79+
(** The same as {!test} except that it is more permissive on the types of input *)
80+
external testAny : 'a -> bool = "#is_nil_undef"
81+
7982
type boolean
8083
(** The value could be either {!Js.true_} or {!Js.false_}.
8184
Note in BuckleScript, [boolean] has different representation from OCaml's [bool],

jscomp/test/Makefile

+2-1
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,8 @@ OTHERS := test_literals a test_ari test_export2 test_internalOO test_obj_simple_
198198
escape_esmodule\
199199
esmodule_ref\
200200
miss_colon_test\
201-
gpr_1245_test
201+
gpr_1245_test\
202+
gpr_2126_test
202203
# bs_uncurry_test
203204
# needs Lam to get rid of Uncurry arity first
204205

lib/js/caml_sys.js

+11-4
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,17 @@ function caml_sys_getcwd() {
4545
function caml_sys_get_argv() {
4646
var match = typeof (process) === "undefined" ? undefined : (process);
4747
if (match !== undefined) {
48-
return /* tuple */[
49-
match.argv[0],
50-
match.argv
51-
];
48+
if (match.argv == null) {
49+
return /* tuple */[
50+
"",
51+
/* array */[""]
52+
];
53+
} else {
54+
return /* tuple */[
55+
match.argv[0],
56+
match.argv
57+
];
58+
}
5259
} else {
5360
return /* tuple */[
5461
"",

0 commit comments

Comments
 (0)