On Jun 25, 12:40 pm, Johan Compagner <[email protected]> wrote: > now i am a bit confuse:) > is my patch correct that i do or is the current behavior correct? > > if i read this: > > http://www.ecma-international.org/publications/files/ECMA-ST/ECMA-262... > > and then 11.8.6 i dont really se what should happen if Result(2) is null. > > but 15.3.5.3 tells a bit more about the HashInstance method an there it > tells use that if it is null then return false > So i guess he patch that i made should be done in the core of rhino > (browsers do also the same) > > johan > > > > On Thu, Jun 25, 2009 at 18:10, Norris Boyd <[email protected]> wrote: > > On Jun 25, 10:36 am, Johan Compagner <[email protected]> wrote: > > > Hi, > > > > in java you can use the instanceof check on null and that will return > > false. > > > But in rhino this results in a undefined error. > > > > var str = "str" > > > if (str instanceof String) // works > > > > but > > > > var str = null; // or just var str; so undefined.. > > > if (str instanceof String) // doesnt works > > > > is this the spec? Or just a bug in rhino > > > > If i patch rhino: > > > > ScriptRuntime: *public* *static* *boolean* instanceOf(Object a, Object b, > > > Context cx) > > > > i add the line: > > > > * > > > > if > > > * (a == *null* || a == Undefined.*instance*) *return* *false*; > > > > right after the if(b) check. Then above code works and i dont have to add > > > extra checks for null.. > > > > johan > > > This is correct. See ECMA 262, section 11.8.6. > > > --N > > _______________________________________________ > > dev-tech-js-engine-rhino mailing list > > [email protected] > >https://lists.mozilla.org/listinfo/dev-tech-js-engine-rhino
Sorry, I didn't read your example closely enough--I thought you were talking about the right hand side of the instanceof operator. Rhino does what you expect on null for the left hand side of instanceof: "null instanceof String" evaluates to false. --N _______________________________________________ dev-tech-js-engine-rhino mailing list [email protected] https://lists.mozilla.org/listinfo/dev-tech-js-engine-rhino
