-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAA.js
170 lines (136 loc) · 3.35 KB
/
AA.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
// Generated by ReScript, PLEASE EDIT WITH CARE
'use strict';
var Js_exn = require("rescript/lib/js/js_exn.js");
var Caml_array = require("rescript/lib/js/caml_array.js");
var Caml_exceptions = require("rescript/lib/js/caml_exceptions.js");
var Caml_js_exceptions = require("rescript/lib/js/caml_js_exceptions.js");
var tests = [];
function addTest(t) {
tests.push(t);
}
function addTest1(t, x) {
tests.push(function () {
return t(x);
});
}
async function foo(x, y) {
return x + y | 0;
}
async function bar(ff) {
var a = await ff(3, 4);
var b = await foo(5, 6);
return a + b | 0;
}
async function baz() {
return await bar(foo);
}
async function testBaz() {
var n = await baz();
console.log("baz returned", n);
}
tests.push(testBaz);
var E = /* @__PURE__ */Caml_exceptions.create("AA.E");
async function e1() {
throw {
RE_EXN_ID: E,
_1: 1000,
Error: new Error()
};
}
async function e2() {
return Js_exn.raiseError("Some JS error");
}
async function e3() {
return await e1();
}
async function e4() {
return await e2();
}
var e5 = (function() { return Promise.reject(new Error('fail')) });
async function testTryCatch(fn) {
try {
return await fn();
}
catch (raw_n){
var n = Caml_js_exceptions.internalToOCamlException(raw_n);
if (n.RE_EXN_ID === E) {
console.log("testTryCatch: E", n._1);
return ;
}
if (n.RE_EXN_ID === "JsError") {
console.log("testTryCatch: JsError");
return ;
}
throw n;
}
}
addTest1(testTryCatch, e1);
addTest1(testTryCatch, e2);
addTest1(testTryCatch, e3);
addTest1(testTryCatch, e4);
addTest1(testTryCatch, e5);
async function singlePromise(x) {
return x + 1 | 0;
}
async function nestedPromise(x) {
var x$1 = singlePromise(x + 1 | 0);
[Promise.resolve(x$1)];
return 32;
}
var explainError = ((e)=>e.toString());
async function testFetch(url) {
var response;
try {
response = await fetch(url);
}
catch (raw_e){
var e = Caml_js_exceptions.internalToOCamlException(raw_e);
if (e.RE_EXN_ID === "JsError") {
console.log("Fetch returned an error:", explainError(e._1));
return ;
}
throw e;
}
var status = response.status;
console.log("Fetch returned status:", status);
}
addTest1(testFetch, "https://www.google.com/sdkjdkghdsg");
addTest1(testFetch, "https://www.google.comsdkjdkghdsg");
async function withCallback() {
return async function (x) {
return await Promise.resolve(x) + 1 | 0;
};
}
async function testWithCallback() {
console.log("callback returned", await (await withCallback())(3));
}
tests.push(testWithCallback);
async function runAllTests(n) {
if (n >= 0 && n < tests.length) {
await Caml_array.get(tests, n)();
return await runAllTests(n + 1 | 0);
}
}
runAllTests(0);
exports.tests = tests;
exports.addTest = addTest;
exports.addTest1 = addTest1;
exports.foo = foo;
exports.bar = bar;
exports.baz = baz;
exports.testBaz = testBaz;
exports.E = E;
exports.e1 = e1;
exports.e2 = e2;
exports.e3 = e3;
exports.e4 = e4;
exports.e5 = e5;
exports.testTryCatch = testTryCatch;
exports.singlePromise = singlePromise;
exports.nestedPromise = nestedPromise;
exports.explainError = explainError;
exports.testFetch = testFetch;
exports.withCallback = withCallback;
exports.testWithCallback = testWithCallback;
exports.runAllTests = runAllTests;
/* Not a pure module */