解读 JPM "useless expression"



所以我有一个小问题。我试着为我试图开发的附加组件运行"jpm测试"。但每次我尝试运行它时,它只显示

console.log: bf4c_autoloader: [JavaScript Warning: "TypeError: useless expression" {file: "resource://gre/modules/commonjs/toolkit/loader.js -> resource://gre/modules/commonjs/sdk/util/sequence.js" line: 333}]

我不知道在哪里搜索这个错误。我唯一发现的就是这个。以下是我使用的所有文件:

index.js(主)

var tabs = require("sdk/tabs");
var data = require("sdk/self").data;
var prefs = require("sdk/simple-prefs").prefs;
tabs.on("ready", runScript);
//tabs.open("http://battlelog.battlefield.com/bf4");
var re = /battlelog.battlefield.com/bf4/;
function runScript(tab) {
    if(re.test(tab.url)){
        console.log("Found battlelog tab.");
        var worker = tab.attach({
            contentScriptFile: data.url("bf4_checker.js")
        });
        worker.port.on("sendingUsername",bf4Username)
        worker.port.on("sendingUserid",bf4Userid)
    }else{
        console.log("Looking if bf4c tab");
        var worker = tab.attach({
            contentScriptFile: data.url("bf4c_checker.js")
        });
        //see https://developer.mozilla.org/en-US/Add-ons/SDK/Guides/Content_Scripts#Communicating_with_the_add-on for further reference
        worker.port.on("bf4cCheckCallback",bf4cCheckCallback)
    }
}
function bf4cCheckCallback(m){
    //{'bf4cPage' : false,'addownAllowed':false}
    console.log(((m.bf4cPage)? 'Is a bf4c page':'Another page') + ", " + ((m.addownAllowed)? 'bf4c addon allowed!':'bf4c addon not allowed!'))
}
function bf4Username(name){
    prefs.setUsername = name;
}
function bf4Userid(id){
    prefs.setUserid =  id;
    console.log(prefs)
}

bf4_checker.js

function searchUsername(){
    if(elements = document.getElementsByClassName("username")){
        for (var i = 0; i < elements.length; i++) {
            if(elements[i].href){
                return elements[i].innerHTML;
            }
        };      
    }
    return false;
}
function searchUserid(name){
    if(elements = document.getElementsByClassName("wfont")){
        re = new RegExp('/bf4/soldier/'+name+'/stats/(\d+)/');
        for (var i = 0; i < elements.length; i++) {
            if(typeof (result = re.exec(elements[i].href)) == 'object'){
                return (parseInt(result[1]))
            }
        }       
    }
    return false;
}
if(username = searchUsername()){
    self.port.emit('sendingUsername',username);
    if(id = searchUserid(username)){
        self.port.emit('sendingUserid',id);
    }
}
function callback(mutations) {
    var re = /(highlight)/;
    mutations.forEach(function(mutationRecord) {
        var sepe = splittedClasses(mutationRecord.target.className)
        if(mutationRecord.attributeName == "class" && sepe.indexOf('highlight') > -1 && sepe.indexOf('popover-visible') == -1 && mutationRecord.target.className != mutationRecord.oldValue){
            console.log("Got new battlereport! went fromnt"+ mutationRecord.oldValue +"nt"+ mutationRecord.target.className)
        }
    });
}
function splittedClasses(className){
    var classes = className.split(" ");
    for (var i = 0; i < classes.length; i++) {
        if(classes[i] == ""){
            classes.splice(i,1);
        }
    };
    return classes;
}
if(target = document.getElementById('battlereports-icon')){
    console.log("initialized listener !")
    var observer = new MutationObserver(callback);
        observer.observe(target,{ attributes : true, attributeOldValue: true, attributeFilter : ['class'] });   
}
function metaKeyUp (event) {
    var key = event.keyCode || event.which;
    if (key == 65) {
        if(target.className != "log tools-item reports  highlight"){
            console.log("highlighted the report button");
            target.className = "log tools-item reports  highlight";
        }
    }
}
document.body.addEventListener("keyup",metaKeyUp.bind(this))

最后一个bf4c_checker.js

function isBF4CPage(){
    var header = document.getElementsByTagName("meta");
    for (var i = 0; i < header.length; i++) {
        var curr = header[i];
        if(curr.name == "x-bf4c-page"){
            return {'bf4cPage' : true,'addownAllowed': (curr.content == "true")? true : false};
        }
    }
    return {'bf4cPage' : false,'addownAllowed':false};
}
self.port.emit('bf4cCheckCallback',isBF4CPage())

好吧,我只是愚蠢地理解了jpm test的实际用途,我建议阅读这篇文章,这篇文章都向你展示了如何实际使用这个函数。所以我的问题不在于我的代码,只是它试图做一些我以前没有减速的事情。

相关内容

  • 没有找到相关文章

最新更新