--- a/js/xpconnect/tests/chrome/test_xrayToJS.xul
+++ b/js/xpconnect/tests/chrome/test_xrayToJS.xul
@@ -140,18 +140,16 @@ https://bugzilla.mozilla.org/show_bug.cg
// 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 version = Cc["@mozilla.org/xre/app-info;1"].getService(Ci.nsIXULAppInfo).version;
var isNightlyBuild = version.endsWith("a1");
var isReleaseBuild = !version.contains("a");
- const jsHasSymbols = typeof Symbol === "function";
- const kIteratorSymbol = jsHasSymbols ? Symbol.iterator : "@@iterator";
var gPrototypeProperties = {};
gPrototypeProperties['Date'] =
["getTime", "getTimezoneOffset", "getYear", "getFullYear", "getUTCFullYear",
"getMonth", "getUTCMonth", "getDate", "getUTCDate", "getDay", "getUTCDay",
"getHours", "getUTCHours", "getMinutes", "getUTCMinutes", "getSeconds",
"getUTCSeconds", "getMilliseconds", "getUTCMilliseconds", "setTime",
"setYear", "setFullYear", "setUTCFullYear", "setMonth", "setUTCMonth",
"setDate", "setUTCDate", "setHours", "setUTCHours", "setMinutes",
@@ -164,25 +162,25 @@ https://bugzilla.mozilla.org/show_bug.cg
the JS engine filters it out of getOwnPropertyNames */
["constructor", "toSource", "toString", "toLocaleString", "valueOf", "watch",
"unwatch", "hasOwnProperty", "isPrototypeOf", "propertyIsEnumerable",
"__defineGetter__", "__defineSetter__", "__lookupGetter__", "__lookupSetter__"];
gPrototypeProperties['Array'] =
["length", "toSource", "toString", "toLocaleString", "join", "reverse", "sort", "push",
"pop", "shift", "unshift", "splice", "concat", "slice", "lastIndexOf", "indexOf",
"forEach", "map", "reduce", "reduceRight", "filter", "some", "every", "find",
- "findIndex", "copyWithin", "fill", kIteratorSymbol, "entries", "keys", "constructor"];
+ "findIndex", "copyWithin", "fill", Symbol.iterator, "entries", "keys", "constructor"];
if (isNightlyBuild) {
gPrototypeProperties['Array'].push('includes');
}
for (var c of typedArrayClasses) {
gPrototypeProperties[c] = ["constructor", "BYTES_PER_ELEMENT"];
}
gPrototypeProperties['TypedArray'] =
- ["length", "buffer", "byteLength", "byteOffset", kIteratorSymbol, "subarray",
+ ["length", "buffer", "byteLength", "byteOffset", Symbol.iterator, "subarray",
"set", "copyWithin", "find", "findIndex", "forEach","indexOf", "lastIndexOf", "reverse",
"join", "every", "some", "reduce", "reduceRight", "entries", "keys", "values"];
if (isNightlyBuild) {
gPrototypeProperties['TypedArray'].push('includes');
}
for (var c of errorObjectClasses) {
gPrototypeProperties[c] = ["constructor", "name",
// We don't actually resolve these empty data properties
@@ -270,40 +268,36 @@ https://bugzilla.mozilla.org/show_bug.cg
let xrayProto = Object.getPrototypeOf(xray);
let localProto = window[classname].prototype;
let desiredProtoProps = Object.getOwnPropertyNames(localProto).sort();
is(desiredProtoProps.toSource(),
gPrototypeProperties[classname].filter(id => typeof id === "string").toSource(),
"A property on the " + classname +
" prototype has changed! You need a security audit from an XPConnect peer");
- if (jsHasSymbols) {
- is(Object.getOwnPropertySymbols(localProto).map(uneval).sort().toSource(),
- gPrototypeProperties[classname].filter(id => typeof id !== "string").map(uneval).sort().toSource(),
- "A symbol-keyed property on the " + classname +
- " prototype has been changed! You need a security audit from an XPConnect peer");
- }
+ is(Object.getOwnPropertySymbols(localProto).map(uneval).sort().toSource(),
+ gPrototypeProperties[classname].filter(id => typeof id !== "string").map(uneval).sort().toSource(),
+ "A symbol-keyed property on the " + classname +
+ " prototype has been changed! You need a security audit from an XPConnect peer");
let protoProps = filterOut(desiredProtoProps, propsToSkip);
let protoCallables = protoProps.filter(name => propertyIsGetter(localProto, name, classname) ||
typeof localProto[name] == 'function' &&
name != 'constructor');
ok(protoCallables.length > 0, "Need something to test");
is(xrayProto, iwin[classname].prototype, "Xray proto is correct");
is(xrayProto, xray.__proto__, "Proto accessors agree");
var protoProto = classname == "Object" ? null : iwin.Object.prototype;
is(Object.getPrototypeOf(xrayProto), protoProto, "proto proto is correct");
testProtoCallables(protoCallables, xray, xrayProto, localProto);
is(Object.getOwnPropertyNames(xrayProto).sort().toSource(),
protoProps.toSource(), "getOwnPropertyNames works");
- if (jsHasSymbols) {
- is(Object.getOwnPropertySymbols(xrayProto).map(uneval).sort().toSource(),
- gPrototypeProperties[classname].filter(id => typeof id !== "string").map(uneval).sort().toSource(),
- protoProps.toSource(), "getOwnPropertySymbols works");
- }
+ is(Object.getOwnPropertySymbols(xrayProto).map(uneval).sort().toSource(),
+ gPrototypeProperties[classname].filter(id => typeof id !== "string").map(uneval).sort().toSource(),
+ protoProps.toSource(), "getOwnPropertySymbols works");
is(xrayProto.constructor, iwin[classname], "constructor property works");
xrayProto.expando = 42;
is(xray.expando, 42, "Xrayed instances see proto expandos");
is(xray2.expando, 42, "Xrayed instances see proto expandos");
}
@@ -325,21 +319,19 @@ https://bugzilla.mozilla.org/show_bug.cg
var uniqueSymbol;
function testObject() {
testXray('Object', Cu.unwaiveXrays(Cu.waiveXrays(iwin).Object.create(new iwin.Object())),
new iwin.Object(), []);
// Construct an object full of tricky things.
let symbolProps = '';
- if (jsHasSymbols) {
- uniqueSymbol = iwin.eval('var uniqueSymbol = Symbol("uniqueSymbol"); uniqueSymbol');
- symbolProps = `, [uniqueSymbol]: 43,
- [Symbol.for("registrySymbolProp")]: 44`;
- }
+ uniqueSymbol = iwin.eval('var uniqueSymbol = Symbol("uniqueSymbol"); uniqueSymbol');
+ symbolProps = `, [uniqueSymbol]: 43,
+ [Symbol.for("registrySymbolProp")]: 44`;
var trickyObject =
iwin.eval(`(function() {
var o = new Object({
primitiveProp: 42, objectProp: { foo: 2 },
xoProp: top.location, hasOwnProperty: 10,
get getterProp() { return 2; },
set setterProp(x) { },
get getterSetterProp() { return 3; },
@@ -361,21 +353,19 @@ https://bugzilla.mozilla.org/show_bug.cg
// instance, and therefore has a vestigial .length. But we don't want to
// show that over Xrays, and generally want .length to just appear as an
// |own| data property. So we add it to the ignore list here, and check it
// separately.
let propsToSkip = ['length'];
testXray('Array', new iwin.Array(20), new iwin.Array(), propsToSkip);
let symbolProps = '';
- if (jsHasSymbols) {
- uniqueSymbol = iwin.eval('var uniqueSymbol = Symbol("uniqueSymbol"); uniqueSymbol');
- symbolProps = `trickyArray[uniqueSymbol] = 43;
- trickyArray[Symbol.for("registrySymbolProp")] = 44;`;
- }
+ uniqueSymbol = iwin.eval('var uniqueSymbol = Symbol("uniqueSymbol"); uniqueSymbol');
+ symbolProps = `trickyArray[uniqueSymbol] = 43;
+ trickyArray[Symbol.for("registrySymbolProp")] = 44;`;
var trickyArray =
iwin.eval(`var trickyArray = [];
trickyArray.primitiveProp = 42;
trickyArray.objectProp = { foo: 2 };
trickyArray.xoProp = top.location;
trickyArray.hasOwnProperty = 10;
Object.defineProperty(trickyArray, 'getterProp', { get: function() { return 2; }});
Object.defineProperty(trickyArray, 'setterProp', { set: function(x) {}});
@@ -418,31 +408,27 @@ https://bugzilla.mozilla.org/show_bug.cg
is(Cu.unwaiveXrays(trickyObject.wrappedJSObject.xoProp), top.location, "Underlying object has xo property");
// Test getOwnPropertyNames.
var expectedNames = ['objectProp', 'primitiveProp'];
if (trickyObject instanceof iwin.Array)
expectedNames.push('length');
is(Object.getOwnPropertyNames(trickyObject).sort().toSource(),
expectedNames.sort().toSource(), "getOwnPropertyNames should be filtered correctly");
- if (jsHasSymbols) {
- var expectedSymbols = [Symbol.for("registrySymbolProp"), uniqueSymbol];
- is(Object.getOwnPropertySymbols(trickyObject).map(uneval).sort().toSource(),
- expectedSymbols.map(uneval).sort().toSource(),
- "getOwnPropertySymbols should be filtered correctly");
- }
+ var expectedSymbols = [Symbol.for("registrySymbolProp"), uniqueSymbol];
+ is(Object.getOwnPropertySymbols(trickyObject).map(uneval).sort().toSource(),
+ expectedSymbols.map(uneval).sort().toSource(),
+ "getOwnPropertySymbols should be filtered correctly");
// Test that cloning uses the Xray view.
var cloned = Cu.cloneInto(trickyObject, this);
is(Object.getOwnPropertyNames(cloned).sort().toSource(),
expectedNames.sort().toSource(), "structured clone should use the Xray view");
- if (jsHasSymbols) {
- is(Object.getOwnPropertySymbols(cloned).map(uneval).sort().toSource(),
- "[]", "structured cloning doesn't clone symbol-keyed properties yet");
- }
+ is(Object.getOwnPropertySymbols(cloned).map(uneval).sort().toSource(),
+ "[]", "structured cloning doesn't clone symbol-keyed properties yet");
// Test iteration and in-place modification. Beware of 'expando', which is the property
// we placed on the xray proto.
var propCount = 0;
for (let prop in trickyObject) {
if (prop == 'primitiveProp')
trickyObject[prop] = trickyObject[prop] - 10;
if (prop != 'expando')