Skip to content

Commit 7f19f24

Browse files
authored
Merge pull request #7 from AndrewBrownK/fix-in-node
Fix _unsafeReadProtoTagged in node.js
2 parents 5e6aa3e + 9dd1280 commit 7f19f24

File tree

1 file changed

+17
-3
lines changed

1 file changed

+17
-3
lines changed

src/Web/Internal/FFI.js

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,23 @@
11
"use strict";
22

33
exports._unsafeReadProtoTagged = function (nothing, just, name, value) {
4-
var ty = window[name];
5-
if (ty != null && value instanceof ty) {
6-
return just(value);
4+
if (typeof window !== "undefined") {
5+
var ty = window[name];
6+
if (ty != null && value instanceof ty) {
7+
return just(value);
8+
}
9+
return nothing;
10+
}
11+
var obj = value;
12+
while (obj != null) {
13+
var proto = Object.getPrototypeOf(obj);
14+
var constructorName = proto.constructor.name;
15+
if (constructorName === name) {
16+
return just(value);
17+
} else if (constructorName === "Object") {
18+
return nothing;
19+
}
20+
obj = proto;
721
}
822
return nothing;
923
};

0 commit comments

Comments
 (0)