forked from rescript-lang/rescript
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcamlinternalLazy.js
57 lines (49 loc) · 1.03 KB
/
camlinternalLazy.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
'use strict';
var Caml_exceptions = require("./caml_exceptions.js");
function is_val(l) {
return l.LAZY_DONE;
}
var Undefined = Caml_exceptions.create("CamlinternalLazy.Undefined");
function forward_with_closure(blk, closure) {
var result = closure();
blk.VAL = result;
blk.LAZY_DONE = true;
return result;
}
function raise_undefined() {
throw {
RE_EXN_ID: Undefined,
Error: new Error()
};
}
function force(lzv) {
if (lzv.LAZY_DONE) {
return lzv.VAL;
} else {
var closure = lzv.VAL;
lzv.VAL = raise_undefined;
try {
return forward_with_closure(lzv, closure);
}
catch (e){
lzv.VAL = (function () {
throw e;
});
throw e;
}
}
}
function force_val(lzv) {
if (lzv.LAZY_DONE) {
return lzv.VAL;
} else {
var closure = lzv.VAL;
lzv.VAL = raise_undefined;
return forward_with_closure(lzv, closure);
}
}
exports.Undefined = Undefined;
exports.force = force;
exports.force_val = force_val;
exports.is_val = is_val;
/* No side effect */