Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

print() inside a script sometime may not print the args #1356

Closed
nmondal opened this issue Jul 18, 2023 · 7 comments
Closed

print() inside a script sometime may not print the args #1356

nmondal opened this issue Jul 18, 2023 · 7 comments

Comments

@nmondal
Copy link
Contributor

nmondal commented Jul 18, 2023

This is coming from here:
nmondal/cowj#35

The reason why the print() was not working is a premature optimization in the rhino code base.
Specifically:
org/mozilla/javascript/engine/Builtins.java

Has this code:

public static void print(Context cx, Scriptable thisObj, Object[] args, Function f)
      throws IOException {
    Builtins self = getSelf(thisObj);
    for (Object arg : args) {
      self.stdout.write(ScriptRuntime.toString(arg));
    }
    self.stdout.write('\n'); // bug here, assumes line buffering and auto flush 
  }

Problem happens with this, self.stdout is not flushed. If one does flush it, the result is immediate.
This is a bug and we should let Mozilla folks replace the last line as:

self.stdout.println()

That should do it.

@p-bakker
Copy link
Collaborator

Feel like providing a PR with a testcase and a fix?

@nmondal
Copy link
Contributor Author

nmondal commented Jul 22, 2023

Sure.. @p-bakker let's do it!

nmondal added a commit to nmondal/rhino that referenced this issue Jul 22, 2023
@nmondal
Copy link
Contributor Author

nmondal commented Jul 22, 2023

@p-bakker here we go : #1358

@p-bakker
Copy link
Collaborator

@rbri how does this PR look to you?

@nmondal
Copy link
Contributor Author

nmondal commented Jul 23, 2023

@p-bakker ... things run! Now .. we need to get some committers.. how?

@p-bakker
Copy link
Collaborator

As @rbri is one of the committers, I think/hope he'll take care of it :-)

Otherwise, just give it a bit of time 'till one of the other comitters gets around to it, all volunteers here.

rbri pushed a commit that referenced this issue Jul 25, 2023
@rbri
Copy link
Collaborator

rbri commented Jul 25, 2023

Thanks again.

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants