function run_test() { var epsb = new Cu.Sandbox(["http://example.com", "http://example.org"], { wantExportHelpers: true }); var subsb = new Cu.Sandbox("http://example.com", { wantGlobalProperties: ["XMLHttpRequest"] }); var subsb2 = new Cu.Sandbox("http://example.com", { wantGlobalProperties: ["XMLHttpRequest"] }); var xorigsb = new Cu.Sandbox("http://test.com", { wantGlobalProperties: ["XMLHttpRequest"] });
// Exported function should be able to be call from the // target sandbox. Native arguments should be just wrapped // every other argument should be cloned.
Cu.evalInSandbox("(" + function () { native = new XMLHttpRequest();
xrayed2 = XPCNativeWrapper(new XMLHttpRequest());
mixed = { xrayed: xrayed, xrayed2: xrayed2 };
tobecloned = { cloned: "cloned" };
invokedCallback = false;
callback = function() { invokedCallback = true; };
imported(this, 42, tobecloned, native, mixed, callback);
equal(imported.length, 6);
ok(invokedCallback);
}.toSource() + ")()", subsb);
// Invoking an exported function with cross-origin arguments should throw.
subsb.xoNative = Cu.evalInSandbox('new XMLHttpRequest()', xorigsb); try {
Cu.evalInSandbox('imported(this, xoNative)', subsb); Assert.ok(false);
} catch (e) { Assert.ok(/denied|insecure/.test(e));
}
// Callers can opt-out of the above.
subsb.xoNative = Cu.evalInSandbox('new XMLHttpRequest()', xorigsb); try { Assert.equal(Cu.evalInSandbox('echoAllowXO(xoNative)', subsb), subsb.xoNative); Assert.ok(true);
} catch (e) { Assert.ok(false);
}
// Apply should work and |this| should carry over appropriately.
Cu.evalInSandbox("(" + function() { var someThis = {};
imported.apply(someThis, [someThis, 42, tobecloned, native, mixed]);
}.toSource() + ")()", subsb);
// Exporting should throw if principal of the source sandbox does // not subsume the principal of the target.
Cu.evalInSandbox("(" + function() { try{
exportFunction(function() {}, this.xorigsb, { defineAs: "denied" });
ok(false);
} catch (e) {
ok(e.toString().indexOf('Permission denied') > -1);
}
}.toSource() + ")()", epsb);
// Exporting should throw if the principal of the source sandbox does // not subsume the principal of the function.
epsb.xo_function = new xorigsb.Function();
Cu.evalInSandbox("(" + function() { try{
exportFunction(xo_function, this.subsb, { defineAs: "denied" });
ok(false);
} catch (e) {
dump('Exception: ' + e);
ok(e.toString().indexOf('Permission denied') > -1);
}
}.toSource() + ")()", epsb);
// Let's create an object in the target scope and add privileged // function to it as a property.
Cu.evalInSandbox("(" + function() { var newContentObject = createObjectIn(subsb, { defineAs: "importedObject" });
exportFunction(funToExport, newContentObject, { defineAs: "privMethod" });
}.toSource() + ")()", epsb);
// exportFunction and createObjectIn should be available from Cu too. var newContentObject = Cu.createObjectIn(subsb, { defineAs: "importedObject2" }); var wasCalled = false;
Cu.exportFunction(function(arg) { wasCalled = arg.wasCalled; },
newContentObject, { defineAs: "privMethod" });
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.