Reviewers: felix8a,

Description:
test-scan-guest testScanner is unnecessarily fragile because it exposes
more ordinary object structure than just what was tested for, possibly
reacting to changes in the scan or problem reporting than what it was
looking for. Now the test object graph is run through detach(), which
reproduces the graph with no [[Prototype]]s to keep it to the explicitly
written structure.

Please review this at https://codereview.appspot.com/24710043/

Affected files (+27, -3 lines):
  M     tests/com/google/caja/plugin/test-scan-guest.js


Index: tests/com/google/caja/plugin/test-scan-guest.js
===================================================================
--- tests/com/google/caja/plugin/test-scan-guest.js     (revision 5627)
+++ tests/com/google/caja/plugin/test-scan-guest.js     (working copy)
@@ -1451,6 +1451,28 @@
     }
   };

+  // used by testScanner only
+  /** Make a simple isolated object graph. */
+  function detach(object, seen) {
+    if (object !== Object(object)) { return object; }
+    if (!seen) { seen = new WeakMap(); }
+    if (seen.has(object)) { return seen.get(object); }
+    if (Object.getPrototypeOf(object) !== Object.prototype) {
+      throw new Error('non-Object not supported');
+    }
+    var copy = Object.create(null);
+    Object.getOwnPropertyNames(object).forEach(function(prop) {
+      var desc = Object.getOwnPropertyDescriptor(object, prop);
+      ['value', 'get', 'set'].forEach(function (descProp) {
+ if (descProp in desc) { desc[descProp] = detach(desc[descProp], seen); }
+      });
+      Object.defineProperty(copy, prop, desc);
+    });
+    if (!Object.isExtensible(object)) { Object.preventExtensions(copy); }
+    seen.set(object, copy);
+    return copy;
+  }
+
   /** Test the scanner's own functionality. */
   window.testScanner = function testScanner() {
     // non-identifier props in programs
@@ -1464,10 +1486,12 @@
         pass('testScanner');
       }
     });
+
+    // each property here is an 'object is extensible' problem
+    var specimen = detach(Object.freeze({a: {}, 1: {}, '!': {}}));
+
     scanner.skip('Object');
-    // each property here is an 'object is extensible' problem
-    scanner.queue(Context.root(Object.freeze({a: {}, 1: {}, '!': {}}),
-        'foo', 'bar'));
+    scanner.queue(Context.root(specimen, 'foo', 'bar'));
     scanner.scan();

     // test trueApply which has proven to be tricky.


--

--- You received this message because you are subscribed to the Google Groups "Google Caja Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to