Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Unified Diff: convert_js.py

Issue 10213003: Make JsEngine::Evaluate() return a wrapper for v8::Value to accessdifferent variable types easily (Closed)
Patch Set: Addressed review comments Created April 17, 2013, 7:56 a.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | include/AdblockPlus.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: convert_js.py
===================================================================
--- a/convert_js.py
+++ b/convert_js.py
@@ -9,40 +9,47 @@ from abp_rewrite import doRewrite
def toCString(string):
string = string.replace('\\', '\\\\').replace('"', '\\"')
string = string.replace('\r', '').replace('\n', '\\n')
# Work around MSVC line length limitation
#(see http://msdn.microsoft.com/en-us/library/dddywwsc(v=vs.80).aspx)
string = re.sub(r'(.{16000})(.)', r'\1"\n"\2', string, re.S)
return '"%s"' % string.encode('utf-8')
-def convert(convertFiles, verbatimFiles, outFile):
- outHandle = open(outFile, 'wb')
- print >>outHandle, 'const char* jsSources[] = {'
-
- for file in verbatimFiles:
+def printFilesVerbatim(outHandle, files):
+ for file in files:
fileHandle = codecs.open(file, 'rb', encoding='utf-8')
print >>outHandle, toCString(os.path.basename(file)) + ','
print >>outHandle, toCString(fileHandle.read()) + ','
fileHandle.close()
+def convert(verbatimBefore, convertFiles, verbatimAfter, outFile):
+ outHandle = open(outFile, 'wb')
+ print >>outHandle, 'const char* jsSources[] = {'
+
+ printFilesVerbatim(outHandle, verbatimBefore)
+
convertFiles = map(lambda f: f if os.path.isabs(f) else os.path.join(baseDir, f), convertFiles)
converted = doRewrite(convertFiles, ['module=true', 'source_repo=https://hg.adblockplus.org/adblockplus/'])
print >>outHandle, toCString('adblockplus.js') + ','
print >>outHandle, toCString(converted) + ','
+ printFilesVerbatim(outHandle, verbatimAfter)
+
print >>outHandle, '0, 0'
print >>outHandle, '};'
if __name__ == '__main__':
args = sys.argv[1:]
outFile = args.pop()
- verbatimFiles = []
- while len(args):
- file = args.pop()
- if file == '--':
- break
+ verbatimBefore = []
+ verbatimAfter = []
+ convertFiles = []
+ for fileName in args:
+ if fileName.startswith('before='):
+ verbatimBefore.append(fileName.replace('before=', ''))
+ elif fileName.startswith('after='):
+ verbatimAfter.append(fileName.replace('after=', ''))
else:
- verbatimFiles.insert(0, file)
+ convertFiles.append(fileName)
- convertFiles = args
- convert(convertFiles, verbatimFiles, outFile)
+ convert(verbatimBefore, convertFiles, verbatimAfter, outFile)
« no previous file with comments | « no previous file | include/AdblockPlus.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld