[Pkg-javascript-commits] [uglifyjs] 26/190: No longer use `vm` to load code.

Antonio Terceiro terceiro at moszumanska.debian.org
Sun Aug 7 23:17:10 UTC 2016


This is an automated email from the git hooks/post-receive script.

terceiro pushed a commit to annotated tag upstream/2.7.0
in repository uglifyjs.

commit 99233c44cc125fa1a96a47b863dbfb3ec0c3fadc
Author: Mihai Bazon <mihai.bazon at gmail.com>
Date:   Thu Sep 24 17:57:47 2015 +0300

    No longer use `vm` to load code.
    
    Improves performance 2x on node > 0.10.
    
    Ref #636
---
 bin/uglifyjs     |  1 -
 lib/ast.js       |  1 +
 tools/exports.js | 16 ++++++++++++++++
 tools/node.js    | 40 ++++++++++------------------------------
 4 files changed, 27 insertions(+), 31 deletions(-)

diff --git a/bin/uglifyjs b/bin/uglifyjs
index 4768f76..fbb053d 100755
--- a/bin/uglifyjs
+++ b/bin/uglifyjs
@@ -254,7 +254,6 @@ if (ARGS.self) {
     }
     files = UglifyJS.FILES;
     if (!ARGS.wrap) ARGS.wrap = "UglifyJS";
-    ARGS.export_all = true;
 }
 
 var ORIG_MAP = ARGS.in_source_map;
diff --git a/lib/ast.js b/lib/ast.js
index c317670..c5ec816 100644
--- a/lib/ast.js
+++ b/lib/ast.js
@@ -81,6 +81,7 @@ function DEFNODE(type, props, methods, base) {
     ctor.DEFMETHOD = function(name, method) {
         this.prototype[name] = method;
     };
+    exports["AST_" + type] = ctor;
     return ctor;
 };
 
diff --git a/tools/exports.js b/tools/exports.js
new file mode 100644
index 0000000..a27cef9
--- /dev/null
+++ b/tools/exports.js
@@ -0,0 +1,16 @@
+exports["Compressor"] = Compressor;
+exports["DefaultsError"] = DefaultsError;
+exports["Dictionary"] = Dictionary;
+exports["JS_Parse_Error"] = JS_Parse_Error;
+exports["MAP"] = MAP;
+exports["OutputStream"] = OutputStream;
+exports["SourceMap"] = SourceMap;
+exports["TreeTransformer"] = TreeTransformer;
+exports["TreeWalker"] = TreeWalker;
+exports["base54"] = base54;
+exports["defaults"] = defaults;
+exports["mangle_properties"] = mangle_properties;
+exports["merge"] = merge;
+exports["parse"] = parse;
+exports["push_uniq"] = push_uniq;
+exports["string_template"] = string_template;
diff --git a/tools/node.js b/tools/node.js
index eba2bc1..f604866 100644
--- a/tools/node.js
+++ b/tools/node.js
@@ -1,26 +1,5 @@
 var path = require("path");
 var fs = require("fs");
-var vm = require("vm");
-
-var UglifyJS = vm.createContext({
-    console       : console,
-    process       : process,
-    Buffer        : Buffer,
-    MOZ_SourceMap : require("source-map")
-});
-
-function load_global(file) {
-    file = path.resolve(path.dirname(module.filename), file);
-    try {
-        var code = fs.readFileSync(file, "utf8");
-        return vm.runInContext(code, UglifyJS, file);
-    } catch(ex) {
-        // XXX: in case of a syntax error, the message is kinda
-        // useless. (no location information).
-        console.log("ERROR in file: " + file + " / " + ex);
-        process.exit(1);
-    }
-};
 
 var FILES = exports.FILES = [
     "../lib/utils.js",
@@ -32,24 +11,25 @@ var FILES = exports.FILES = [
     "../lib/compress.js",
     "../lib/sourcemap.js",
     "../lib/mozilla-ast.js",
-    "../lib/propmangle.js"
+    "../lib/propmangle.js",
+    "./exports.js",
 ].map(function(file){
     return fs.realpathSync(path.join(path.dirname(__filename), file));
 });
 
-FILES.forEach(load_global);
+var UglifyJS = exports;
+
+new Function("MOZ_SourceMap", "exports", FILES.map(function(file){
+    return fs.readFileSync(file, "utf8");
+}).join("\n\n"))(
+    require("source-map"),
+    UglifyJS
+);
 
 UglifyJS.AST_Node.warn_function = function(txt) {
     console.error("WARN: %s", txt);
 };
 
-// XXX: perhaps we shouldn't export everything but heck, I'm lazy.
-for (var i in UglifyJS) {
-    if (UglifyJS.hasOwnProperty(i)) {
-        exports[i] = UglifyJS[i];
-    }
-}
-
 exports.minify = function(files, options) {
     options = UglifyJS.defaults(options, {
         spidermonkey : false,

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/uglifyjs.git



More information about the Pkg-javascript-commits mailing list