mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 1215606 - Ensure that DevToolsUtils.assert is properly exported; r=jsantell
This commit is contained in:
parent
84cfa9ca73
commit
83ab00ba37
@ -458,6 +458,25 @@ exports.dbg_assert = function dbg_assert(cond, e) {
|
||||
}
|
||||
};
|
||||
|
||||
exports.defineLazyGetter(this, "AppConstants", () => {
|
||||
const scope = {};
|
||||
Cu.import("resource://gre/modules/AppConstants.jsm", scope);
|
||||
return scope.AppConstants;
|
||||
});
|
||||
|
||||
/**
|
||||
* No operation. The empty function.
|
||||
*/
|
||||
exports.noop = function () { };
|
||||
|
||||
function reallyAssert(condition, message) {
|
||||
if (!condition) {
|
||||
const err = new Error("Assertion failure: " + message);
|
||||
exports.reportException("DevToolsUtils.assert", err);
|
||||
throw err;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* DevToolsUtils.assert(condition, message)
|
||||
*
|
||||
@ -477,23 +496,11 @@ exports.dbg_assert = function dbg_assert(cond, e) {
|
||||
* This is an improvement over `dbg_assert`, which doesn't actually cause any
|
||||
* fatal behavior, and is therefore much easier to accidentally ignore.
|
||||
*/
|
||||
exports.defineLazyGetter(exports, "assert", () => {
|
||||
function noop(condition, msg) { }
|
||||
|
||||
function assert(condition, message) {
|
||||
if (!condition) {
|
||||
const err = new Error("Assertion failure: " + message);
|
||||
exports.reportException("DevToolsUtils.assert", err);
|
||||
throw err;
|
||||
}
|
||||
}
|
||||
|
||||
const scope = {};
|
||||
Cu.import("resource://gre/modules/AppConstants.jsm", scope);
|
||||
const { DEBUG, DEBUG_JS_MODULES } = scope.AppConstants;
|
||||
|
||||
return (DEBUG || DEBUG_JS_MODULES || exports.testing) ? assert : noop;
|
||||
});
|
||||
Object.defineProperty(exports, "assert", {
|
||||
get: () => (AppConstants.DEBUG || AppConstants.DEBUG_JS_MODULES || this.testing)
|
||||
? reallyAssert
|
||||
: exports.noop,
|
||||
})
|
||||
|
||||
/**
|
||||
* Defines a getter on a specified object for a module. The module will not
|
||||
|
@ -9,6 +9,11 @@ const DevToolsUtils = require("devtools/shared/DevToolsUtils");
|
||||
|
||||
// Register a console listener, so console messages don't just disappear
|
||||
// into the ether.
|
||||
|
||||
// If for whatever reason the test needs to post console errors that aren't
|
||||
// failures, set this to true.
|
||||
var ALLOW_CONSOLE_ERRORS = false;
|
||||
|
||||
var errorCount = 0;
|
||||
var listener = {
|
||||
observe: function (aMessage) {
|
||||
@ -35,7 +40,10 @@ var listener = {
|
||||
while (DebuggerServer.xpcInspector.eventLoopNestLevel > 0) {
|
||||
DebuggerServer.xpcInspector.exitNestedEventLoop();
|
||||
}
|
||||
do_throw("head_dbg.js got console message: " + string + "\n");
|
||||
|
||||
if (!ALLOW_CONSOLE_ERRORS) {
|
||||
do_throw("head_devtools.js got console message: " + string + "\n");
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
36
devtools/shared/tests/unit/test_assert.js
Normal file
36
devtools/shared/tests/unit/test_assert.js
Normal file
@ -0,0 +1,36 @@
|
||||
/* -*- js-indent-level: 2; indent-tabs-mode: nil -*- */
|
||||
/* Any copyright is dedicated to the Public Domain.
|
||||
http://creativecommons.org/publicdomain/zero/1.0/ */
|
||||
|
||||
// Test DevToolsUtils.assert
|
||||
|
||||
ALLOW_CONSOLE_ERRORS = true;
|
||||
|
||||
function run_test() {
|
||||
// Enable assertions.
|
||||
DevToolsUtils.testing = true;
|
||||
|
||||
const { assert } = DevToolsUtils;
|
||||
equal(typeof assert, "function");
|
||||
|
||||
try {
|
||||
assert(true, "this assertion should not fail");
|
||||
} catch (e) {
|
||||
// If you catch assertion failures in practice, I will hunt you down. I get
|
||||
// email notifications every time it happens.
|
||||
ok(false, "Should not get an error for an assertion that should not fail. Got "
|
||||
+ DevToolsUtils.safeErrorString(e));
|
||||
}
|
||||
|
||||
let assertionFailed = false;
|
||||
try {
|
||||
assert(false, "this assertion should fail");
|
||||
} catch (e) {
|
||||
ok(e.message.startsWith("Assertion failure:"),
|
||||
"Should be an assertion failure error");
|
||||
assertionFailed = true;
|
||||
}
|
||||
|
||||
ok(assertionFailed,
|
||||
"The assertion should have failed, which should throw an error when assertions are enabled.");
|
||||
}
|
@ -6,6 +6,7 @@ skip-if = toolkit == 'android' || toolkit == 'gonk'
|
||||
support-files =
|
||||
exposeLoader.js
|
||||
|
||||
[test_assert.js]
|
||||
[test_fetch-chrome.js]
|
||||
[test_fetch-file.js]
|
||||
[test_fetch-http.js]
|
||||
|
Loading…
Reference in New Issue
Block a user