-
Notifications
You must be signed in to change notification settings - Fork 851
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make console API available in embedding usage.
- Loading branch information
1 parent
6f29fa5
commit e2b6307
Showing
3 changed files
with
53 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
toolsrc/org/mozilla/javascript/tools/shell/ShellConsolePrinter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
/* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ | ||
|
||
package org.mozilla.javascript.tools.shell; | ||
|
||
import java.io.IOException; | ||
import java.nio.charset.Charset; | ||
import org.mozilla.javascript.Context; | ||
import org.mozilla.javascript.NativeConsole; | ||
|
||
/** Provide a printer use in console API */ | ||
class ShellConsolePrinter implements NativeConsole.ConsolePrinter { | ||
private static final long serialVersionUID = 5869832740127501857L; | ||
|
||
@Override | ||
public void print(NativeConsole.Level level, String msg) { | ||
try { | ||
ShellConsole console = Main.getGlobal().getConsole(Charset.defaultCharset()); | ||
console.println(level + " " + msg); | ||
} catch (IOException e) { | ||
throw Context.reportRuntimeError(e.getMessage()); | ||
} | ||
} | ||
} |