Bug 1568903 - Part 10: Update test_xrayToJS to handle the new AggregateError object and the Promise method. r=peterv,jorendorff
☠☠ backed out by cfe990fab350 ☠ ☠
authorAndré Bargull <andre.bargull@gmail.com>
Fri, 15 Nov 2019 10:34:04 +0000
changeset 502146 76ad398222a6809bef3116d77b580ef3e9339cce
parent 502145 f4d9fda6d7f2504b1e8bde4f50603a7013f0917f
child 502147 dde69745453204c798161277bf2c905183b1b545
push id114172
push userdluca@mozilla.com
push dateTue, 19 Nov 2019 11:31:10 +0000
treeherdermozilla-inbound@b5c5ba07d3db [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerspeterv, jorendorff
bugs1568903
milestone72.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 1568903 - Part 10: Update test_xrayToJS to handle the new AggregateError object and the Promise method. r=peterv,jorendorff Differential Revision: https://phabricator.services.mozilla.com/D51660
js/xpconnect/tests/chrome/test_xrayToJS.xhtml
--- a/js/xpconnect/tests/chrome/test_xrayToJS.xhtml
+++ b/js/xpconnect/tests/chrome/test_xrayToJS.xhtml
@@ -27,30 +27,48 @@ https://bugzilla.mozilla.org/show_bug.cg
       f();
       ok(false, "Should have thrown: " + msg);
     } catch (e) {
       ok(true, "Threw as expected: " + msg);
       ok(rgxp.test(e), "Message correct: " + e);
     }
   }
 
+  var {AppConstants} = SpecialPowers.Cu.import("resource://gre/modules/AppConstants.jsm", {});
+  var isNightlyBuild = AppConstants.NIGHTLY_BUILD;
+  var isReleaseOrBeta = AppConstants.RELEASE_OR_BETA;
+
   typedArrayClasses = ['Uint8Array', 'Int8Array', 'Uint16Array', 'Int16Array',
                        'Uint32Array', 'Int32Array', 'Float32Array', 'Float64Array',
                        'Uint8ClampedArray'];
   errorObjectClasses = ['Error', 'InternalError', 'EvalError', 'RangeError', 'ReferenceError',
                         'SyntaxError', 'TypeError', 'URIError'];
+  if (isNightlyBuild) {
+    errorObjectClasses.push('AggregateError');
+  }
 
   // A simpleConstructors entry can either be the name of a constructor as a
   // string, or an object containing the properties `name`, and `args`.
   // In the former case, the constructor is invoked without any args; in the
   // latter case, it is invoked with `args` as the arguments list.
   simpleConstructors = ['Object', 'Function', 'Array', 'Boolean', 'Date', 'Number',
                         'String', 'RegExp', 'ArrayBuffer', 'WeakMap', 'WeakSet', 'Map', 'Set',
-                        {name: 'Promise', args: [function(){}]}].concat(typedArrayClasses)
-                                                                .concat(errorObjectClasses);
+                        {name: 'Promise', args: [function(){}]}];
+
+  // All TypedArray constructors can be called with zero arguments.
+  simpleConstructors = simpleConstructors.concat(typedArrayClasses);
+
+  // All Error constructors except AggregateError can be called with zero arguments.
+  simpleConstructors = simpleConstructors.concat(errorObjectClasses.map(name) => {
+    if (name === 'AggregateError') {
+      // AggregateError throws when called without an iterable object as its first argument.
+      return {name: 'AggregateError', args: [[]]};
+    }
+    return name;
+  });
 
   function go() {
     window.iwin = document.getElementById('ifr').contentWindow;
 
     // Test constructors that can be instantiated with zero arguments, or with
     // a fixed set of arguments provided using `...rest`.
     for (var c of simpleConstructors) {
       var args = [];
@@ -162,19 +180,16 @@ https://bugzilla.mozilla.org/show_bug.cg
     SimpleTest.finish();
   }
 
   // Maintain a static list of the properties that are available on each standard
   // prototype, so that we make sure to audit any new ones to make sure they're
   // Xray-safe.
   //
   // DO NOT CHANGE WTIHOUT REVIEW FROM AN XPCONNECT PEER.
-  var {AppConstants} = SpecialPowers.Cu.import("resource://gre/modules/AppConstants.jsm", {});
-  var isNightlyBuild = AppConstants.NIGHTLY_BUILD;
-  var isReleaseOrBeta = AppConstants.RELEASE_OR_BETA;
   var gPrototypeProperties = {};
   var gConstructorProperties = {};
   function constructorProps(arr) {
     // Some props live on all constructors
     return arr.concat(["prototype", "length", "name"]);
   }
   gPrototypeProperties['Date'] =
     ["getTime", "getTimezoneOffset", "getYear", "getFullYear", "getUTCFullYear",
@@ -219,16 +234,19 @@ https://bugzilla.mozilla.org/show_bug.cg
      "reverse", "join", "every", "some", "reduce", "reduceRight", "entries", "keys", "values",
      "slice", "map", "filter"];
   // There is no TypedArray constructor, looks like.
   is(window.TypedArray, undefined, "If this ever changes, add to this test!");
   for (var c of errorObjectClasses) {
       gPrototypeProperties[c] = ["constructor", "name", "message", "stack"];
       gConstructorProperties[c] = constructorProps([]);
   }
+  if (gPrototypeProperties['AggregateError']) {
+      gPrototypeProperties['AggregateError'].push("errors");
+  }
   // 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",
      "length", "name", "arguments", "caller", Symbol.hasInstance];
   gConstructorProperties['Function'] = constructorProps([])
@@ -242,16 +260,19 @@ https://bugzilla.mozilla.org/show_bug.cg
                       "leftContext", "rightContext", "$1", "$2", "$3", "$4",
                       "$5", "$6", "$7", "$8", "$9", "$_", "$&", "$+",
                       "$`", "$'", Symbol.species])
 
   gPrototypeProperties['Promise'] =
     ["constructor", "catch", "then", "finally", Symbol.toStringTag];
   gConstructorProperties['Promise'] =
     constructorProps(["resolve", "reject", "all", "allSettled", "race", Symbol.species]);
+  if (isNightlyBuild) {
+    gConstructorProperties['Promise'].push("any");
+  }
 
   gPrototypeProperties['ArrayBuffer'] =
     ["constructor", "byteLength", "slice", Symbol.toStringTag];
   gConstructorProperties['ArrayBuffer'] =
     constructorProps(["isView", Symbol.species]);
 
   is(typeof SharedArrayBuffer, "undefined", "Enable tests!");
 
@@ -811,33 +832,54 @@ https://bugzilla.mozilla.org/show_bug.cg
   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());
 
     // 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');
+      var args = ['some message'];
+      if (c === 'AggregateError') {
+        // AggregateError's first argument is the list of aggregated errors.
+        args.unshift(['error 1', 'error 2']);
+      }
+      var e = new iwin[c](...args);
       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], name == 'message' ? "" : undefined, name + " property skipped after suspicious replacement");
       }
       testProperty('message', x => x == 'some message', 'some other message', 42);
       testProperty('fileName', x => x == '', 'otherFilename.html', new iwin.Object());
       testProperty('columnNumber', x => x == 1, 99, 99.5);
       testProperty('lineNumber', x => x == 0, 50, 'foo');
 
+      if (c === 'AggregateError') {
+        let {errors} = e;
+        is(errors.length, 2, "errors property has the correct length");
+        is(errors[0], 'error 1', "errors[0] has the correct value");
+        is(errors[1], 'error 2', "errors[1] has the correct value");
+
+        try {
+          e.wrappedJSObject.errors = [];
+
+          throw new Error("Missing exception");
+        } catch (exc) {
+          is(exc.name, "TypeError", "setting the errors property throws a TypeError");
+        }
+        is(e.errors.length, 2, "errors property can't be set");
+      }
+
       // 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.
       //
       // Furthermore, xrays should always return an error's original stack, and
       // not overwrite it.
       var stack = e.stack;
       ok(/^\s*$/.test(stack), "stack property should be correct");