mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-17 07:15:46 +00:00
Bug 1722718 - [xpconnect] Allow Javascript to print to stderr. r=kmag
Differential Revision: https://phabricator.services.mozilla.com/D121094
This commit is contained in:
parent
9c91451cc2
commit
0edcc72b48
@ -101,8 +101,13 @@ interface nsIScheduledGCCallback : nsISupports
|
||||
[scriptable, builtinclass, uuid(86003fe3-ee9a-4620-91dc-eef8b1e58815)]
|
||||
interface nsIXPCComponents_Utils : nsISupports
|
||||
{
|
||||
/*
|
||||
* Prints the provided message to stderr.
|
||||
*/
|
||||
void printStderr(in AUTF8String message);
|
||||
|
||||
/* reportError is designed to be called from JavaScript only.
|
||||
/*
|
||||
* reportError is designed to be called from JavaScript only.
|
||||
*
|
||||
* It will report a JS Error object to the JS console, and return. It
|
||||
* is meant for use in exception handler blocks which want to "eat"
|
||||
|
@ -1317,6 +1317,12 @@ nsXPCComponents_Utils::CreateServicesCache(JSContext* aCx,
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsXPCComponents_Utils::PrintStderr(const nsACString& message) {
|
||||
printf_stderr("%s", PromiseFlatUTF8String(message).get());
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsXPCComponents_Utils::ReportError(HandleValue error, HandleValue stack,
|
||||
JSContext* cx) {
|
||||
|
14
js/xpconnect/tests/unit/test_print_stderr.js
Normal file
14
js/xpconnect/tests/unit/test_print_stderr.js
Normal file
@ -0,0 +1,14 @@
|
||||
/* 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/. */
|
||||
|
||||
add_task(async function() {
|
||||
Assert.throws(
|
||||
() => Cu.printStderr(),
|
||||
/Not enough arguments/,
|
||||
"Without argument printStderr throws"
|
||||
);
|
||||
|
||||
const types = ["", "foo", 42, true, null, {foo: "bar"}];
|
||||
types.forEach(type => Cu.printStderr(type));
|
||||
});
|
@ -159,3 +159,4 @@ head = head_watchdog.js
|
||||
[test_wrapped_js_enumerator.js]
|
||||
[test_uawidget_scope.js]
|
||||
[test_uninitialized_lexical.js]
|
||||
[test_print_stderr.js]
|
||||
|
Loading…
Reference in New Issue
Block a user