aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlon Zakai <alonzakai@gmail.com>2011-08-07 21:35:17 -0700
committerAlon Zakai <alonzakai@gmail.com>2011-08-07 21:35:17 -0700
commit7172aacb563367fae198c25743827ef1195083aa (patch)
tree6681cb0ce8a247e79f7f5fbe4c2b252f3248187a
parent19d18fbffd8f79bbe7cece5806903b2a6c1561e9 (diff)
filesystem workaround for closure compiler, +closure compiler test
-rw-r--r--src/library.js28
-rw-r--r--tests/runner.py22
2 files changed, 39 insertions, 11 deletions
diff --git a/src/library.js b/src/library.js
index 4d7e95b3..e2d75f84 100644
--- a/src/library.js
+++ b/src/library.js
@@ -25,16 +25,6 @@ LibraryManager.library = {
$FS__deps: ['$ERRNO_CODES', '__setErrNo', 'stdin', 'stdout', 'stderr'],
$FS__postset: 'FS.init();',
$FS: {
- // The main file system tree. All the contents are inside this.
- root: {
- read: true,
- write: false,
- isFolder: true,
- isDevice: false,
- timestamp: Date.now(),
- inodeNumber: 1,
- contents: {}
- },
// The path to the current folder.
currentPath: '/',
// The inode to assign to the next created object.
@@ -145,6 +135,7 @@ LibraryManager.library = {
// set to true and the object is a symbolic link, it will be returned as is
// instead of being resolved. Links embedded in the path as still resolved.
findObject: function(path, dontResolveLastLink) {
+ FS.ensureRoot();
var ret = FS.analyzePath(path, dontResolveLastLink);
if (ret.exists) {
return ret.object;
@@ -286,12 +277,27 @@ LibraryManager.library = {
if (!success) ___setErrNo(ERRNO_CODES.EIO);
return success;
},
+ ensureRoot: function() {
+ if (FS.root) return;
+ // The main file system tree. All the contents are inside this.
+ FS.root = {
+ read: true,
+ write: false,
+ isFolder: true,
+ isDevice: false,
+ timestamp: Date.now(),
+ inodeNumber: 1,
+ contents: {}
+ };
+ },
// Initializes the filesystems with stdin/stdout/stderr devices, given
// optional handlers.
init: function(input, output, error) {
// Make sure we initialize only once.
if (FS.init.initialized) return;
- else FS.init.initialized = true;
+ FS.init.initialized = true;
+
+ FS.ensureRoot();
// Default handlers.
if (!input) input = function() {
diff --git a/tests/runner.py b/tests/runner.py
index abbedd70..ebebfc16 100644
--- a/tests/runner.py
+++ b/tests/runner.py
@@ -3343,6 +3343,28 @@ Child2:9
### Tests for tools
+ def test_closure_compiler(self):
+ src = '''
+ #include<stdio.h>
+ int main() {
+ printf("*closured*\\n");
+ return 0;
+ }
+ '''
+
+ def add_cc(filename):
+ Popen(['java', '-jar', CLOSURE_COMPILER,
+ '--compilation_level', 'ADVANCED_OPTIMIZATIONS',
+ '--formatting', 'PRETTY_PRINT',
+ '--variable_map_output_file', filename + '.vars',
+ '--js', filename, '--js_output_file', filename + '.cc.js'], stdout=PIPE, stderr=STDOUT).communicate()
+ assert not re.search('function \w\(', open(filename, 'r').read()) # closure generates this kind of stuff - functions with single letters. Normal doesn't.
+ src = open(filename + '.cc.js', 'r').read()
+ assert re.search('function \w\(', src) # see before
+ assert 'function _main()' not in src # closure should have wiped it out
+ open(filename, 'w').write(src)
+ self.do_test(src, '*closured*', post_build=add_cc)
+
def test_safe_heap(self):
global SAFE_HEAP, SAFE_HEAP_LINES