-
-
Notifications
You must be signed in to change notification settings - Fork 405
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
Implement Display for function objects #361
Comments
I can take a stab at this! |
Sure! Let's wait for #255 to land first, though :) |
#255 landed, so you can start working on this! :D |
quick question: getting the name of the function doesn't seem to be trivial. I don't think the Function object stores that info. Is there a reason for that? I might be missing something |
As you say, it's not trivial, but it's there. It's set as an internal field, so you need to call to Note that there are also anonymous functions that don't have name, and I think that we are not assigning a name on assignment of an anonymous function (which is something we should at some point in the future). |
@1ntEgr8 how is it going with this? |
@jasonwilliams sorry, i've been busy with work. i'll try to get this done within the next week. sorry for the delayed response |
I'm actually fine with printing the function as an object with its properties. Like: {
prototype: {
constructor: [Cycle],
__proto__: {
constructor: {
setPrototypeOf: {
length: 2
},
prototype: [Cycle],
name: Object,
length: 1,
defineProperty: {
length: 3
},
getPrototypeOf: {
length: 1
},
is: {
length: 2
},
__proto__: {
constructor: {
name: Function,
prototype: [Cycle],
length: 1,
__proto__: undefined
},
__proto__: undefined
}
},
hasOwnProperty: {
length: 0
},
propertyIsEnumerable: {
length: 0
},
toString: {
length: 0
}
}
},
length: 0,
__proto__: {
constructor: {
name: Function,
prototype: [Cycle],
length: 1,
__proto__: undefined
},
__proto__: undefined
}
} This is something that currently gets outputted on: const a = function () {}; a But for
I would like at first to output function in |
@1ntEgr8 has there been any progress with this? |
Took a stab at it! I saw your release on the Reddit and thought I might try and contribute. There are some fiddly bits about where to source the name of a function from for sure. I think the function name should be included in the Function enum instead of its wrapping value. (Or maybe both?) I think it should be possible. All of the points of construction of function have access to the name. Just wanted to get your thoughts on it |
Calling Display (console.logging) on a function object will print its inner properties.
We need to implement Display for function objects, currently there arent any rules for function objects.
An entry would need to be made here:
https://github.com/jasonwilliams/boa/blob/master/boa/src/builtins/value/mod.rs#L728-L783
for
ObjectKind::Function
.If the function is builtIn you can use
String() { [native code] }
for an Ordinary function you may need to try displaying the Node inside.
You can test by adding
then running it.
Relies on jasonwilliams#255 being merged
See also:
https://github.com/jasonwilliams/boa/blob/master/docs/debugging.md
The text was updated successfully, but these errors were encountered: