UNPKG

2.21 kBJavaScriptView Raw
1// Make sure Map.prototype.set returns the Map instance, per spec.
2// https://github.com/apollographql/apollo-client/issues/4024
3var testMap = new Map();
4if (testMap.set(1, 2) !== testMap) {
5 var set_1 = testMap.set;
6 Map.prototype.set = function () {
7 var args = [];
8 for (var _i = 0; _i < arguments.length; _i++) {
9 args[_i] = arguments[_i];
10 }
11 set_1.apply(this, args);
12 return this;
13 };
14}
15// Make sure Set.prototype.add returns the Set instance, per spec.
16var testSet = new Set();
17if (testSet.add(3) !== testSet) {
18 var add_1 = testSet.add;
19 Set.prototype.add = function () {
20 var args = [];
21 for (var _i = 0; _i < arguments.length; _i++) {
22 args[_i] = arguments[_i];
23 }
24 add_1.apply(this, args);
25 return this;
26 };
27}
28var frozen = {};
29if (typeof Object.freeze === "function") {
30 Object.freeze(frozen);
31}
32try {
33 // If non-extensible objects can't be stored as keys in a Map, make sure we
34 // do not freeze/seal/etc. an object without first attempting to put it in a
35 // Map. For example, this gives the React Native Map polyfill a chance to tag
36 // objects before they become non-extensible:
37 // https://github.com/facebook/react-native/blob/98a6f19d7c/Libraries/vendor/core/Map.js#L44-L50
38 // https://github.com/apollographql/react-apollo/issues/2442#issuecomment-426489517
39 testMap.set(frozen, frozen).delete(frozen);
40}
41catch (_a) {
42 var wrap = function (method) {
43 return (method &&
44 (function (obj) {
45 try {
46 // If .set succeeds, also call .delete to avoid leaking memory.
47 testMap.set(obj, obj).delete(obj);
48 }
49 finally {
50 // If .set or .delete fails, the exception will be silently swallowed
51 // by this return-from-finally statement:
52 return method.call(Object, obj);
53 }
54 }));
55 };
56 Object.freeze = wrap(Object.freeze);
57 Object.seal = wrap(Object.seal);
58 Object.preventExtensions = wrap(Object.preventExtensions);
59}
60export {};
61//# sourceMappingURL=fixPolyfills.native.js.map
\No newline at end of file