diff options
author | Nik Nyby <nikolas@gnu.org> | 2015-04-02 21:38:58 -0400 |
---|---|---|
committer | Nik Nyby <nikolas@gnu.org> | 2015-04-02 21:38:58 -0400 |
commit | 9b79c2a61be72965c001c8d9779a7b3188628613 (patch) | |
tree | 509cff8478e2d42aeddd04e83d1be8a6d2c80453 /lib/js_checker/js_checker.js | |
parent | 50a734f27491098d19c6267c3b21b0a1507879d3 (diff) | |
download | librejsxul-9b79c2a61be72965c001c8d9779a7b3188628613.tar.lz librejsxul-9b79c2a61be72965c001c8d9779a7b3188628613.tar.xz librejsxul-9b79c2a61be72965c001c8d9779a7b3188628613.zip |
Add Ruben's isFreeLicensed check for external scripts
Diffstat (limited to 'lib/js_checker/js_checker.js')
-rw-r--r-- | lib/js_checker/js_checker.js | 46 |
1 files changed, 32 insertions, 14 deletions
diff --git a/lib/js_checker/js_checker.js b/lib/js_checker/js_checker.js index 21bfeaf..da3ebe6 100644 --- a/lib/js_checker/js_checker.js +++ b/lib/js_checker/js_checker.js @@ -161,7 +161,6 @@ JsChecker.prototype.isFreeLicensed = function(script) { * Takes in some javascript code (as string). * Uses Narcissus parser to build an abstract syntax tree. * Checks for trivialness. - * */ JsChecker.prototype.searchJs = function(jsCode, resultReady, url) { var that = this; @@ -204,20 +203,39 @@ JsChecker.prototype.searchJs = function(jsCode, resultReady, url) { this.freeToken = types.emptyTypeObj(); this.nontrivialness = types.emptyTypeObj(); - // use this.hash to keep track of comments made by the nontrivial - // checker code about why/how the code is found to be nontrivial. - this.nonTrivialChecker = - nonTrivialModule.nonTrivialChecker(this.hash); - - // register callback and hash. So that result - // can be passed. - setHashCallback( - this.hash, this.handleTree.bind(this), this.notification); + if (typeof url === 'undefined' || url === null) { + // use this.hash to keep track of comments made by the nontrivial + // checker code about why/how the code is found to be nontrivial. + this.nonTrivialChecker = + nonTrivialModule.nonTrivialChecker(this.hash); + + // register callback and hash. So that result + // can be passed. + setHashCallback( + this.hash, this.handleTree.bind(this), this.notification); + + // parse using ChromeWorker. + console.debug( + 'JsChecker.searchJs(): starting narcissusWorker.parse()'); + narcissusWorker.parse(this.jsCode, this.hash); + } else { + // Handle external scripts + console.debug('Analyzing external script: ' + url); + this.parseTree = {}; + if (this.isFreeLicensed(this.jsCode)) { + this.parseTree.freeTrivialCheck = type.trivialWithComment( + 'This script is under free software licenses: ' + url); + } else { + this.parseTree.freeTrivialCheck = type.nontrivialWithComment( + 'This external script is not under free software ' + + 'licenses: ' + url); + } - // parse using ChromeWorker. - console.debug( - 'JsChecker.searchJs(): starting narcissusWorker.parse()'); - narcissusWorker.parse(this.jsCode, this.hash); + // Cache result with hash of script for future checks + scriptsCached.addEntry( + this.jsCode, this.parseTree.freeTrivialCheck, + this.relationChecker, true, this.url); + } } catch (x) { console.debug('error', x); this.handleTree(false, x); |