Skip to content
This repository was archived by the owner on Oct 4, 2020. It is now read-only.

Commit cfcd0c5

Browse files
authored
Merge pull request #146 from purescript-web/ie-safe-tagged
Fix `unsafeReadProtoTagged` so it works in IE
2 parents de2b148 + 8a98119 commit cfcd0c5

File tree

1 file changed

+21
-16
lines changed

1 file changed

+21
-16
lines changed

src/DOM/Util/FFI.js

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,27 @@
11
"use strict";
22

3-
exports._unsafeReadProtoTagged = function (name) {
4-
return function (failure) {
5-
return function (success) {
6-
return function (value) {
7-
var obj = value;
8-
while (obj != null) {
9-
var proto = Object.getPrototypeOf(obj);
10-
var ctor = proto.constructor.name;
11-
if (ctor === name) {
12-
return success(value);
13-
} else if (ctor === "Object") {
14-
return failure(Object.getPrototypeOf(value).constructor.name);
3+
exports._unsafeReadProtoTagged = (function () {
4+
var tagOf = function (value) {
5+
return Object.prototype.toString.call(value).slice(8, -1);
6+
};
7+
return function (name) {
8+
return function (failure) {
9+
return function (success) {
10+
return function (value) {
11+
var obj = value;
12+
while (obj != null) {
13+
var proto = Object.getPrototypeOf(obj);
14+
var ctor = tagOf(proto);
15+
if (ctor === name) {
16+
return success(value);
17+
} else if (ctor === "Object") {
18+
return failure(tagOf(value));
19+
}
20+
obj = proto;
1521
}
16-
obj = proto;
17-
}
18-
return failure(Object.getPrototypeOf(value).constructor.name);
22+
return failure(tagOf(value));
23+
};
1924
};
2025
};
2126
};
22-
};
27+
}());

0 commit comments

Comments
 (0)