Fixed implicit global pollution problem (bug 666165)
This commit is contained in:
Родитель
fc036f841b
Коммит
353ca9e860
|
@ -4,6 +4,7 @@
|
|||
.DS_Store
|
||||
.coverage
|
||||
.figleaf
|
||||
*.swp
|
||||
/validator/constants_local.py
|
||||
/src
|
||||
/extras/jslibs
|
||||
|
|
|
@ -64,9 +64,10 @@ def test_pollution_implicit_from_fun():
|
|||
|
||||
assert not _do_test_raw("""
|
||||
(function() {
|
||||
a = "foo";
|
||||
b = "foo";
|
||||
c = "foo";
|
||||
var a = "foo";
|
||||
var b = "foo";
|
||||
var c = "foo";
|
||||
var d = "foo";
|
||||
})()
|
||||
""", ignore_pollution=False).failed()
|
||||
|
||||
|
|
|
@ -206,10 +206,9 @@ def _define_var(traverser, node):
|
|||
# TODO : Test to make sure len(values) == len(vars)
|
||||
for value in declaration["init"]["elements"]:
|
||||
if vars[0]:
|
||||
traverser._set_variable(
|
||||
vars[0],
|
||||
JSWrapper(traverser._traverse_node(value),
|
||||
traverser=traverser))
|
||||
traverser._set_variable(vars[0], JSWrapper(
|
||||
traverser._traverse_node(value),
|
||||
traverser=traverser))
|
||||
vars = vars[1:] # Pop off the first value
|
||||
|
||||
# It's being assigned by a JSArray (presumably)
|
||||
|
@ -218,9 +217,7 @@ def _define_var(traverser, node):
|
|||
assigner = traverser._traverse_node(declaration["init"])
|
||||
for value in assigner.value.elements:
|
||||
if vars[0]:
|
||||
traverser._set_variable(
|
||||
vars[0],
|
||||
value)
|
||||
traverser._set_variable(vars[0], value)
|
||||
vars = vars[1:]
|
||||
|
||||
elif declaration["id"]["type"] == "ObjectPattern":
|
||||
|
@ -242,16 +239,12 @@ def _define_var(traverser, node):
|
|||
init_obj.get(traverser,
|
||||
prop_name))
|
||||
elif prop["value"]["type"] == "ObjectPattern":
|
||||
_proc_objpattern(init_obj.get(traverser,
|
||||
prop_name),
|
||||
_proc_objpattern(init_obj.get(traverser, prop_name),
|
||||
prop["value"]["properties"])
|
||||
|
||||
if init is not None:
|
||||
_proc_objpattern(init_obj=init,
|
||||
properties=declaration["id"]["properties"])
|
||||
#else:
|
||||
# FIXME : Is this even supposed to be possible?
|
||||
# No idea why this is happening,
|
||||
|
||||
else:
|
||||
var_name = declaration["id"]["name"]
|
||||
|
@ -496,7 +489,7 @@ def _expr_assignment(traverser, node):
|
|||
"readonly" in global_dict else
|
||||
True)
|
||||
|
||||
traverser._set_variable(node_left["name"], right)
|
||||
traverser._set_variable(node_left["name"], right, glob=True)
|
||||
elif node_left["type"] == "MemberExpression":
|
||||
member_object = trace_member(traverser, node_left["object"])
|
||||
global_overwrite = (member_object.is_global and
|
||||
|
|
|
@ -409,9 +409,9 @@ class Traverser:
|
|||
|
||||
self._debug("SETTING_OBJECT")
|
||||
|
||||
context_count = len(self.contexts)
|
||||
for i in range(context_count):
|
||||
context = self.contexts[context_count - i - 1]
|
||||
i = 0
|
||||
for context in reversed(self.contexts):
|
||||
i += 1
|
||||
if context.has_var(name):
|
||||
self._debug("SETTING_OBJECT>>LOCAL>>%d" % i)
|
||||
context.set(name, value)
|
||||
|
|
Загрузка…
Ссылка в новой задаче