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

internal interface IConstructor #1144

Closed
lahma opened this issue Apr 22, 2022 Discussed in #1141 · 9 comments · Fixed by #1440
Closed

internal interface IConstructor #1144

lahma opened this issue Apr 22, 2022 Discussed in #1141 · 9 comments · Fixed by #1440

Comments

@lahma
Copy link
Collaborator

lahma commented Apr 22, 2022

Discussed in #1141

Originally posted by viceice April 22, 2022
Was this intentional to no longer make that interface public? I use that for a custom type, which implements this interface.

internal interface IConstructor

I'm basicall doing something like this:

internal sealed class UuidConstructor : FunctionInstance, IConstructor

changed in v3.0.0-beta-2038 via

@viceice
Copy link
Contributor

viceice commented Apr 22, 2022

Can we make those interfaces public again until a better solution is found?

@dan3988
Copy link

dan3988 commented Jun 13, 2022

Could FunctionInstance not implement IConstructor, with a virtual implementation that throws a type error by default? That way IConstructor can be made internal and we can still create custom constructors by overriding that method.

@lahma
Copy link
Collaborator Author

lahma commented Jun 13, 2022

@dan3988 what's your use case, I'd favor something simpler like the model I'm proposing in this PR. Building against IConstructor usually means that you are implementing the ECMA spec.

@dan3988
Copy link

dan3988 commented Jun 13, 2022

@lahma I have some custom classes I've implemented similarly to the ECMA classes inside Jint/Native, where I have a separate C# class for the constructor, prototype and instance.

@lahma
Copy link
Collaborator Author

lahma commented Jun 14, 2022

Sorry to sound like a broken record, but can you give a more specific example. Doing the constructor-prototype-instance route seems quite involved compared to what it would be if we could make the interop do the leg work.

@dan3988
Copy link

dan3988 commented Jun 14, 2022

I've extracted some of the code from the project into a repo with some examples of javascript classes:

There are 30-40 classes implemented this way in our project. It was written this way as we wanted the following

  • Classes in the script that inherit other custom classes, so that instanceof would work in our scripts
  • Classes that have a constructor object, but are not instantiatable inside the script (like the Window constructor in a browser)
  • A way of adding properties with a different name to the C# method / property
  • A way of adding properties with symbol keys, such as Symbol.toPrimitive

@lahma
Copy link
Collaborator Author

lahma commented Jun 14, 2022

@dan3988 excellent! thanks for taking the time to describe your use case, I'll try to delve into this and see if there is easier way or should we just open APIs again.

@viceice
Copy link
Contributor

viceice commented Jun 14, 2022

maybe a constructor base class is enough

@EnCey
Copy link
Contributor

EnCey commented Nov 21, 2022

bump, I'm facing the same problem now 😅
my use case is to call async .NET methods, which I've gotten to work, but it blocks me from going the TypeReference route, at least I don't see how that would work.

A constructor base class could also set the Function.PrototypeObject, which is something the UuidConstructor example does and feels like a good default.

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 a pull request may close this issue.

4 participants