On further inspection, it definitely looks like I've encountered bug #374918:
https://bugzilla.mozilla.org/show_bug.cgi?id=374918 In my test case (which was actually a very poor example since both cases used the same values it appeared to work correctly), change the first set of *.prototype.isa to equal something else like "bad!", and you end up with this: string=string, bad! (ok!) array=1,2,3, ok! (ok!) number=42, bad! (ok!) bool=true, bad! (ok!) date=Thu Oct 02 2008 03:18:35 GMT-0700 (PDT), ok! (ok!) Coincidentally, Marc Guillemot just posted about this yesterday (which I clearly missed...) http://groups.google.com/group/mozilla.dev.tech.js-engine.rhino/browse_thread/thread/ddc2994b60894387# On Oct 2, 2:58 am, tlrobinson <[EMAIL PROTECTED]> wrote: > If I set a property on a primitive object's prototype, it doesn't seem > to be propagated to instanced of that primitive, but *not* in the > Rhino shell, only if I create a scope with initStandardObjects. Also, > built in objects that aren't primitives, but actual Objects (like > Array and Date) work correctly, it's only String, Number, and Boolean. > > Here's a test case. As you can see, only Array and Date objects > correctly inherit the "isa" property from their prototypes, even > though it clearly *is* set on the prototype: > > print("== Shell scope =="); > > String.prototype.isa = "ok!"; > Array.prototype.isa = "ok!"; > Number.prototype.isa = "ok!"; > Boolean.prototype.isa = "ok!"; > Date.prototype.isa = "ok!"; > > var string = "string"; > print("string=" + string + ", " + string.isa + " (" + > String.prototype.isa + ")"); > var array = [1,2,3]; > print("array=" + array + ", " + array.isa + " (" + > Array.prototype.isa + ")"); > var number = 42; > print("number=" + number + ", " + number.isa + " (" + > Number.prototype.isa + ")"); > var bool = true; > print("bool=" + bool + ", " + bool.isa + " (" + > Boolean.prototype.isa + ")"); > var date = new Date(); > print("date=" + date + ", " + date.isa + " (" + Date.prototype.isa > + ")"); > > cx = Packages.org.mozilla.javascript.Context.enter(); > scope = cx.initStandardObjects(); > cx.evaluateString(scope, '\ > print = function(obj) > { java.lang.System.out.println(String(obj)); }; \ > print("== Standard scope =="); \ > String.prototype.isa = "ok!"; \ > Array.prototype.isa = "ok!"; \ > Number.prototype.isa = "ok!"; \ > Boolean.prototype.isa = "ok!"; \ > Date.prototype.isa = "ok!"; \ > var string = "string"; \ > print("string=" + string + ", " + string.isa + " (" + > String.prototype.isa + ")"); \ > var array = [1,2,3]; \ > print("array=" + array + ", " + array.isa + " (" + > Array.prototype.isa + ")"); \ > var number = 42; \ > print("number=" + number + ", " + number.isa + " (" + > Number.prototype.isa + ")"); \ > var bool = true; \ > print("bool=" + bool + ", " + bool.isa + " (" + > Boolean.prototype.isa + ")"); \ > var date = new Date(); \ > print("date=" + date + ", " + date.isa + " (" + > Date.prototype.isa + ")");', > "<cmd>", 1, null); > > Any idea what's going on? Is this a manifestation of this > bug:https://bugzilla.mozilla.org/show_bug.cgi?id=374918 > > We use this technique in Objective-J (http://cappuccino.org) to "toll- > free bridge" the built in JS objects to their Objective-J > counterparts, so it would be great if it worked in Rhino (already does > work, only in the shell) > > Thanks. _______________________________________________ dev-tech-js-engine-rhino mailing list [email protected] https://lists.mozilla.org/listinfo/dev-tech-js-engine-rhino
