Created
September 26, 2014 17:53
-
-
Save jorendorff/340a567d73f68dd0b115 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Taken from http://dxr.mozilla.org/mozilla-central/source/js/xpconnect/tests/chrome/test_xrayToJS.xul | |
... | |
// 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); | |
} | |
// Test Object in more detail. | |
var num = new iwin.Object(4); | |
is(Cu.waiveXrays(num).valueOf(), 4, "primitive object construction works"); | |
is(global(num), iwin, "correct global for num"); | |
var obj = new iwin.Object(); | |
obj.foo = 2; | |
var withProto = Cu.unwaiveXrays(Cu.waiveXrays(iwin).Object.create(obj)); | |
is(global(withProto), iwin, "correct global for withProto"); | |
is(Cu.waiveXrays(withProto).foo, 2, "Inherits properly"); | |
... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Clearly that could be rewritten like this: | |
test("constructors that can be instantiated with zero arguments", function () { | |
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); | |
} | |
}); | |
test("Object in more detail", function () { | |
var num = new iwin.Object(4); | |
is(Cu.waiveXrays(num).valueOf(), 4, "primitive object construction works"); | |
is(global(num), iwin, "correct global for num"); | |
var obj = new iwin.Object(); | |
obj.foo = 2; | |
var withProto = Cu.unwaiveXrays(Cu.waiveXrays(iwin).Object.create(obj)); | |
is(global(withProto), iwin, "correct global for withProto"); | |
is(Cu.waiveXrays(withProto).foo, 2, "Inherits properly"); | |
... | |
}); | |
// but then it is not clear what the code does. you must go find the test() function and read it to find out if the tests are run synchronously, conditionally, etc. so it's not zero cost is what i'm saying. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment