Closed Bug 60235 Opened 24 years ago Closed 22 years ago

Cannot override existing methods in new instances of sealed classes

Categories

(Rhino Graveyard :: Core, defect, P3)

x86
Other
defect

Tracking

(Not tracked)

VERIFIED FIXED

People

(Reporter: dnavas, Assigned: norrisboyd)

Details

I'm not sure if this is intended behavior or not -- it's odd if it's intended, as it makes it difficult to use sealed classes, but anyway.... If you create a sealed class, you cannot create an object whose prototype is that sealed class and override a method that was originally declared in the sealed class. I changed this by doing the following, but I don't know what the definition of sealed is. I can see why it's a gray area, but if sealed objects are supposed to represent reusable prototypes, don't you need to override methods like toString(), etc? Index: ScriptableObject.java =================================================================== RCS file: /src/master/org/mozilla/javascript/ScriptableObject.java,v retrieving revision 1.3 diff -u -r1.3 ScriptableObject.java --- ScriptableObject.java 2000/11/04 00:10:09 1.3 +++ ScriptableObject.java 2000/11/15 21:44:29 @@ -226,7 +226,19 @@ } Slot slot = slots[slotIndex]; if ((slot.attributes & ScriptableObject.READONLY) != 0) - return; + { + // Allow function override, even if functions are sealed! + // Note that we can override a function to point to void or an actu al property value, + // we should really check the existing value if we want to just sea l functions. + // We don't want to make readonly properties settable, now, do we?! + // [Properties like Math.PI, etc...] +//System.out.println("Setting: " + name + " to: " + value + " on: " + start + " for: " + this); + if ( start == this || !(slot.value instanceof Function) + || ((slot.flags & (Slot.HAS_SETTER|Slot.HAS_GETTER)) != 0) ) + { + return; + } + } if ((slot.flags & Slot.HAS_SETTER) != 0) { GetterSlot getterSlot = (GetterSlot) slot; try {
As a result of changes in sealed semantics, see bug 203013, one can now overrides properties from object's prototype even if the prototype is sealed.
Status: NEW → RESOLVED
Closed: 22 years ago
Resolution: --- → FIXED
Marking Verified - see bug 203013.
Status: RESOLVED → VERIFIED
Targeting as resolved against 1.5R5
Target Milestone: --- → 1.5R5
You need to log in before you can comment on or make changes to this bug.