Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2360)

Unified Diff: Source/platform/streams/js2c.py

Issue 924713002: [WIP] ReadableStream V8 extension (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: More complete implementation Created 5 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « Source/platform/streams/WebStreams.cpp ('k') | public/platform/WebStreams.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/platform/streams/js2c.py
diff --git a/Source/platform/streams/js2c.py b/Source/platform/streams/js2c.py
new file mode 100644
index 0000000000000000000000000000000000000000..d716404b1cca1a152a20817971cdafbb4777e229
--- /dev/null
+++ b/Source/platform/streams/js2c.py
@@ -0,0 +1,62 @@
+#!/usr/bin/env python
+#
+# Copyright 2015 The Chromium Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+
+import optparse
+import textwrap
+
+TEMPLATE = """\
+// Copyright 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// This file was generated from .js source files by GYP. If you
+// want to make changes to this file you should either change the
+// javascript source files or the GYP script.
+
+namespace %(namespace)s {
+
+const char %(var_name)s[] = {
+%(c_array)s
+};
+
+} // namespace %(namespace)s
+"""
+
+
+def ToCArray(byte_sequence):
+ result = []
+ for chr in byte_sequence:
+ result.append(str(ord(chr)))
+ joined = ", ".join(result)
+ return textwrap.fill(joined, 80)
+
+
+def JS2C(source, target, namespace, var_name):
+ input = open(source, "r")
+ source_bytes = input.read()
+
+ template_params = {
+ "namespace": namespace,
+ "var_name": var_name,
+ "c_array": ToCArray(source_bytes)
+ }
+
+ output = open(target, "wb") # don't output CRLF on Windows
+ output.write(TEMPLATE % template_params)
+ output.close()
+
+
+parser = optparse.OptionParser()
+parser.set_usage("""js2c source.js out.cpp namespace var_name
+ sources.js: input JS file.
+ out.cpp: C++ code to be generated.
+ namespace: namespace the array will be declared in.
+ varName: the name of the variable for the array.
+ """)
+(options, args) = parser.parse_args()
+
+JS2C(args[0], args[1], args[2], args[3])
« no previous file with comments | « Source/platform/streams/WebStreams.cpp ('k') | public/platform/WebStreams.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698