Mercurial > hg > isophonics-drupal-site
diff vendor/jcalderonzumba/mink-phantomjs-driver/src/JavascriptTrait.php @ 12:7a779792577d
Update Drupal core to v8.4.5 (via Composer)
author | Chris Cannam |
---|---|
date | Fri, 23 Feb 2018 15:52:07 +0000 |
parents | 4c8ae668cc8c |
children |
line wrap: on
line diff
--- a/vendor/jcalderonzumba/mink-phantomjs-driver/src/JavascriptTrait.php Fri Feb 23 15:51:18 2018 +0000 +++ b/vendor/jcalderonzumba/mink-phantomjs-driver/src/JavascriptTrait.php Fri Feb 23 15:52:07 2018 +0000 @@ -15,7 +15,7 @@ * @param string $script */ public function executeScript($script) { - $this->browser->execute($script); + $this->browser->execute($this->fixSelfExecutingFunction($script)); } /** @@ -24,7 +24,11 @@ * @return mixed */ public function evaluateScript($script) { - return $this->browser->evaluate($script); + $script = preg_replace('/^return\s+/', '', $script); + + $script = $this->fixSelfExecutingFunction($script); + + return $this->browser->evaluate($script); } /** @@ -40,10 +44,32 @@ $end = $start + $timeout / 1000.0; do { $result = $this->browser->evaluate($condition); + if ($result) { + // No need to wait any longer when the condition is met already. + return TRUE; + } usleep(100000); } while (microtime(true) < $end && !$result); return (bool)$result; } + /** + * Fixes self-executing functions to allow evaluating them. + * + * The self-executing function must be wrapped in braces to work. + * + * @param string $script + * + * @return string + */ + private function fixSelfExecutingFunction($script) + { + if (preg_match('/^function[\s\(]/', $script)) { + $script = preg_replace('/;$/', '', $script); + $script = '(' . $script . ')'; + } + + return $script; + } }