Skip to content

Fix errors on non-browser env that does not have Element#attachEvent#399

Closed
twada wants to merge 1 commit into
qunitjs:masterfrom
twada:fix_error_on_node_and_rhino
Closed

Fix errors on non-browser env that does not have Element#attachEvent#399
twada wants to merge 1 commit into
qunitjs:masterfrom
twada:fix_error_on_node_and_rhino

Conversation

@twada

@twada twada commented Jan 28, 2013

Copy link
Copy Markdown

Fixes errors on non-browser environment that does not have Element#attachEvent.
Reverts some part of f249711

Error on Node.js

/path/to/qunit.js:1506
        elem.attachEvent( "on" + type, fn );
             ^
TypeError: Object #<Object> has no method 'attachEvent'

Error on Rhino

js: uncaught JavaScript runtime exception: TypeError: Cannot find function attachEvent in object [object global].

@Krinkle

Krinkle commented Jan 28, 2013

Copy link
Copy Markdown
Member

Please provide a full stacktrace.

addEvent should not be called in a non-browser environment. By not having an else case you're masking an error, that's unacceptable.

@twada

twada commented Jan 29, 2013

Copy link
Copy Markdown
Author

@Krinkle @jzaefferer , sorry for my poor information. Here is the full stacktrace on Node.js.

/Users/takuto/work/git-sandbox/github/qunit-tap/test/compatibility/1.11.0/qunit.js:1506
        elem.attachEvent( "on" + type, fn );
             ^
TypeError: Object #<Object> has no method 'attachEvent'
    at addEvent (/Users/takuto/work/git-sandbox/github/qunit-tap/test/compatibility/1.11.0/qunit.js:1506:8)
    at /Users/takuto/work/git-sandbox/github/qunit-tap/test/compatibility/1.11.0/qunit.js:1184:1
    at Object.<anonymous> (/Users/takuto/work/git-sandbox/github/qunit-tap/test/compatibility/1.11.0/qunit.js:2152:2)
    at Module._compile (module.js:449:26)
    at Object.Module._extensions..js (module.js:467:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)
    at Module.require (module.js:362:17)
    at require (module.js:378:17)
    at Object.<anonymous> (/Users/takuto/work/git-sandbox/github/qunit-tap/test/node/test_helper.js:18:13)

The root cause is calling addEvent( window, "load", QUnit.load ); on line 1184.

By not having an else case you're masking an error, that's unacceptable.

Agreed. In f249711 you said

executing it immediately is not a solution. That'll call it with the wrong arguments, with the wrong context at the wrong time.

And I respect your decision in my patch. However, not calling addEvent on non-browser enviroment is the best solution in this case. I agreed.

@Krinkle

Krinkle commented Jan 29, 2013

Copy link
Copy Markdown
Member
By not having an else case you're masking an error, that's unacceptable.
Agreed.

Well, your patch removes the else case, masking the error.

If it is okay not to call QUnit.load in a non-browser environment (which is effectively what this patch re-enforces), then the solution is to do that, not to mask it.

if ( ..browser.. ) { addEvent( .., .. QUnit.load ); seems like a more solid solution. That makes the fact that QUnit.load is not called explicit as opposed to implied behind a mask.

@twada

twada commented Jan 29, 2013

Copy link
Copy Markdown
Author

If it is okay not to call QUnit.load in a non-browser environment (which is effectively what this patch re-enforces), then the solution is to do that, not to mask it.

Now I totally agree with you. So I withdraw this PR now, then open another PR if I can.
Thanks.

@twada

twada commented Jan 29, 2013

Copy link
Copy Markdown
Author

Pull-requested again as #401

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants