From d4edc4c8614d43d3b46c6d01bbc00bd00835587e Mon Sep 17 00:00:00 2001 From: Bruce Mitchener Date: Thu, 20 Feb 2014 18:03:33 +0700 Subject: strict fix: Don't define functions within conditionals or try blocks. --- src/preamble.js | 248 ++++++++++++++++++++++++++++---------------------------- 1 file changed, 124 insertions(+), 124 deletions(-) (limited to 'src/preamble.js') diff --git a/src/preamble.js b/src/preamble.js index 1c9de066..27a98422 100644 --- a/src/preamble.js +++ b/src/preamble.js @@ -683,6 +683,130 @@ function stringToUTF32(str, outPtr) { Module['stringToUTF32'] = stringToUTF32; function demangle(func) { + var i = 3; + // params, etc. + var basicTypes = { + 'v': 'void', + 'b': 'bool', + 'c': 'char', + 's': 'short', + 'i': 'int', + 'l': 'long', + 'f': 'float', + 'd': 'double', + 'w': 'wchar_t', + 'a': 'signed char', + 'h': 'unsigned char', + 't': 'unsigned short', + 'j': 'unsigned int', + 'm': 'unsigned long', + 'x': 'long long', + 'y': 'unsigned long long', + 'z': '...' + }; + var subs = []; + var first = true; + function dump(x) { + //return; + if (x) Module.print(x); + Module.print(func); + var pre = ''; + for (var a = 0; a < i; a++) pre += ' '; + Module.print (pre + '^'); + } + function parseNested() { + i++; + if (func[i] === 'K') i++; // ignore const + var parts = []; + while (func[i] !== 'E') { + if (func[i] === 'S') { // substitution + i++; + var next = func.indexOf('_', i); + var num = func.substring(i, next) || 0; + parts.push(subs[num] || '?'); + i = next+1; + continue; + } + if (func[i] === 'C') { // constructor + parts.push(parts[parts.length-1]); + i += 2; + continue; + } + var size = parseInt(func.substr(i)); + var pre = size.toString().length; + if (!size || !pre) { i--; break; } // counter i++ below us + var curr = func.substr(i + pre, size); + parts.push(curr); + subs.push(curr); + i += pre + size; + } + i++; // skip E + return parts; + } + function parse(rawList, limit, allowVoid) { // main parser + limit = limit || Infinity; + var ret = '', list = []; + function flushList() { + return '(' + list.join(', ') + ')'; + } + var name; + if (func[i] === 'N') { + // namespaced N-E + name = parseNested().join('::'); + limit--; + if (limit === 0) return rawList ? [name] : name; + } else { + // not namespaced + if (func[i] === 'K' || (first && func[i] === 'L')) i++; // ignore const and first 'L' + var size = parseInt(func.substr(i)); + if (size) { + var pre = size.toString().length; + name = func.substr(i + pre, size); + i += pre + size; + } + } + first = false; + if (func[i] === 'I') { + i++; + var iList = parse(true); + var iRet = parse(true, 1, true); + ret += iRet[0] + ' ' + name + '<' + iList.join(', ') + '>'; + } else { + ret = name; + } + paramLoop: while (i < func.length && limit-- > 0) { + //dump('paramLoop'); + var c = func[i++]; + if (c in basicTypes) { + list.push(basicTypes[c]); + } else { + switch (c) { + case 'P': list.push(parse(true, 1, true)[0] + '*'); break; // pointer + case 'R': list.push(parse(true, 1, true)[0] + '&'); break; // reference + case 'L': { // literal + i++; // skip basic type + var end = func.indexOf('E', i); + var size = end - i; + list.push(func.substr(i, size)); + i += size + 2; // size + 'EE' + break; + } + case 'A': { // array + var size = parseInt(func.substr(i)); + i += size.toString().length; + if (func[i] !== '_') throw '?'; + i++; // skip _ + list.push(parse(true, 1, true)[0] + ' [' + size + ']'); + break; + } + case 'E': break paramLoop; + default: ret += '?' + c; break paramLoop; + } + } + } + if (!allowVoid && list.length === 1 && list[0] === 'void') list = []; // avoid (void) + return rawList ? list : ret + flushList(); + } try { // Special-case the entry point, since its name differs from other name mangling. if (func == 'Object._main' || func == '_main') { @@ -696,130 +820,6 @@ function demangle(func) { case 'n': return 'operator new()'; case 'd': return 'operator delete()'; } - var i = 3; - // params, etc. - var basicTypes = { - 'v': 'void', - 'b': 'bool', - 'c': 'char', - 's': 'short', - 'i': 'int', - 'l': 'long', - 'f': 'float', - 'd': 'double', - 'w': 'wchar_t', - 'a': 'signed char', - 'h': 'unsigned char', - 't': 'unsigned short', - 'j': 'unsigned int', - 'm': 'unsigned long', - 'x': 'long long', - 'y': 'unsigned long long', - 'z': '...' - }; - function dump(x) { - //return; - if (x) Module.print(x); - Module.print(func); - var pre = ''; - for (var a = 0; a < i; a++) pre += ' '; - Module.print (pre + '^'); - } - var subs = []; - function parseNested() { - i++; - if (func[i] === 'K') i++; // ignore const - var parts = []; - while (func[i] !== 'E') { - if (func[i] === 'S') { // substitution - i++; - var next = func.indexOf('_', i); - var num = func.substring(i, next) || 0; - parts.push(subs[num] || '?'); - i = next+1; - continue; - } - if (func[i] === 'C') { // constructor - parts.push(parts[parts.length-1]); - i += 2; - continue; - } - var size = parseInt(func.substr(i)); - var pre = size.toString().length; - if (!size || !pre) { i--; break; } // counter i++ below us - var curr = func.substr(i + pre, size); - parts.push(curr); - subs.push(curr); - i += pre + size; - } - i++; // skip E - return parts; - } - var first = true; - function parse(rawList, limit, allowVoid) { // main parser - limit = limit || Infinity; - var ret = '', list = []; - function flushList() { - return '(' + list.join(', ') + ')'; - } - var name; - if (func[i] === 'N') { - // namespaced N-E - name = parseNested().join('::'); - limit--; - if (limit === 0) return rawList ? [name] : name; - } else { - // not namespaced - if (func[i] === 'K' || (first && func[i] === 'L')) i++; // ignore const and first 'L' - var size = parseInt(func.substr(i)); - if (size) { - var pre = size.toString().length; - name = func.substr(i + pre, size); - i += pre + size; - } - } - first = false; - if (func[i] === 'I') { - i++; - var iList = parse(true); - var iRet = parse(true, 1, true); - ret += iRet[0] + ' ' + name + '<' + iList.join(', ') + '>'; - } else { - ret = name; - } - paramLoop: while (i < func.length && limit-- > 0) { - //dump('paramLoop'); - var c = func[i++]; - if (c in basicTypes) { - list.push(basicTypes[c]); - } else { - switch (c) { - case 'P': list.push(parse(true, 1, true)[0] + '*'); break; // pointer - case 'R': list.push(parse(true, 1, true)[0] + '&'); break; // reference - case 'L': { // literal - i++; // skip basic type - var end = func.indexOf('E', i); - var size = end - i; - list.push(func.substr(i, size)); - i += size + 2; // size + 'EE' - break; - } - case 'A': { // array - var size = parseInt(func.substr(i)); - i += size.toString().length; - if (func[i] !== '_') throw '?'; - i++; // skip _ - list.push(parse(true, 1, true)[0] + ' [' + size + ']'); - break; - } - case 'E': break paramLoop; - default: ret += '?' + c; break paramLoop; - } - } - } - if (!allowVoid && list.length === 1 && list[0] === 'void') list = []; // avoid (void) - return rawList ? list : ret + flushList(); - } return parse(); } catch(e) { return func; -- cgit v1.2.3-18-g5258