| 17:08 | <bradleymeck> | is there a sane way to get an iterator from a value with a patched @@iterator as if it did not have a monkey patched @@iterator on it (no mutation)? |
| 17:09 | <bradleymeck> | in particular in Node we have a "safe" Set that won't call out to monkey patched methods if you mutate the original global, but we noticed the iterable parameter is coercing using patched globals and we don't really want that |
| 17:09 | <bradleymeck> | we could make a huge if/else to call the primordial @@iterator for a given type |
| 17:09 | <bradleymeck> | but that seems... bad? |
| 17:44 | <ljharb> | that's the only way i know of |
| 17:44 | <ljharb> | array spread syntax, Array.from, for..of, all are "unsafe" in that sense since they call into "not the original" Symbol.iterator method |
| 17:52 | <bradleymeck> | fun fun |
| 18:01 | <Bakkot> | bradleymeck assuming the monkey-patching is sticking @@iterator on the instance, you could just walk up the prototype chain explicitly |
| 18:01 | <bradleymeck> | Bakkot: not if they replace Array.prototype[@@iterator] ? |
| 18:01 | <Bakkot> | right, that is not sticking it on the instance |
| 18:08 | <bradleymeck> | Bakkot: yea this is just random user code we run in the same realm as |
| 18:08 | <jridgewell> | Are you just trying to do `[...x]`? |
| 18:08 | <jridgewell> | Or for-of? |
| 18:10 | <bradleymeck> | jridgewell: we are trying to construct a subclass of a Map and we are providing something to it's first param |
| 18:10 | <bradleymeck> | its |
| 18:10 | <jridgewell> | Could just use a helper function? |
| 18:10 | <jridgewell> | Check if `iterable[@@iterator]` is patched |
| 18:11 | <bradleymeck> | we can write one, but thats effort to maintain |
| 18:11 | <bradleymeck> | also if we are crawling to see if something is patched we can just call the primordial value |
| 18:19 | <jridgewell> | Yah, I guess the easiest way would just be to `super(%Array.p.@@iterator%.call(v))` |
| 18:21 | <bradleymeck> | jridgewell: problem is it isn't always an iterator 😂 |
| 18:21 | <bradleymeck> | so was hoping there was some kind of method to help |
| 18:21 | <jridgewell> | Doesn't it have to be an iterable? |
| 18:21 | <jridgewell> | (if given) |
| 18:22 | <bradleymeck> | yes, but `[...Array.prototype[Symbol.iterator].call(new Map())]` is empty for example |
| 18:22 | <bradleymeck> | well populate that map with [[1,1]] |
| 18:22 | <bradleymeck> | still empty |
| 18:42 | <ljharb> | bradleymeck: you'd have to cache the original Map.prototype[Symbol.iterator], and then install it as a nonconfigurable own property on the subclass's prototype, i think |
| 18:42 | <bradleymeck> | for each parameter type possible yea |
| 18:42 | <bradleymeck> | not just since we are a subclass |
| 18:42 | <bradleymeck> | though, we already cache almost all intrinsics so... |