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