aboutsummaryrefslogtreecommitdiff
path: root/test/sandbox.js
blob: 2f9ec6771d7bbcc9dd82ae4560e60e828d8bd753 (about) (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
var semver = require("semver");
var vm = require("vm");

var setupContext = new vm.Script([
    "[ Array, Boolean, Error, Function, Number, Object, RegExp, String ].forEach(function(f) {",
    "    f.toString = Function.prototype.toString;",
    "});",
    "Function.prototype.toString = function() {",
    "    var id = 100000;",
    "    return function() {",
    "        var n = this.name;",
    "        if (!/^F[0-9]{6}N$/.test(n)) {",
    '            n = "F" + ++id + "N";',
].concat(Object.getOwnPropertyDescriptor(Function.prototype, "name").configurable ? [
    '            Object.defineProperty(this, "name", {',
    "                get: function() {",
    "                    return n;",
    "                }",
    "            });",
] : [], [
    "        }",
    '        return "function(){}";',
    "    };",
    "}();",
    "this;",
]).join("\n"));

function createContext() {
    var ctx = vm.createContext(Object.defineProperty({}, "console", { value: { log: log } }));
    var global = setupContext.runInContext(ctx);
    return ctx;

    function safe_log(arg, level) {
        if (arg) switch (typeof arg) {
        case "function":
            return arg.toString();
        case "object":
            if (arg === global) return "[object global]";
            if (/Error$/.test(arg.name)) return arg.toString();
            arg.constructor.toString();
            if (level--) for (var key in arg) {
                var desc = Object.getOwnPropertyDescriptor(arg, key);
                if (!desc || !desc.get) arg[key] = safe_log(arg[key], level);
            }
        }
        return arg;
    }

    function log(msg) {
        if (arguments.length == 1 && typeof msg == "string") return console.log("%s", msg);
        return console.log.apply(console, [].map.call(arguments, function(arg) {
            return safe_log(arg, 3);
        }));
    }
}

exports.run_code = function(code, toplevel, timeout) {
    timeout = timeout || 5000;
    var stdout = "";
    var original_write = process.stdout.write;
    process.stdout.write = function(chunk) {
        stdout += chunk;
    };
    try {
        vm.runInContext(toplevel ? "(function(){" + code + "})()" : code, createContext(), { timeout: timeout });
        return stdout;
    } catch (ex) {
        return ex;
    } finally {
        process.stdout.write = original_write;
    }
};

function strip_func_ids(text) {
    return ("" + text).replace(/F[0-9]{6}N/g, "<F<>N>");
}

exports.same_stdout = semver.satisfies(process.version, "0.12") ? function(expected, actual) {
    if (typeof expected != typeof actual) return false;
    if (typeof expected == "object" && typeof expected.name == "string" && typeof expected.message == "string") {
        if (expected.name !== actual.name) return false;
        if (typeof actual.message != "string") return false;
        expected = expected.message.slice(expected.message.lastIndexOf("\n") + 1);
        actual = actual.message.slice(actual.message.lastIndexOf("\n") + 1);
    }
    return strip_func_ids(expected) == strip_func_ids(actual);
} : function(expected, actual) {
    return typeof expected == typeof actual && strip_func_ids(expected) == strip_func_ids(actual);
};
exports.has_toplevel = function(options) {
    return options.toplevel
        || options.mangle && options.mangle.toplevel
        || options.compress && options.compress.toplevel;
};
1:02:45 +0200'>2015-05-17gnu: libpagemaker: Rename duplicate 'native-inputs' field....* gnu/packages/libreoffice.scm (libpagemaker): Rename duplicate 'native-inputs' field to 'propagated-inputs'. Corrects commit 86d648e. Andreas Enge 2015-05-16gnu: libwps: Propagate input....* gnu/packages/libreoffice.scm (libwps): Move librevenge from 'inputs' to 'propagated-inputs'. Andreas Enge 2015-05-16gnu: libmwaw: Propagate input....* gnu/packages/libreoffice.scm (libmwaw): Move librevenge from 'inputs' to 'propagated-inputs'. Andreas Enge 2015-05-16gnu: libodfgen: Propagate input....* gnu/packages/libreoffice.scm (libodfgen): Move librevenge from 'inputs' to 'propagated-inputs'. Andreas Enge 2015-05-16gnu: libvisio: Propagate inputs....* gnu/packages/libreoffice.scm (libvisio): Move icu4c, librevenge and libxml2 from 'inputs' to 'propagated-inputs'. Andreas Enge 2015-05-16gnu: libpagemaker: Propagate input....* gnu/packages/libreoffice.scm (libpagemaker): Move librevenge from 'inputs' to 'propagated-inputs'. Andreas Enge 2015-05-16gnu: libmspub: Propagate inputs....* gnu/packages/libreoffice.scm (libmspub): Move icu4c, librevenge and zlib from 'inputs' to 'propagated-inputs'. Andreas Enge 2015-05-16gnu: libfreehand: Propagate inputs....* gnu/packages/libreoffice.scm (libfreehand): Move librevenge and zlib from 'inputs' to 'propagated-inputs'. Andreas Enge 2015-05-16gnu: libetonyek: Propagate inputs....* gnu/packages/libreoffice.scm (libetonyek): Move librevenge and libxml2 from 'inputs' to 'propagated-inputs'. Andreas Enge 2015-05-16gnu: libcdr: Propagate inputs....* gnu/packages/libreoffice.scm (libcdr): Move icu4c, lcms, librevenge and zlib from 'inputs' to 'propagated-inputs'. Andreas Enge 2015-05-16gnu: libabw: Propagate inputs....* gnu/packages/libreoffice.scm (libabw): Move librevenge and libxml2 from 'inputs' to 'propagated-inputs'. Andreas Enge 2015-05-16gnu: libcmis: Propagate inputs....* gnu/packages/libreoffice.scm (libcmis): Move curl and libxml2 from 'inputs' to 'propagated-inputs'. Andreas Enge 2015-05-16gnu: libwpg: Propagate input....* gnu/packages/libreoffice.scm (libwpg): Move libwpg from 'inputs' to 'propagated-inputs'. Andreas Enge 2015-05-16gnu: libe-book: Propagate inputs....* gnu/packages/libreoffice.scm (libe-book): Move icu4c, librevenge and libxml2 from 'inputs' to 'propagated-inputs'. Andreas Enge 2015-05-16gnu: libwpd: Propagate input....* gnu/packages/libreoffice.scm (libwpd): Move librevenge from 'inputs' to 'propagated-inputs'. * gnu/packages/libreoffice.scm (libwpg)[inputs]: Drop librevenge. Andreas Enge 2015-05-14gnu: Add libcmis....* gnu/packages/libreoffice.scm (libcmis): New variable. Co-authored-by: John Darrington <jmd@gnu.org> Andreas Enge 2015-05-11gnu: Add MyThes....* gnu/packages/libreoffice.scm (mythes): New variable. Andreas Enge 2015-05-11gnu: Add hyphen....* gnu/packages/libreoffice.scm (hyphen): New variable. Andreas Enge 2015-05-11gnu: Add hunspell....* gnu/packages/libreoffice.scm (hunspell): New variable. Andreas Enge 2015-05-07gnu: Add libwps....* gnu/packages/libreoffice.scm (libwps): New variable. Andreas Enge 2015-05-07gnu: Add libmwaw....* gnu/packages/libreoffice.scm (libmwaw): New variable. Andreas Enge 2015-05-07gnu: Add libodfgen....* gnu/packages/libreoffice.scm (libodfgen): New variable. Andreas Enge 2015-05-06gnu: Add libvisio....* gnu/packages/libreoffice.scm (libvisio): New variable. Andreas Enge 2015-05-06gnu: Add libpagemaker....* gnu/packages/libreoffice.scm (libpagemaker): New variable. Andreas Enge 2015-05-06gnu: Add libmspub....* gnu/packages/libreoffice.scm (libmspub): New variable. Andreas Enge 2015-05-06gnu: Add libfreehand....* gnu/packages/libreoffice.scm (libfreehand): New variable. Andreas Enge 2015-05-06gnu: Add libexttextcat....* gnu/packages/libreoffice.scm (libexttextcat): New variable. Andreas Enge 2015-05-06gnu: Add libetonyek....* gnu/packages/libreoffice.scm (libetonyek): New variable. Andreas Enge 2015-05-06gnu: Add libcdr....* gnu/packages/libreoffice.scm (libcdr): New variable. Andreas Enge 2015-05-06gnu: Add libabw....* gnu/packages/libreoffice.scm (libabw): New variable. Andreas Enge 2015-05-05gnu: librevenge, libwpd, libwpg: Fix 'license' field....* gnu/packages/libreoffice.scm (librevenge, libwpd, libwpg): Fix 'license' field to be a list of <license>. Ludovic Courtès 2015-05-04gnu: Add libwpg....* gnu/packages/libreoffice.scm (libwpg): New variable. Andreas Enge 2015-05-03gnu: Add libe-book....* gnu/packages/libreoffice.scm (libe-book): New variable. Co-authored-by: John Darrington <jmd@gnu.org> Andreas Enge 2015-05-03gnu: Add libwpd....* gnu/packages/libreoffice.scm (libwpd): New variable. Andreas Enge 2015-05-03gnu: Add librevenge....* gnu/packages/libreoffice.scm (librevenge): New variable. Co-authored-by: John Darrington <jmd@gnu.org> Andreas Enge 2015-04-30gnu: Add orcus....* gnu/packages/libreoffice.scm (orcus): New variable. Andreas Enge 2015-04-27gnu: Add ixion....* gnu/packages/libreoffice.scm: New file. * gnu-system.am (GNU_SYSTEM_MODULES): Add it. Co-authored-by: John Darrington <jmd@gnu.org> Andreas Enge