Skip to content

Commit daa97f1

Browse files
authored
Js.Promise -> Js.Promise2 (rescript-lang#3313)
1 parent 3ae7949 commit daa97f1

21 files changed

+1938
-1676
lines changed

Diff for: jscomp/others/build.ninja

+3-2
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,8 @@ build others/js_null_undefined.cmi : cc others/js_null_undefined.mli | runtime
106106
build others/js_obj.cmi others/js_obj.cmj : cc others/js_obj.ml | runtime
107107
build others/js_option.cmj : cc others/js_option.ml | others/js_exn.cmj others/js_option.cmi runtime
108108
build others/js_option.cmi : cc others/js_option.mli | runtime
109-
build others/js_promise.cmi others/js_promise.cmj : cc others/js_promise.ml | runtime
109+
build others/js_promise.cmi others/js_promise.cmj : cc others/js_promise.ml | others/js_promise2.cmj runtime
110+
build others/js_promise2.cmi others/js_promise2.cmj : cc others/js_promise2.ml | runtime
110111
build others/js_re.cmi : cc others/js_re.mli | others/js_re2.cmi runtime
111112
build others/js_re2.cmi : cc others/js_re2.mli | runtime
112113
build others/js_result.cmj : cc others/js_result.ml | others/js_result.cmi runtime
@@ -121,7 +122,7 @@ build others/js_undefined.cmj : cc others/js_undefined.ml | others/js_exn.cmj ot
121122
build others/js_undefined.cmi : cc others/js_undefined.mli | runtime
122123
build others/js_vector.cmj : cc others/js_vector.ml | others/js_vector.cmi runtime
123124
build others/js_vector.cmi : cc others/js_vector.mli | runtime
124-
build js_pkg : phony others/js_array.cmi others/js_array.cmj others/js_array2.cmi others/js_array2.cmj others/js_cast.cmi others/js_cast.cmj others/js_console.cmi others/js_console.cmj others/js_date.cmi others/js_date.cmj others/js_dict.cmi others/js_dict.cmj others/js_exn.cmi others/js_exn.cmj others/js_float.cmi others/js_float.cmj others/js_global.cmi others/js_global.cmj others/js_int.cmi others/js_int.cmj others/js_json.cmi others/js_json.cmj others/js_list.cmi others/js_list.cmj others/js_mapperRt.cmi others/js_mapperRt.cmj others/js_math.cmi others/js_math.cmj others/js_null.cmi others/js_null.cmj others/js_null_undefined.cmi others/js_null_undefined.cmj others/js_obj.cmi others/js_obj.cmj others/js_option.cmi others/js_option.cmj others/js_promise.cmi others/js_promise.cmj others/js_re.cmi others/js_re2.cmi others/js_result.cmi others/js_result.cmj others/js_string.cmi others/js_string.cmj others/js_string2.cmi others/js_string2.cmj others/js_typed_array.cmi others/js_typed_array.cmj others/js_typed_array2.cmi others/js_typed_array2.cmj others/js_types.cmi others/js_types.cmj others/js_undefined.cmi others/js_undefined.cmj others/js_vector.cmi others/js_vector.cmj
125+
build js_pkg : phony others/js_array.cmi others/js_array.cmj others/js_array2.cmi others/js_array2.cmj others/js_cast.cmi others/js_cast.cmj others/js_console.cmi others/js_console.cmj others/js_date.cmi others/js_date.cmj others/js_dict.cmi others/js_dict.cmj others/js_exn.cmi others/js_exn.cmj others/js_float.cmi others/js_float.cmj others/js_global.cmi others/js_global.cmj others/js_int.cmi others/js_int.cmj others/js_json.cmi others/js_json.cmj others/js_list.cmi others/js_list.cmj others/js_mapperRt.cmi others/js_mapperRt.cmj others/js_math.cmi others/js_math.cmj others/js_null.cmi others/js_null.cmj others/js_null_undefined.cmi others/js_null_undefined.cmj others/js_obj.cmi others/js_obj.cmj others/js_option.cmi others/js_option.cmj others/js_promise.cmi others/js_promise.cmj others/js_promise2.cmi others/js_promise2.cmj others/js_re.cmi others/js_re2.cmi others/js_result.cmi others/js_result.cmj others/js_string.cmi others/js_string.cmj others/js_string2.cmi others/js_string2.cmj others/js_typed_array.cmi others/js_typed_array.cmj others/js_typed_array2.cmi others/js_typed_array2.cmj others/js_types.cmi others/js_types.cmj others/js_undefined.cmi others/js_undefined.cmj others/js_vector.cmi others/js_vector.cmj
125126
build others/belt_Array.cmj : cc others/belt_Array.ml | others/belt.cmi others/belt_Array.cmi others/js_math.cmj js_pkg runtime
126127
build others/belt_Array.cmi : cc others/belt_Array.mli | runtime
127128
build others/belt_Debug.cmi others/belt_Debug.cmj : cc others/belt_Debug.ml | runtime

Diff for: jscomp/others/js_promise.ml

+7-7
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@
2929
]}
3030
*)
3131

32-
type + 'a t
33-
type error (* abstract error type *)
32+
type + 'a t = 'a Js_promise2.t
33+
type error = Js_promise2.error
3434

3535

3636
external make : (resolve:('a -> unit [@bs]) ->
@@ -53,17 +53,17 @@ external then_ : ('a -> 'b t [@bs.uncurry]) -> 'b t = "then" [@@bs.send.pipe: 'a
5353

5454
external catch : (error -> 'a t [@bs.uncurry]) -> 'a t = "catch" [@@bs.send.pipe: 'a t]
5555
(* [ p|> catch handler]
56-
Note in JS the returned promise type is actually runtime dependent,
57-
if promise is rejected, it will pick the [handler] otherwise the original promise,
56+
Note in JS the returned promise type is actually runtime dependent,
57+
if promise is rejected, it will pick the [handler] otherwise the original promise,
5858
to make it strict we enforce reject handler
5959
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/catch
6060
*)
6161

6262

6363
(*
64-
let errorAsExn (x : error) (e : (exn ->'a option))=
65-
if Caml_exceptions.isCamlExceptionOrOpenVariant (Obj.magic x ) then
66-
e (Obj.magic x)
64+
let errorAsExn (x : error) (e : (exn ->'a option))=
65+
if Caml_exceptions.isCamlExceptionOrOpenVariant (Obj.magic x ) then
66+
e (Obj.magic x)
6767
else None
6868
[%bs.error? ]
6969
*)

Diff for: jscomp/others/js_promise2.ml

+69
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
(* Copyright (C) 2015-2016 Bloomberg Finance L.P.
2+
*
3+
* This program is free software: you can redistribute it and/or modify
4+
* it under the terms of the GNU Lesser General Public License as published by
5+
* the Free Software Foundation, either version 3 of the License, or
6+
* (at your option) any later version.
7+
*
8+
* In addition to the permissions granted to you by the LGPL, you may combine
9+
* or link a "work that uses the Library" with a publicly distributed version
10+
* of this file to produce a combined library or application, then distribute
11+
* that combined work under the terms of your choosing, with no requirement
12+
* to comply with the obligations normally placed on you by section 4 of the
13+
* LGPL version 3 (or the corresponding section of a later version of the LGPL
14+
* should you choose to use a later version).
15+
*
16+
* This program is distributed in the hope that it will be useful,
17+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
18+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19+
* GNU Lesser General Public License for more details.
20+
*
21+
* You should have received a copy of the GNU Lesser General Public License
22+
* along with this program; if not, write to the Free Software
23+
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *)
24+
25+
(** Specialized bindings to Promise. Note: For simplicity,
26+
this binding does not track the error type, it treat it as an opaque type
27+
{[
28+
29+
]}
30+
*)
31+
32+
type + 'a t
33+
type error (* abstract error type *)
34+
35+
36+
external make : (resolve:('a -> unit [@bs]) ->
37+
reject:(exn -> unit [@bs]) -> unit [@bs.uncurry]) -> 'a t = "Promise" [@@bs.new]
38+
(* [make (fun resolve reject -> .. )] *)
39+
external resolve : 'a -> 'a t = "resolve" [@@bs.val] [@@bs.scope "Promise"]
40+
external reject : exn -> 'a t = "reject" [@@bs.val] [@@bs.scope "Promise"]
41+
external all : 'a t array -> 'a array t = "all" [@@bs.val] [@@bs.scope "Promise"]
42+
external all2 : 'a0 t * 'a1 t -> ('a0 * 'a1) t = "all" [@@bs.val] [@@bs.scope "Promise"]
43+
external all3 : 'a0 t * 'a1 t * 'a2 t -> ('a0 * 'a1 * 'a2 ) t = "all" [@@bs.val] [@@bs.scope "Promise"]
44+
external all4 : 'a0 t * 'a1 t * 'a2 t * 'a3 t -> ('a0 * 'a1 * 'a2 * 'a3 ) t = "all" [@@bs.val] [@@bs.scope "Promise"]
45+
external all5 : 'a0 t * 'a1 t * 'a2 t * 'a3 t * 'a4 t -> ('a0 * 'a1 * 'a2 * 'a3 * 'a4 ) t = "all" [@@bs.val] [@@bs.scope "Promise"]
46+
external all6 : 'a0 t * 'a1 t * 'a2 t * 'a3 t * 'a4 t * 'a5 t -> ('a0 * 'a1 * 'a2 * 'a3 * 'a4 * 'a5 ) t = "all" [@@bs.val] [@@bs.scope "Promise"]
47+
48+
external race : 'a t array -> 'a t = "race" [@@bs.val] [@@bs.scope "Promise"]
49+
50+
external then_ : 'a t -> ('a -> 'b t [@bs.uncurry]) -> 'b t = "then" [@@bs.send]
51+
52+
53+
54+
external catch : 'a t -> (error -> 'a t [@bs.uncurry]) -> 'a t = "catch" [@@bs.send]
55+
(* [ p |. catch handler]
56+
Note in JS the returned promise type is actually runtime dependent,
57+
if promise is rejected, it will pick the [handler] otherwise the original promise,
58+
to make it strict we enforce reject handler
59+
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/catch
60+
*)
61+
62+
63+
(*
64+
let errorAsExn (x : error) (e : (exn ->'a option))=
65+
if Caml_exceptions.isCamlExceptionOrOpenVariant (Obj.magic x ) then
66+
e (Obj.magic x)
67+
else None
68+
[%bs.error? ]
69+
*)

Diff for: jscomp/others/release.ninja

+3-2
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@ build others/js_null_undefined.cmi : cc others/js_null_undefined.mli | runtime
3636
build others/js_obj.cmi others/js_obj.cmj : cc others/js_obj.ml | runtime
3737
build others/js_option.cmj : cc others/js_option.ml | others/js_exn.cmj others/js_option.cmi runtime
3838
build others/js_option.cmi : cc others/js_option.mli | runtime
39-
build others/js_promise.cmi others/js_promise.cmj : cc others/js_promise.ml | runtime
39+
build others/js_promise.cmi others/js_promise.cmj : cc others/js_promise.ml | others/js_promise2.cmj runtime
40+
build others/js_promise2.cmi others/js_promise2.cmj : cc others/js_promise2.ml | runtime
4041
build others/js_re.cmi : cc others/js_re.mli | others/js_re2.cmi runtime
4142
build others/js_re2.cmi : cc others/js_re2.mli | runtime
4243
build others/js_result.cmj : cc others/js_result.ml | others/js_result.cmi runtime
@@ -51,7 +52,7 @@ build others/js_undefined.cmj : cc others/js_undefined.ml | others/js_exn.cmj ot
5152
build others/js_undefined.cmi : cc others/js_undefined.mli | runtime
5253
build others/js_vector.cmj : cc others/js_vector.ml | others/js_vector.cmi runtime
5354
build others/js_vector.cmi : cc others/js_vector.mli | runtime
54-
build js_pkg : phony others/js_array.cmi others/js_array.cmj others/js_array2.cmi others/js_array2.cmj others/js_cast.cmi others/js_cast.cmj others/js_console.cmi others/js_console.cmj others/js_date.cmi others/js_date.cmj others/js_dict.cmi others/js_dict.cmj others/js_exn.cmi others/js_exn.cmj others/js_float.cmi others/js_float.cmj others/js_global.cmi others/js_global.cmj others/js_int.cmi others/js_int.cmj others/js_json.cmi others/js_json.cmj others/js_list.cmi others/js_list.cmj others/js_mapperRt.cmi others/js_mapperRt.cmj others/js_math.cmi others/js_math.cmj others/js_null.cmi others/js_null.cmj others/js_null_undefined.cmi others/js_null_undefined.cmj others/js_obj.cmi others/js_obj.cmj others/js_option.cmi others/js_option.cmj others/js_promise.cmi others/js_promise.cmj others/js_re.cmi others/js_re2.cmi others/js_result.cmi others/js_result.cmj others/js_string.cmi others/js_string.cmj others/js_string2.cmi others/js_string2.cmj others/js_typed_array.cmi others/js_typed_array.cmj others/js_typed_array2.cmi others/js_typed_array2.cmj others/js_types.cmi others/js_types.cmj others/js_undefined.cmi others/js_undefined.cmj others/js_vector.cmi others/js_vector.cmj
55+
build js_pkg : phony others/js_array.cmi others/js_array.cmj others/js_array2.cmi others/js_array2.cmj others/js_cast.cmi others/js_cast.cmj others/js_console.cmi others/js_console.cmj others/js_date.cmi others/js_date.cmj others/js_dict.cmi others/js_dict.cmj others/js_exn.cmi others/js_exn.cmj others/js_float.cmi others/js_float.cmj others/js_global.cmi others/js_global.cmj others/js_int.cmi others/js_int.cmj others/js_json.cmi others/js_json.cmj others/js_list.cmi others/js_list.cmj others/js_mapperRt.cmi others/js_mapperRt.cmj others/js_math.cmi others/js_math.cmj others/js_null.cmi others/js_null.cmj others/js_null_undefined.cmi others/js_null_undefined.cmj others/js_obj.cmi others/js_obj.cmj others/js_option.cmi others/js_option.cmj others/js_promise.cmi others/js_promise.cmj others/js_promise2.cmi others/js_promise2.cmj others/js_re.cmi others/js_re2.cmi others/js_result.cmi others/js_result.cmj others/js_string.cmi others/js_string.cmj others/js_string2.cmi others/js_string2.cmj others/js_typed_array.cmi others/js_typed_array.cmj others/js_typed_array2.cmi others/js_typed_array2.cmj others/js_types.cmi others/js_types.cmj others/js_undefined.cmi others/js_undefined.cmj others/js_vector.cmi others/js_vector.cmj
5556
build others/belt_Array.cmj : cc others/belt_Array.ml | others/belt.cmi others/belt_Array.cmi others/js_math.cmj js_pkg runtime
5657
build others/belt_Array.cmi : cc others/belt_Array.mli | runtime
5758
build others/belt_Debug.cmi others/belt_Debug.cmj : cc others/belt_Debug.ml | runtime

Diff for: jscomp/runtime/js.ml

+3
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,9 @@ module Re2 = Js_re2
238238
module Promise = Js_promise
239239
(** Provide bindings to JS promise *)
240240

241+
module Promise2 = Js_promise2
242+
(** Provide bindings to JS promise *)
243+
241244
module Date = Js_date
242245
(** Provide bindings for JS Date *)
243246

Diff for: jscomp/test/js.js

+97
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
'use strict';
2+
3+
4+
var Internal = /* module */[];
5+
6+
var MapperRt = 0;
7+
8+
var Null = 0;
9+
10+
var Undefined = 0;
11+
12+
var Nullable = 0;
13+
14+
var Null_undefined = 0;
15+
16+
var Exn = 0;
17+
18+
var $$Array = 0;
19+
20+
var Array2 = 0;
21+
22+
var $$String = 0;
23+
24+
var String2 = 0;
25+
26+
var Re = 0;
27+
28+
var Re2 = 0;
29+
30+
var $$Promise = 0;
31+
32+
var Promise2 = 0;
33+
34+
var $$Date = 0;
35+
36+
var Dict = 0;
37+
38+
var Global = 0;
39+
40+
var Json = 0;
41+
42+
var $$Math = 0;
43+
44+
var Obj = 0;
45+
46+
var Typed_array = 0;
47+
48+
var TypedArray2 = 0;
49+
50+
var Types = 0;
51+
52+
var Float = 0;
53+
54+
var Int = 0;
55+
56+
var $$Option = 0;
57+
58+
var Result = 0;
59+
60+
var List = 0;
61+
62+
var Vector = 0;
63+
64+
var Console = 0;
65+
66+
exports.MapperRt = MapperRt;
67+
exports.Internal = Internal;
68+
exports.Null = Null;
69+
exports.Undefined = Undefined;
70+
exports.Nullable = Nullable;
71+
exports.Null_undefined = Null_undefined;
72+
exports.Exn = Exn;
73+
exports.$$Array = $$Array;
74+
exports.Array2 = Array2;
75+
exports.$$String = $$String;
76+
exports.String2 = String2;
77+
exports.Re = Re;
78+
exports.Re2 = Re2;
79+
exports.$$Promise = $$Promise;
80+
exports.Promise2 = Promise2;
81+
exports.$$Date = $$Date;
82+
exports.Dict = Dict;
83+
exports.Global = Global;
84+
exports.Json = Json;
85+
exports.$$Math = $$Math;
86+
exports.Obj = Obj;
87+
exports.Typed_array = Typed_array;
88+
exports.TypedArray2 = TypedArray2;
89+
exports.Types = Types;
90+
exports.Float = Float;
91+
exports.Int = Int;
92+
exports.$$Option = $$Option;
93+
exports.Result = Result;
94+
exports.List = List;
95+
exports.Vector = Vector;
96+
exports.Console = Console;
97+
/* No side effect */

Diff for: jscomp/test/js_promise_basic_test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,7 @@ Mt.from_pair_suites("Js_promise_basic_test", suites[0]);
288288
var twop = Promise.resolve(2);
289289

290290
function then_(prim, prim$1) {
291-
return prim$1.then(Curry.__1(prim));
291+
return prim.then(Curry.__1(prim$1));
292292
}
293293

294294
function re(prim) {

0 commit comments

Comments
 (0)