def _get_contents(self, traverser): if "value" not in self.global_data: return None directory = utils.evaluate_lambdas(traverser, self.global_data["value"]) if directory and callable(self.global_data["value"]): self.global_data["value"] = directory return directory
def _get_contents(self, traverser): if "value" not in self.global_data: return None directory = utils.evaluate_lambdas( traverser, self.global_data["value"]) if directory and callable(self.global_data["value"]): self.global_data["value"] = directory return directory
def get(self, traverser, name, instantiate=False): if name in self.data or instantiate: traverser._debug("Global member found in set data: %s" % name) return super(JSGlobal, self).get( traverser, name, instantiate=instantiate) directory = self._get_contents(traverser) if directory and isinstance(directory, dict) and name in directory: traverser._debug("GETTING (%s) FROM GLOBAL" % name) value = utils.evaluate_lambdas(traverser, directory[name]) if "literal" in value: lit = utils.evaluate_lambdas(traverser, value["literal"]) return JSLiteral(lit, traverser=traverser) return traverser._build_global(name=name, entity=value) traverser._debug("JSObject fallback for member %s in %s" % (name, directory)) return super(JSGlobal, self).get(traverser, name)
def get(self, traverser, name, instantiate=False): if name in self.data or instantiate: traverser._debug("Global member found in set data: %s" % name) return super(JSGlobal, self).get(traverser, name, instantiate=instantiate) directory = self._get_contents(traverser) if directory and isinstance(directory, dict) and name in directory: traverser._debug("GETTING (%s) FROM GLOBAL" % name) value = utils.evaluate_lambdas(traverser, directory[name]) if "literal" in value: lit = utils.evaluate_lambdas(traverser, value["literal"]) return JSLiteral(lit, traverser=traverser) return traverser._build_global(name=name, entity=value) traverser._debug("JSObject fallback for member %s in %s" % (name, directory)) return super(JSGlobal, self).get(traverser, name)
def get_literal_value(self, traverser=None): if "literal" in self.global_data: lit = utils.evaluate_lambdas(traverser, self.global_data["literal"]) return JSLiteral(lit, traverser=traverser) directory = self._get_contents(traverser) if directory and not isinstance(directory, dict): return directory.get_literal_value(traverser=traverser) return super(JSGlobal, self).get_literal_value(traverser)
def get_literal_value(self, traverser=None): traverser = traverser or self.traverser if "literal" in self.global_data: return utils.evaluate_lambdas(traverser, self.global_data["literal"]) directory = self._get_contents(traverser) if directory and not isinstance(directory, dict): return directory.get_literal_value(traverser=traverser) return super(JSGlobal, self).get_literal_value(traverser)
def UnaryExpression(traverser, node): operator = node["operator"] arg = traverser.traverse_node(node["argument"]) if (isinstance(arg, JSGlobal) and "literal" in arg.global_data and not (operator == "typeof" and "undefined" in arg.global_data)): arg = JSLiteral(utils.evaluate_lambdas(traverser, arg.global_data["literal"]), traverser=traverser) if operator in UNARY_OPERATORS: traverser._debug("Defined unary operator (%s)" % operator) return JSLiteral(UNARY_OPERATORS[node["operator"]](arg, traverser), traverser=traverser) elif operator == "void": traverser._debug("Void unary operator") from predefinedentities import resolve_entity return JSGlobal(resolve_entity(traverser, "undefined"), traverser=traverser) elif operator == "typeof": traverser._debug("Typeof unary operator") return JSLiteral(_expr_unary_typeof(arg)) else: traverser._debug("Undefined unary operator") return JSObject(traverser=traverser)
def UnaryExpression(traverser, node): operator = node["operator"] arg = traverser.traverse_node(node["argument"]) if ( isinstance(arg, JSGlobal) and "literal" in arg.global_data and not (operator == "typeof" and "undefined" in arg.global_data) ): arg = JSLiteral(utils.evaluate_lambdas(traverser, arg.global_data["literal"]), traverser=traverser) if operator in UNARY_OPERATORS: traverser._debug("Defined unary operator (%s)" % operator) return JSLiteral(UNARY_OPERATORS[node["operator"]](arg, traverser), traverser=traverser) elif operator == "void": traverser._debug("Void unary operator") from predefinedentities import resolve_entity return JSGlobal(resolve_entity(traverser, "undefined"), traverser=traverser) elif operator == "typeof": traverser._debug("Typeof unary operator") return JSLiteral(_expr_unary_typeof(arg)) else: traverser._debug("Undefined unary operator") return JSObject(traverser=traverser)
def __init__(self, global_data, traverser=None, **kw): self.global_data = utils.evaluate_lambdas(traverser, global_data) super(JSGlobal, self).__init__(traverser=traverser, **kw) if "typeof" in self.global_data: self.TYPEOF = self.global_data["typeof"]