Merge remote-tracking branch 'remotes/origin/xdccore-J-sasha' into xdccore-J-dr
diff --git a/src/packages/xdc/rov/Program.xs b/src/packages/xdc/rov/Program.xs
index 60c481b..225e593 100644
--- a/src/packages/xdc/rov/Program.xs
+++ b/src/packages/xdc/rov/Program.xs
@@ -902,17 +902,31 @@
                   "The definition for " + cmod.viewMap[i].structName
                   + " is not found in " + cmod.capsule.$path);
             }
-            /* Create the status map and bind it to the struct */
-            var status = new Object();
-            for (var p in new mod.useMod[cmod.viewMap[i].structName]()) {
-                status[p] = null;
-            }
-            var prot = mod.useMod[cmod.viewMap[i].structName].prototype;
-            prot.$status = status;
-            /* $status is intentionally not enumerable to prevent adding it as
-             * a column later.
+
+            /* Check if we already encountered this structure. Nothing is
+             * stopping two different views sharing the same view structure.
              */
-            Object.defineProperty(prot, "$status", {enumerable: false});
+            var pt = mod.useMod[cmod.viewMap[i].structName].prototype;
+            if (!("$status" in pt)) {
+                /* Create the status map and bind it to the struct */
+                var status = new Object();
+                for (var p in new mod.useMod[cmod.viewMap[i].structName]()) {
+                    status[p] = null;
+                }
+
+                Object.freeze(status);
+                /* $status is intentionally not enumerable and not writable to
+                 * prevent adding it as a column later. Object.freeze() above
+                 * was added because to prevent changing values in '$status',
+                 * while 'writable' prevents assigning something else to
+                 * '$status'.
+                 * The property $status is added to the prototype to serve as a
+                 * default that is used only if no error was reported by calling 
+                 * Program.displayError().
+                 */
+                Object.defineProperty(pt, "$status",
+                    {enumerable: false, writable: false, value: status});
+            }
         }
     }
     if (cmod.argsMap && cmod.argsMap.length > 0) {
@@ -1470,6 +1484,14 @@
                          "message was: " + errorMsg));
     }
 
+    if ("hasOwnProperty" in view && view.hasOwnProperty("$status") != true) {
+        var status = new Object();
+        for (var p in view) {
+            status[p] = null;
+        }
+        Object.defineProperty(view, "$status",
+                {enumerable: false, value: status, writable: true});
+    }
     view.$status[fieldName] = errorMsg;
 }