From 7bc1cc3ef50280d205609d79b5f0b60e96e4a060 Mon Sep 17 00:00:00 2001 From: Andreas Tolfsen Date: Thu, 4 Aug 2016 18:20:18 +0100 Subject: [PATCH] Bug 1290966 - Remove callback function argument from sync scripts; r=automatedtester MozReview-Commit-ID: CaDSYA5PNFp --HG-- extra : rebase_source : 1d85bd860359d511c58b546d19037a989196a43e --- testing/marionette/evaluate.js | 15 +++++++++++---- .../marionette/tests/unit/test_execute_script.py | 4 ++++ 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/testing/marionette/evaluate.js b/testing/marionette/evaluate.js index 5a7ff18f0935..4bd3946b697d 100644 --- a/testing/marionette/evaluate.js +++ b/testing/marionette/evaluate.js @@ -102,6 +102,7 @@ evaluate.sandbox = function(sb, script, args = [], opts = {}) { let timeoutId, timeoutHandler, unloadHandler; let promise = new Promise((resolve, reject) => { + let src = ""; sb[COMPLETE] = resolve; timeoutHandler = () => reject(new ScriptTimeoutError("Timed out")); unloadHandler = () => reject( @@ -109,14 +110,20 @@ evaluate.sandbox = function(sb, script, args = [], opts = {}) { // wrap in function if (!opts.directInject) { - sb[CALLBACK] = sb[COMPLETE]; + if (opts.async) { + sb[CALLBACK] = sb[COMPLETE]; + } sb[ARGUMENTS] = Cu.cloneInto(args, sb, {wrapReflectors: true}); // callback function made private // so that introspection is possible // on the arguments object - script = `${ARGUMENTS}.push(rv => ${CALLBACK}(rv));` + - `(function() { ${script} }).apply(null, ${ARGUMENTS})`; + if (opts.async) { + sb[CALLBACK] = sb[COMPLETE]; + src += `${ARGUMENTS}.push(rv => ${CALLBACK}(rv));`; + } + + src += `(function() { ${script} }).apply(null, ${ARGUMENTS})`; // marionetteScriptFinished is not WebDriver conformant, // hence it is only exposed to immutable sandboxes @@ -144,7 +151,7 @@ evaluate.sandbox = function(sb, script, args = [], opts = {}) { let res; try { res = Cu.evalInSandbox( - script, sb, "1.8", opts.filename || "dummy file", 0); + src, sb, "1.8", opts.filename || "dummy file", 0); } catch (e) { let err = new JavaScriptError( e, diff --git a/testing/marionette/harness/marionette/tests/unit/test_execute_script.py b/testing/marionette/harness/marionette/tests/unit/test_execute_script.py index 4b3f075bc631..814646074c09 100644 --- a/testing/marionette/harness/marionette/tests/unit/test_execute_script.py +++ b/testing/marionette/harness/marionette/tests/unit/test_execute_script.py @@ -233,6 +233,10 @@ class TestExecuteContent(MarionetteTestCase): self.assertTrue( send("return typeof window.wrappedJSObject == 'undefined'")) + def test_no_callback(self): + self.assertTrue(self.marionette.execute_script( + "return typeof arguments[0] == 'undefined'")) + class TestExecuteChrome(TestExecuteContent): def setUp(self):