Closed NAllred91 closed 4 years ago
I'm about 90% sure that the problem is that .createFunctionBase_
sets <func>.prototype
, but not <func>.prototype.consructor
(which should of course be set to <func>
).
For native functions this oversight is corrected in .createNativeFunction
, but nowhere does it appear that it is done for user functions.
Yea, the comment for createNativeFunction
points out that some functions can't be called as constructors. I'm unsure if the user can write a function in es5 that can't be called as a constructor though?
I know arrow functions can't be called as constructors, but I'm not sure if there is a way to write a function that can't be called as a constructor is es5?
createNativeFunction
can be called with the boolean to make the function not a constructor, but maybe that logic should be moved intocreateFunctionBase_
and have the boolean passed through?In that case, I think
createFunction
could always callcreateFunctionBase_
with the boolean set to true?
There are a few options but that is probably the most straight forward.
I'm unsure if the user can write a function in es5 that can't be called as a constructor though?
I am not aware of any mechanism by which a user could do that in ES5 (and I am fairly familiar with the spec).
Yep! this seems to fix the issue I've been running into!
Let me know if you'd like me to make a pull request.
I think this should fix it.
I'm not sure I completely understand what is wrong here, but I have a some code you can run through the demo and in your browser console to see the difference.
In JS-Interpreter, it seems that
this.constructor
is expected to be called with a proto. If you pass inthis
to the constructor the new instance has the properties from the prototype, but then you can't pass in the arguments to the constructor.