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

Create Print() function #142

Closed
jasonwilliams opened this issue Oct 8, 2019 · 8 comments · Fixed by #267
Closed

Create Print() function #142

jasonwilliams opened this issue Oct 8, 2019 · 8 comments · Fixed by #267
Assignees
Labels
good first issue Good for newcomers Hacktoberfest Hacktoberfest 2021 - https://hacktoberfest.digitalocean.com

Comments

@jasonwilliams
Copy link
Member

jasonwilliams commented Oct 8, 2019

Arises from:
jasonwilliams#74

1. `print()` function in the global scope (or similar). SpiderMonkey's JavaScript shell defines this as: 
    > Evaluates the expression(s) and displays the result(s) on `stdout`, separated by spaces (" ") and terminated by a newline ("\n").

For Boa Shell we need a print function, the implementation is virtually the same as https://github.com/jasonwilliams/boa/blob/master/src/lib/js/console.rs#L11-L98

It might be worth abstracting the above logic into its own function, and have console.log() and print() use it.

print() should only be available in shell

So you will need to add it to the realm there.
You may need to create a helper function in realm which lets you add Objects to the global scope.

Spidermonkey equivalent

https://github.com/mozilla/gecko-dev/blob/master/js/src/shell/js.cpp#L2687-L2724

@jasonwilliams jasonwilliams added good first issue Good for newcomers Hacktoberfest Hacktoberfest 2021 - https://hacktoberfest.digitalocean.com labels Oct 8, 2019
@jasonwilliams jasonwilliams added this to the Boa Shell milestone Oct 8, 2019
@Emanon42
Copy link
Contributor

Emanon42 commented Oct 8, 2019

Interest in this. Can I take a try?

@jasonwilliams
Copy link
Member Author

Sure!

@jasonwilliams
Copy link
Member Author

In terms of the helper, there exists one in the spec:
https://tc39.es/ecma262/#sec-getglobalobject

The Execution context should have a getRealmObject method.
It might be worth returning a reference to the realm object for now.

You will need this to add Print to the global object before running

@louiidev
Copy link

louiidev commented Oct 9, 2019

if you call print() in the browser(chrome) it opens the printer prompt

@jasonwilliams
Copy link
Member Author

@louisgjphnson this method won’t be in the final binary, only in the shell

@IovoslavIovchev
Copy link
Contributor

@Emanon42 note that what we need is close to some of the work done in #171, so you can take a look (specifically having Display, console.log and print share some logic).

@Emanon42
Copy link
Contributor

Emanon42 commented Nov 1, 2019

@IovoslavIovchev @jasonwilliams thanks! I have to delay my contribution on this issue because of my uni coursework :p
I will finish this before December!

@IovoslavIovchev
Copy link
Contributor

@Emanon42 no worries, take your time

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers Hacktoberfest Hacktoberfest 2021 - https://hacktoberfest.digitalocean.com
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants