Пример #1
0
function read () {
    var IO = require('../../lib/jison/util/io');
    try {
        return IO.read(IO.join.apply(IO,[__dirname].concat([].slice.call(arguments,0))));
    } catch(e) {
        var fs = require("file");
        return fs.path(fs.dirname(module.id)).join.apply(fs.path(fs.dirname(module.id)),arguments)
            .read({charset: "utf-8"});
    }
}
Пример #2
0
exports["test lex grammar bootstrap"] = function () {
    var fs = require("file");

    var lexgrammar = lex.parse(fs.path(fs.dirname(module.id))
            .join('lex', 'lex_grammar.jisonlex')
            .read({charset: "utf-8"}));

    var expected = JSON.parse(fs.path(fs.dirname(module.id))
            .join('lex', 'lex_grammar.lex.json')
            .read({charset: "utf-8"}));

    assert.deepEqual(lexgrammar, expected, "grammar should be parsed correctly");
};
exports.testDispatchTrivialEvent = function(test) {
  var file = require("file");
  var url = require("url");
  var mydir = file.dirname(url.toFilename(__url__));
  var indexUrl = url.fromFilename(file.join(mydir, "test-tab-events.html"));

  var tracker = tabBrowser.whenContentLoaded(
    function(window) {
      if (window.location == indexUrl) {
        function checkGotFoo() {
          test.assertEqual(window.wrappedJSObject.gotFoo, true,
                           "foo event should have been dispatched");
          window.close();
          timer.setTimeout(function() {
                             tracker.unload();
                             test.done();
                           }, ARB_TIMEOUT);
        }

        test.assertEqual(window.wrappedJSObject.gotFoo, false,
                         "foo event should not have been dispatched yet");

        timer.setTimeout(function() {
                           tabEvents.dispatchTrivialEvent("foo");
                           timer.setTimeout(checkGotFoo, 10);
                         }, 10);
      }
    });

  tabBrowser.addTab(indexUrl);
  test.waitUntilDone(5000);
};
Пример #4
0
            aTask.prerequisites().forEach(function(aFilename)
            {
                // Our prerequisites will contain directories due to filedir.
                if (!FILE.isFile(aFilename))
                    return;

                var dirname = FILE.dirname(aFilename);

                if (aFilename.indexOf(sourcesPath) === 0)
                {
                    var relativePath = flattensSources ? FILE.basename(aFilename) : FILE.relative(sourcesPath, aFilename);

                    // FIXME: We need to do this for now due to file.read adding newlines in Rhino. Revert when fixed.
                    //fileStream.write(FILE.read(aFilename, "b").decodeToString("UTF-8"));
                    fileStream.write("p;" + relativePath.length + ";" + relativePath);

                    var fileContents = FILE.read(aFilename, "b").decodeToString("UTF-8");

                    fileStream.write("t;" + fileContents.length + ";" + fileContents);
                }

                else if (aFilename.indexOf(resourcesPath) === 0 && !isImage(aFilename))
                {
                    var resourcePath = "Resources/" + FILE.relative(resourcesPath, aFilename);

                    fileStream.write("p;");

                    contents = FILE.read(aFilename, "b").decodeToString("UTF-8");

                    fileStream.write(resourcePath.length + ";" + resourcePath + contents);
                }
            }, this);
Пример #5
0
            aTask.prerequisites().forEach(function(aFilename)
            {

                if (!FILE.isFile(aFilename))
                    return;

                var dirname = FILE.dirname(aFilename);

                if (aFilename.indexOf(sourcesPath) === 0)
                {
                    var relativePath = flattensSources ? FILE.basename(aFilename) : FILE.relative(sourcesPath, aFilename);



                    fileStream.write("p;" + relativePath.length + ";" + relativePath);

                    var fileContents = FILE.read(aFilename, "b").decodeToString("UTF-8");

                    fileStream.write("t;" + fileContents.length + ";" + fileContents);
                }

                else if (aFilename.indexOf(resourcesPath) === 0 && !isImage(aFilename))
                {
                    var resourcePath = "Resources/" + FILE.relative(resourcesPath, aFilename);

                    fileStream.write("p;");

                    contents = FILE.read(aFilename, "b").decodeToString("UTF-8");

                    fileStream.write(resourcePath.length + ";" + resourcePath + contents);
                }
            }, this);
Пример #6
0
exports.resolve = function (id, baseId) {
    id = String(id);
    if (id.charAt(0) == ".") {
        id = (baseId ? file.dirname(baseId) : file.cwd()) + "/" + id;
    }
    // module ids need to use forward slashes, despite what the OS might say
    return file.normal(id).replace(/\\/g, '/');
};
Пример #7
0
exports.filedir = function()
{
    var fileTask = FileTask.defineTask.apply(FileTask, arguments),
        fileDirectory = FILE.dirname(fileTask.name());

    exports.directory (fileDirectory);
    exports.file (fileTask.name(), fileDirectory);
}
Пример #8
0
exports["test ANSI C lexical grammar"] = function () {
    var fs = require("file");

    var lexgrammar = lex.parse(fs.path(fs.dirname(module.id))
            .join('lex', 'ansic.jisonlex')
            .read({charset: "utf-8"}));

    assert.ok(lexgrammar, "grammar should be parsed correctly");
};
Пример #9
0
function readVersion () {
    var pack;
    try {
        pack = IO.read(IO.join(__dirname,'..','..','package.json'));
    } catch(e) {
        var fs = require("file");
        pack = fs.path(fs.dirname(module.id)).canonical().join('..','package.json')
            .read({charset: "utf-8"});
    }
    return JSON.parse(pack).version;
}
Пример #10
0
    CFHTTPRequest.prototype.responseText = function ()
    {
        if (this._URL.slice(-2) === ".j")
        {
            var tmpFile = FILE.canonical(FILE.join(FILE.dirname(this._URL.split(":")[1]), ".detect_missing_imports"));

            // hackishly give the file a window object
            FILE.write(tmpFile, "window = {};\n" + this._nativeRequest.responseText);
            var result = cPreprocessedFileContents(tmpFile);
            FILE.remove(tmpFile);
        }
        else
            result = this._nativeRequest.responseText;
        return result;
    };
exports.testBasic = function(test) {
  var manager = require("json-channel").createManager("boop");
  var file = require("file");
  var url = require("url");
  var mydir = file.dirname(url.toFilename(__url__));
  var indexUrl = url.fromFilename(file.join(mydir, "test-json-channel.html"));

  var tracker = tabBrowser.whenContentLoaded(
    function(window) {
      if (window.location == indexUrl) {
        var foo = window.document.getElementById("foo");
        var channel = manager.addChannel(window);
        channel.whenMessaged(
          function(data) {
            test.assertEqual(data, "HAI2u!",
                             "chrome channel.whenMessaged() works.");
            channel.send("O YEA!");
            timer.setTimeout(
              function() {
                test.assertEqual(foo.textContent,
                                 'got "O YEA!"',
                                 "content channel.whenMessaged works.");
                test.assertEqual(manager.channels.length,
                                 1,
                                 "channel count is correct");
                window.close();
                timer.setTimeout(function() {
                                   test.assertEqual(
                                     manager.channels.length,
                                     0,
                                     "channel closed on window close"
                                   );
                                   manager.unload();
                                   tracker.unload();
                                   test.done();
                                 }, ARB_TIMEOUT);
              },
              ARB_TIMEOUT);
            return {msg: 'gotcha'};
          });
      }
    });

  tabBrowser.addTab(indexUrl);
  test.waitUntilDone(5000);
};
Пример #12
0
exports.directory = function(aDirectory)
{
    var oldLength = null;

    while (aDirectory !== "." && aDirectory.length !== oldLength)
    {
        exports.fileCreate(aDirectory, function(aTask)
        {
            var taskName = aTask.name();

            if (!FILE.exists(taskName))
                FILE.mkdirs(taskName);
        });

        oldLength = aDirectory.length;
        aDirectory = FILE.dirname(aDirectory);
    }
}
Пример #13
0
    filenames.forEach(function(aFilename)
    {
        var directory = FILE.dirname(aFilename);

        if (directory === ".")
            directory = "";

        // Empty string is an acceptable common directory.
        if (aCommonDirectory === null)
            aCommonDirectory = directory;

        else
        {
            var index = 0,
                count = Math.min(directory.length, aFilename.length);

            for (; index < count && aCommonDirectory.charAt(index) === directory.charAt(index); ++index) ;

            aCommonDirectory = directory.substr(0, index);
        }
    });
Пример #14
0
function multipartFile(name) {
    return File.join(File.dirname(module.path), "multipart", name);
}
Пример #15
0
 getApplicationRoot: function getApplicationRoot()
 {
     var root = file.join(file.dirname(system.args[0]), 'app');
     print("ActiveController getApplicationRoot="+root)
     return root;
 }
Пример #16
0
 exports['test ' + util.repr(path)] = function () {
     var actual = fs.dirname(path);
     assert.eq(expected, actual, util.repr(path));
 };
Пример #17
0
function multipart_file(name) {
    return File.join(File.dirname(require.fileName), "multipart", name);
}
Пример #18
0
    {
        if (!anEnvironment.spritesImages())
            return;

        filedir (infoPlistProductPath, this.buildProductStaticPathForEnvironment(anEnvironment));
    }, this);

    this.enhance([infoPlistProductPath]);
}

BundleTask.License  =   {
                            LGPL_v2_1   : "LGPL_v2_1",
                            MIT         : "MIT"
                        };

var LICENSES_PATH   = FILE.join(FILE.absolute(FILE.dirname(module.path)), "LICENSES"),
    LICENSE_PATHS   =   {
                            "LGPL_v2_1" : FILE.join(LICENSES_PATH, "LGPL-v2.1"),
                            "MIT"       : FILE.join(LICENSES_PATH, "MIT")
                        };

BundleTask.prototype.defineLicenseTask = function()
{
    var license = this.license();

    if (!license)
        return;

    var licensePath = LICENSE_PATHS[license];
        licenseProductPath = FILE.join(this.buildProductPath(), "LICENSE");
Пример #19
0
BundleTask.prototype.defineResourceTask = function(aResourcePath, aDestinationPath)
{
    if (this.spritesResources() && BundleTask.isSpritable(aResourcePath))
    {
        this.environments().forEach(function(/*Environment*/ anEnvironment)
        {
            if (!anEnvironment.spritesImages())
                return;

            var folder = anEnvironment.name() + ".environment",
                spritedDestinationPath = FILE.join(this.buildIntermediatesProductPath(), folder, "Resources", FILE.relative(this.resourcesPath(), aDestinationPath));

            filedir (spritedDestinationPath, function()
            {
                FILE.write(spritedDestinationPath, base64.encode(FILE.read(aResourcePath, "b")), { charset:"UTF-8" });
            });

            filedir (this.buildProductDataURLPathForEnvironment(anEnvironment), [spritedDestinationPath]);
            filedir (this.buildProductMHTMLPathForEnvironment(anEnvironment), [spritedDestinationPath]);
            filedir (this.buildProductMHTMLDataPathForEnvironment(anEnvironment), [spritedDestinationPath]);
            filedir (this.buildProductMHTMLTestPathForEnvironment(anEnvironment), [spritedDestinationPath]);

        }, this);
    }

    var extension = FILE.extension(aResourcePath),
        extensionless = aResourcePath.substr(0, aResourcePath.length - extension.length);
    // NOT:
    // (extname === ".cib" && (FILE.exists(extensionless + '.xib') || FILE.exists(extensionless + '.nib') && !this._preventsNib2Cib) ||
    // (extname === ".xib" || extname === ".nib") && !this.shouldIncludeNibsAndXibs())
    if ((extension !== ".cib" || !FILE.exists(extensionless + ".xib") && !FILE.exists(extensionless + ".nib") || this._preventsNib2Cib) &&
        ((extension !== ".xib" && extension !== ".nib") || this.includesNibsAndXibs()))
    {
        filedir (aDestinationPath, [aResourcePath], function()
        {
            if (FILE.exists(aDestinationPath))
                try { FILE.rmtree(aDestinationPath); } catch (anException) { }

            if (FILE.isDirectory(aResourcePath))
                FILE.copyTree(aResourcePath, aDestinationPath);
            else
                FILE.copy(aResourcePath, aDestinationPath);
        });

        this.enhance([aDestinationPath]);
    }

    if ((extension === ".xib" || extension === ".nib") && !this._preventsNib2Cib)
    {
        var cibDestinationPath = FILE.join(FILE.dirname(aDestinationPath), FILE.basename(aDestinationPath, extension)) + ".cib";

        var nib2cibFlags = this.nib2cibFlags();

        if (!nib2cibFlags)
            nib2cibFlags = "";

        else if (nib2cibFlags.join)
            nib2cibFlags = nib2cibFlags.join(" ");

        filedir (cibDestinationPath, [aResourcePath], function()
        {
            OS.system("nib2cib " + aResourcePath + " "  + cibDestinationPath + " " + nib2cibFlags);
        });

        this.enhance([cibDestinationPath]);
    }
}
Пример #20
0
// Adapted from https://developer.mozilla.org/En/Using_web_workers

var FILE = require("file"),
    Worker = require("worker").Worker;

var worker = new Worker(FILE.join(FILE.dirname(module.path), "fibonacci-worker.js"));  

worker.onmessage = function(event) {  
    print("Got: " + event.data);  
}

worker.onerror = function(error) {  
    print("Worker error: " + error.message);  
}

worker.postMessage(5);

// event loop
while(true) require("event-queue").nextEvent()();