-
Notifications
You must be signed in to change notification settings - Fork 8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
should hooks be called with this
set to the object they are pulled from?
#15
Comments
since you can do: const self = new Set([], {
allowed: [1,2,3],
coerceValue(v) {
if (!self.allowed.contains(v)) throw new Error('not allowed');
}
}) already, it doesn't seem to add any capabilities, just avoids some developer pain? (thus, yes) |
The closest prior-art in the ECMAScript proposal to this are Proxy traps. For proxy traps, Having
Your example is incorrect. const self = {
allowed: [1,2,3],
coerceValue(v) {
if (!self.allowed.contains(v)) throw new Error('not allowed');
}
};
new Set([], self); |
ohhhh you want it to be the options object. that seems super weird to me. |
That's what happens for Proxy Handlers: const handler = {
get(target, key) {
console.assert(this === handler);
}
};
new Proxy({}, handler).x; |
Doing the same as proxy handlers seems fine. |
@rbuckton if mimicking Proxy handlers, should we lookup the functions off the options bag every time like proxies do? see: let i = 0;
let o = new Proxy({}, {
get ["get"]() {
let n = i++;
return () => n;
}
});
console.log(o.x, o.x);
// 0 1 |
That seems like it'd create a performance hit :-/ |
@ljharb i believe recent proxy optimization passes in some engines do optimize it out once you hit the full compiler. Perhaps an implementer with knowledge of proxy optimizations being done like @MayaLekova might be able to comment if the same optimization would be ok here? |
For proxies in V8 we currently do the trap lookup on each call, but we have the idea to eventually use more detailed feedback and speculate that the handler stays the same (and deoptimize if that's not the case). Looks to me that the same optimization can be applied in this collections use-case as well. Personally I think that being consistent with other similar use-cases (like Proxy handlers) would be the better option. |
this has been updated to align with how Proxy handlers are called and collection moved from |
The text was updated successfully, but these errors were encountered: