Subj : Re: Class protection from multiple script execution using the same To : netscape.public.mozilla.jseng From : Matthew Mondor Date : Mon Jul 26 2004 04:05 am On Fri, 23 Jul 2004 22:05:27 -0400 Brendan Eich wrote: > If you define a property on a class prototype with the JSPROP_SHARED > attribute, then no shadowing copy will be created on a directly > referenced instance that delegates to the prototype. > > If you predefine a proto-property without JSPROP_SHARED, on the other > hand, then any delegating instance on which you set the object will have > > its class addProperty called when the shadowing property is created in > that instance. So if you thought that the property was already added > (to the prototype), and therefore is not being added to the delegating > instance, then you were misconceiving what addProperty does. This now makes sense, I was able to set the default class prototype's addProperty() method to a custom one returning JS_TRUE by default, so that I can add my properties and methods from C dode, and then making it return JS_FALSE, but I indeed had to also add the JSPROP_SHARED flag to the properties I defined from C code, so that addProperty() wasn't internally called to create shadow copies at runtime. > You have to be very careful in *when* you cause addProperty to fail. > But sealing is better, which is why we support it (as does Rhino). I tried using JS_SealObject(), however this also caused assignments to fail on existing properties in the user JS code, even if the properties were not readonly. It really sealed it in that sense :). As a side note: I noticed that readonly properties cannot be assigned new values from user code, as expected, but that it does not generate an error of any kind. The operation just seems to silently be ignored. Is that the intended behavior? If so, is there a way to track these user code bugs? Perhaps overriding the setProperty() method or such in this case? Or using debugger hooks? I did not attempt to use debugging features yet, but it seems to be something I will have to do soon anyways for various reasons. Thanks for the replies btw, you seem to be doing very good work on this newsgroup answering technical questions of most postings, it is very appreciated that you took the time to answer my questions. Matt .