summaryrefslogtreecommitdiff
path: root/Source/JavaScriptCore/Scripts/jsmin.py
diff options
context:
space:
mode:
Diffstat (limited to 'Source/JavaScriptCore/Scripts/jsmin.py')
-rw-r--r--Source/JavaScriptCore/Scripts/jsmin.py22
1 files changed, 14 insertions, 8 deletions
diff --git a/Source/JavaScriptCore/Scripts/jsmin.py b/Source/JavaScriptCore/Scripts/jsmin.py
index 372418b4d..7f110c9d3 100644
--- a/Source/JavaScriptCore/Scripts/jsmin.py
+++ b/Source/JavaScriptCore/Scripts/jsmin.py
@@ -28,12 +28,14 @@ import sys
is_3 = sys.version_info >= (3, 0)
if is_3:
import io
+ python_text_type = str
else:
import StringIO
try:
import cStringIO
except ImportError:
cStringIO = None
+ python_text_type = basestring
__all__ = ['jsmin', 'JavascriptMinify']
@@ -79,14 +81,18 @@ class JavascriptMinify(object):
def write(char):
# all of this is to support literal regular expressions.
# sigh
- if char in 'return':
+ if str(char) in 'return':
self.return_buf += char
self.is_return = self.return_buf == 'return'
self.outs.write(char)
if self.is_return:
self.return_buf = ''
- read = self.ins.read
+ def read(n):
+ char = self.ins.read(n)
+ if not isinstance(char, python_text_type):
+ raise ValueError("ERROR: The script jsmin.py can only handle text input, but it received input of type %s" % type(char))
+ return char
space_strings = "abcdefghijklmnopqrstuvwxyz"\
"ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_$\\"
@@ -118,8 +124,8 @@ class JavascriptMinify(object):
write(previous)
elif not previous:
return
- elif previous >= '!':
- if previous in "'\"":
+ elif str(previous) >= "!":
+ if str(previous) in "'\"":
in_quote = previous
write(previous)
previous_non_space = previous
@@ -166,7 +172,7 @@ class JavascriptMinify(object):
if numslashes % 2 == 0:
in_quote = ''
write(''.join(quote_buf))
- elif next1 in '\r\n':
+ elif str(next1) in '\r\n':
if previous_non_space in newlineend_strings \
or previous_non_space > '~':
while 1:
@@ -179,7 +185,7 @@ class JavascriptMinify(object):
or next2 > '~' or next2 == '/':
do_newline = True
break
- elif next1 < '!' and not in_re:
+ elif str(next1) < '!' and not in_re:
if (previous_non_space in space_strings \
or previous_non_space > '~') \
and (next2 in space_strings or next2 > '~'):
@@ -217,14 +223,14 @@ class JavascriptMinify(object):
do_newline = False
write(next1)
- if not in_re and next1 in "'\"`":
+ if not in_re and str(next1) in "'\"`":
in_quote = next1
quote_buf = []
previous = next1
next1 = next2
- if previous >= '!':
+ if str(previous) >= '!':
previous_non_space = previous
if previous == '\\':