aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormax99x <max99x@gmail.com>2011-08-26 01:31:20 +0300
committermax99x <max99x@gmail.com>2011-08-26 01:32:36 +0300
commitb7fcc0e14805f1ef5d0cd70d8d237a005379c73d (patch)
tree3e6e2bc3d54a0ddac924cc32a06b47bfddc6a85e
parent1d3e667d6b06402e33c20c93d044a8694790435e (diff)
Switched from "var x = function x() {}" to plain "function x() {}" for lib functions.
-rw-r--r--src/jsifier.js10
-rw-r--r--tests/runner.py8
2 files changed, 11 insertions, 7 deletions
diff --git a/src/jsifier.js b/src/jsifier.js
index 94f78134..ab381a03 100644
--- a/src/jsifier.js
+++ b/src/jsifier.js
@@ -285,6 +285,7 @@ function JSify(data, functionsOnly, givenFunctions, givenGlobalVariables) {
var snippet = LibraryManager.library[ident];
var redirectedIdent = null;
var deps = LibraryManager.library[ident + '__deps'] || [];
+ var isFunction = false;
if (typeof snippet === 'string') {
if (LibraryManager.library[snippet]) {
@@ -309,10 +310,10 @@ function JSify(data, functionsOnly, givenFunctions, givenGlobalVariables) {
snippet = '{' + members.join(', ') + ' }';
}
} else if (typeof snippet === 'function') {
+ isFunction = true;
snippet = snippet.toString();
- if (/function ?\(/.exec(snippet)) { // name the function, if not already named
- snippet = snippet.replace('function', 'function _' + ident);
- }
+ // name the function; overwrite if it's already named
+ snippet = snippet.replace(/function(?:\s+([^(]+))?\s*\(/, 'function _' + ident + '(');
}
var postsetId = ident + '__postset';
@@ -334,7 +335,8 @@ function JSify(data, functionsOnly, givenFunctions, givenGlobalVariables) {
} else {
ident = '_' + ident;
}
- var text = (deps ? '\n' + deps.map(addFromLibrary).join('\n') : '') + 'var ' + ident + '=' + snippet + ';';
+ var text = (deps ? '\n' + deps.map(addFromLibrary).join('\n') : '');
+ text += isFunction ? snippet : 'var ' + ident + '=' + snippet + ';';
if (ident in EXPORTED_FUNCTIONS) {
text += '\nModule["' + ident + '"] = ' + ident + ';';
}
diff --git a/tests/runner.py b/tests/runner.py
index 907e2c91..d3d483de 100644
--- a/tests/runner.py
+++ b/tests/runner.py
@@ -3674,9 +3674,11 @@ Child2:9
try:
def post(filename):
lines = open(filename, 'r').readlines()
- line = filter(lambda line: '___assert_fail(' in line, lines)[0]
- assert '//@line 7 "' in line, 'Must have debug info with the line number'
- assert 'src.cpp"\n' in line, 'Must have debug info with the filename'
+ lines = filter(lambda line: '___assert_fail(' in line, lines)
+ found_line_num = any(('//@line 7 "' in line) for line in lines)
+ found_filename = any(('src.cpp"\n' in line) for line in lines)
+ assert found_line_num, 'Must have debug info with the line number'
+ assert found_filename, 'Must have debug info with the filename'
self.do_test(src, '*nothingatall*', post_build=post)
except Exception, e:
# This test *should* fail