Skip to content

Instantly share code, notes, and snippets.

@jorendorff
Last active October 7, 2023 23:24
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jorendorff/0627479bde2eeaa410f1 to your computer and use it in GitHub Desktop.
Save jorendorff/0627479bde2eeaa410f1 to your computer and use it in GitHub Desktop.
Before:
// 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]),
"we end up with the appropriate constructor: " + c);
is(Cu.unwaiveXrays(Cu.waiveXrays(new iwin[c]).constructor), iwin[c],
"constructor property is set up right: " + c);
let expectedProto = /Opaque/.test(new iwin[c]) ? iwin['Object'].prototype
: iwin[c].prototype;
is(Object.getPrototypeOf(new iwin[c]), expectedProto,
"prototype is correct: " + c);
is(global(new iwin[c]), iwin, "Got the right global: " + c);
}
After:
// Test constructors that can be instantiated with zero arguments.
var waiveXrays = Components.utils.waiveXrays;
var unwaiveXrays = Components.utils.unwaiveXrays;
for (var name of simpleConstructors) {
let constructor = childWindow[name];
ok(constructor, "Constructors appear: " + name);
is(constructor, unwaiveXrays(childWindow.wrappedJSObject[name]),
"we end up with the appropriate constructor: " + name);
let instance = new constructor;
is(unwaiveXrays(waiveXrays(instance).constructor), constructor,
"constructor property is set up right: " + name);
let expectedProto = /Opaque/.test(instance) ? childWindow.Object.prototype
: constructor.prototype;
is(Object.getPrototypeOf(instance), expectedProto,
"prototype is correct: " + name);
is(global(instance), childWindow, "Got the right global: " + name);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment