Bug 891107 - Part 3: Report argument type error as TypeError in js-ctypes. r=jorendorff

This commit is contained in:
Tooru Fujisawa 2015-04-22 18:26:14 +09:00
Родитель eac8d1b1f4
Коммит 84b9e85db2
10 изменённых файлов: 201 добавлений и 87 удалений

Просмотреть файл

@ -1303,6 +1303,24 @@ ArrayLengthOverflow(JSContext* cx, unsigned expectedLength, HandleObject arrObj,
return false;
}
static bool
ArgumentRangeMismatch(JSContext* cx, const char* arg, const char* func,
const char* range)
{
JS_ReportErrorNumber(cx, GetErrorMessage, nullptr,
CTYPESMSG_ARG_RANGE_MISMATCH, arg, func, range);
return false;
}
static bool
ArgumentTypeMismatch(JSContext* cx, const char* arg, const char* func,
const char* type)
{
JS_ReportErrorNumber(cx, GetErrorMessage, nullptr,
CTYPESMSG_ARG_TYPE_MISMATCH, arg, func, type);
return false;
}
static bool
EmptyFinalizerError(JSContext* cx, ConversionType convType,
HandleObject funObj = NullPtr(), unsigned argIndex = 0)
@ -4371,8 +4389,8 @@ CType::CreateArray(JSContext* cx, unsigned argc, jsval* vp)
// Convert the length argument to a size_t.
size_t length = 0;
if (args.length() == 1 && !jsvalToSize(cx, args[0], false, &length)) {
JS_ReportError(cx, "argument must be a nonnegative integer");
return false;
return ArgumentTypeMismatch(cx, "", "CType.prototype.array",
"a nonnegative integer");
}
JSObject* result = ArrayType::CreateInternal(cx, baseType, length, args.length() == 1);
@ -4554,8 +4572,7 @@ PointerType::Create(JSContext* cx, unsigned argc, jsval* vp)
jsval arg = args[0];
RootedObject obj(cx);
if (arg.isPrimitive() || !CType::IsCType(obj = &arg.toObject())) {
JS_ReportError(cx, "first argument must be a CType");
return false;
return ArgumentTypeMismatch(cx, "", "PointerType", "a CType");
}
JSObject* result = CreateInternal(cx, obj);
@ -4852,17 +4869,15 @@ ArrayType::Create(JSContext* cx, unsigned argc, jsval* vp)
return ArgumentLengthError(cx, "ArrayType", "one or two", "s");
}
if (args[0].isPrimitive() ||
!CType::IsCType(&args[0].toObject())) {
JS_ReportError(cx, "first argument must be a CType");
return false;
if (args[0].isPrimitive() || !CType::IsCType(&args[0].toObject())) {
return ArgumentTypeMismatch(cx, "first ", "ArrayType", "a CType");
}
// Convert the length argument to a size_t.
size_t length = 0;
if (args.length() == 2 && !jsvalToSize(cx, args[1], false, &length)) {
JS_ReportError(cx, "second argument must be a nonnegative integer");
return false;
return ArgumentTypeMismatch(cx, "second ", "ArrayType",
"a nonnegative integer");
}
RootedObject baseType(cx, &args[0].toObject());
@ -4973,8 +4988,9 @@ ArrayType::ConstructData(JSContext* cx,
RootedValue lengthVal(cx);
if (!JS_GetProperty(cx, arg, "length", &lengthVal) ||
!jsvalToSize(cx, lengthVal, false, &length)) {
JS_ReportError(cx, "argument must be an array object or length");
return false;
return ArgumentTypeMismatch(cx, "",
"size undefined ArrayType constructor",
"an array object or integer");
}
} else if (args[0].isString()) {
@ -5006,8 +5022,9 @@ ArrayType::ConstructData(JSContext* cx,
}
} else {
JS_ReportError(cx, "argument must be an array object or length");
return false;
return ArgumentTypeMismatch(cx, "",
"size undefined ArrayType constructor",
"an array object or integer");
}
// Construct a new ArrayType of defined length, for the new CData object.
@ -5397,8 +5414,7 @@ StructType::Create(JSContext* cx, unsigned argc, jsval* vp)
jsval name = args[0];
if (!name.isString()) {
JS_ReportError(cx, "first argument must be a string");
return false;
return ArgumentTypeMismatch(cx, "first ", "StructType", "a string");
}
// Get ctypes.StructType.prototype from the ctypes.StructType constructor.
@ -5415,8 +5431,7 @@ StructType::Create(JSContext* cx, unsigned argc, jsval* vp)
if (args.length() == 2) {
RootedObject arr(cx, args[1].isPrimitive() ? nullptr : &args[1].toObject());
if (!arr || !JS_IsArrayObject(cx, arr)) {
JS_ReportError(cx, "second argument must be an array");
return false;
return ArgumentTypeMismatch(cx, "second ", "StructType", "an array");
}
// Define the struct fields.
@ -5691,13 +5706,13 @@ StructType::Define(JSContext* cx, unsigned argc, jsval* vp)
jsval arg = args[0];
if (arg.isPrimitive()) {
JS_ReportError(cx, "argument must be an array");
return false;
return ArgumentTypeMismatch(cx, "", "StructType.prototype.define",
"an array");
}
RootedObject arr(cx, arg.toObjectOrNull());
if (!JS_IsArrayObject(cx, arr)) {
JS_ReportError(cx, "argument must be an array");
return false;
return ArgumentTypeMismatch(cx, "", "StructType.prototype.define",
"an array");
}
return DefineInternal(cx, obj, arr);
@ -5981,8 +5996,8 @@ StructType::AddressOfField(JSContext* cx, unsigned argc, jsval* vp)
}
if (!args[0].isString()) {
JS_ReportError(cx, "argument must be a string");
return false;
return ArgumentTypeMismatch(cx, "", "StructType.prototype.addressOfField",
"a string");
}
JSFlatString* str = JS_FlattenString(cx, args[0].toString());
@ -6332,8 +6347,7 @@ FunctionType::Create(JSContext* cx, unsigned argc, jsval* vp)
if (args[2].isObject())
arrayObj = &args[2].toObject();
if (!arrayObj || !JS_IsArrayObject(cx, arrayObj)) {
JS_ReportError(cx, "third argument must be an array");
return false;
return ArgumentTypeMismatch(cx, "third ", "FunctionType", "an array");
}
uint32_t len;
@ -7204,15 +7218,13 @@ CData::Cast(JSContext* cx, unsigned argc, jsval* vp)
}
if (args[0].isPrimitive() || !CData::IsCData(&args[0].toObject())) {
JS_ReportError(cx, "first argument must be a CData");
return false;
return ArgumentTypeMismatch(cx, "first ", "ctypes.cast", "a CData");
}
RootedObject sourceData(cx, &args[0].toObject());
JSObject* sourceType = CData::GetCType(sourceData);
if (args[1].isPrimitive() || !CType::IsCType(&args[1].toObject())) {
JS_ReportError(cx, "second argument must be a CType");
return false;
return ArgumentTypeMismatch(cx, "second ", "ctypes.cast", "a CType");
}
RootedObject targetType(cx, &args[1].toObject());
@ -7244,8 +7256,7 @@ CData::GetRuntime(JSContext* cx, unsigned argc, jsval* vp)
}
if (args[0].isPrimitive() || !CType::IsCType(&args[0].toObject())) {
JS_ReportError(cx, "first argument must be a CType");
return false;
return ArgumentTypeMismatch(cx, "", "ctypes.getRuntime", "a CType");
}
RootedObject targetType(cx, &args[0].toObject());
@ -8069,8 +8080,10 @@ Int64Base::ToString(JSContext* cx,
if (arg.isInt32())
radix = arg.toInt32();
if (!arg.isInt32() || radix < 2 || radix > 36) {
JS_ReportError(cx, "radix argument must be an integer between 2 and 36");
return false;
if (isUnsigned) {
return ArgumentRangeMismatch(cx, "", "UInt64.prototype.toString", "an integer at least 2 and no greater than 36");
}
return ArgumentRangeMismatch(cx, "", "Int64.prototype.toString", "an integer at least 2 and no greater than 36");
}
}
@ -8196,12 +8209,11 @@ Int64::Compare(JSContext* cx, unsigned argc, jsval* vp)
if (args.length() != 2) {
return ArgumentLengthError(cx, "Int64.compare", "two", "s");
}
if (args[0].isPrimitive() ||
args[1].isPrimitive() ||
!Int64::IsInt64(&args[0].toObject()) ||
!Int64::IsInt64(&args[1].toObject())) {
JS_ReportError(cx, "compare takes two Int64 arguments");
return false;
if (args[0].isPrimitive() || !Int64::IsInt64(&args[0].toObject())) {
return ArgumentTypeMismatch(cx, "first ", "Int64.compare", "a Int64");
}
if (args[1].isPrimitive() ||!Int64::IsInt64(&args[1].toObject())) {
return ArgumentTypeMismatch(cx, "second ", "Int64.compare", "a Int64");
}
JSObject* obj1 = &args[0].toObject();
@ -8232,8 +8244,7 @@ Int64::Lo(JSContext* cx, unsigned argc, jsval* vp)
return ArgumentLengthError(cx, "Int64.lo", "one", "");
}
if (args[0].isPrimitive() || !Int64::IsInt64(&args[0].toObject())) {
JS_ReportError(cx, "lo takes one Int64 argument");
return false;
return ArgumentTypeMismatch(cx, "", "Int64.lo", "a Int64");
}
JSObject* obj = &args[0].toObject();
@ -8252,8 +8263,7 @@ Int64::Hi(JSContext* cx, unsigned argc, jsval* vp)
return ArgumentLengthError(cx, "Int64.hi", "one", "");
}
if (args[0].isPrimitive() || !Int64::IsInt64(&args[0].toObject())) {
JS_ReportError(cx, "hi takes one Int64 argument");
return false;
return ArgumentTypeMismatch(cx, "", "Int64.hi", "a Int64");
}
JSObject* obj = &args[0].toObject();
@ -8371,12 +8381,11 @@ UInt64::Compare(JSContext* cx, unsigned argc, jsval* vp)
if (args.length() != 2) {
return ArgumentLengthError(cx, "UInt64.compare", "two", "s");
}
if (args[0].isPrimitive() ||
args[1].isPrimitive() ||
!UInt64::IsUInt64(&args[0].toObject()) ||
!UInt64::IsUInt64(&args[1].toObject())) {
JS_ReportError(cx, "compare takes two UInt64 arguments");
return false;
if (args[0].isPrimitive() || !UInt64::IsUInt64(&args[0].toObject())) {
return ArgumentTypeMismatch(cx, "first ", "UInt64.compare", "a UInt64");
}
if (args[1].isPrimitive() || !UInt64::IsUInt64(&args[1].toObject())) {
return ArgumentTypeMismatch(cx, "second ", "UInt64.compare", "a UInt64");
}
JSObject* obj1 = &args[0].toObject();
@ -8403,8 +8412,7 @@ UInt64::Lo(JSContext* cx, unsigned argc, jsval* vp)
return ArgumentLengthError(cx, "UInt64.lo", "one", "");
}
if (args[0].isPrimitive() || !UInt64::IsUInt64(&args[0].toObject())) {
JS_ReportError(cx, "lo takes one UInt64 argument");
return false;
return ArgumentTypeMismatch(cx, "", "UInt64.lo", "a UInt64");
}
JSObject* obj = &args[0].toObject();
@ -8423,8 +8431,7 @@ UInt64::Hi(JSContext* cx, unsigned argc, jsval* vp)
return ArgumentLengthError(cx, "UInt64.hi", "one", "");
}
if (args[0].isPrimitive() || !UInt64::IsUInt64(&args[0].toObject())) {
JS_ReportError(cx, "hi takes one UInt64 argument");
return false;
return ArgumentTypeMismatch(cx, "", "UInt64.hi", "a UInt64");
}
JSObject* obj = &args[0].toObject();

Просмотреть файл

@ -34,4 +34,6 @@ MSG_DEF(CTYPESMSG_EMPTY_FIN, 1, JSEXN_TYPEERR, "attempting to convert an emp
MSG_DEF(CTYPESMSG_FIN_SIZE_ERROR,2, JSEXN_TYPEERR, "expected an object with the same size as argument 1 of {0}, got {1}")
/* native function */
MSG_DEF(CTYPESMSG_ARG_RANGE_MISMATCH,3, JSEXN_RANGEERR, "{0}argument of {1} must be {2}")
MSG_DEF(CTYPESMSG_ARG_TYPE_MISMATCH,3, JSEXN_TYPEERR, "{0}argument of {1} must be {2}")
MSG_DEF(CTYPESMSG_WRONG_ARG_LENGTH,3, JSEXN_TYPEERR, "{0} takes {1} argument{2}")

Просмотреть файл

@ -66,13 +66,13 @@ if (typeof assertNoWarning === 'undefined') {
};
}
if (typeof assertTypeErrorMessage === 'undefined') {
var assertTypeErrorMessage = function assertTypeErrorMessage(f, test) {
if (typeof assertErrorMessage === 'undefined') {
var assertErrorMessage = function assertErrorMessage(f, ctor, test) {
try {
f();
} catch (e) {
if (!(e instanceof TypeError))
throw new Error("Assertion failed: expected exception TypeError, got " + e);
if (!(e instanceof ctor))
throw new Error("Assertion failed: expected exception " + ctor.name + ", got " + e);
if (typeof test == "string") {
if (test != e.message)
throw new Error("Assertion failed: expeceted " + test + ", got " + e.message);
@ -82,6 +82,18 @@ if (typeof assertTypeErrorMessage === 'undefined') {
}
return;
}
throw new Error("Assertion failed: expected exception TypeError, no exception thrown");
throw new Error("Assertion failed: expected exception " + ctor.name + ", no exception thrown");
};
}
if (typeof assertTypeErrorMessage === 'undefined') {
var assertTypeErrorMessage = function assertTypeErrorMessage(f, test) {
assertErrorMessage(f, TypeError, test);
};
}
if (typeof assertRangeErrorMessage === 'undefined') {
var assertRangeErrorMessage = function assertRangeErrorMessage(f, test) {
assertErrorMessage(f, RangeError, test);
};
}

Просмотреть файл

@ -0,0 +1,17 @@
load(libdir + 'asserts.js');
function test() {
assertTypeErrorMessage(() => { ctypes.int32_t.array({}); },
"argument of CType.prototype.array must be a nonnegative integer");
assertTypeErrorMessage(() => { ctypes.ArrayType(1); },
"first argument of ArrayType must be a CType");
assertTypeErrorMessage(() => { ctypes.ArrayType(ctypes.int32_t, {}); },
"second argument of ArrayType must be a nonnegative integer");
assertTypeErrorMessage(() => { ctypes.char.array()({}); },
"argument of size undefined ArrayType constructor must be an array object or integer");
assertTypeErrorMessage(() => { ctypes.char.array()(false); },
"argument of size undefined ArrayType constructor must be an array object or integer");
}
if (typeof ctypes === "object")
test();

Просмотреть файл

@ -0,0 +1,13 @@
load(libdir + 'asserts.js');
function test() {
assertTypeErrorMessage(() => { ctypes.cast(1, 2); },
"first argument of ctypes.cast must be a CData");
assertTypeErrorMessage(() => { ctypes.cast(ctypes.int32_t(0), 2); },
"second argument of ctypes.cast must be a CType");
assertTypeErrorMessage(() => { ctypes.getRuntime(1); },
"argument of ctypes.getRuntime must be a CType");
}
if (typeof ctypes === "object")
test();

Просмотреть файл

@ -0,0 +1,9 @@
load(libdir + 'asserts.js');
function test() {
assertTypeErrorMessage(() => { ctypes.FunctionType(ctypes.default_abi, ctypes.int32_t, 1); },
"third argument of FunctionType must be an array");
}
if (typeof ctypes === "object")
test();

Просмотреть файл

@ -0,0 +1,28 @@
load(libdir + 'asserts.js');
function test() {
assertRangeErrorMessage(() => { ctypes.Int64(0).toString("a"); },
"argument of Int64.prototype.toString must be an integer at least 2 and no greater than 36");
assertTypeErrorMessage(() => { ctypes.Int64.compare(1, 2); },
"first argument of Int64.compare must be a Int64");
assertTypeErrorMessage(() => { ctypes.Int64.compare(ctypes.Int64(0), 2); },
"second argument of Int64.compare must be a Int64");
assertTypeErrorMessage(() => { ctypes.Int64.lo(1); },
"argument of Int64.lo must be a Int64");
assertTypeErrorMessage(() => { ctypes.Int64.hi(1); },
"argument of Int64.hi must be a Int64");
assertRangeErrorMessage(() => { ctypes.UInt64(0).toString("a"); },
"argument of UInt64.prototype.toString must be an integer at least 2 and no greater than 36");
assertTypeErrorMessage(() => { ctypes.UInt64.compare(1, 2); },
"first argument of UInt64.compare must be a UInt64");
assertTypeErrorMessage(() => { ctypes.UInt64.compare(ctypes.UInt64(0), 2); },
"second argument of UInt64.compare must be a UInt64");
assertTypeErrorMessage(() => { ctypes.UInt64.lo(1); },
"argument of UInt64.lo must be a UInt64");
assertTypeErrorMessage(() => { ctypes.UInt64.hi(1); },
"argument of UInt64.hi must be a UInt64");
}
if (typeof ctypes === "object")
test();

Просмотреть файл

@ -0,0 +1,9 @@
load(libdir + 'asserts.js');
function test() {
assertTypeErrorMessage(() => { ctypes.PointerType({}); },
"argument of PointerType must be a CType");
}
if (typeof ctypes === "object")
test();

Просмотреть файл

@ -0,0 +1,17 @@
load(libdir + 'asserts.js');
function test() {
assertTypeErrorMessage(() => { ctypes.StructType(1); },
"first argument of StructType must be a string");
assertTypeErrorMessage(() => { ctypes.StructType("a", 1); },
"second argument of StructType must be an array");
assertTypeErrorMessage(() => { ctypes.StructType("a").define(1); },
"argument of StructType.prototype.define must be an array");
assertTypeErrorMessage(() => { ctypes.StructType("a").define({}); },
"argument of StructType.prototype.define must be an array");
assertTypeErrorMessage(() => { ctypes.StructType("a", [{x:ctypes.int32_t}])().addressOfField(1); },
"argument of StructType.prototype.addressOfField must be a string");
}
if (typeof ctypes === "object")
test();

Просмотреть файл

@ -331,9 +331,9 @@ function run_Int64_tests() {
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);
do_check_throws(function() { i.toString(1); }, Error);
do_check_throws(function() { i.toString(37); }, Error);
do_check_throws(function() { i.toString(0); }, RangeError);
do_check_throws(function() { i.toString(1); }, RangeError);
do_check_throws(function() { i.toString(37); }, RangeError);
do_check_throws(function() { i.toString(10, 2); }, TypeError);
// Test Int64.toSource().
@ -445,18 +445,18 @@ function run_Int64_tests() {
do_check_eq(ctypes.Int64.compare(ctypes.Int64(-5), ctypes.Int64(-5)), 0);
do_check_eq(ctypes.Int64.compare(ctypes.Int64(-5), ctypes.Int64(-4)), -1);
do_check_eq(ctypes.Int64.compare(ctypes.Int64(-4), ctypes.Int64(-5)), 1);
do_check_throws(function() { ctypes.Int64.compare(ctypes.Int64(4), ctypes.UInt64(4)); }, Error);
do_check_throws(function() { ctypes.Int64.compare(4, 5); }, Error);
do_check_throws(function() { ctypes.Int64.compare(ctypes.Int64(4), ctypes.UInt64(4)); }, TypeError);
do_check_throws(function() { ctypes.Int64.compare(4, 5); }, TypeError);
// Test ctypes.Int64.{lo,hi}.
do_check_eq(ctypes.Int64.lo(ctypes.Int64(0x28590a1c921de000)), 0x921de000);
do_check_eq(ctypes.Int64.hi(ctypes.Int64(0x28590a1c921de000)), 0x28590a1c);
do_check_eq(ctypes.Int64.lo(ctypes.Int64(-0x28590a1c921de000)), 0x6de22000);
do_check_eq(ctypes.Int64.hi(ctypes.Int64(-0x28590a1c921de000)), -0x28590a1d);
do_check_throws(function() { ctypes.Int64.lo(ctypes.UInt64(0)); }, Error);
do_check_throws(function() { ctypes.Int64.hi(ctypes.UInt64(0)); }, Error);
do_check_throws(function() { ctypes.Int64.lo(0); }, Error);
do_check_throws(function() { ctypes.Int64.hi(0); }, Error);
do_check_throws(function() { ctypes.Int64.lo(ctypes.UInt64(0)); }, TypeError);
do_check_throws(function() { ctypes.Int64.hi(ctypes.UInt64(0)); }, TypeError);
do_check_throws(function() { ctypes.Int64.lo(0); }, TypeError);
do_check_throws(function() { ctypes.Int64.hi(0); }, TypeError);
// Test ctypes.Int64.join.
do_check_eq(ctypes.Int64.join(0, 0).toString(), "0");
@ -502,9 +502,9 @@ function run_UInt64_tests() {
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);
do_check_throws(function() { i.toString(1); }, Error);
do_check_throws(function() { i.toString(37); }, Error);
do_check_throws(function() { i.toString(0); }, RangeError);
do_check_throws(function() { i.toString(1); }, RangeError);
do_check_throws(function() { i.toString(37); }, RangeError);
do_check_throws(function() { i.toString(10, 2); }, TypeError);
// Test UInt64.toSource().
@ -592,18 +592,18 @@ function run_UInt64_tests() {
do_check_eq(ctypes.UInt64.compare(ctypes.UInt64(5), ctypes.UInt64(5)), 0);
do_check_eq(ctypes.UInt64.compare(ctypes.UInt64(5), ctypes.UInt64(4)), 1);
do_check_eq(ctypes.UInt64.compare(ctypes.UInt64(4), ctypes.UInt64(5)), -1);
do_check_throws(function() { ctypes.UInt64.compare(ctypes.UInt64(4), ctypes.Int64(4)); }, Error);
do_check_throws(function() { ctypes.UInt64.compare(4, 5); }, Error);
do_check_throws(function() { ctypes.UInt64.compare(ctypes.UInt64(4), ctypes.Int64(4)); }, TypeError);
do_check_throws(function() { ctypes.UInt64.compare(4, 5); }, TypeError);
// Test ctypes.UInt64.{lo,hi}.
do_check_eq(ctypes.UInt64.lo(ctypes.UInt64(0x28590a1c921de000)), 0x921de000);
do_check_eq(ctypes.UInt64.hi(ctypes.UInt64(0x28590a1c921de000)), 0x28590a1c);
do_check_eq(ctypes.UInt64.lo(ctypes.UInt64(0xa8590a1c921de000)), 0x921de000);
do_check_eq(ctypes.UInt64.hi(ctypes.UInt64(0xa8590a1c921de000)), 0xa8590a1c);
do_check_throws(function() { ctypes.UInt64.lo(ctypes.Int64(0)); }, Error);
do_check_throws(function() { ctypes.UInt64.hi(ctypes.Int64(0)); }, Error);
do_check_throws(function() { ctypes.UInt64.lo(0); }, Error);
do_check_throws(function() { ctypes.UInt64.hi(0); }, Error);
do_check_throws(function() { ctypes.UInt64.lo(ctypes.Int64(0)); }, TypeError);
do_check_throws(function() { ctypes.UInt64.hi(ctypes.Int64(0)); }, TypeError);
do_check_throws(function() { ctypes.UInt64.lo(0); }, TypeError);
do_check_throws(function() { ctypes.UInt64.hi(0); }, TypeError);
// Test ctypes.UInt64.join.
do_check_eq(ctypes.UInt64.join(0, 0).toString(), "0");
@ -1374,8 +1374,8 @@ function run_StructType_tests() {
do_check_throws(function() { ctypes.StructType(); }, TypeError);
do_check_throws(function() { ctypes.StructType("a", [], 5); }, TypeError);
do_check_throws(function() { ctypes.StructType(null, []); }, Error);
do_check_throws(function() { ctypes.StructType("a", null); }, Error);
do_check_throws(function() { ctypes.StructType(null, []); }, TypeError);
do_check_throws(function() { ctypes.StructType("a", null); }, TypeError);
// Check that malformed descriptors are an error.
do_check_throws(function() {
@ -1659,9 +1659,9 @@ function run_PointerType_tests() {
do_check_throws(function() { ctypes.PointerType(); }, TypeError);
do_check_throws(function() { ctypes.PointerType(ctypes.int32_t, 5); }, TypeError);
do_check_throws(function() { ctypes.PointerType(null); }, Error);
do_check_throws(function() { ctypes.PointerType(ctypes.int32_t()); }, Error);
do_check_throws(function() { ctypes.PointerType("void"); }, Error);
do_check_throws(function() { ctypes.PointerType(null); }, TypeError);
do_check_throws(function() { ctypes.PointerType(ctypes.int32_t()); }, TypeError);
do_check_throws(function() { ctypes.PointerType("void"); }, TypeError);
let name = "g_t";
let g_t = ctypes.StructType(name, [{ a: ctypes.int32_t }, { b: ctypes.double }]);
@ -1844,10 +1844,10 @@ function run_FunctionType_tests() {
}, TypeError);
do_check_throws(function() {
ctypes.FunctionType(ctypes.default_abi, ctypes.void_t, ctypes.void_t);
}, Error);
}, TypeError);
do_check_throws(function() {
ctypes.FunctionType(ctypes.default_abi, ctypes.void_t, null);
}, Error);
}, TypeError);
do_check_throws(function() {
ctypes.FunctionType(ctypes.default_abi, ctypes.int32_t());
}, Error);
@ -1961,9 +1961,9 @@ function run_ArrayType_tests() {
[ "elementType", "length" ], [], [ "length" ], [ "addressOfElement" ]);
do_check_throws(function() { ctypes.ArrayType(); }, TypeError);
do_check_throws(function() { ctypes.ArrayType(null); }, Error);
do_check_throws(function() { ctypes.ArrayType(null); }, TypeError);
do_check_throws(function() { ctypes.ArrayType(ctypes.int32_t, 1, 5); }, TypeError);
do_check_throws(function() { ctypes.ArrayType(ctypes.int32_t, -1); }, Error);
do_check_throws(function() { ctypes.ArrayType(ctypes.int32_t, -1); }, TypeError);
let name = "g_t";
let g_t = ctypes.StructType(name, [{ a: ctypes.int32_t }, { b: ctypes.double }]);
@ -2036,7 +2036,7 @@ function run_ArrayType_tests() {
} else {
do_check_throws(function() {
ctypes.ArrayType(ctypes.int8_t, ctypes.UInt64("0xffffffffffffffff"));
}, Error);
}, TypeError);
do_check_throws(function() {
ctypes.ArrayType(ctypes.int16_t, ctypes.UInt64("0x8000000000000000"));
}, Error);