[Pkg-javascript-commits] [node-asn1.js] 93/202: api: fallback to anonymous function

Bastien Roucariès rouca at moszumanska.debian.org
Thu Apr 20 19:18:57 UTC 2017


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

rouca pushed a commit to branch master
in repository node-asn1.js.

commit c5d84398045da7bb797d65efca057ba719753277
Author: Alexey Komarov <alex7kom at gmail.com>
Date:   Sat Apr 18 21:55:05 2015 +0300

    api: fallback to anonymous function
    
    `vm-browserify` uses `eval()` which is disabled in Chrome Apps (completely)
    and Extensions (by default CSP). If can't execute `vm.runInThisContext`
    to create named function, fallback to unnamed function expression.
---
 lib/asn1/api.js | 16 ++++++++++++----
 1 file changed, 12 insertions(+), 4 deletions(-)

diff --git a/lib/asn1/api.js b/lib/asn1/api.js
index c76495e..0e8a201 100644
--- a/lib/asn1/api.js
+++ b/lib/asn1/api.js
@@ -1,6 +1,5 @@
 var asn1 = require('../asn1');
 var inherits = require('inherits');
-var vm = require('vm');
 
 var api = exports;
 
@@ -17,9 +16,18 @@ function Entity(name, body) {
 };
 
 Entity.prototype._createNamed = function createNamed(base) {
-  var named = vm.runInThisContext('(function ' + this.name + '(entity) {\n' +
-    '  this._initNamed(entity);\n' +
-    '})');
+  var named;
+  try {
+    named = require('vm').runInThisContext(
+      '(function ' + this.name + '(entity) {\n' +
+      '  this._initNamed(entity);\n' +
+      '})'
+    );
+  } catch (e) {
+    named = function (entity) {
+      this._initNamed(entity);
+    };
+  }
   inherits(named, base);
   named.prototype._initNamed = function initnamed(entity) {
     base.call(this, entity);

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



More information about the Pkg-javascript-commits mailing list