| 1 |
<?php |
| 2 |
|
| 3 |
require_once('JavaScriptStatements.php'); |
| 4 |
require_once('JavaScriptArray.php'); |
| 5 |
require_once('Destructable.php'); |
| 6 |
|
| 7 |
class JavaScriptFunctionCall extends Destructable { |
| 8 |
protected $call; |
| 9 |
protected $args; |
| 10 |
|
| 11 |
protected $assignment; |
| 12 |
protected $resolved_args; |
| 13 |
protected $name; |
| 14 |
protected $global_scope; |
| 15 |
|
| 16 |
public function __construct($call, $args, $instantiated = FALSE) { |
| 17 |
$this->call = $call; |
| 18 |
$this->args = $args; |
| 19 |
} |
| 20 |
|
| 21 |
public function __destruct() { |
| 22 |
$this->mem_flush('call', 'args', 'assignment', 'resolved_args', 'name', 'global_scope'); |
| 23 |
} |
| 24 |
|
| 25 |
private function resolve() { |
| 26 |
if (!$this->call->is_lookup()) { |
| 27 |
$this->global_scope = FALSE; |
| 28 |
$this->name = NULL; |
| 29 |
} |
| 30 |
else { |
| 31 |
list ($this->global_scope, $this->name) = $this->call->resolve(); |
| 32 |
} |
| 33 |
} |
| 34 |
|
| 35 |
public function name() { |
| 36 |
if (!isset($this->name)) { |
| 37 |
$this->resolve(); |
| 38 |
} |
| 39 |
return $this->name; |
| 40 |
} |
| 41 |
|
| 42 |
public function setAssignment($assignment) { |
| 43 |
$this->assignment = $assignment; |
| 44 |
} |
| 45 |
|
| 46 |
public function assignment() { |
| 47 |
if ($this->assignment) { |
| 48 |
if ($this->assignment->is_lookup()) { |
| 49 |
list(, $assignment) = $this->assignment->resolve(); |
| 50 |
return $assignment; |
| 51 |
} |
| 52 |
} |
| 53 |
return NULL; |
| 54 |
} |
| 55 |
|
| 56 |
public function is_global () { |
| 57 |
if (!isset($this->global_scope)) { |
| 58 |
$this->resolve(); |
| 59 |
} |
| 60 |
return !!$this->global_scope; |
| 61 |
} |
| 62 |
|
| 63 |
public function type() { |
| 64 |
|
| 65 |
return 'Object'; |
| 66 |
} |
| 67 |
|
| 68 |
public function arguments() { |
| 69 |
if (isset($this->resolved_args)) { |
| 70 |
return $this->resolved_args; |
| 71 |
} |
| 72 |
return ($this->resolved_args = new JavaScriptArray($this->args)); |
| 73 |
} |
| 74 |
} |