Bug 729589 - Fix js-ctypes tests for compartment-per-global. r=jorendorff
authorBobby Holley <bobbyholley@gmail.com>
Tue, 27 Mar 2012 11:33:25 -0700
changeset 90437 b5986b6f6bde63cf9ad804a2b5eebeafa4691061
parent 90436 3c6e6afdfd4a0bbbb6fb19da1ba5de108a5c4f0e
child 90438 90f6c3fe8638b58012c687ccf4f5e1bbbcd85dfe
push id22358
push userkhuey@mozilla.com
push dateWed, 28 Mar 2012 14:41:10 +0000
treeherdermozilla-central@c3fd0768d46a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjorendorff
bugs729589
milestone14.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 729589 - Fix js-ctypes tests for compartment-per-global. r=jorendorff
toolkit/components/ctypes/tests/unit/test_jsctypes.js.in
--- a/toolkit/components/ctypes/tests/unit/test_jsctypes.js.in
+++ b/toolkit/components/ctypes/tests/unit/test_jsctypes.js.in
@@ -43,42 +43,30 @@ try {
   // harness to give us the 'ctypes' object.
   Components.utils.import("resource://gre/modules/ctypes.jsm");
 } catch(e) {
 }
 
 CTYPES_TEST_LIB = ctypes.libraryName("jsctypes-test");
 CTYPES_UNICODE_LIB = ctypes.libraryName("jsctyp\u00E8s-t\u00EB\u00DFt");
 
-function getParent(obj, fun)
-{
-  if (typeof parent === "function")
-    fun(parent(obj));
-}
-
-function checkParentIsCTypes(o)
-{
-  function parentIsCTypes(p) { do_check_true(p === ctypes); }
-  getParent(o, parentIsCTypes);
-}
-
 function do_check_throws(f, type, stack)
 {
   if (!stack) {
     try {
       // We might not have a 'Components' object.
       stack = Components.stack.caller;
     } catch (e) {
     }
   }
 
   try {
     f();
   } catch (exc) {
-    if (exc instanceof type) {
+    if (exc.constructor.name === type.name) {
       do_check_true(true);
       return;
     }
     do_throw("expected " + type.name + " exception, caught " + exc, stack);
   }
   do_throw("expected " + type.name + " exception, none thrown", stack);
 }
 
@@ -264,30 +252,20 @@ function run_abstract_class_tests()
   // Test that ctypes.CType is an abstract constructor that throws.
   do_check_throws(function() { ctypes.CType(); }, Error);
   do_check_throws(function() { new ctypes.CType() }, Error);
 
   // Test that classes and prototypes are set up correctly.
   do_check_class(ctypes.CType, "Function");
   do_check_class(ctypes.CType.prototype, "CType");
 
-  checkParentIsCTypes(ctypes.CType);
-  getParent(ctypes, function(p) {
-    do_check_true(Object.getPrototypeOf(ctypes.CType) === p.Function.prototype);
-    do_check_true(ctypes.CType instanceof p.Function);
-  });
-
   do_check_true(ctypes.CType.hasOwnProperty("prototype"));
   do_check_throws(function() { ctypes.CType.prototype(); }, Error);
   do_check_throws(function() { new ctypes.CType.prototype() }, Error);
-  checkParentIsCTypes(ctypes.CType.prototype);
-  getParent(ctypes, function(p) {
-    do_check_true(Object.getPrototypeOf(ctypes.CType.prototype) === p.Function.prototype);
-    do_check_true(ctypes.CType.prototype instanceof p.Function);
-  });
+  
   do_check_true(ctypes.CType.prototype.hasOwnProperty("constructor"));
   do_check_true(ctypes.CType.prototype.constructor === ctypes.CType);
 
   // Check that ctypes.CType.prototype has the correct properties and functions.
   do_check_true(ctypes.CType.prototype.hasOwnProperty("name"));
   do_check_true(ctypes.CType.prototype.hasOwnProperty("size"));
   do_check_true(ctypes.CType.prototype.hasOwnProperty("ptr"));
   do_check_true(ctypes.CType.prototype.hasOwnProperty("array"));
@@ -311,25 +289,20 @@ function run_abstract_class_tests()
   // Test that ctypes.CData is an abstract constructor that throws.
   do_check_throws(function() { ctypes.CData(); }, Error);
   do_check_throws(function() { new ctypes.CData() }, Error);
 
   // Test that classes and prototypes are set up correctly.
   do_check_class(ctypes.CData, "Function");
   do_check_class(ctypes.CData.prototype, "CData");
 
-  checkParentIsCTypes(ctypes.CData);
   do_check_true(ctypes.CData.__proto__ === ctypes.CType.prototype);
   do_check_true(ctypes.CData instanceof ctypes.CType);
 
   do_check_true(ctypes.CData.hasOwnProperty("prototype"));
-  checkParentIsCTypes(ctypes.CData.prototype);
-  getParent(ctypes, function(p) {
-    do_check_true(Object.getPrototypeOf(ctypes.CData.prototype) === p.Object.prototype);
-  });
   do_check_true(ctypes.CData.prototype.hasOwnProperty("constructor"));
   do_check_true(ctypes.CData.prototype.constructor === ctypes.CData);
 
   // Check that ctypes.CData.prototype has the correct properties and functions.
   do_check_true(ctypes.CData.prototype.hasOwnProperty("value"));
   do_check_true(ctypes.CData.prototype.hasOwnProperty("address"));
   do_check_true(ctypes.CData.prototype.hasOwnProperty("readString"));
   do_check_true(ctypes.CData.prototype.hasOwnProperty("toString"));
@@ -350,24 +323,17 @@ function run_abstract_class_tests()
 
 function run_Int64_tests() {
   do_check_throws(function() { ctypes.Int64(); }, Error);
 
   // Test that classes and prototypes are set up correctly.
   do_check_class(ctypes.Int64, "Function");
   do_check_class(ctypes.Int64.prototype, "Int64");
 
-  checkParentIsCTypes(ctypes.Int64);
-  getParent(ctypes, function(p) {
-    do_check_true(Object.getPrototypeOf(ctypes.Int64) === p.Function.prototype);
-    do_check_true(Object.getPrototypeOf(ctypes.Int64.prototype) === p.Object.prototype);
-  });
-
   do_check_true(ctypes.Int64.hasOwnProperty("prototype"));
-  checkParentIsCTypes(ctypes.Int64.prototype);
   do_check_true(ctypes.Int64.prototype.hasOwnProperty("constructor"));
   do_check_true(ctypes.Int64.prototype.constructor === ctypes.Int64);
 
   // Check that ctypes.Int64 and ctypes.Int64.prototype have the correct
   // properties and functions.
   do_check_true(ctypes.Int64.hasOwnProperty("compare"));
   do_check_true(ctypes.Int64.hasOwnProperty("lo"));
   do_check_true(ctypes.Int64.hasOwnProperty("hi"));
@@ -375,17 +341,16 @@ function run_Int64_tests() {
   do_check_true(ctypes.Int64.prototype.hasOwnProperty("toString"));
   do_check_true(ctypes.Int64.prototype.hasOwnProperty("toSource"));
 
   // Check that the shared functions on ctypes.Int64.prototype throw.
   do_check_throws(function() { ctypes.Int64.prototype.toString(); }, Error);
   do_check_throws(function() { ctypes.Int64.prototype.toSource(); }, Error);
 
   let i = ctypes.Int64(0);
-  checkParentIsCTypes(i);
   do_check_true(i.__proto__ === ctypes.Int64.prototype);
   do_check_true(i instanceof ctypes.Int64);
 
   // Test Int64.toString([radix]).
   do_check_eq(i.toString(), "0");
   for (let radix = 2; radix <= 36; ++radix)
     do_check_eq(i.toString(radix), "0");
   do_check_throws(function() { i.toString(0); }, Error);
@@ -529,26 +494,17 @@ function run_Int64_tests() {
 
 function run_UInt64_tests() {
   do_check_throws(function() { ctypes.UInt64(); }, Error);
 
   // Test that classes and prototypes are set up correctly.
   do_check_class(ctypes.UInt64, "Function");
   do_check_class(ctypes.UInt64.prototype, "UInt64");
 
-  checkParentIsCTypes(ctypes.UInt64);
-  getParent(ctypes, function(p) {
-    do_check_true(Object.getPrototypeOf(ctypes.UInt64) === p.Function.prototype);
-  });
-
   do_check_true(ctypes.UInt64.hasOwnProperty("prototype"));
-  checkParentIsCTypes(ctypes.UInt64.prototype);
-  getParent(ctypes, function(p) {
-    do_check_true(Object.getPrototypeOf(ctypes.UInt64.prototype) === p.Object.prototype);
-  });
   do_check_true(ctypes.UInt64.prototype.hasOwnProperty("constructor"));
   do_check_true(ctypes.UInt64.prototype.constructor === ctypes.UInt64);
 
   // Check that ctypes.UInt64 and ctypes.UInt64.prototype have the correct
   // properties and functions.
   do_check_true(ctypes.UInt64.hasOwnProperty("compare"));
   do_check_true(ctypes.UInt64.hasOwnProperty("lo"));
   do_check_true(ctypes.UInt64.hasOwnProperty("hi"));
@@ -556,17 +512,16 @@ function run_UInt64_tests() {
   do_check_true(ctypes.UInt64.prototype.hasOwnProperty("toString"));
   do_check_true(ctypes.UInt64.prototype.hasOwnProperty("toSource"));
 
   // Check that the shared functions on ctypes.UInt64.prototype throw.
   do_check_throws(function() { ctypes.UInt64.prototype.toString(); }, Error);
   do_check_throws(function() { ctypes.UInt64.prototype.toSource(); }, Error);
 
   let i = ctypes.UInt64(0);
-  checkParentIsCTypes(i);
   do_check_true(i.__proto__ === ctypes.UInt64.prototype);
   do_check_true(i instanceof ctypes.UInt64);
 
   // Test UInt64.toString([radix]).
   do_check_eq(i.toString(), "0");
   for (let radix = 2; radix <= 36; ++radix)
     do_check_eq(i.toString(radix), "0");
   do_check_throws(function() { i.toString(0); }, Error);
@@ -793,21 +748,19 @@ function offsetof(struct, member) {
 
 // Test the class and prototype hierarchy for a given basic type 't'.
 function run_basic_class_tests(t)
 {
   // Test that classes and prototypes are set up correctly.
   do_check_class(t, "CType");
   do_check_class(t.prototype, "CData");
 
-  checkParentIsCTypes(t);
   do_check_true(t.__proto__ === ctypes.CType.prototype);
   do_check_true(t instanceof ctypes.CType);
 
-  checkParentIsCTypes(t.prototype);
   do_check_true(t.prototype.__proto__ === ctypes.CData.prototype);
   do_check_true(t.prototype instanceof ctypes.CData);
   do_check_true(t.prototype.constructor === t);
 
   // Check that the shared properties and functions on 't.prototype' throw.
   do_check_throws(function() { t.prototype.value; }, Error);
   do_check_throws(function() { t.prototype.value = null; }, Error);
   do_check_throws(function() { t.prototype.address(); }, Error);
@@ -816,17 +769,16 @@ function run_basic_class_tests(t)
   // toString and toSource are called by the web console during inspection,
   // so we don't want them to throw.
   do_check_eq(t.prototype.toString(), '[CData proto object]');
   do_check_eq(t.prototype.toSource(), '[CData proto object]');
 
   // Test that an instance 'd' of 't' is a CData.
   let d = t();
   do_check_class(d, "CData");
-  checkParentIsCTypes(d);
   do_check_true(d.__proto__ === t.prototype);
   do_check_true(d instanceof t);
   do_check_true(d.constructor === t);
 }
 
 function run_bool_tests(library) {
   let t = ctypes.bool;
   run_basic_class_tests(t);
@@ -1341,23 +1293,16 @@ function run_jschar_tests(library, t, na
 
 // Test the class and prototype hierarchy for a given type constructor 'c'.
 function run_type_ctor_class_tests(c, t, t2, props, fns, instanceProps, instanceFns, specialProps)
 {
   // Test that classes and prototypes are set up correctly on the type ctor 'c'.
   do_check_class(c, "Function");
   do_check_class(c.prototype, "CType");
 
-  checkParentIsCTypes(c);
-  getParent(ctypes, function(p) {
-    do_check_true(Object.getPrototypeOf(c) === p.Function.prototype);
-    do_check_true(c instanceof p.Function);
-  });
-
-  checkParentIsCTypes(c.prototype);
   do_check_true(c.prototype.__proto__ === ctypes.CType.prototype);
   do_check_true(c.prototype instanceof ctypes.CType);
   do_check_true(c.prototype.constructor === c);
 
   // Check that 'c.prototype' has the correct properties and functions.
   for each (let p in props)
     do_check_true(c.prototype.hasOwnProperty(p));
   for each (let f in fns)
@@ -1369,28 +1314,25 @@ function run_type_ctor_class_tests(c, t,
   for each (let f in fns)
     do_check_throws(function() { c.prototype[f](); }, Error);
 
   // Test that classes and prototypes are set up correctly on a constructed
   // type 't'.
   do_check_class(t, "CType");
   do_check_class(t.prototype, "CData");
 
-  checkParentIsCTypes(t);
   do_check_true(t.__proto__ === c.prototype);
   do_check_true(t instanceof c);
 
-  checkParentIsCTypes(t.prototype);
   do_check_class(t.prototype.__proto__, "CData");
   // 't.prototype.__proto__' is the common ancestor of all types constructed
   // from 'c'; while not available from 'c' directly, it should be identically
   // equal to 't2.prototype.__proto__' where 't2' is a different CType
   // constructed from 'c'.
   do_check_true(t.prototype.__proto__ === t2.prototype.__proto__);
-  checkParentIsCTypes(Object.getPrototypeOf(t.prototype));
   do_check_true(t.prototype.__proto__.__proto__ === ctypes.CData.prototype);
   do_check_true(t.prototype instanceof ctypes.CData);
   do_check_true(t.prototype.constructor === t);
 
   // Check that 't.prototype.__proto__' has the correct properties and
   // functions.
   for each (let p in instanceProps)
     do_check_true(t.prototype.__proto__.hasOwnProperty(p));
@@ -1418,17 +1360,16 @@ function run_type_ctor_class_tests(c, t,
 
   // Make sure we can access 'prototype' on a CTypeProto.
   do_check_true(Object.getPrototypeOf(c.prototype.prototype) === ctypes.CType.prototype.prototype);
 
   // Test that an instance 'd' of 't' is a CData.
   if (t.__proto__ != ctypes.FunctionType.prototype) {
     let d = t();
     do_check_class(d, "CData");
-    checkParentIsCTypes(d);
     do_check_true(d.__proto__ === t.prototype);
     do_check_true(d instanceof t);
     do_check_true(d.constructor === t);
   }
 }
 
 function run_StructType_tests() {
   run_type_ctor_class_tests(ctypes.StructType,
@@ -1609,17 +1550,17 @@ function run_StructType_tests() {
   }
 
   let g = g_t();
   do_check_eq(g.a, 0);
   do_check_eq(g.b, 0);
   g = new g_t(1, 2);
   do_check_eq(g.a, 1);
   do_check_eq(g.b, 2);
-  do_check_throws(function() { g_t(1); }, Error);
+  do_check_throws(function() { g_t(1); }, TypeError);
   do_check_throws(function() { g_t(1, 2, 3); }, Error);
 
   for (let field in g)
     do_check_true(field == "a" || field == "b");
 
   let g_a = g.address();
   do_check_true(g_a.constructor === g_t.ptr);
   do_check_eq(g_a.contents.a, g.a);
@@ -1651,21 +1592,21 @@ function run_StructType_tests() {
   do_check_eq(s.b.b, s2.b.b);
 
   // Test that structs can be set from an object using 'value'.
   do_check_throws(function() { s.value; }, Error);
   let s_init = { "a": 2, "b": { "a": 9, "b": 5 }, "c": 13 };
   s.value = s_init;
   do_check_eq(s.b.a, 9);
   do_check_eq(s.c, 13);
-  do_check_throws(function() { s.value = 5; }, Error);
-  do_check_throws(function() { s.value = ctypes.int32_t(); }, Error);
+  do_check_throws(function() { s.value = 5; }, TypeError);
+  do_check_throws(function() { s.value = ctypes.int32_t(); }, TypeError);
   do_check_throws(function() { s.value = {}; }, Error);
   do_check_throws(function() { s.value = { "a": 2 }; }, Error);
-  do_check_throws(function() { s.value = { "a": 2, "b": 5, "c": 10 }; }, Error);
+  do_check_throws(function() { s.value = { "a": 2, "b": 5, "c": 10 }; }, TypeError);
   do_check_throws(function() {
     s.value = { "5": 2, "b": { "a": 9, "b": 5 }, "c": 13 };
   }, Error);
   do_check_throws(function() {
     s.value = { "a": 2, "b": { "a": 9, "b": 5 }, "c": 13, "d": 17 };
   }, Error);
   do_check_throws(function() {
     s.value = { "a": 2, "b": { "a": 9, "b": 5, "e": 9 }, "c": 13 };
@@ -1677,17 +1618,17 @@ function run_StructType_tests() {
   do_check_eq(s.b.a, 9);
   do_check_eq(s.c, 13);
   let v_t = ctypes.StructType("v_t", [{ "x": ctypes.int32_t }]);
   let v = v_t({ "x": 5 });
   do_check_eq(v.x, 5);
   v = v_t(8);
   do_check_eq(v.x, 8);
   let w_t = ctypes.StructType("w_t", [{ "y": v_t }]);
-  do_check_throws(function() { w_t(9); }, Error);
+  do_check_throws(function() { w_t(9); }, TypeError);
   let w = w_t({ "x": 3 });
   do_check_eq(w.y.x, 3);
   w = w_t({ "y": { "x": 19 } });
   do_check_eq(w.y.x, 19);
   let u_t = ctypes.StructType("u_t", [{ "z": ctypes.ArrayType(ctypes.int32_t, 3) }]);
   let u = u_t([1, 2, 3]);
   do_check_eq(u.z[1], 2);
   u = u_t({ "z": [4, 5, 6] });
@@ -1753,32 +1694,32 @@ function run_PointerType_tests() {
   p = p_t(5);
   do_check_eq(ptrValue(p), 5);
   p = p_t(ctypes.UInt64(10));
   do_check_eq(ptrValue(p), 10);
 
   // Test ImplicitConvert.
   p.value = null;
   do_check_eq(ptrValue(p), 0);
-  do_check_throws(function() { p.value = 5; }, Error);
+  do_check_throws(function() { p.value = 5; }, TypeError);
 
   // Test opaque pointers.
   let f_t = ctypes.StructType("FILE").ptr;
   do_check_eq(f_t.name, "FILE*");
   do_check_eq(f_t.toSource(), 'ctypes.StructType("FILE").ptr');
   let f = new f_t();
   do_check_throws(function() { f.contents; }, Error);
   do_check_throws(function() { f.contents = 0; }, Error);
   let f = f_t(5);
   do_check_throws(function() { f.contents = 0; }, Error);
   do_check_eq(f.toSource(), 'FILE.ptr(ctypes.UInt64("0x5"))');
 
-  do_check_throws(function() { f_t(p); }, Error);
-  do_check_throws(function() { f.value = p; }, Error);
-  do_check_throws(function() { p.value = f; }, Error);
+  do_check_throws(function() { f_t(p); }, TypeError);
+  do_check_throws(function() { f.value = p; }, TypeError);
+  do_check_throws(function() { p.value = f; }, TypeError);
 
   // Test void pointers.
   let v_t = ctypes.PointerType(ctypes.void_t);
   do_check_true(v_t === ctypes.voidptr_t);
   let v = v_t(p);
   do_check_eq(ptrValue(v), ptrValue(p));
 
   // Test 'contents'.
@@ -1879,25 +1820,25 @@ function run_FunctionType_tests() {
   f = fp_t(5);
   do_check_eq(ptrValue(f), 5);
   f = fp_t(ctypes.UInt64(10));
   do_check_eq(ptrValue(f), 10);
 
   // Test ImplicitConvert.
   f.value = null;
   do_check_eq(ptrValue(f), 0);
-  do_check_throws(function() { f.value = 5; }, Error);
+  do_check_throws(function() { f.value = 5; }, TypeError);
   do_check_eq(f.toSource(),
     'ctypes.FunctionType(ctypes.default_abi, g_t).ptr(ctypes.UInt64("0x0"))');
 
   // Test ImplicitConvert from a function pointer of different type.
   let f2_t = ctypes.FunctionType(ctypes.default_abi, g_t, [ ctypes.int32_t ]);
   let f2 = f2_t.ptr();
-  do_check_throws(function() { f.value = f2; }, Error);
-  do_check_throws(function() { f2.value = f; }, Error);
+  do_check_throws(function() { f.value = f2; }, TypeError);
+  do_check_throws(function() { f2.value = f; }, TypeError);
 
   // Test that converting to a voidptr_t works.
   let v = ctypes.voidptr_t(f2);
   do_check_eq(v.toSource(), 'ctypes.voidptr_t(ctypes.UInt64("0x0"))');
 
   // Test some more complex names.
   do_check_eq(fp_t.array().name, "g_t(*[])()");
   do_check_eq(fp_t.array().ptr.name, "g_t(*(*)[])()");
@@ -2055,17 +1996,17 @@ function run_ArrayType_tests() {
   do_check_eq(c2.length, 6);
   do_check_eq(c2[3], c[3]);
 
   c.value = c;
   do_check_eq(c[3], 4);
   do_check_throws(function() { c.value; }, Error);
   do_check_throws(function() { c.value = [1, 2, 3, 4, 5]; }, Error);
   do_check_throws(function() { c.value = [1, 2, 3, 4, 5, 6, 7]; }, Error);
-  do_check_throws(function() { c.value = [1, 2, 7.4, 4, 5, 6]; }, Error);
+  do_check_throws(function() { c.value = [1, 2, 7.4, 4, 5, 6]; }, TypeError);
   do_check_throws(function() { c.value = []; }, Error);
 }
 
 function run_type_toString_tests() {
   var c = ctypes;
 
   // Figure out whether we can create functions with ctypes.stdcall_abi and ctypes.winapi_abi.
   var haveStdCallABI;
@@ -2530,17 +2471,17 @@ function run_variadic_tests(library) {
   do_check_eq(result[2], 16);
   
   do_check_true(!!(sum_va_type().value = sum_va_type()));
   let sum_notva_type = ctypes.FunctionType(sum_va_type.targetType.abi,
                                            sum_va_type.targetType.returnType,
                                            [ctypes.uint8_t]).ptr;
   do_check_throws(function() {
     sum_va_type().value = sum_notva_type();
-  }, Error);
+  }, TypeError);
 }
 
 function run_static_data_tests(library)
 {
   const rect_t = new ctypes.StructType("RECT",
                        [{ top   : ctypes.int32_t },
                         { left  : ctypes.int32_t },
                         { bottom: ctypes.int32_t },