aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAlon Zakai <alonzakai@gmail.com>2012-12-13 12:35:54 -0800
committerAlon Zakai <alonzakai@gmail.com>2012-12-13 12:36:18 -0800
commitf7dd2645ee157a60cce28cb7db9327728699d544 (patch)
treeab33a546454079ee39dac4a459b285eae34a319d /src
parent125256db5c00421c00ef2afbb0e909a81ab3d1d1 (diff)
chunk very large array literals in global constants, to avoid 'array initializer too large errors' closes #194
Diffstat (limited to 'src')
-rw-r--r--src/parseTools.js22
1 files changed, 21 insertions, 1 deletions
diff --git a/src/parseTools.js b/src/parseTools.js
index 4a76a9a2..b2093da3 100644
--- a/src/parseTools.js
+++ b/src/parseTools.js
@@ -1328,7 +1328,27 @@ function makePointer(slab, pos, allocator, type, ptr) {
types = de[0];
}
}
- return 'allocate(' + slab + ', ' + JSON.stringify(types) + (allocator ? ', ' + allocator : '') + (allocator == 'ALLOC_NONE' ? ', ' + ptr : '') + ')';
+ // JS engines sometimes say array initializers are too large. Work around that by chunking and calling concat to combine at runtime
+ var chunkSize = 10240;
+ function chunkify(array) {
+ // break very large slabs into parts
+ var ret = '';
+ var index = 0;
+ while (index < array.length) {
+ ret = (ret ? ret + '.concat(' : '') + '[' + array.slice(index, index + chunkSize).map(JSON.stringify) + ']' + (ret ? ')' : '');
+ index += chunkSize;
+ }
+ return ret;
+ }
+ if (typeof slab == 'string' && evaled && evaled.length > chunkSize) {
+ slab = chunkify(evaled);
+ }
+ if (typeof types != 'string' && types.length > chunkSize) {
+ types = chunkify(types);
+ } else {
+ types = JSON.stringify(types);
+ }
+ return 'allocate(' + slab + ', ' + types + (allocator ? ', ' + allocator : '') + (allocator == 'ALLOC_NONE' ? ', ' + ptr : '') + ')';
}
function makeGetSlabs(ptr, type, allowMultiple, unsigned) {