Bug 987669 - Tests. r=gabor
authorBobby Holley <bobbyholley@gmail.com>
Fri, 11 Jul 2014 09:09:22 -0700
changeset 215533 48b4e65d344d71e132ee97c79ab542b939d058b9
parent 215532 a2cbaa33712041d83416da86e33618f1a4e80b58
child 215534 4dfa43eb6862a1d795cdbb7a9e7ffb2ce1dbed51
push id515
push userraliiev@mozilla.com
push dateMon, 06 Oct 2014 12:51:51 +0000
treeherdermozilla-release@267c7a481bef [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersgabor
bugs987669
milestone33.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 987669 - Tests. r=gabor
js/xpconnect/tests/chrome/test_xrayToJS.xul
--- a/js/xpconnect/tests/chrome/test_xrayToJS.xul
+++ b/js/xpconnect/tests/chrome/test_xrayToJS.xul
@@ -33,20 +33,21 @@ https://bugzilla.mozilla.org/show_bug.cg
       ok(true, "Threw as expected: " + msg);
       ok(rgxp.test(e), "Message correct: " + e);
     }
   }
 
   typedArrayClasses = ['Uint8Array', 'Int8Array', 'Uint16Array', 'Int16Array',
                        'Uint32Array', 'Int32Array', 'Float32Array', 'Float64Array',
                        'Uint8ClampedArray'];
+  errorObjectClasses = ['Error', 'InternalError', 'EvalError', 'RangeError', 'ReferenceError',
+                        'SyntaxError', 'TypeError', 'URIError'];
   simpleConstructors = ['Object', 'Function', 'Array', 'Boolean', 'Date', 'Number',
-                        'String', 'RegExp', 'Error', 'InternalError', 'EvalError',
-                        'RangeError', 'ReferenceError', 'SyntaxError', 'TypeError',
-                        'URIError', 'ArrayBuffer', 'WeakMap', 'Map', 'Set'].concat(typedArrayClasses);
+                        'String', 'RegExp', 'ArrayBuffer', 'WeakMap', 'Map', 'Set'].concat(typedArrayClasses)
+                                                                                   .concat(errorObjectClasses);
 
   function go() {
     window.iwin = document.getElementById('ifr').contentWindow;
 
     // Test constructors that can be instantiated with zero arguments.
     for (var c of simpleConstructors) {
       ok(iwin[c], "Constructors appear: " + c);
       is(iwin[c], Cu.unwaiveXrays(iwin.wrappedJSObject[c]),
@@ -134,16 +135,18 @@ https://bugzilla.mozilla.org/show_bug.cg
     testDate();
 
     testObject();
 
     testArray();
 
     testTypedArrays();
 
+    testErrorObjects();
+
     // We could also test DataView and Iterator here for completeness, but it's
     // more trouble than it's worth.
 
 
     SimpleTest.finish();
   }
 
   // Maintain a static list of the properties that are available on each standard
@@ -177,16 +180,30 @@ https://bugzilla.mozilla.org/show_bug.cg
       "reducePar", "scanPar", "scatterPar", "filterPar", "find", "findIndex", "copyWithin",
       "fill", "@@iterator", "entries", "keys", "constructor"];
   for (var c of typedArrayClasses) {
     gPrototypeProperties[c] = ["constructor", "BYTES_PER_ELEMENT", "length", "buffer",
                                "byteLength", "byteOffset", "@@iterator", "subarray", "set"];
     if (!isReleaseBuild)
       gPrototypeProperties[c].push("move");
   }
+  for (var c of errorObjectClasses) {
+      gPrototypeProperties[c] = ["constructor", "name",
+                                 // We don't actually resolve these empty data properties
+                                 // onto the Xray prototypes, but we list them here to make
+                                 // the test happy.
+                                 "lineNumber", "columnNumber", "fileName", "message", "stack"];
+  }
+  // toString and toSource only live on the parent proto (Error.prototype).
+  gPrototypeProperties['Error'].push('toString');
+  gPrototypeProperties['Error'].push('toSource');
+
+  gPrototypeProperties['Function'] =
+    ["constructor", "toSource", "toString", "apply", "call", "bind",
+     "isGenerator", "length", "name", "arguments", "caller"];
   gPrototypeProperties['Function'] =
     ["constructor", "toSource", "toString", "apply", "call", "bind",
      "isGenerator", "length", "name", "arguments", "caller"];
 
   function filterOut(array, props) {
     return array.filter(p => props.indexOf(p) == -1);
   }
 
@@ -421,12 +438,44 @@ function testTrickyObject(trickyObject) 
          "Only indexed properties visible over Xrays");
       Object.defineProperty(t.wrappedJSObject, 'length', {value: 42});
       is(t.wrappedJSObject.length, 42, "Set tricky expando")
       is(t.length, 10, "Length accessor works over Xrays")
       is(t.byteLength, t.length * window[c].prototype.BYTES_PER_ELEMENT, "byteLength accessor works over Xrays")
     }
   }
 
+  function testErrorObjects() {
+    // We only invoke testXray with Error, because that function isn't set up
+    // to deal with dependent classes and fixing it up is more trouble than
+    // it's worth.
+    testXray('Error', new iwin.Error('some error message'), new iwin.Error(),
+             ['fileName', 'lineNumber', 'columnNumber', 'message', 'stack']);
+
+    // Make sure that the dependent classes have their prototypes set up correctly.
+    for (let c of errorObjectClasses.filter(x => x != "Error")) {
+      var e = new iwin[c]('some message');
+      is(Object.getPrototypeOf(e).name, c, "Prototype has correct name");
+      is(Object.getPrototypeOf(Object.getPrototypeOf(e)), iwin.Error.prototype, "Dependent prototype set up correctly");
+      is(e.name, c, "Exception name inherited correctly");
+
+      function testProperty(name, criterion, goodReplacement, faultyReplacement) {
+        ok(criterion(e[name]), name + " property is correct: " + e[name]);
+        e.wrappedJSObject[name] = goodReplacement;
+        is(e[name], goodReplacement, name + " property ok after replacement: " + goodReplacement);
+        e.wrappedJSObject[name] = faultyReplacement;
+        is(e[name], undefined, name + " property censored after suspicious replacement");
+      }
+      testProperty('message', x => x == 'some message', 'some other message', 42);
+      testProperty('fileName', x => /xul/.test(x), 'otherFilename.html', new iwin.Object());
+      // Note - an Exception newed via Xrays is going to have an empty stack given the
+      // current semantics and implementation. This tests the current behavior, but that
+      // may change in bug 1036527 or similar.
+      testProperty('stack', x => /^\s*$/.test(x), 'some other stack', new iwin.WeakMap());
+      testProperty('columnNumber', x => x > 5 && x < 100, 99, 99.5);
+      testProperty('lineNumber', x => x > 100 && x < 10000, 50, 'foo');
+    }
+  }
+
   ]]>
   </script>
   <iframe id="ifr" onload="go();" src="http://example.org/tests/js/xpconnect/tests/mochitest/file_empty.html" />
 </window>