Bug 786639 - XPCChromeObjectWrapper __exposedProps__ should expose the content of typed arrays like UInt8Array. r=bholley
authorAndrew Sutherland <asutherland@asutherland.org>
Wed, 05 Sep 2012 14:05:32 -0700
changeset 104335 460d24605a7b04737697f43abf6b8174365c290b
parent 104334 8278070827904ca5d8bc3bcdabfc7a94fc71b569
child 104336 e919c8cdb667ef78d9737e0bcae6bfc9ec980cf0
push id23417
push userryanvm@gmail.com
push dateThu, 06 Sep 2012 02:27:31 +0000
treeherdermozilla-central@501f4e46a88c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbholley
bugs786639
milestone18.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 786639 - XPCChromeObjectWrapper __exposedProps__ should expose the content of typed arrays like UInt8Array. r=bholley
js/xpconnect/tests/chrome/test_bug760109.xul
js/xpconnect/wrappers/AccessCheck.cpp
--- a/js/xpconnect/tests/chrome/test_bug760109.xul
+++ b/js/xpconnect/tests/chrome/test_bug760109.xul
@@ -52,16 +52,20 @@ https://bugzilla.mozilla.org/show_bug.cg
     // Try some operations that modify the array.
     is(chromeArray.pop(), 'z', "Able to call pop");
     is(chromeArray.push('z'), 3, "Able to call push");
     chromeArray.reverse();
     is(chromeArray.join(''), 'zba', "Able to call reverse");
     chromeArray.sort();
     is(chromeArray.join(''), 'abz', "Able to call sort");
 
+    // Make sure we can see the data on the typed array
+    is(chromeTypedArray.length, 3, "Able to check typed array length");
+    is(chromeTypedArray[0], 10, "Able to access typed array data");
+
     // We should be able to .hasOwnProperty on the Object, and have
     // it filter the objects we can see.
     ok(chromeObject.hasOwnProperty('foo'), "Should see r property");
     ok(!chromeObject.hasOwnProperty('bar'), "Shouldn't see non-exposed property");
     ok(chromeObject.hasOwnProperty('baz'), "Should see rw property");
   }
 
   // We use a constructor to create the test object so that there's an
@@ -74,16 +78,17 @@ https://bugzilla.mozilla.org/show_bug.cg
     this.__exposedProps__ = {foo: 'r', baz: 'rw'};
   }
   SomeConstructor.prototype.__exposedProps__ = {};
 
   const Cu = Components.utils;
   var sb = new Cu.Sandbox('http://www.example.org');
   sb.chromeArray = ['a', 'b', 'z'];
   sb.chromeArray.__exposedProps__ = {};
+  sb.chromeTypedArray = new Uint8Array([10, 20, 30]);
   sb.chromeObject = new SomeConstructor();
   sb.ok = ok;
   sb.is = is;
   Cu.evalInSandbox('(' + sandboxCode.toSource() + ')();', sb);
 
   ]]>
   </script>
 </window>
--- a/js/xpconnect/wrappers/AccessCheck.cpp
+++ b/js/xpconnect/wrappers/AccessCheck.cpp
@@ -414,17 +414,18 @@ ExposedPropertiesOnly::check(JSContext *
     // Unfortunately, |cx| can be in either compartment when we call ::check. :-(
     JSAutoCompartment ac(cx, wrappedObject);
 
     JSBool found = false;
     if (!JS_HasPropertyById(cx, wrappedObject, exposedPropsId, &found))
         return false;
 
     // Always permit access to "length" and indexed properties of arrays.
-    if (JS_IsArrayObject(cx, wrappedObject) &&
+    if ((JS_IsArrayObject(cx, wrappedObject) ||
+         JS_IsTypedArrayObject(wrappedObject, cx)) &&
         ((JSID_IS_INT(id) && JSID_TO_INT(id) >= 0) ||
          (JSID_IS_STRING(id) && JS_FlatStringEqualsAscii(JSID_TO_FLAT_STRING(id), "length")))) {
         perm = PermitPropertyAccess;
         return true; // Allow
     }
 
     // If no __exposedProps__ existed, deny access.
     if (!found) {