Skip to content
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

Add ObjectWrapperReportedMemberTypes to Options #1947

Merged
merged 3 commits into from
Aug 17, 2024

Conversation

lofcz
Copy link
Contributor

@lofcz lofcz commented Aug 16, 2024

Implements the feature discussed in #1945.

@lofcz lofcz force-pushed the feat-get-own-properties-ext branch 4 times, most recently from 91b39c0 to c2d36eb Compare August 16, 2024 21:31
Copy link
Collaborator

@lahma lahma left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this needs some discussion.

The JavaScript behavior for get/set etc:

var base = {
  baseField: "foo",
  funcBase() {
  },
  get propBase() {
  },
  set propBase(val) {
  },
};

var a = {
  aField: 0,
  funcA() {
  },
  get propA() {
  },
  set propA(val) {
  },
}

Object.setPrototypeOf(a, base);

console.log("own: " + Object.getOwnPropertyNames(a));

console.log("enumerable properties");

for (var k in a) {
  console.log(k);
}

Output:

own: aField,funcA,propA
enumerable properties
aField
funcA
propA
baseField
funcBase
propBase

So the correct output for the "full" test case should be:

jsProps.Should().BeSameAs(["A", "F"]);

It should not contain inherited ones and property get/set and not listed as it's implied by the property. GetType is already special cased in configuration anyway not to be allowed as it opens reflection. So I think only addition should be own methods that are not property get/set or any other special name (m.IsSpecialName).

Jint.Tests/Runtime/InteropTests.cs Show resolved Hide resolved
engine.SetValue("clrInstance", new ClrMembersVisibilityTestClass());

var getValue = engine.Evaluate("clrInstance.get_A()");
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe just engine.Evaluate("clrInstance.get_A()").Should().Be(10);, but I'm goin to argument that the current behavior is wrong

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

well not sure if the possibility to call is wrong, but the idiomatic way is to evaluate clrInstance.A

Jint.Tests/Runtime/InteropTests.cs Outdated Show resolved Hide resolved
Jint.Tests/Runtime/InteropTests.cs Outdated Show resolved Hide resolved
Jint/Options.cs Outdated Show resolved Hide resolved
@lofcz
Copy link
Contributor Author

lofcz commented Aug 17, 2024

Thanks for the feedback, the requested changes are in 654d557, we can squash it after your review.

  1. All three flags for CLR types are now set on by default.
  2. The "full" test returns ["A", "F"]
  3. Added the List<>.Should() asserts.

@lofcz lofcz force-pushed the feat-get-own-properties-ext branch from fa4a4f1 to 654d557 Compare August 17, 2024 14:11
@lofcz lofcz requested a review from lahma August 17, 2024 14:17
@lofcz
Copy link
Contributor Author

lofcz commented Aug 17, 2024

I have no idea why or how the Linux tests are failing:

Passed! - Failed: 0, Passed: 64848, Skipped: 7253, Total: 72101, Duration: 1 m 1 s - Jint.Tests.Test262.dll (net8.0)
Error: Process completed with exit code 1.

Maybe this?

[xUnit.net 00:00:04.07] [FATAL ERROR] System.AppDomainUnloadedException

@lahma
Copy link
Collaborator

lahma commented Aug 17, 2024

No worries, I'll look into this and from quick look seems good. Thanks for iterating and discussing 👍🏻

Copy link
Collaborator

@lahma lahma left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, I tweaked a bit for readability. Thanks for fixing this!

@lofcz
Copy link
Contributor Author

lofcz commented Aug 17, 2024

@lahma why are we taking DeclaredOnly fields and methods but not properties?

@lahma lahma merged commit 2e7ec9d into sebastienros:main Aug 17, 2024
3 checks passed
@lahma
Copy link
Collaborator

lahma commented Aug 17, 2024

@lahma why are we taking DeclaredOnly fields and methods but not properties?

It would break existing test case, if you want to check the feasibility for the change, a PR and investigation is always welcome 🙂

@lofcz
Copy link
Contributor Author

lofcz commented Aug 17, 2024

Could you point me to the failing test? I'm using Windows box and tests were passing here (or maybe I'm just stupid and didn't run all the tests?) without the DeclaredOnly constraint. I'd like to look into lifting it, as the current version won't report inherited fields/methods, which I need for the debugger scenario described in the linked issue.
I see the issue is with the full framework, as usual -.-

@lahma
Copy link
Collaborator

lahma commented Aug 17, 2024

For me it's EngineShouldStringifyAnJObjectListWithValuesCorrectly and it's enough to have foreach (var p in ClrType.GetProperties(BindingFlags | BindingFlags.DeclaredOnly)) when runnin on NET 8.

@lahma
Copy link
Collaborator

lahma commented Aug 17, 2024

So I guess it's a case of dynamic where nobody knows where the properties originate from. It's been a PITA for so long but a valid use case - probably ExpandoObject related or something.

@lofcz
Copy link
Contributor Author

lofcz commented Aug 17, 2024

I've run the two tests included in this PR and they fail for net462 which I've not noticed before:
image
This is without any changes. The EngineShouldStringifyAnJObjectListWithValuesCorrectly seems to be another thing.

Is the Windows test run configured here in CI running both .net fw and core configurations? I can fix the test for the full fw, I just fail to understand how the CI tests passed.

@lahma
Copy link
Collaborator

lahma commented Aug 17, 2024

This is my result when running on a Windows box with the flag changed for properties against latest main

image

@lofcz
Copy link
Contributor Author

lofcz commented Aug 17, 2024

This one is passing for me, both with and without the DeclaredOnly flag:
image
My SDK is 8.0.302

@lahma
Copy link
Collaborator

lahma commented Aug 17, 2024

Let build server be the judge: #1948

Failed test summary: https://github.com/sebastienros/jint/actions/runs/10434541945?pr=1948

@lofcz
Copy link
Contributor Author

lofcz commented Aug 17, 2024

I'll try to get my environment to be consistent with the build server then and look into the failing test.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants