Open
Description
Problem
Currently JavaScript.Net does not fully support prototype related use cases:
While it is possible to register a function which creates a new object like this:
_context.SetParameter("TestClass", new Func<TestClass>(() => new TestClass()));
_context.Run(@"
let c = new TestClass();
c.foo()").Should().Be(true);
problems with this approach:
instanceOf
checks are not working.c instanceof TestClass
is false- Prototype extensions are not working (
TestClass.prototype.newMethod = function() {...}
)
Things to consider for the solution
- Objects which are created by C# code should also be able to pass to JavaScript under an existing prototype
- Fine grained control about which types are constructable by JS is required
Solution proposal
- add method like
SetConstructor(ConstructorInfo constructor)
to the context which generates a prototype and registers under the name - when wrapping an object:
- lookup whether a prototype already exists for the type
- if no prototype is known: generate a prototype (but do not make it available to the context under a name)
- wrap object by using the newly generated or existing prototype
Side notes
This could also improve performance of wrapping objects since the analysis of type is only required once, repetitive passing could become a lot faster.
/cc @spahnke
@oliverbock do you think the proposal above is sane? Then I would start to implement it.
Metadata
Metadata
Assignees
Labels
No labels