Changeset 249095 in webkit
- Timestamp:
- Aug 26, 2019, 7:36:47 AM (7 years ago)
- Location:
- trunk/Source/JavaScriptCore
- Files:
-
- 3 edited
-
ChangeLog (modified) (1 diff)
-
Scripts/jsmin.py (modified) (3 diffs)
-
Scripts/make-js-file-arrays.py (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/JavaScriptCore/ChangeLog
r249078 r249095 1 2019-08-26 Carlos Alberto Lopez Perez <clopez@igalia.com> 2 3 Missing media controls when WebKit is built with Python3 4 https://bugs.webkit.org/show_bug.cgi?id=194367 5 6 Reviewed by Carlos Garcia Campos. 7 8 The JavaScript minifier script jsmin.py expects a text stream 9 with text type as input, but the script make-js-file-arrays.py 10 was passing to it a FileIO() object. So, when the jsmin script 11 called read() over this object, python3 was returning a type of 12 bytes, but for python2 it returns type str. 13 14 This caused two problems: first that jsmin failed to do any minifying 15 because it was comparing strings with a variable of type bytes. 16 The second major problem was in the write() function, when the 17 jsmin script tried to convert a byte character to text by calling 18 str() on it. Because what this does is not to convert from byte 19 type to string, but to simply generate a string with the format b'c'. 20 So the jsmin script was returning back as minified JS complete 21 garbage in the form of "b't'b'h'b'h'b'i" for python3. 22 23 Therefore, when WebKit was built with python3 this broke everything 24 that depended on the embedded JS code that make-js-file-arrays.py 25 was supposed to generate, like the media controls and the WebDriver 26 atoms. 27 28 Fix this by reworking the code in make-js-file-arrays script to 29 read the data from the file using a TextIOWrapper in python 3 30 with decoding for 'utf-8'. This ensures that the jsmin receives 31 a text type. For python2 keep using the same FileIO class. 32 33 On the jsmin.py script remove the problematic call to str() inside 34 the write() function when running with python3. 35 On top of that, add an extra check in jsmin.py script to make it 36 fail if the character type read is not the one expected. This 37 will cause the build to fail instead of failing silently like 38 now. I did some tests and the runtime cost of this extra check 39 is almost zero. 40 41 * Scripts/jsmin.py: 42 (JavascriptMinify.minify.write): 43 (JavascriptMinify): 44 * Scripts/make-js-file-arrays.py: 45 (main): 46 1 47 2019-08-23 Devin Rousso <drousso@apple.com> 2 48 -
trunk/Source/JavaScriptCore/Scripts/jsmin.py
r236321 r249095 29 29 if is_3: 30 30 import io 31 python_text_type = str 31 32 else: 32 33 import StringIO … … 35 36 except ImportError: 36 37 cStringIO = None 38 python_text_type = basestring 37 39 38 40 … … 83 85 self.return_buf += char 84 86 self.is_return = self.return_buf == 'return' 85 if sys.version_info.major == 2: 86 self.outs.write(char) 87 else: 88 self.outs.write(str(char)) 87 self.outs.write(char) 89 88 if self.is_return: 90 89 self.return_buf = '' 91 90 92 read = self.ins.read 91 def read(n): 92 char = self.ins.read(n) 93 if not isinstance(char, python_text_type): 94 raise ValueError("ERROR: The script jsmin.py can only handle text input, but it received input of type %s" % type(char)) 95 return char 93 96 94 97 space_strings = "abcdefghijklmnopqrstuvwxyz"\ -
trunk/Source/JavaScriptCore/Scripts/make-js-file-arrays.py
r236321 r249095 27 27 from optparse import OptionParser 28 28 import sys 29 if sys.version_info.major == 2: 30 from StringIO import StringIO 31 else: 32 from io import StringIO 33 from jsmin import JavascriptMinify 29 from jsmin import jsmin 30 is_3 = sys.version_info >= (3, 0) 34 31 35 32 … … 72 69 print('namespace {0:s} {{'.format(namespace), file=sourceFile) 73 70 74 jsm = JavascriptMinify()71 for inputFileName in inputPaths: 75 72 76 for inputFileName in inputPaths: 77 inputStream = io.FileIO(inputFileName) 78 outputStream = StringIO() 73 if is_3: 74 inputStream = io.open(inputFileName, encoding='utf-8') 75 else: 76 inputStream = io.FileIO(inputFileName) 77 78 data = inputStream.read() 79 79 80 80 if not options.no_minify: 81 jsm.minify(inputStream, outputStream) 82 characters = outputStream.getvalue() 81 characters = jsmin(data) 83 82 else: 84 characters = inputStream.read()83 characters = data 85 84 86 size = len(characters) 85 if is_3: 86 codepoints = bytearray(characters, encoding='utf-8') 87 else: 88 codepoints = list(map(ord, characters)) 89 90 # Use the size of codepoints instead of the characters 91 # because UTF-8 characters may need more than one byte. 92 size = len(codepoints) 93 87 94 variableName = os.path.splitext(os.path.basename(inputFileName))[0] 88 95 … … 90 97 print('const char {0:s}JavaScript[{1:d}] = {{'.format(variableName, size), file=sourceFile) 91 98 92 codepoints = list(map(ord, characters))93 99 for codepointChunk in chunk(codepoints, 16): 94 100 print(' {0:s},'.format(','.join(map(stringifyCodepoint, codepointChunk))), file=sourceFile)
Note:
See TracChangeset
for help on using the changeset viewer.