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: Added tests, resolved type conversion ambiguities, implemented some missing API calls Created April 15, 2013, 6:23 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') | include/AdblockPlus/JsEngine.h » ('J')
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,48 @@ 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):
+def convert(verbatimBefore, convertFiles, verbatimAfter, outFile):
outHandle = open(outFile, 'wb')
print >>outHandle, 'const char* jsSources[] = {'
- for file in verbatimFiles:
+ for file in verbatimBefore:
fileHandle = codecs.open(file, 'rb', encoding='utf-8')
print >>outHandle, toCString(os.path.basename(file)) + ','
print >>outHandle, toCString(fileHandle.read()) + ','
fileHandle.close()
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) + ','
+ for file in verbatimAfter:
Felix Dahlke 2013/04/16 15:14:33 Given how this is the same code as above, I think
+ fileHandle = codecs.open(file, 'rb', encoding='utf-8')
+ print >>outHandle, toCString(os.path.basename(file)) + ','
+ print >>outHandle, toCString(fileHandle.read()) + ','
+ fileHandle.close()
+
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') | include/AdblockPlus/JsEngine.h » ('J')

Powered by Google App Engine
This is Rietveld