Commit 40acade
authored
fix: fetch proxy compatible with node 24 (#333)
In NodeJS v24 undici Response objects are constructed using a mixin
pattern that looks like this:
```javascript
class Test {
#prop = "foo"
get prop() {
return this.#prop
}
static getProp(test) {
return test.#prop
}
}
function mixin(prototype, getInternal) {
const methods = {
status() {
return getInternal(this)
},
}
Object.assign(prototype.prototype, methods)
}
mixin(Test, Test.getProp)
const test = new Test()
const proxied = new Proxy(test, {
get(target, prop) {
const r = Reflect.get(target, prop)
if (typeof r === "function") {
return r.bind(target)
}
return r
},
})
console.log(test.prop)
console.log(test.status())
console.log(proxied.prop)
console.log(proxied.status())
```
If we don't bind functions, then we'll get errors like this:
```shell
return test.#prop
^
TypeError: Cannot read private member #prop from an object whose class did not declare it
at getProp
at Proxy.status
at Object.<anonymous>
```1 parent c4ad101 commit 40acade
1 file changed
Lines changed: 11 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
38 | 38 | | |
39 | 39 | | |
40 | 40 | | |
41 | | - | |
| 41 | + | |
42 | 42 | | |
43 | 43 | | |
44 | 44 | | |
45 | 45 | | |
46 | | - | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
47 | 56 | | |
48 | 57 | | |
49 | 58 | | |
| |||
0 commit comments