Bug 1605854 - Fix remaining tests using uneval/toSource r=mccr8,bzbarsky

Differential Revision: https://phabricator.services.mozilla.com/D58685

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Tom Schuster 2020-01-07 13:19:30 +00:00
Родитель d1b15f3063
Коммит c73016a38b
16 изменённых файлов: 26 добавлений и 37 удалений

Просмотреть файл

@ -91,7 +91,7 @@
for (var p in b) bProps.push(p); for (var p in b) bProps.push(p);
is (aProps.length, bProps.length, 'Props match'); is (aProps.length, bProps.length, 'Props match');
is (aProps.sort().toSource(), bProps.sort().toSource(), 'Props match - using toSource()'); is (aProps.sort().toString(), bProps.sort().toString(), 'Props names match');
for (var p in a) { for (var p in a) {
compare(a[p], b[p]); compare(a[p], b[p]);
@ -106,7 +106,7 @@
} }
if (type != 'null') { if (type != 'null') {
is (a.toSource(), b.toSource(), 'Matching using toSource()'); is (a, b, 'Same value');
} }
} }

Просмотреть файл

@ -31,10 +31,10 @@ function getCOW(x) {
x = Cu.waiveXrays(x); x = Cu.waiveXrays(x);
var rval = {}; var rval = {};
if (typeof x == "function") if (typeof x == "function")
rval = eval(uneval(x)); rval = eval(`(${x.toString()})`);
for (var i in x) { for (var i in x) {
if (x.__lookupGetter__(i)) if (x.__lookupGetter__(i))
rval.__defineGetter__(i, eval(uneval(x.__lookupGetter__(i)))) rval.__defineGetter__(i, eval(`(${x.__lookupGetter__(i).toString()})`))
else else
rval[i] = getCOW(x[i]); rval[i] = getCOW(x[i]);
} }
@ -59,7 +59,7 @@ function COWTests() {
return names; return names;
} }
// This function is actually decompiled and run inside a // This function is actually stringified and run inside a
// sandbox with content privileges. // sandbox with content privileges.
// TODO: This could use some refactoring; creating helper // TODO: This could use some refactoring; creating helper
@ -204,8 +204,8 @@ function COWTests() {
} }
} }
// Decompile the COW test suite, re-evaluate it in the sandbox and execute it. // Stringify the COW test suite and directly evaluate it in the sandbox.
Cu.evalInSandbox('(' + uneval(COWTests) + ')()', sandbox); Cu.evalInSandbox('(' + COWTests.toString() + ')()', sandbox);
// Test that COWed objects passing from content to chrome get unwrapped. // Test that COWed objects passing from content to chrome get unwrapped.
function returnCOW() { function returnCOW() {
@ -214,7 +214,7 @@ function returnCOW() {
} }
var unwrapped = Cu.evalInSandbox( var unwrapped = Cu.evalInSandbox(
'(' + uneval(returnCOW) + ')()', '(' + returnCOW.toString() + ')()',
sandbox sandbox
); );

Просмотреть файл

@ -28,11 +28,11 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=990353
function frameLoaded() { function frameLoaded() {
switch (++gLoadCount) { switch (++gLoadCount) {
case 1: case 1:
ok(/native code/.test(window[0].canary.toSource()), "System function should be sourceless: " + window[0].canary.toSource()); ok(/native code/.test(window[0].canary.toString()), "System function should be sourceless: " + window[0].canary.toString());
ok(/native code/.test(window[0].onload.toSource()), "System event handler should be sourceless: " + window[0].onload.toSource()); ok(/native code/.test(window[0].onload.toString()), "System event handler should be sourceless: " + window[0].onload.toString());
var sb = new Cu.Sandbox('http://www.example.com', { discardSource: true }); var sb = new Cu.Sandbox('http://www.example.com', { discardSource: true });
Cu.evalInSandbox('function canary() { var someBitOfSource = 42; }', sb); Cu.evalInSandbox('function canary() { var someBitOfSource = 42; }', sb);
ok(/native code/.test(sb.canary.toSource()), "Function from sandbox with explicit discarding should be sourceless"); ok(/native code/.test(sb.canary.toString()), "Function from sandbox with explicit discarding should be sourceless");
try { try {
window[0].throwSomething(); window[0].throwSomething();
ok(false, "should have thrown"); ok(false, "should have thrown");
@ -43,8 +43,8 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=990353
window[0].location = "http://example.org/tests/js/xpconnect/tests/chrome/file_discardSystemSource.html"; window[0].location = "http://example.org/tests/js/xpconnect/tests/chrome/file_discardSystemSource.html";
break; break;
case 2: case 2:
ok(/someBitOfSource/.test(Cu.waiveXrays(window[0]).canary.toSource()), "Content function should have source"); ok(/someBitOfSource/.test(Cu.waiveXrays(window[0]).canary.toString()), "Content function should have source");
ok(/someBitOfSource/.test(Cu.waiveXrays(window[0]).onload.toSource()), "Content event handler should have source"); ok(/someBitOfSource/.test(Cu.waiveXrays(window[0]).onload.toString()), "Content event handler should have source");
testWorker(); testWorker();
break; break;
} }
@ -65,7 +65,7 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=990353
function go() { function go() {
// We should have our own source, because the pref wasn't enabled when we // We should have our own source, because the pref wasn't enabled when we
// were loaded. // were loaded.
ok(/someBitOfSource/.test(canary.toSource()), "Should have own source"); ok(/someBitOfSource/.test(canary.toString()), "Should have own source");
window[0].frameElement.onload = frameLoaded; window[0].frameElement.onload = frameLoaded;
window[0].location = "file_discardSystemSource.html"; window[0].location = "file_discardSystemSource.html";

Просмотреть файл

@ -2,4 +2,4 @@ function canary() {
var someBitOfSource = 42; var someBitOfSource = 42;
} }
postMessage(canary.toSource()); postMessage(canary.toString());

Просмотреть файл

@ -46,7 +46,7 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=390488
function matches(s, p, name) { function matches(s, p, name) {
ok(s.match(p) != null, ok(s.match(p) != null,
name + " - got " + uneval(s) + ", expected a string matching " + uneval(p)); name + " - got " + s + ", expected a string matching " + p);
} }
function checkForStacks() { function checkForStacks() {

Просмотреть файл

@ -19,17 +19,6 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=628410
<script type="application/javascript"> <script type="application/javascript">
/** Test for Bug 628410 **/ /** Test for Bug 628410 **/
{
// window.toSource() will throw if SpecialPowers is defined on the window and
// permissive COWs are not enabled for the global that owns its frame message
// manager.
let sp = window.SpecialPowers;
window.SpecialPowers = null;
window.toSource();
window.SpecialPowers = sp;
}
window.toString(); window.toString();
InstallTrigger + ""; InstallTrigger + "";
console + ""; console + "";

Просмотреть файл

@ -27,7 +27,7 @@ function runSandboxTest(testFunc, argString) {
var finishFuncName = 'finish_' + testFunc.name; var finishFuncName = 'finish_' + testFunc.name;
SpecialPowers.Cu.exportFunction(_ => resolvePromise(), sb, SpecialPowers.Cu.exportFunction(_ => resolvePromise(), sb,
{ defineAs: finishFuncName }); { defineAs: finishFuncName });
SpecialPowers.Cu.evalInSandbox('(' + testFunc.toSource() + ')' + SpecialPowers.Cu.evalInSandbox('(' + testFunc.toString() + ')' +
'(' + argString + ')' + '(' + argString + ')' +
'.then(' + finishFuncName + ');', sb); '.then(' + finishFuncName + ');', sb);
return testPromise; return testPromise;

Просмотреть файл

@ -24,7 +24,7 @@ function loadPrivilegedScriptTest() {
var contentProcessType = SpecialPowers.isMainProcess(); var contentProcessType = SpecialPowers.isMainProcess();
var port; var port;
try { try {
port = SpecialPowers.loadPrivilegedScript(loadPrivilegedScriptTest.toSource()); port = SpecialPowers.loadPrivilegedScript(loadPrivilegedScriptTest.toString());
} catch (e) { } catch (e) {
ok(false, "loadPrivilegedScript shoulde not throw"); ok(false, "loadPrivilegedScript shoulde not throw");
} }

Просмотреть файл

@ -1348,7 +1348,7 @@ SimpleTest.monitorConsole = function (continuation, msgs, forbidUnexpectedMsgs)
} }
var counter = 0; var counter = 0;
var assertionLabel = msgs.toSource(); var assertionLabel = JSON.stringify(msgs);
function listener(msg) { function listener(msg) {
if (msg.message === "SENTINEL" && !msg.isScriptError) { if (msg.message === "SENTINEL" && !msg.isScriptError) {
is(counter, msgs.length, is(counter, msgs.length,

Просмотреть файл

@ -29,7 +29,7 @@ function testData(data) {
}; };
function compare(prop, expected) { function compare(prop, expected) {
if (uneval(data[prop]) == uneval(expected)) if (JSON.stringify(data[prop]) == JSON.stringify(expected))
return; return;
if (response.result) if (response.result)
response.status = ""; response.status = "";

Просмотреть файл

@ -344,7 +344,7 @@ var classifierTester = {
async function fn(frame, iframeId, depth) { async function fn(frame, iframeId, depth) {
return SpecialPowers.spawn( return SpecialPowers.spawn(
frame, frame,
[iframeId, depth, fn.toSource()], [iframeId, depth, fn.toString()],
async (iframeId, depth, fnSource) => { async (iframeId, depth, fnSource) => {
// eslint-disable-next-line no-eval // eslint-disable-next-line no-eval
let fnGetIframePluginInfo = eval(`(() => (${fnSource}))()`); let fnGetIframePluginInfo = eval(`(() => (${fnSource}))()`);

Просмотреть файл

@ -190,7 +190,7 @@ async function runTest(test, expectedFlag, expectedTrackingResource, prefs) {
], ],
]; ];
info("Testing: " + config.toSource() + "\n"); info("Testing: " + JSON.stringify(config) + "\n");
await SpecialPowers.pushPrefEnv({ set: config.concat(prefs) }); await SpecialPowers.pushPrefEnv({ set: config.concat(prefs) });

Просмотреть файл

@ -42,7 +42,7 @@ async function runTest(test) {
[ "privacy.trackingprotection.socialtracking.enabled", false ], [ "privacy.trackingprotection.socialtracking.enabled", false ],
]}); ]});
info("Testing: " + test.config.toSource() + "\n"); info("Testing: " + JSON.stringify(test.config) + "\n");
// Let's load an image with a random query string, just to avoid network cache. // Let's load an image with a random query string, just to avoid network cache.
let result = await new Promise(resolve => { let result = await new Promise(resolve => {

Просмотреть файл

@ -42,7 +42,7 @@ async function runTest(test) {
[ "privacy.trackingprotection.socialtracking.enabled", false ], [ "privacy.trackingprotection.socialtracking.enabled", false ],
]}); ]});
info("Testing: " + test.config.toSource() + "\n"); info("Testing: " + JSON.stringify(test.config) + "\n");
// Let's load an image with a random query string, just to avoid network cache. // Let's load an image with a random query string, just to avoid network cache.
let result = await new Promise(resolve => { let result = await new Promise(resolve => {

Просмотреть файл

@ -42,7 +42,7 @@ async function runTest(test) {
[ "privacy.trackingprotection.socialtracking.enabled", true ], [ "privacy.trackingprotection.socialtracking.enabled", true ],
]}); ]});
info("Testing: " + test.config.toSource() + "\n"); info("Testing: " + JSON.stringify(test.config) + "\n");
// Let's load an image with a random query string, just to avoid network cache. // Let's load an image with a random query string, just to avoid network cache.
let result = await new Promise(resolve => { let result = await new Promise(resolve => {

Просмотреть файл

@ -75,7 +75,7 @@ const sandboxScript = function(shadowRoot) {
win.wrappedJSObject.spanElementFromUAWidget = span; win.wrappedJSObject.spanElementFromUAWidget = span;
win.wrappedJSObject.divElementFromUAWidget = shadowRoot.lastChild; win.wrappedJSObject.divElementFromUAWidget = shadowRoot.lastChild;
}; };
SpecialPowers.Cu.evalInSandbox("this.script = " + sandboxScript.toSource(), sandbox); SpecialPowers.Cu.evalInSandbox("this.script = " + sandboxScript.toString(), sandbox);
sandbox.script(div.shadowRoot); sandbox.script(div.shadowRoot);
ok(window.spanElementFromUAWidget instanceof HTMLSpanElement, "<span> exposed"); ok(window.spanElementFromUAWidget instanceof HTMLSpanElement, "<span> exposed");