Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
87 changes: 86 additions & 1 deletion Jint.Tests/Runtime/ProxyTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -455,7 +455,7 @@
Assert.Equal(2, TestClass.Instance.PropertySideEffect); // second call to PropertySideEffect
}

[Fact]
[Fact]
public void ToObjectReturnsProxiedToObject()
{
_engine
Expand All @@ -482,4 +482,89 @@
""");

}

[Fact]
public void ProxyClrObjectMethod()
{
var res = _engine

Check failure on line 489 in Jint.Tests/Runtime/ProxyTests.cs

View workflow job for this annotation

GitHub Actions / linux - ARM

Jint.Tests.Runtime.ProxyTests.ProxyClrObjectMethod

Jint.Runtime.JavaScriptException : 'get' on proxy: property 'Add' is a read-only and non-configurable data property on the proxy target but the proxy did not return its actual value (expected 'function Jint.Tests.Runtime.ProxyTests+TestClass.Add() { [native code] }' but got 'function () { [native code] }') ---- Jint.Runtime.JavaScriptException+JavaScriptErrorWrapperException : 'get' on proxy: property 'Add' is a read-only and non-configurable data property on the proxy target but the proxy did not return its actual value (expected 'function Jint.Tests.Runtime.ProxyTests+TestClass.Add() { [native code] }' but got 'function () { [native code] }')

Check failure on line 489 in Jint.Tests/Runtime/ProxyTests.cs

View workflow job for this annotation

GitHub Actions / linux

Jint.Tests.Runtime.ProxyTests.ProxyClrObjectMethod

Jint.Runtime.JavaScriptException : 'get' on proxy: property 'Add' is a read-only and non-configurable data property on the proxy target but the proxy did not return its actual value (expected 'function Jint.Tests.Runtime.ProxyTests+TestClass.Add() { [native code] }' but got 'function () { [native code] }') ---- Jint.Runtime.JavaScriptException+JavaScriptErrorWrapperException : 'get' on proxy: property 'Add' is a read-only and non-configurable data property on the proxy target but the proxy did not return its actual value (expected 'function Jint.Tests.Runtime.ProxyTests+TestClass.Add() { [native code] }' but got 'function () { [native code] }')

Check failure on line 489 in Jint.Tests/Runtime/ProxyTests.cs

View workflow job for this annotation

GitHub Actions / macos

Jint.Tests.Runtime.ProxyTests.ProxyClrObjectMethod

Jint.Runtime.JavaScriptException : 'get' on proxy: property 'Add' is a read-only and non-configurable data property on the proxy target but the proxy did not return its actual value (expected 'function Jint.Tests.Runtime.ProxyTests+TestClass.Add() { [native code] }' but got 'function () { [native code] }') ---- Jint.Runtime.JavaScriptException+JavaScriptErrorWrapperException : 'get' on proxy: property 'Add' is a read-only and non-configurable data property on the proxy target but the proxy did not return its actual value (expected 'function Jint.Tests.Runtime.ProxyTests+TestClass.Add() { [native code] }' but got 'function () { [native code] }')
.SetValue("T", new TestClass())
.Evaluate("""
const handler = {
get(target, property, receiver) {

if (property == "Add") {
return function(...args) { return 42};
}

return Reflect.get(...arguments);
}
};

const p = new Proxy(T, handler);
p.Add(5,3); // throws 'get' on proxy: property 'Add' is a read-only and non-configurable data property
// on the proxy target but the proxy did not return its actual value
// (expected 'function Jint.Tests.Runtime.ProxyTests+TestClass.Add() { [native code] }' but got 'function () { [native code] }')
""");

Assert.Equal(42, res.AsInteger());
}

[Fact]
public void ProxyClrObjectMethodWithDelegate()
{
var res = _engine

Check failure on line 515 in Jint.Tests/Runtime/ProxyTests.cs

View workflow job for this annotation

GitHub Actions / linux - ARM

Jint.Tests.Runtime.ProxyTests.ProxyClrObjectMethodWithDelegate

Jint.Runtime.JavaScriptException : 'get' on proxy: property 'Add' is a read-only and non-configurable data property on the proxy target but the proxy did not return its actual value (expected 'function Jint.Tests.Runtime.ProxyTests+TestClass.Add() { [native code] }' but got 'function () { [native code] }') ---- Jint.Runtime.JavaScriptException+JavaScriptErrorWrapperException : 'get' on proxy: property 'Add' is a read-only and non-configurable data property on the proxy target but the proxy did not return its actual value (expected 'function Jint.Tests.Runtime.ProxyTests+TestClass.Add() { [native code] }' but got 'function () { [native code] }')

Check failure on line 515 in Jint.Tests/Runtime/ProxyTests.cs

View workflow job for this annotation

GitHub Actions / linux

Jint.Tests.Runtime.ProxyTests.ProxyClrObjectMethodWithDelegate

Jint.Runtime.JavaScriptException : 'get' on proxy: property 'Add' is a read-only and non-configurable data property on the proxy target but the proxy did not return its actual value (expected 'function Jint.Tests.Runtime.ProxyTests+TestClass.Add() { [native code] }' but got 'function () { [native code] }') ---- Jint.Runtime.JavaScriptException+JavaScriptErrorWrapperException : 'get' on proxy: property 'Add' is a read-only and non-configurable data property on the proxy target but the proxy did not return its actual value (expected 'function Jint.Tests.Runtime.ProxyTests+TestClass.Add() { [native code] }' but got 'function () { [native code] }')

Check failure on line 515 in Jint.Tests/Runtime/ProxyTests.cs

View workflow job for this annotation

GitHub Actions / macos

Jint.Tests.Runtime.ProxyTests.ProxyClrObjectMethodWithDelegate

Jint.Runtime.JavaScriptException : 'get' on proxy: property 'Add' is a read-only and non-configurable data property on the proxy target but the proxy did not return its actual value (expected 'function Jint.Tests.Runtime.ProxyTests+TestClass.Add() { [native code] }' but got 'function () { [native code] }') ---- Jint.Runtime.JavaScriptException+JavaScriptErrorWrapperException : 'get' on proxy: property 'Add' is a read-only and non-configurable data property on the proxy target but the proxy did not return its actual value (expected 'function Jint.Tests.Runtime.ProxyTests+TestClass.Add() { [native code] }' but got 'function () { [native code] }')
.SetValue("T", new TestClass())
.Evaluate("""
const handler = {
get(target, property, receiver) {

if (property == "Add") {
return (...args) => 42;
}

return Reflect.get(...arguments);
}
};

const p = new Proxy(T, handler);
p.Add(5,3); // throws 'get' on proxy: property 'Add' is a read-only and non-configurable data property
// on the proxy target but the proxy did not return its actual value
// (expected 'function Jint.Tests.Runtime.ProxyTests+TestClass.Add() { [native code] }' but got 'function () { [native code] }')
""");

Assert.Equal(42, res.AsInteger());
}

[Fact]
public void ProxyClrObjectWithTmpObjectMethod()
{
var res = _engine
.SetValue("T", new TestClass())
.Evaluate("""
const handler = {
get(target, property, receiver) {

if (property == "Add") {
return (...args) => target.target[property](...args) + 34;
}

if (typeof target.target[property] === "function")
return (...args) => target.target[property](...args);

return Reflect.get(target.target, property, receiver)
}
};

const tmpObj = { target: T };
const p = new Proxy(tmpObj, handler);

const name = p.Name;
p.SayHello();
const res = p.Add(5,3); // works now

name + " " + res
""");

Assert.Equal("My Name is Test 42", res.AsString());
}
}
Loading