Bug 1337899 - [marionette] - Fix construction of script src. r=ato

Marionette builds the final javascript source to execute by
using the specified body, and wrapping it into an anonymouse
function.

Because all of this happens in a single line, a comment in
the last line of the script body will cause the source only
half-wise constructed, and the post-wrapping code assumed
as comment too.

MozReview-Commit-ID: CXtUKfr8jKO

--HG--
extra : rebase_source : 8f5e7bce8cb2bcd2d32409212003f9369f2f5a30
This commit is contained in:
Henrik Skupin 2018-08-01 16:48:02 +02:00
parent b1ef7da4b4
commit ad47be0ed3
2 changed files with 6 additions and 1 deletions

View File

@ -115,7 +115,9 @@ evaluate.sandbox = function(sb, script, args = [],
src += `${ARGUMENTS}.push(rv => ${CALLBACK}(rv));`;
}
src += `(function() { ${script} }).apply(null, ${ARGUMENTS})`;
src += `(function() {
${script}
}).apply(null, ${ARGUMENTS})`;
// timeout and unload handlers
scriptTimeoutID = setTimeout(timeoutHandler, timeout);

View File

@ -349,6 +349,9 @@ class TestExecuteContent(MarionetteTestCase):
sandbox=None)
self.assert_is_web_element(el)
def test_comment_in_last_line(self):
self.marionette.execute_script(" // comment ")
@skip_if_mobile("Modal dialogs not supported in Fennec")
def test_return_value_on_alert(self):
res = self.marionette._send_message("WebDriver:ExecuteScript", {"script": "alert()"})