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