-
Notifications
You must be signed in to change notification settings - Fork 1
StdLib Reflect Proxy
Roger Johansson edited this page Jan 14, 2026
·
1 revision
Metaprogramming utilities for intercepting and customizing object operations.
A built-in object providing methods for interceptable JavaScript operations.
Implementation Status: 100% Complete
| Method | Status | Description |
|---|---|---|
Reflect.apply(target, thisArg, args) |
Implemented | Calls function with args |
Reflect.construct(target, args, newTarget) |
Implemented | Calls constructor |
Reflect.defineProperty(target, prop, desc) |
Implemented | Defines property |
Reflect.deleteProperty(target, prop) |
Implemented | Deletes property |
Reflect.get(target, prop, receiver) |
Implemented | Gets property value |
Reflect.getOwnPropertyDescriptor(target, prop) |
Implemented | Gets descriptor |
Reflect.getPrototypeOf(target) |
Implemented | Gets prototype |
Reflect.has(target, prop) |
Implemented | Checks for property (in) |
Reflect.isExtensible(target) |
Implemented | Checks extensibility |
Reflect.ownKeys(target) |
Implemented | Gets all own keys |
Reflect.preventExtensions(target) |
Implemented | Prevents extensions |
Reflect.set(target, prop, value, receiver) |
Implemented | Sets property |
Reflect.setPrototypeOf(target, proto) |
Implemented | Sets prototype |
| Operation | Reflect | Object |
|---|---|---|
| Returns | Boolean success | Object or throws |
| Errors | Returns false | Throws TypeError |
| Use Case | Proxy trap forwarding | General use |
Creates a proxy that intercepts operations on a target object.
Implementation Status: 69% Complete (9/13 traps)
| Method | Status | Description |
|---|---|---|
new Proxy(target, handler) |
Implemented | Creates proxy |
Proxy.revocable(target, handler) |
Implemented | Creates revocable proxy |
| Trap | Status | Intercepts |
|---|---|---|
get(target, prop, receiver) |
Implemented | Property read |
set(target, prop, value, receiver) |
Implemented | Property write |
has(target, prop) |
Implemented |
in operator |
deleteProperty(target, prop) |
Implemented |
delete operator |
defineProperty(target, prop, desc) |
Implemented | Property definition |
getOwnPropertyDescriptor(target, prop) |
Implemented | Descriptor lookup |
ownKeys(target) |
Implemented | Key enumeration |
getPrototypeOf(target) |
Implemented | Prototype access |
setPrototypeOf(target, proto) |
Implemented | Prototype modification |
| Trap | Status | Intercepts |
|---|---|---|
apply(target, thisArg, args) |
Not Implemented | Function call |
construct(target, args, newTarget) |
Not Implemented |
new operator |
isExtensible(target) |
Not Implemented | Extensibility check |
preventExtensions(target) |
Not Implemented | Extension prevention |
const { proxy, revoke } = Proxy.revocable(target, handler);
proxy.foo; // Works
revoke();
proxy.foo; // TypeError: proxy revokedconst handler = {
get(target, prop, receiver) {
console.log(`Getting ${prop}`);
return Reflect.get(target, prop, receiver);
},
set(target, prop, value, receiver) {
console.log(`Setting ${prop} = ${value}`);
return Reflect.set(target, prop, value, receiver);
}
};
const proxy = new Proxy({}, handler);
proxy.x = 42; // "Setting x = 42"
proxy.x; // "Getting x"const validator = {
set(target, prop, value) {
if (prop === 'age' && typeof value !== 'number') {
throw new TypeError('Age must be a number');
}
return Reflect.set(target, prop, value);
}
};
const person = new Proxy({}, validator);
person.age = 30; // OK
person.age = "30"; // TypeErrorProxy traps should forward to the target via Reflect methods:
// Correct - forwards to target
get(target, prop, receiver) {
return Reflect.get(target, prop, receiver);
}
// Wrong - loses prototype chain
get(target, prop) {
return target[prop];
}The proxy enforces certain invariants:
- Non-configurable properties cannot be hidden
- Non-extensible objects cannot gain properties
- Sealed/frozen objects maintain their state
| Type | Files |
|---|---|
| Reflect |
StdLib/Reflect/ReflectPrototype.cs, ReflectHelper.cs
|
| Proxy |
StdLib/Proxy/ProxyConstructor.cs, JsTypes/JsProxy.cs
|
- Proxy-and-Reflect - Deep dive into implementation
- StdLib-Object - Object methods for comparison