Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeError: Cannot call method 'emit' of undefined #11

Open
rmarlow opened this issue Feb 14, 2015 · 3 comments
Open

TypeError: Cannot call method 'emit' of undefined #11

rmarlow opened this issue Feb 14, 2015 · 3 comments

Comments

@rmarlow
Copy link

rmarlow commented Feb 14, 2015

I'm testing some code of mine that seems to have an error in it. It works fine in a browser, but it errors in node-qunit-phantomjs. When the error is thrown though, my error results in another error within node-qunit-phantomjs, like so:

root@local-dev:/path/to/tests# node-qunit-phantomjs mytest.js.html
Testing /path/to/tests/mytest.js.html

/usr/lib/node_modules/node-qunit-phantomjs/index.js:67
                this.emit('error', new Error(e));
                     ^
TypeError: Cannot call method 'emit' of undefined
    at /usr/lib/node_modules/node-qunit-phantomjs/index.js:67:22
    at ChildProcess.exithandler (child_process.js:646:7)
    at ChildProcess.emit (events.js:117:20)
    at maybeClose (child_process.js:756:16)
    at Process.ChildProcess._handle.onexit (child_process.js:823:5)

Looking at the source, the "this" keyword seems to not be pointing at what it thinks it is. I'm going to proceed trying to debug my own code for what is throwing the original error, but do you have any clues as to why the "this" keyword is not in the correct scope here, or a possible fix?

@rmarlow
Copy link
Author

rmarlow commented Feb 14, 2015

node is v0.10.33, OS is Ubuntu 12.04.4

@rmarlow
Copy link
Author

rmarlow commented Feb 14, 2015

I've followed it back to a point in the code where there's a var that is a reference to a function is being called with arguments. In browser (Chrome Version 40.0.2214.111 m), it works fine and calls the referenced function properly, and I can also console.log the var and see the contents of the function it should be calling. But in node-qunit-phantomjs, I keep getting an error thrown as soon as I try to console.log the var or call the function that it references. The error is being thrown at the line return fromArray + '{' + newLine + prettyObject(element, indent) + indent + '}';

this.prettyPrint = function (jsObject, indentLength, outputTo, fullFunction) {
    //adapted from https://github.com/cvadillo/js-object-pretty-print
    "use strict";

    ...

    prettyObjectPrint = function (object, indent) {
        var value = [],
            property;
        indent += indentString;
        for (property in object) {
            if (object.hasOwnProperty(property)) {
                value.push(indent + property + ': ' + pretty(object[property], indent));
            }
        }
        return value.join(newLineJoin) + newLine;
    };

    ...

    pretty = function (element, indent, fromArray) {
        ...
        switch (type) {
            ...
            case 'object':
                if (element === null) {
                    return fromArray + '"null"';
                } else {
                    visited.push(element);
                    return fromArray + '{' + newLine + prettyObject(element, indent) + indent + '}';
                }

            ...
        }
    };

    if (indentLength === undefined) {
        indentLength = 4;
    }
    ...
    prettyObject = outputTo === 'json' ? prettyObjectJSON : prettyObjectPrint;
    ...
    return pretty(jsObject, '');
};

@famousgarkin
Copy link

+1, same problem here with 1.2.0 on Node.js v0.12.2.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants