Subj : Re: Class protection from multiple script execution using the same To : netscape.public.mozilla.jseng From : Matthew Mondor Date : Thu Jul 22 2004 08:00 am Just adding this followup to specify exactly where my problem occurs: Matthew Mondor wrote: [...] > /* > * Make sure that it is not possible to add properties to this object > * from user code, overriding the addProperty() class method. > */ > /* > * XXX Seems to have no effect! It works if I set it in the api_class > * structure directly from the start, but then I cannot add properties > * in the above code. And if I use a boolean flag to change the > * behavior of class_property_add() after executing the above code, > * it appears that even setting properties fail in user code, for some > * reason (although logically only setProperty() method should be > * invoked in this case?) > */ > api_class.addProperty = class_property_add; > /* protect = JS_TRUE;*/ > /* Finally initialize our new class */ > if ((class = JS_InitClass(ctx, global, api, &api_class, NULL, 0, NULL, > NULL, NULL, NULL)) == NULL) { > (void) fprintf(stderr, "Error initializing API class\n"); > exit(EXIT_FAILURE); > } > /* > * Make sure that noone can delete our class, setting the permanent > * and read only flags. > */ > if (JS_GetPropertyAttributes(ctx, global, "API", &prop_flags, > &prop_found) && prop_found) > (void) JS_SetPropertyAttributes(ctx, global, "API", > prop_flags | JSPROP_PERMANENT | JSPROP_READONLY, > &prop_found); > else { > (void) fprintf(stderr, "Error modifying API attributes\n"); > exit(EXIT_FAILURE); > } [...] So despite my efforts, the test js script is able to add properties, as well as methods, to the test API class, when it should not be able to. Also, it appears for some reason that there is confusion between the properties add and set methods, since overriding the add methods also seems to cause problems when assigning a value to an existing, non-readonly property... Thanks again, Matt .