summaryrefslogtreecommitdiffstats
path: root/js/xpconnect/tests/unit/test_xrayed_iterator.js
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 00:47:55 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 00:47:55 +0000
commit26a029d407be480d791972afb5975cf62c9360a6 (patch)
treef435a8308119effd964b339f76abb83a57c29483 /js/xpconnect/tests/unit/test_xrayed_iterator.js
parentInitial commit. (diff)
downloadfirefox-26a029d407be480d791972afb5975cf62c9360a6.tar.xz
firefox-26a029d407be480d791972afb5975cf62c9360a6.zip
Adding upstream version 124.0.1.upstream/124.0.1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'js/xpconnect/tests/unit/test_xrayed_iterator.js')
-rw-r--r--js/xpconnect/tests/unit/test_xrayed_iterator.js40
1 files changed, 40 insertions, 0 deletions
diff --git a/js/xpconnect/tests/unit/test_xrayed_iterator.js b/js/xpconnect/tests/unit/test_xrayed_iterator.js
new file mode 100644
index 0000000000..26d40420a3
--- /dev/null
+++ b/js/xpconnect/tests/unit/test_xrayed_iterator.js
@@ -0,0 +1,40 @@
+Services.prefs.setBoolPref("security.allow_eval_with_system_principal", true);
+registerCleanupFunction(() => {
+ Services.prefs.clearUserPref("security.allow_eval_with_system_principal");
+});
+
+function run_test() {
+
+ var toEval = [
+ "var customIterator = {",
+ " _array: [6, 7, 8, 9]",
+ "};",
+ "customIterator[Symbol.iterator] = function* () {",
+ " for (var i = 0; i < this._array.length; ++i)",
+ " yield this._array[i];",
+ "};"
+ ].join('\n');
+
+ function checkIterator(iterator) {
+ var control = [6, 7, 8, 9];
+ var i = 0;
+ for (var item of iterator) {
+ Assert.equal(item, control[i]);
+ ++i;
+ }
+ }
+
+ // First, try in our own scope.
+ eval(toEval);
+ checkIterator(customIterator);
+
+ // Next, try a vanilla CCW.
+ var sbChrome = Cu.Sandbox(this);
+ Cu.evalInSandbox(toEval, sbChrome, '1.7');
+ checkIterator(sbChrome.customIterator);
+
+ // Finally, try an Xray waiver.
+ var sbContent = Cu.Sandbox('http://www.example.com');
+ Cu.evalInSandbox(toEval, sbContent, '1.7');
+ checkIterator(Cu.waiveXrays(sbContent.customIterator));
+}