diff options
| author | Konstantin Tokarev <annulen@yandex.ru> | 2020-02-25 22:21:50 +0300 |
|---|---|---|
| committer | Konstantin Tokarev <annulen@yandex.ru> | 2020-02-25 22:24:39 +0300 |
| commit | cd875b317ba9ef63f946d2a07b7e67c1e05f93ac (patch) | |
| tree | 807d09de3cd29ff85cb6ecb0f6ded0271f14e12d /Source/JavaScriptCore/Scripts/make-js-file-arrays.py | |
| parent | 4f0fa41c49404871e361370baf1cf62029177b94 (diff) | |
| download | qtwebkit-cd875b317ba9ef63f946d2a07b7e67c1e05f93ac.tar.gz | |
Import QtWebKit commit 887b98440a46eb30f8a1998e930ddd9218934e1e
Change-Id: I87077d70c358887aa76233566c2e864d1eeb8f73
Reviewed-by: Konstantin Tokarev <annulen@yandex.ru>
Diffstat (limited to 'Source/JavaScriptCore/Scripts/make-js-file-arrays.py')
| -rwxr-xr-x | Source/JavaScriptCore/Scripts/make-js-file-arrays.py | 57 |
1 files changed, 34 insertions, 23 deletions
diff --git a/Source/JavaScriptCore/Scripts/make-js-file-arrays.py b/Source/JavaScriptCore/Scripts/make-js-file-arrays.py index 65056646a..d9ffb602e 100755 --- a/Source/JavaScriptCore/Scripts/make-js-file-arrays.py +++ b/Source/JavaScriptCore/Scripts/make-js-file-arrays.py @@ -21,11 +21,13 @@ # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +from __future__ import print_function import io import os from optparse import OptionParser -from StringIO import StringIO -from jsmin import JavascriptMinify +import sys +from jsmin import jsmin +is_3 = sys.version_info >= (3, 0) def stringifyCodepoint(code): @@ -36,7 +38,7 @@ def stringifyCodepoint(code): def chunk(list, chunkSize): - for i in xrange(0, len(list), chunkSize): + for i in range(0, len(list), chunkSize): yield list[i:i + chunkSize] @@ -46,11 +48,11 @@ def main(): parser.add_option('-n', '--namespace', help='Namespace to use') (options, arguments) = parser.parse_args() if not options.namespace: - print 'Error: must provide a namespace' + print('Error: must provide a namespace') parser.print_usage() exit(-1) if len(arguments) < 3: - print 'Error: must provide at least 3 arguments' + print('Error: must provide at least 3 arguments') parser.print_usage() exit(-1) @@ -60,38 +62,47 @@ def main(): inputPaths = arguments[2:] headerFile = open(headerPath, 'w') - print >> headerFile, 'namespace {0:s} {{'.format(namespace) + print('namespace {0:s} {{'.format(namespace), file=headerFile) sourceFile = open(sourcePath, 'w') - print >> sourceFile, '#include "{0:s}"'.format(os.path.basename(headerPath)) - print >> sourceFile, 'namespace {0:s} {{'.format(namespace) - - jsm = JavascriptMinify() + print('#include "{0:s}"'.format(os.path.basename(headerPath)), file=sourceFile) + print('namespace {0:s} {{'.format(namespace), file=sourceFile) for inputFileName in inputPaths: - inputStream = io.FileIO(inputFileName) - outputStream = StringIO() + + if is_3: + inputStream = io.open(inputFileName, encoding='utf-8') + else: + inputStream = io.FileIO(inputFileName) + + data = inputStream.read() if not options.no_minify: - jsm.minify(inputStream, outputStream) - characters = outputStream.getvalue() + characters = jsmin(data) else: - characters = inputStream.read() + characters = data + + if is_3: + codepoints = bytearray(characters, encoding='utf-8') + else: + codepoints = list(map(ord, characters)) + + # Use the size of codepoints instead of the characters + # because UTF-8 characters may need more than one byte. + size = len(codepoints) - size = len(characters) variableName = os.path.splitext(os.path.basename(inputFileName))[0] - print >> headerFile, 'extern const char {0:s}JavaScript[{1:d}];'.format(variableName, size) - print >> sourceFile, 'const char {0:s}JavaScript[{1:d}] = {{'.format(variableName, size) + print('extern const char {0:s}JavaScript[{1:d}];'.format(variableName, size), file=headerFile) + print('const char {0:s}JavaScript[{1:d}] = {{'.format(variableName, size), file=sourceFile) - codepoints = map(ord, characters) for codepointChunk in chunk(codepoints, 16): - print >> sourceFile, ' {0:s},'.format(','.join(map(stringifyCodepoint, codepointChunk))) + print(' {0:s},'.format(','.join(map(stringifyCodepoint, codepointChunk))), file=sourceFile) - print >> sourceFile, '};' + print('};', file=sourceFile) - print >> headerFile, '}} // namespace {0:s}'.format(namespace) - print >> sourceFile, '}} // namespace {0:s}'.format(namespace) + print('}} // namespace {0:s}'.format(namespace), file=headerFile) + print('}} // namespace {0:s}'.format(namespace), file=sourceFile) if __name__ == '__main__': main() |
