Bug 731442 - Back out f9145dab4be9 (bug 718543) due to test failures. r=backout
authorBobby Holley <bobbyholley@gmail.com>
Tue, 06 Mar 2012 11:05:29 -0800
changeset 88324 75fcd465d5064f8d00c7c04f76434806b3c5b2cb
parent 88323 0d50471180387c0b0fcfd4c05d331daa56b665db
child 88325 78e56fd22f2a9b424865dd62b1de528e6e1d397d
push id22190
push userbobbyholley@gmail.com
push dateTue, 06 Mar 2012 19:08:24 +0000
treeherdermozilla-central@75fcd465d506 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbackout
bugs731442, 718543
milestone13.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 731442 - Back out f9145dab4be9 (bug 718543) due to test failures. r=backout
testing/mochitest/tests/SimpleTest/specialpowersAPI.js
testing/mochitest/tests/test_SpecialPowersExtension.html
--- a/testing/mochitest/tests/SimpleTest/specialpowersAPI.js
+++ b/testing/mochitest/tests/SimpleTest/specialpowersAPI.js
@@ -112,38 +112,30 @@ function isXrayWrapper(x) {
 }
 
 // We can't call apply() directy on Xray-wrapped functions, so we have to be
 // clever.
 function doApply(fun, invocant, args) {
   return Function.prototype.apply.call(fun, invocant, args);
 }
 
-// Use a weak map to cache wrappers. This allows the wrappers to preserve identity.
-var wrapperCache = WeakMap();
-
 function wrapPrivileged(obj) {
 
   // Primitives pass straight through.
   if (!isWrappable(obj))
     return obj;
 
   // No double wrapping.
   if (isWrapper(obj))
     throw "Trying to double-wrap object!";
 
-  // Try the cache.
-  if (wrapperCache.has(obj))
-    return wrapperCache.get(obj);
-
   // Make our core wrapper object.
   var handler = new SpecialPowersHandler(obj);
 
   // If the object is callable, make a function proxy.
-  var wrapper;
   if (typeof obj === "function") {
     var callTrap = function() {
       // The invocant and arguments may or may not be wrappers. Unwrap them if necessary.
       var invocant = unwrapIfWrapped(this);
       var unwrappedArgs = Array.prototype.slice.call(arguments).map(unwrapIfWrapped);
 
       return wrapPrivileged(doApply(obj, invocant, unwrappedArgs));
     };
@@ -157,26 +149,21 @@ function wrapPrivileged(obj) {
       var FakeConstructor = function() {
         doApply(obj, this, unwrappedArgs);
       };
       FakeConstructor.prototype = obj.prototype;
 
       return wrapPrivileged(new FakeConstructor());
     };
 
-    wrapper = Proxy.createFunction(handler, callTrap, constructTrap);
-  }
-  // Otherwise, just make a regular object proxy.
-  else {
-    wrapper = Proxy.create(handler);
+    return Proxy.createFunction(handler, callTrap, constructTrap);
   }
 
-  // Cache the wrapper and return it.
-  wrapperCache.set(obj, wrapper);
-  return wrapper;
+  // Otherwise, just make a regular object proxy.
+  return Proxy.create(handler);
 };
 
 function unwrapPrivileged(x) {
 
   // We don't wrap primitives, so sometimes we have a primitive where we'd
   // expect to have a wrapper. The proxy pretends to be the type that it's
   // emulating, so we can just as easily check isWrappable() on a proxy as
   // we can on an unwrapped object.
@@ -377,16 +364,19 @@ SpecialPowersAPI.prototype = {
    * object containing a reference to the underlying object, where all method
    * calls and property accesses are transparently performed with the System
    * Principal. Moreover, objects obtained from the wrapper (including properties
    * and method return values) are wrapped automatically. Thus, after a single
    * call to SpecialPowers.wrap(), the wrapper layer is transitively maintained.
    *
    * Known Issues:
    *
+   *  - The wrapping function does not preserve identity, so
+   *    SpecialPowers.wrap(foo) !== SpecialPowers.wrap(foo). See bug 718543.
+   *
    *  - The wrapper cannot see expando properties on unprivileged DOM objects.
    *    That is to say, the wrapper uses Xray delegation.
    *
    *  - The wrapper sometimes guesses certain ES5 attributes for returned
    *    properties. This is explained in a comment in the wrapper code above,
    *    and shouldn't be a problem.
    */
   wrap: wrapPrivileged,
--- a/testing/mochitest/tests/test_SpecialPowersExtension.html
+++ b/testing/mochitest/tests/test_SpecialPowersExtension.html
@@ -129,23 +129,16 @@ function starttest(){
   noxray.__proto__ = noxray_proto;
   var noxray_wrapper = SpecialPowers.wrap(noxray);
   is(noxray_wrapper.c, 32, "Regular properties should work.");
   is(noxray_wrapper.a, 5, "Shadow properties should work.");
   is(noxray_wrapper.b, 12, "Proto properties should work.");
   noxray.b = 122;
   is(noxray_wrapper.b, 122, "Should be able to shadow.");
 
-  // Check that the wrapper preserves identity.
-  var someIdentityObject = {a: 2};
-  ok(SpecialPowers.wrap(someIdentityObject) === SpecialPowers.wrap(someIdentityObject),
-     "SpecialPowers wrapping should preserve identity!");
-  ok(webnav === SpecialPowers.wrap(SpecialPowers.unwrap(webnav)),
-     "SpecialPowers wrapping should preserve identity!");
-
   info("\nProfile::SpecialPowersRunTime: " + (new Date() - startTime) + "\n");
   SimpleTest.finish();
 }
 </script>
 </pre>
 </body>
 </html>