-
Hi, Example class TestClass
{
public string Name => "My Name is Test";
} new Engine()
.SetValue("T", new TestClass())
.Execute("""
const handler = {
get(target, property, receiver) {
if (!target[property]) {
return (...args) => "Not available";
}
// return target[property];
return Reflect.get(target, property, receiver);
}
};
const p = new Proxy(T, handler);
const t = p.GetX();
// const name = p.Name; // When commenting this in, an exception is thrown
"""); Am I doing something wrong here or did I understand something wrong? Or isn't it supported to use a Proxy on a clr object? |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 1 reply
-
I have made a mistake below, It's really a bug.
All CLR Object Property is non-configurable, and the |
Beta Was this translation helpful? Give feedback.
-
It's all in
/// <summary>
/// https://tc39.es/ecma262/#sec-proxy-object-internal-methods-and-internal-slots-get-p-receiver
/// </summary>
public override JsValue Get(JsValue property, JsValue receiver)
{
AssertTargetNotRevoked(property);
var target = _target;
if (property == KeyFunctionRevoke || !TryCallHandler(TrapGet, new[] { target, TypeConverter.ToPropertyKey(property), receiver }, out var result))
{
return target.Get(property, receiver);
}
var targetDesc = target.GetOwnProperty(property);
if (targetDesc != PropertyDescriptor.Undefined)
{
var targetValue = targetDesc.Value;
if (targetDesc.IsDataDescriptor() && !targetDesc.Configurable && !targetDesc.Writable && !ReferenceEquals(result, targetValue))
{
ExceptionHelper.ThrowTypeError(_engine.Realm, $"'get' on proxy: property '{property}' is a read-only and non-configurable data property on the proxy target but the proxy did not return its actual value (expected '{targetValue}' but got '{result}')");
}
if (targetDesc.IsAccessorDescriptor() && !targetDesc.Configurable && (targetDesc.Get ?? Undefined).IsUndefined() && !result.IsUndefined())
{
ExceptionHelper.ThrowTypeError(_engine.Realm, $"'get' on proxy: property '{property}' is a non-configurable accessor property on the proxy target and does not have a getter function, but the trap did not return 'undefined' (got '{result}')");
}
}
return result;
} |
Beta Was this translation helpful? Give feedback.
-
@lahma Please reopen #1643 , I can comfirm it's a bug and I can provide a fix:
That's a pure js example which works in V8, but failed in Jint, caused by let o = Object.defineProperty({}, 'value', {
configurable: false,
value: 'oz',
});
const handler = {
get(target, property, receiver) {
return 'Mozilla'.substring(1,3);
}
};
let p = new Proxy(o, handler);
let pv = p.value; |
Beta Was this translation helpful? Give feedback.
-
I can confirm that now the example works as expected. Thank you! |
Beta Was this translation helpful? Give feedback.
@lahma Please reopen #1643 , I can comfirm it's a bug and I can provide a fix:
ReferenceEquals
on data property value comparingThat's a pure js example which works in V8, but failed in Jint, caused by
ReferenceEquals