Skip to content
This repository has been archived by the owner on Feb 1, 2019. It is now read-only.

Commit

Permalink
Merge pull request #356 from magopian/bump-spidermonkey
Browse files Browse the repository at this point in the history
bump spidermonkey
  • Loading branch information
magopian committed Nov 26, 2015
2 parents 4581703 + 8ec235f commit 8fbd554
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 2 deletions.
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ argparse==1.1
fastchardet==0.2.0
mock==1.0.0
simplejson==3.8.0
spidermonkey==41.0a2.post1
spidermonkey==44.0a2.post2
38 changes: 38 additions & 0 deletions tests/test_js_syntax.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,44 @@ def test(block):
yield test, block


def test_generators():
"""
Tests that generators inside simple `function`s (opposed to `function*`)
are not raising syntax errors.
We use `version(180)` in `testcases.javascript.jsshell.JSShell` so we don't
use the latest "version" (185 at the time of this writing) when running
spidermonkey. See
https://developer.mozilla.org/en-US/docs/Mozilla/Projects/SpiderMonkey/JSAPI_reference/JSVersion) # noqa
which deprecates generators with 'function' (see
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/Legacy_generator_function) # noqa
If we get to the point where we want to drop support for generators as
`function`s, then we'll need to remove `version(180)` and modify this test.
"""

ID = ('javascript', 'dangerous_global', 'eval')

EVIL = 'eval(evilStuff)'
BLOCKS = (
'function foo() { %s; yield 1; }',
'function foo() { yield %s; }',
'var foo = function () { %s; yield 1; }',
'function* foo() { %s; yield 1; }',
'function* foo() { yield %s; }',
'var foo = function* () { %s; yield 1; }'
)

def test(block):
# The following should raise a "dangerous global", and not a syntax
# error.
err = _do_test_raw(block % EVIL)
assert err.message_count == 1, \
'Missing expected failure for block: %s' % block
eq_(err.warnings[0]['id'], ID)

for block in BLOCKS:
yield test, block


class TestTemplateString(TestCase):
WARNING = {'id': ('testcases_chromemanifest', 'test_resourcemodules',
'resource_modules')}
Expand Down
7 changes: 6 additions & 1 deletion validator/testcases/javascript/jsshell.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,12 @@ class JSShell(Spidermonkey):
"""

def __init__(self):
super(JSShell, self).__init__(code=self.SCRIPT)
# Use "version(180)" so we don't use the latest version (185 at the
# time of this writing:
# https://developer.mozilla.org/en-US/docs/Mozilla/Projects/SpiderMonkey/JSAPI_reference/JSVersion) # noqa
# which deprecates generators with 'function' (see
# https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/Legacy_generator_function) # noqa
super(JSShell, self).__init__(code=['version(180)', self.SCRIPT])

def __del__(self):
if self.returncode is None:
Expand Down

0 comments on commit 8fbd554

Please sign in to comment.