Gave deprecated FX7 XPCOM interface functions a return value so they don't trigger the iterative interpreter. (bug 672569)

This commit is contained in:
Matt Basta 2011-07-19 15:46:42 -07:00
Родитель 6424015f29
Коммит f879f8a842
5 изменённых файлов: 29 добавлений и 21 удалений

Просмотреть файл

@ -3,22 +3,24 @@
import sys
import os
from validator.errorbundler import ErrorBundle
from validator.outputhandlers.shellcolors import OutputHandler
import validator.testcases.scripting as scripting
from validator.testcases.javascript.traverser import MockBundler
import validator.testcases.javascript.traverser
import validator.testcases.javascript.spidermonkey as spidermonkey
validator.testcases.javascript.traverser.DEBUG = True
if __name__ == '__main__':
err = ErrorBundle(instant=True)
err.handler = OutputHandler(sys.stdout, False)
err.supported_versions = {}
if len(sys.argv) > 1:
path = sys.argv[1]
script = open(path).read()
err = MockBundler()
scripting.test_js_file(err=err,
filename=path,
data=script)
else:
err = MockBundler()
trav = validator.testcases.javascript.traverser.Traverser(err, "stdin")
trav._push_context()
while True:

Просмотреть файл

@ -229,7 +229,7 @@ def test_fx7_nsIDOMFile():
""", versions={'{ec8030f7-c20a-464f-9b0e-13a3a9e97384}':
versions_after("firefox", "7.0a1")})
assert not err.failed()
assert err.notices
assert len(err.notices) == 1
assert err.compat_summary["errors"]
@ -252,5 +252,6 @@ def test_fx7_nsIJSON():
""", versions={'{ec8030f7-c20a-464f-9b0e-13a3a9e97384}':
versions_after("firefox", "7.0a1")})
assert not err.failed()
assert err.notices
assert len(err.notices) == 1
assert err.compat_summary["errors"]

Просмотреть файл

@ -12,7 +12,7 @@ class ErrorBundle(object):
'separating the sorrow and collecting up all the cream.' It's
borderline magical."""
def __init__(self, determined=True, listed=True):
def __init__(self, determined=True, listed=True, instant=False):
self.handler = None
@ -28,9 +28,6 @@ class ErrorBundle(object):
self.ending_tier = 1
self.tier = 1
self.metadata = {}
self.determined = determined
self.subpackages = []
self.package_stack = []
@ -42,13 +39,16 @@ class ErrorBundle(object):
self.overrides = None
self.pushable_resources = {}
self.metadata = {}
if listed:
self.resources["listed"] = True
self.instant = instant
self.determined = determined
# TODO: Break off into version helper
self.supported_versions = None
self.version_requirements = None
if listed:
self.resources["listed"] = True
def error(self, err_id, error,
description='', filename='', line=None, column=None,
context=None, tier=None, for_appversions=None,
@ -137,6 +137,9 @@ class ErrorBundle(object):
# ADDED TO THE STACK!
if message["for_appversions"]:
if not self.supports_version(message["for_appversions"]):
if self.instant:
print "(Instant error discarded)"
self._print_message(type_, message, verbose=True)
return
elif self.version_requirements:
# If there was no for_appversions but there were version
@ -172,6 +175,10 @@ class ErrorBundle(object):
tree[last_id]['__messages'].append(uid)
# If instant mode is turned on, output the message immediately.
if self.instant:
self._print_message(type_, message, verbose=True)
def set_type(self, type_):
"Stores the type of addon we're scanning"
self.detected_type = type_

Просмотреть файл

@ -250,6 +250,8 @@ def nsIDOMFile_deprec(wrapper, arguments, traverser):
versions_after("firefox", "7.0a1")},
tier=5)
return JSWrapper(JSObject(), traverser=traverser)
def nsIJSON_deprec(wrapper, arguments, traverser):
"""Throw a compatibility error about removed XPCOM methods."""
@ -269,3 +271,5 @@ def nsIJSON_deprec(wrapper, arguments, traverser):
versions_after("firefox", "7.0a1")},
tier=5)
return JSWrapper(JSObject(), traverser=traverser)

Просмотреть файл

@ -44,7 +44,7 @@ class MockBundler:
return True
def error(self, err_id, error, description, filename="",
line=1, column=0, context=None):
line=1, column=0, context=None, compatibility_type=None):
"Represents a mock error"
# Increment the message counter
@ -72,19 +72,13 @@ class MockBundler:
print "in %s:line %d (%d)" % (file, line, column)
def warning(self, err_id, warning, description, filename="",
line=1, column=0, context=None):
line=1, column=0, context=None, compatibility_type=None):
self.error(err_id, warning, description, file, line, column, context)
def notice(self, err_id, notice, description, filename="",
line=1, column=0, context=None):
line=1, column=0, context=None, compatibility_type=None):
self.error(err_id, notice, description, file, line, column, context)
def info(self, id, title, description, filename="",
line=1, column=0, context=None):
print "Obsolete use of 'info'"
assert None
self.error(id, title, description, file, line, column, context)
class Traverser:
"Traverses the AST Tree and determines problems with a chunk of JS."