Menu

#525 HTMLCollection.call() returns NOT_FOUND rather than null

closed
None
5
2012-10-21
2007-09-26
Kor Nielsen
No

The following javascript expression returns false, when it should return true:

document.all('elementThatDoesNotExist') == null

This also results in a warning from rhino:

RHINO USAGE WARNING: Missed Context.javaToJS() conversion:
Rhino runtime detected object org.mozilla.javascript.UniqueTag@b1074a: NOT_FOUND of class org.mozilla.javascript.UniqueTag where it expected String, Number, Boolean or Scriptable instance. Please check your code for missing Context.javaToJS() call.

This is happening because HTMLCollection.call() returns NOT_FOUND rather than null when an item does not exist.

I have attached a patch which fixes the problem and includes a unit test to reproduce it.

Discussion

  • Kor Nielsen

    Kor Nielsen - 2007-09-26

    HtmlCollection-Call-NonExistentItem.patch

     
  • Marc Guillemot

    Marc Guillemot - 2007-09-27

    Logged In: YES
    user_id=402164
    Originator: NO

    you're right for document.all for IE but for instance FF supports document.all too and returns undefined (ie NOT_FOUND for Rhino).

    Therefore, yes it should be fixed but I guess that you're patch isn't fine grained enough.

     
  • Kor Nielsen

    Kor Nielsen - 2007-09-27

    Logged In: YES
    user_id=1899485
    Originator: YES

    I don't think htmlunit allows you to use document.all with firefox. I ran my unit test with BrowserVersion.FIREFOX_2, and received this error:

    com.gargoylesoftware.htmlunit.ScriptException: TypeError: Cannot find function all.

     
  • Kor Nielsen

    Kor Nielsen - 2007-09-27

    Logged In: YES
    user_id=1899485
    Originator: YES

    Also, rhino doesn't allow NOT_FOUND to be returned from a function (although I think you can return Undefined.instance instead). NOT_FOUND is used with Scriptable.get().

     
  • Marc Guillemot

    Marc Guillemot - 2007-10-08

    Logged In: YES
    user_id=402164
    Originator: NO

    now fixed in SVN. Thanks.

    I'm sorry: I haven't fully read your description and I've missed your patch. The consequence is that it took me more time as I had to write a test by myself. Next time I will look more carefully.

    I haven't changed the configuration and document.all is still not allowed for FF.

     

Log in to post a comment.