diff options
author | Alon Zakai <azakai@mozilla.com> | 2010-12-30 21:42:06 -0800 |
---|---|---|
committer | Alon Zakai <azakai@mozilla.com> | 2010-12-30 21:42:06 -0800 |
commit | ff4341e7d5bfb82cc711146ab80e31635e5865b7 (patch) | |
tree | e8c25ce0f8d7fe869e48531c4c277ea7f95db7c4 /src/jsifier.js | |
parent | 47f29aed8aa7905c24562188d2d7e2861972ebed (diff) |
simple django-style substitution/macros
Diffstat (limited to 'src/jsifier.js')
-rw-r--r-- | src/jsifier.js | 20 |
1 files changed, 16 insertions, 4 deletions
diff --git a/src/jsifier.js b/src/jsifier.js index ba6cc232..3669f87f 100644 --- a/src/jsifier.js +++ b/src/jsifier.js @@ -110,9 +110,10 @@ function JSify(data, functionsOnly, givenTypes, givenFunctions, givenGlobalVaria value = indexizeFunctions(value); var offset = calcFastOffset(ptr, pos, noNeedFirst); if (SAFE_HEAP) { - return 'SAFE_HEAP_STORE(' + offset + ', ' + value + ', "' + safeQuote(type) + '")'; + if (type !== 'null') type = '"' + safeQuote(type) + '"'; + return 'SAFE_HEAP_STORE(' + offset + ', ' + value + ', ' + type + ');'; } else { - return makeGetSlabs(ptr, type, true).map(function(slab) { return slab + '[' + offset + '] = ' + value }).join('; '); + return makeGetSlabs(ptr, type, true).map(function(slab) { return slab + '[' + offset + '] = ' + value }).join('; ') + ';'; } } @@ -964,6 +965,15 @@ function JSify(data, functionsOnly, givenTypes, givenFunctions, givenGlobalVaria // Final combiner function finalCombiner(items) { + // Does simple 'macro' substitution, using Django-like syntax, + // {{{ code }}} will be replaced with |eval(code)|. + function processMacros(text) { + return text.replace(/{{{[^}]+}}}/g, function(str) { + str = str.substr(3, str.length-6); + return eval(str).toString(); + }); + } + var ret = []; if (!functionsOnly) { ret = ret.concat(items.filter(function(item) { return item.intertype == 'type' })); @@ -982,8 +992,10 @@ function JSify(data, functionsOnly, givenTypes, givenFunctions, givenGlobalVaria var body = preprocess(read('preamble.js').replace('{{RUNTIME}}', getRuntime()) + ret + read('postamble.js'), CONSTANTS); var globalVars = items.filter(function(item) { return item.intertype == 'GlobalVariable' }).map(function(item) { return item.JS }).join('\n'); var globalVarsPostSets = items.filter(function(item) { return item.intertype == 'GlobalVariablePostSet' }).map(function(item) { return item.JS }).join('\n'); - return read('shell.js').replace('{{BODY}}', indentify(body, 2)) - .replace('{{GLOBAL_VARS}}', indentify(globalVars+'\n\n\n'+globalVarsPostSets, 4)); + return processMacros( + read('shell.js').replace('{{BODY}}', indentify(body, 2)) + .replace('{{GLOBAL_VARS}}', indentify(globalVars+'\n\n\n'+globalVarsPostSets, 4)) + ); } // Data |