Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6245977
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T12:36:21+00:00 2026-05-24T12:36:21+00:00

The javascript interpreter triggerred a SytaxError after i compressed my code, but i don’t

  • 0

The javascript interpreter triggerred a SytaxError after i compressed my code, but i don’t know the exact position triggered this problem at my code. It’s very hard to find out. I tried jsLint aslo, but it can’t point out problem aslo.

(function(){var session,start,end,pool={length:0},result=[],id=0;function poolAdd(procedure,expected,description){pool[id+++""]={"description":description||"No description","procedure":procedure,"expected":expected};pool["length"]++;return id-1;}function poolRun(id){var actual,expect,pass,test=pool[id];if(test){try{actual=typeof test.procedure==="function"?test.procedure():test.procedure;expect=typeof test.expected==="function"?test.expected():test.expected;pass=actual===expect;if(pass){test["pass"]=true}else{test["fail"]={"actual":actual,"expect":expect}}}catch(e){test["fail"]={"message":e.toString()}}finally{delete pool[id];pool.length--;return result.push(test)-1;}}return-1;}function percentage(fraction){return!(fraction>=0&&fraction<=1)?"Not available":(fraction*100+"").substr(0,5)+"%"}function Statics(data,session){if(this instanceof Statics){this.data=(data||result).slice(0);if(session){this.session={id:session.id,end:session.end,start:session.start}}}else{return new Statics(data,session)}}Statics.prototype={statics:function(format){var temp,report,passed=[],failed=[];format=format||"text";for(var i=0,l=this.data.length;i<l;i++){temp=this.data[i];if(typeof temp==="number"){temp=result[temp+""]}temp.pass&&passed.push(temp);temp.fail&&failed.push(temp)}if(format==="text"){report=[];report.push("***"+(this.session?" Session("+this.session.id+")":"")+" Test Report ***");report.push("  Cost: "+(this.session?(this.session.end-this.session.start)/1000:(end-start)/1000)+" seconds");report.push(" Total: "+this.data.length);report.push("Passed: "+passed.length);report.push("Failed: "+failed.length);report.push("Percet: "+percentage(passed.length/this.data.length));if(failed.length>0){report.push("Detail:");for(var i=0,l=failed.length;i<l;i++){temp=failed[i];if(temp.fail.message){report.push(i+1+")."+" >>>EXCEPTION THROWN<<< in test("+temp.description+") "+temp.fail.message)}else{report.push(i+1+")."+" >>>VALUE NOT MATCH<<< in test("+temp.description+") "+" expected "+temp.fail.expect+" actual "+temp.fail.actual)}}}return report.join("\n")}}}function session_start(){session=new Session();session.start=+new Date;}function session_end(){session&&(session.end=+new Date)}function session_destory(){session=null}function Session(){this.id=QQWB.uid();this.idPool=[];}Session.prototype={_addId:function(id){this.idPool.push(id)},add:function(procedure,expected,description){this._addId(poolAdd(procedure,expected,description));return this},run:function(){var temp,statics,results=[];for(var i=0,l=this.idPool.length;i<l;i++){temp=poolRun(this.idPool[i]);temp&&results.push(temp)}session_end();statics=Statics(results,session);session_destory();return statics}};QQWB.extend("test",{add:function(procedure,expected,description){session_start();session._addId(poolAdd(procedure,expected,description));return session},run:function(){session_destory();start=+new Date;for(var id in pool){if(id!=='length'&&pool.hasOwnProperty(id)){poolRun(id)}}end=+new Date;return Statics()},remains:function(){return pool.length}})}());

added my original code

(function (){

    var 
        session, // test session
        start, // start time of call test.run()
        end, // end time of test.run()
        pool = {length:0}, // pool of all the tests removed from pool when test done
        result = [], // pool of the result of test
        id = 0; // test unique id auto increment

    /**
     * Add a test item to pool
     * 
     * @access private
     * @return {Number} the index in the pool
     */
    function poolAdd(procedure, expected, description) {
        pool[id+++""] = {
              "description": description || "No description"
             ,"procedure": procedure
             ,"expected": expected
        };
        pool["length"]++; // maintain the length property of pool
        return id - 1; // id of current test
    }

    /**
     * Run a test
     *
     * Test item will be marked as pass or fail then move from
     * test's pool to result's pool
     *
     * @access private
     * @param id {Number} the index in the test pool
     * @return {Number} the index in the result pool
     */
    function poolRun(id) {
        var 
            actual, // actual value
            expect, // expected value
            pass, // indicate test whether passed
            test = pool[id]; // the test object

        if (test) {
            try{
                actual = typeof test.procedure === "function" ? test.procedure() : test.procedure; // run test procedure
                expect = typeof test.expected === "function" ? test.expected() : test.expected; // run expect procedure
                pass = actual === expect;
                if (pass) {
                   test["pass"] = true;
               } else {
                   test["fail"] = {
                       "actual": actual
                      ,"expect": expect
                   }
               }
            } catch (e) {
                test["fail"] = {
                    "message": e.toString()
                }
            } finally {
                delete pool[id]; // remove from pool
                pool.length--; // maintain the length property of pool
                return result.push(test) - 1; // the index in the result array for current test item
            }
        }
        return -1; // id not valid
    }

    /**
     * Float to percentage string
     *
     * @access private
     * @param fraction {Number} float number
     * @return {String} percentage string
     */
    function percentage (fraction) {
        return !(fraction >= 0 && fraction <= 1) ? "Not available" : (fraction * 100 + "").substr(0,5) + "%";
    }

    /**
     * Statics constructor
     *
     * Self invoke constructor
     *
     * Note:
     * If data is passed in,it means the statics running in a session
     * Data contains *position* of result pool
     *
     * @access private
     * @param data {Array} partial result keys array or the result
     * @return {Statics} a statics instance
     */
    function Statics(data, session) {
        if (this instanceof Statics) {
            this.data = (data || result).slice(0); // clone array
            if (session) {
                this.session = { 
                    id: session.id
                   ,end: session.end
                   ,start: session.start
                };
            }
        } else {
            return new Statics(data, session);
        }
    }

    Statics.prototype = {
        /**
         * Get statics
         *
         * Currently only support text statics
         *
         * @access public
         * @param format {String} text,xml,json etc.
         * @return {Mixed} result statics
         */
        statics: function (format) {
            var 
                temp, // temp value
                report, // statics report
                passed = [], // passed tests pool
                failed = []; // failed tests pool

            format = format || "text"; // default report type is text

            for (var i=0,l=this.data.length; i<l; i++) {
                temp = this.data[i];
                if (typeof temp === "number") { // convert key to its value
                    temp = result[temp+""];
                }
                temp.pass && passed.push(temp);
                temp.fail && failed.push(temp);
            }

            if (format === "text") {
                report = [];
                report.push("***" + (this.session ? " Session(" + this.session.id +")":"") + " Test Report ***");
                report.push("  Cost: " + (this.session ? (this.session.end - this.session.start)/1000 : (end - start)/1000) + " seconds");
                report.push(" Total: " + this.data.length);
                report.push("Passed: " + passed.length);
                report.push("Failed: " + failed.length);
                report.push("Percet: " + percentage(passed.length/this.data.length));
                if (failed.length > 0) {
                    report.push("Detail:");
                    for (var i=0,l=failed.length; i<l; i++) {
                        temp = failed[i];
                        if (temp.fail.message) {
                            report.push( i + 1 + ")." + " >>>EXCEPTION THROWN<<< in test(" + temp.description + ") " + temp.fail.message);
                        } else {
                            report.push( i + 1 + ")." + " >>>VALUE NOT MATCH<<< in test(" + temp.description + ") " + " expected " + temp.fail.expect + " actual " + temp.fail.actual);
                        }
                    }
                }
                return report.join("\n");
            }
        } 
    }

    /**
     * Start a new test session
     *
     * @access private
     * @return {Void}
     */
    function session_start() {
     // if checked T.test.add(...); T.test.add(...); will be treated as one session till run is called
     // if (!session) {
            session = new Session();
            session.start = + new Date;
     // }
    }

    /**
     * End current session
     *
     * @access private
     * @return {Void}
     */
    function session_end() {
        session && (session.end = + new Date);
    }

    /**
     * Destory current session
     *
     * @access private
     * @return {Void}
     */
    function session_destory() {
        session = null;
    }

    /**
     * Session constructor
     *
     * @access private
     * @return {Session} session instance
     */
    function Session() {
        this.id = QQWB.uid(); // random session id
        this.idPool = []; // contains id of test
    }

    Session.prototype = {
        /**
         * Add test id to session
         *
         * @access private
         * @param id {Number} test id
         * @return {Void}
         */
        _addId: function (id) {
            this.idPool.push(id);
        }

        /**
         * Add test item to session
         *
         * Note:
         * Test item added to global pool
         * Session just store the position of test in the pool
         *
         * Example usage:
         * T.test
         *       .add(...) //add a test to session(and pool)
         *       .add(...) //add a test to session(and pool)
         *       ...
         *
         *
         * @access public
         * @param procedure {Mixed} the procedure to finish this test
         *                          if procedure is a function it will
         *                          be executed automaticlly
         * @param expected {Mixed}  the expected value of this test
         *                          if expected is a function it will
         *                          be executed automaticlly
         * @param description {String} speak more about this test
         * @return {Session} the current session     
         */
       ,add: function (procedure, expected, description) {
            this._addId(poolAdd(procedure, expected, description));
            return this;
        }

        /**
         * Run the tests in current session
         *
         * Example usage:
         * T.test
         *       .add(...) //add a test to session(and pool)
         *       .add(...) //add a test to session(and pool)
         *       ...
         *       .run() // run the test in this session
         *       .statics() // get statics for this session
         *
         * @access public
         * @return {Statics} statics object
         */
       ,run: function () { // run in session
            var temp,
                statics,
                results = [];
            for (var i=0,l=this.idPool.length; i<l; i++) {
                temp = poolRun(this.idPool[i]);
                temp && results.push(temp);
            }
            session_end(); // record the time of this session end
            statics = Statics(results,session);
            session_destory();// destory test session
            return statics;
        }
    };

    QQWB.extend("test",{

        /**
         * Add test item to session
         *
         * Note:
         * Test item added to global pool
         * Current session will store the position of test in the pool
         *
         * Example usage:
         * T.test
         *       .add(...) //add a test to session(and pool)
         *       .add(...) //add a test to session(and pool)
         *       ...
         *
         * @access public
         * @param procedure {Mixed} the procedure to finish this test
         *                          if procedure is a function it will
         *                          be executed automaticlly
         * @param expected {Mixed}  the expected value of this test
         *                          if expected is a function it will
         *                          be executed automaticlly
         * @param description {String} speak more about this test
         * @return {Session} the current session     
         */
        add: function (procedure, expected, description) {
            session_start(); // spawn a new session object
            session._addId(poolAdd(procedure, expected, description));
            return session;
        }

        /**
         * Run all the tests except the test already done
         *
         * Example usage:
         * T.test
         *       .add(...) //add a test to session(and pool)
         *       .add(...) //add a test to session(and pool)
         *       ...
         *
         * T.test
         *       .run() // run all the tests except already done
         *       .statics() //get full statics of all the tests
         *
         * @access public
         * @return {Statics} statics object
         */
       ,run: function () {
           session_destory(); // destory current session
           start = + new Date; // start time of global test
           for (var id in pool) {
               if (id !== 'length' && pool.hasOwnProperty(id)) {
                   poolRun(id);
               }
           }
           end = + new Date; // end time of global test
           return Statics();
       }
       /**
        * Get count of tests left in the pool
        * 
        * @access public
        * @return {Number} count of tests unfinished yet
        */
       ,remains: function () {
           return pool.length;
       }

    });

}());

This is the script packer
http://dean.edwards.name/packer/

Edited:
I solved this problem by myself finally,I paste the code piece by piece to the packer. finally find out that the defination of Statics.prototype isn’t end with a semicolon which caused SytaxError.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T12:36:23+00:00Added an answer on May 24, 2026 at 12:36 pm

    I tried copying the javascript to http://jsfiddle.net/ then clicking JSLint – gave me all sorts of errors.

    What tool are you using for the compression?

    My guess is missing semicolons.

    For example:

    test["fail"] = {
      "message": e.toString()
    }
    

    Should have a semicolon after the closing brace.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using V8 javascript interpreter on the command line but it has no tab-completion.
I'm under the impression that JavaScript interpreter assumes that the source code it is
Javascript I have code that will hide various sections in a MS CRM form
javascript with> var customer=document.getElementById('custList').value; and that works... Why does it work BUT... var customer=(form1.custList.value);
I am asking this because I use Python, but it could apply to other
I'm working on a JavaScript collator/compositor implemented in Java. It works, but there has
I'm using javascript and have this enumeration: filterType = { Campaign : 'Campaign', Class
I'd like to embed the V8 JavaScript interpreter that ships with Google Chrome within
Is there some sort of interactive ActionScript interpreter? Similar to Firebug's JavaScript command line
When designing a byte code interpreter, is there a consensus these days on whether

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.