GNOME Bugzilla – Bug 558741
Mutual imports cause great confusion
Last modified: 2008-11-09 17:59:00 UTC
If module A imports module B then module B imports module A, what happens is: - module A is loaded once - module B is loaded - module A is loaded a second time - the second copy of module A is stored in imports.a - module B is stored in imports.b - the first copy of module A is stored in imports.a Other modules may be using either the first or second copy of module.A depending on when they were loaded, and in general things go to hell in very unpredictable ways. On import start, the module object needs to be immediately stored in imports.a so that other modules see it is there. On failure, ideally all assignments to imports.* done during the import would be rolled back. Rolling back just the assignment to imports.a could leave things in an inconsistent state, since other modules might reference the dictionary. However, I think getting that right is low priority... it's much less of a pitfall if an exception during a complicated import causes a inconsistent state, then if a succesful import causes an inconsistent state. I'll attach a test case.
Created attachment 121759 [details] [review] Patch adding failing test
Missing "const" in "B = imports.mutualImport.b" Otherwise test looks good (but should not commit until it passes)
Created attachment 122250 [details] [review] Patch fixing problem Here's a patch. It only backs out the immediately failing import and not all imports in the operation (there's a comment in the patch explaining the situation in case anybody runs into corner cases and wants to try and improve.) The dance I do to not regress and set properties with JSPROP_PERMANENT is a bit ridiculous - set the property, do the import, set the property again with JSPROP_PERMANENT. Not sure there's a lot of value there.
Patch looks good to me
Committed.