-
-
Notifications
You must be signed in to change notification settings - Fork 402
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
Implementing native returns for constructor functions #10
Comments
Hey @jasonwilliams, it's nice that you have so clean descriptions of issues 👍 Do you consider to take a PR on this? |
@vitkarpov sure! |
@vitkarpov ECMA spec defines 2 methods for calling and constructing an object, maybe this helps: |
@vitkarpov how you getting on? |
@jasonwilliams now so good, actually I have a pretty basic understanding of Rust, so not being able to articulate in a particular language makes this kind of hard 😞 I'd be happy to follow your PRs and ask questions if you don't mind, I'm sure it's going to be better with time. I'm sorry I didn't tell about it in advance if you're counting on me. |
@vitkarpov no problem, im still learning myself, mainly start on something then ask questions as needed |
@jasonwilliams For clarity: in the description are we suggesting that |
I've been thinking about this for some time, so sorry for the long write up. @someguynamedmatt Our global function objects ( Let's take String as an example. String is exposed to the global scope as a function (make_string) with the methods on its prototype. This is ok for constucting objects but leaves us no room for calling String() normally. Right now when we construct a new string, we actually just call it like a normal function. This means that in exec.rs Construct and Call are currently doing the same thing (except Construct passes Once function objects have been created exprDef::Construct will need to be more clever to return the [[Construct]] func, and ExprDef::Call will need to be more clever to return the [[Cal]] func https://github.com/jasonwilliams/boa/blob/master/src/lib/js/string.rs#L556-L558 can go, ive not been a big fan of passing global in just to do that. Instead there should be a Refactoring Function Objects |
A huge amount of the above work is now done. Constructor functions are now function objects which have a [[Construct]] and a [[Call]] method. Call currently doesn't use the [[Call]] internal slot. This ticket may need to be broken out to others: |
Calling
new String()
currently works however calling String() withoutnew
will fail.You will be returned the global object which has everything in it and causes a stack overflow. This would be the equivalent of traversing every object and property of
window
in the browser.The reason this happens is because String() is currently written to take the
this
value, and attach a primitiveValue field to the slice which is set to the native string. Because we're calling String() without new, there is nothis
passed in, and sothis
becomes the global object rather than a new object we passThe pattern here is this
new Number()
returns an instance of NumberNumber()
returns a primitive numbernew String()
returns an instance of StringString()
returns a primitive stringNotes
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String
Sub issues:
The text was updated successfully, but these errors were encountered: