mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 891107 - Part 2: Report argument length error as TypeError in js-ctypes. r=jorendorff
This commit is contained in:
parent
e4a6c8aa21
commit
bb9df65329
@ -1234,6 +1234,15 @@ ArgumentConvError(JSContext* cx, HandleValue actual, const char* funStr,
|
||||
return false;
|
||||
}
|
||||
|
||||
static bool
|
||||
ArgumentLengthError(JSContext* cx, const char* fun, const char* count,
|
||||
const char* s)
|
||||
{
|
||||
JS_ReportErrorNumber(cx, GetErrorMessage, nullptr,
|
||||
CTYPESMSG_WRONG_ARG_LENGTH, fun, count, s);
|
||||
return false;
|
||||
}
|
||||
|
||||
static bool
|
||||
ArrayLengthMismatch(JSContext* cx, unsigned expectedLength, HandleObject arrObj,
|
||||
unsigned actualLength, HandleValue actual,
|
||||
@ -3834,8 +3843,7 @@ CType::ConstructBasic(JSContext* cx,
|
||||
const CallArgs& args)
|
||||
{
|
||||
if (args.length() > 1) {
|
||||
JS_ReportError(cx, "CType constructor takes zero or one argument");
|
||||
return false;
|
||||
return ArgumentLengthError(cx, "CType constructor", "at most one", "");
|
||||
}
|
||||
|
||||
// construct a CData object
|
||||
@ -4357,8 +4365,7 @@ CType::CreateArray(JSContext* cx, unsigned argc, jsval* vp)
|
||||
|
||||
// Construct and return a new ArrayType object.
|
||||
if (args.length() > 1) {
|
||||
JS_ReportError(cx, "array takes zero or one argument");
|
||||
return false;
|
||||
return ArgumentLengthError(cx, "CType.prototype.array", "at most one", "");
|
||||
}
|
||||
|
||||
// Convert the length argument to a size_t.
|
||||
@ -4497,8 +4504,7 @@ ABI::ToSource(JSContext* cx, unsigned argc, jsval* vp)
|
||||
{
|
||||
CallArgs args = CallArgsFromVp(argc, vp);
|
||||
if (args.length() != 0) {
|
||||
JS_ReportError(cx, "toSource takes zero arguments");
|
||||
return false;
|
||||
return ArgumentLengthError(cx, "ABI.prototype.toSource", "no", "s");
|
||||
}
|
||||
|
||||
JSObject* obj = JS_THIS_OBJECT(cx, vp);
|
||||
@ -4542,8 +4548,7 @@ PointerType::Create(JSContext* cx, unsigned argc, jsval* vp)
|
||||
CallArgs args = CallArgsFromVp(argc, vp);
|
||||
// Construct and return a new PointerType object.
|
||||
if (args.length() != 1) {
|
||||
JS_ReportError(cx, "PointerType takes one argument");
|
||||
return false;
|
||||
return ArgumentLengthError(cx, "PointerType", "one", "");
|
||||
}
|
||||
|
||||
jsval arg = args[0];
|
||||
@ -4608,8 +4613,8 @@ PointerType::ConstructData(JSContext* cx,
|
||||
}
|
||||
|
||||
if (args.length() > 3) {
|
||||
JS_ReportError(cx, "constructor takes 0, 1, 2, or 3 arguments");
|
||||
return false;
|
||||
return ArgumentLengthError(cx, "PointerType constructor", "0, 1, 2, or 3",
|
||||
"s");
|
||||
}
|
||||
|
||||
RootedObject result(cx, CData::Create(cx, obj, NullPtr(), nullptr, true));
|
||||
@ -4643,8 +4648,7 @@ PointerType::ConstructData(JSContext* cx,
|
||||
//
|
||||
if (!looksLikeClosure) {
|
||||
if (args.length() != 1) {
|
||||
JS_ReportError(cx, "first argument must be a function");
|
||||
return false;
|
||||
return ArgumentLengthError(cx, "FunctionType constructor", "one", "");
|
||||
}
|
||||
return ExplicitConvert(cx, args[0], obj, CData::GetData(result),
|
||||
ConversionType::Construct);
|
||||
@ -4845,8 +4849,7 @@ ArrayType::Create(JSContext* cx, unsigned argc, jsval* vp)
|
||||
CallArgs args = CallArgsFromVp(argc, vp);
|
||||
// Construct and return a new ArrayType object.
|
||||
if (args.length() < 1 || args.length() > 2) {
|
||||
JS_ReportError(cx, "ArrayType takes one or two arguments");
|
||||
return false;
|
||||
return ArgumentLengthError(cx, "ArrayType", "one or two", "s");
|
||||
}
|
||||
|
||||
if (args[0].isPrimitive() ||
|
||||
@ -4946,14 +4949,14 @@ ArrayType::ConstructData(JSContext* cx,
|
||||
// with a length argument, or with an actual JS array.
|
||||
if (CType::IsSizeDefined(obj)) {
|
||||
if (args.length() > 1) {
|
||||
JS_ReportError(cx, "constructor takes zero or one argument");
|
||||
return false;
|
||||
return ArgumentLengthError(cx, "size defined ArrayType constructor",
|
||||
"at most one", "");
|
||||
}
|
||||
|
||||
} else {
|
||||
if (args.length() != 1) {
|
||||
JS_ReportError(cx, "constructor takes one argument");
|
||||
return false;
|
||||
return ArgumentLengthError(cx, "size undefined ArrayType constructor",
|
||||
"one", "");
|
||||
}
|
||||
|
||||
RootedObject baseType(cx, GetBaseType(obj));
|
||||
@ -5268,8 +5271,8 @@ ArrayType::AddressOfElement(JSContext* cx, unsigned argc, jsval* vp)
|
||||
}
|
||||
|
||||
if (args.length() != 1) {
|
||||
JS_ReportError(cx, "addressOfElement takes one argument");
|
||||
return false;
|
||||
return ArgumentLengthError(cx, "ArrayType.prototype.addressOfElement",
|
||||
"one", "");
|
||||
}
|
||||
|
||||
RootedObject baseType(cx, GetBaseType(typeObj));
|
||||
@ -5389,8 +5392,7 @@ StructType::Create(JSContext* cx, unsigned argc, jsval* vp)
|
||||
|
||||
// Construct and return a new StructType object.
|
||||
if (args.length() < 1 || args.length() > 2) {
|
||||
JS_ReportError(cx, "StructType takes one or two arguments");
|
||||
return false;
|
||||
return ArgumentLengthError(cx, "StructType", "one or two", "s");
|
||||
}
|
||||
|
||||
jsval name = args[0];
|
||||
@ -5684,8 +5686,7 @@ StructType::Define(JSContext* cx, unsigned argc, jsval* vp)
|
||||
}
|
||||
|
||||
if (args.length() != 1) {
|
||||
JS_ReportError(cx, "define takes one argument");
|
||||
return false;
|
||||
return ArgumentLengthError(cx, "StructType.prototype.define", "one", "");
|
||||
}
|
||||
|
||||
jsval arg = args[0];
|
||||
@ -5772,9 +5773,14 @@ StructType::ConstructData(JSContext* cx,
|
||||
return true;
|
||||
}
|
||||
|
||||
JS_ReportError(cx, "constructor takes 0, 1, or %u arguments",
|
||||
fields->count());
|
||||
return false;
|
||||
size_t count = fields->count();
|
||||
if (count >= 2) {
|
||||
char fieldLengthStr[32];
|
||||
JS_snprintf(fieldLengthStr, 32, "0, 1, or %u", count);
|
||||
return ArgumentLengthError(cx, "StructType constructor", fieldLengthStr,
|
||||
"s");
|
||||
}
|
||||
return ArgumentLengthError(cx, "StructType constructor", "at most one", "");
|
||||
}
|
||||
|
||||
const FieldInfoHash*
|
||||
@ -5970,8 +5976,8 @@ StructType::AddressOfField(JSContext* cx, unsigned argc, jsval* vp)
|
||||
}
|
||||
|
||||
if (args.length() != 1) {
|
||||
JS_ReportError(cx, "addressOfField takes one argument");
|
||||
return false;
|
||||
return ArgumentLengthError(cx, "StructType.prototype.addressOfField",
|
||||
"one", "");
|
||||
}
|
||||
|
||||
if (!args[0].isString()) {
|
||||
@ -6315,8 +6321,7 @@ FunctionType::Create(JSContext* cx, unsigned argc, jsval* vp)
|
||||
// Construct and return a new FunctionType object.
|
||||
CallArgs args = CallArgsFromVp(argc, vp);
|
||||
if (args.length() < 2 || args.length() > 3) {
|
||||
JS_ReportError(cx, "FunctionType takes two or three arguments");
|
||||
return false;
|
||||
return ArgumentLengthError(cx, "FunctionType", "two or three", "s");
|
||||
}
|
||||
|
||||
AutoValueVector argTypes(cx);
|
||||
@ -7161,8 +7166,7 @@ CData::Address(JSContext* cx, unsigned argc, jsval* vp)
|
||||
{
|
||||
CallArgs args = CallArgsFromVp(argc, vp);
|
||||
if (args.length() != 0) {
|
||||
JS_ReportError(cx, "address takes zero arguments");
|
||||
return false;
|
||||
return ArgumentLengthError(cx, "CData.prototype.address", "no", "s");
|
||||
}
|
||||
|
||||
RootedObject obj(cx, JS_THIS_OBJECT(cx, vp));
|
||||
@ -7196,8 +7200,7 @@ CData::Cast(JSContext* cx, unsigned argc, jsval* vp)
|
||||
{
|
||||
CallArgs args = CallArgsFromVp(argc, vp);
|
||||
if (args.length() != 2) {
|
||||
JS_ReportError(cx, "cast takes two arguments");
|
||||
return false;
|
||||
return ArgumentLengthError(cx, "ctypes.cast", "two", "s");
|
||||
}
|
||||
|
||||
if (args[0].isPrimitive() || !CData::IsCData(&args[0].toObject())) {
|
||||
@ -7237,8 +7240,7 @@ CData::GetRuntime(JSContext* cx, unsigned argc, jsval* vp)
|
||||
{
|
||||
CallArgs args = CallArgsFromVp(argc, vp);
|
||||
if (args.length() != 1) {
|
||||
JS_ReportError(cx, "getRuntime takes one argument");
|
||||
return false;
|
||||
return ArgumentLengthError(cx, "ctypes.getRuntime", "one", "");
|
||||
}
|
||||
|
||||
if (args[0].isPrimitive() || !CType::IsCType(&args[0].toObject())) {
|
||||
@ -7270,8 +7272,11 @@ ReadStringCommon(JSContext* cx, InflateUTF8Method inflateUTF8, unsigned argc, js
|
||||
{
|
||||
CallArgs args = CallArgsFromVp(argc, vp);
|
||||
if (args.length() != 0) {
|
||||
JS_ReportError(cx, "readString takes zero arguments");
|
||||
return false;
|
||||
if (inflateUTF8 == JS::UTF8CharsToNewTwoByteCharsZ) {
|
||||
return ArgumentLengthError(cx, "CData.prototype.readString", "no", "s");
|
||||
}
|
||||
return ArgumentLengthError(cx, "CData.prototype.readStringReplaceMalformed",
|
||||
"no", "s");
|
||||
}
|
||||
|
||||
JSObject* obj = CDataFinalizer::GetCData(cx, JS_THIS_OBJECT(cx, vp));
|
||||
@ -7386,8 +7391,7 @@ CData::ToSource(JSContext* cx, unsigned argc, jsval* vp)
|
||||
{
|
||||
CallArgs args = CallArgsFromVp(argc, vp);
|
||||
if (args.length() != 0) {
|
||||
JS_ReportError(cx, "toSource takes zero arguments");
|
||||
return false;
|
||||
return ArgumentLengthError(cx, "CData.prototype.toSource", "no", "s");
|
||||
}
|
||||
|
||||
JSObject* obj = JS_THIS_OBJECT(cx, vp);
|
||||
@ -7615,8 +7619,7 @@ CDataFinalizer::Construct(JSContext* cx, unsigned argc, jsval* vp)
|
||||
}
|
||||
|
||||
if (args.length() != 2) {
|
||||
JS_ReportError(cx, "CDataFinalizer takes 2 arguments");
|
||||
return false;
|
||||
return ArgumentLengthError(cx, "CDataFinalizer constructor", "two", "s");
|
||||
}
|
||||
|
||||
JS::HandleValue valCodePtr = args[1];
|
||||
@ -7830,8 +7833,8 @@ CDataFinalizer::Methods::Forget(JSContext* cx, unsigned argc, jsval* vp)
|
||||
{
|
||||
CallArgs args = CallArgsFromVp(argc, vp);
|
||||
if (args.length() != 0) {
|
||||
JS_ReportError(cx, "CDataFinalizer.prototype.forget takes no arguments");
|
||||
return false;
|
||||
return ArgumentLengthError(cx, "CDataFinalizer.prototype.forget", "no",
|
||||
"s");
|
||||
}
|
||||
|
||||
JS::Rooted<JSObject*> obj(cx, args.thisv().toObjectOrNull());
|
||||
@ -7878,8 +7881,8 @@ CDataFinalizer::Methods::Dispose(JSContext* cx, unsigned argc, jsval* vp)
|
||||
{
|
||||
CallArgs args = CallArgsFromVp(argc, vp);
|
||||
if (args.length() != 0) {
|
||||
JS_ReportError(cx, "CDataFinalizer.prototype.dispose takes no arguments");
|
||||
return false;
|
||||
return ArgumentLengthError(cx, "CDataFinalizer.prototype.dispose", "no",
|
||||
"s");
|
||||
}
|
||||
|
||||
RootedObject obj(cx, JS_THIS_OBJECT(cx, vp));
|
||||
@ -8052,8 +8055,12 @@ Int64Base::ToString(JSContext* cx,
|
||||
bool isUnsigned)
|
||||
{
|
||||
if (args.length() > 1) {
|
||||
JS_ReportError(cx, "toString takes zero or one argument");
|
||||
return false;
|
||||
if (isUnsigned) {
|
||||
return ArgumentLengthError(cx, "UInt64.prototype.toString",
|
||||
"at most one", "");
|
||||
}
|
||||
return ArgumentLengthError(cx, "Int64.prototype.toString",
|
||||
"at most one", "");
|
||||
}
|
||||
|
||||
int radix = 10;
|
||||
@ -8089,8 +8096,10 @@ Int64Base::ToSource(JSContext* cx,
|
||||
bool isUnsigned)
|
||||
{
|
||||
if (args.length() != 0) {
|
||||
JS_ReportError(cx, "toSource takes zero arguments");
|
||||
return false;
|
||||
if (isUnsigned) {
|
||||
return ArgumentLengthError(cx, "UInt64.prototype.toSource", "no", "s");
|
||||
}
|
||||
return ArgumentLengthError(cx, "Int64.prototype.toSource", "no", "s");
|
||||
}
|
||||
|
||||
// Return a decimal string suitable for constructing the number.
|
||||
@ -8121,8 +8130,7 @@ Int64::Construct(JSContext* cx,
|
||||
|
||||
// Construct and return a new Int64 object.
|
||||
if (args.length() != 1) {
|
||||
JS_ReportError(cx, "Int64 takes one argument");
|
||||
return false;
|
||||
return ArgumentLengthError(cx, "Int64 constructor", "one", "");
|
||||
}
|
||||
|
||||
int64_t i = 0;
|
||||
@ -8185,8 +8193,10 @@ bool
|
||||
Int64::Compare(JSContext* cx, unsigned argc, jsval* vp)
|
||||
{
|
||||
CallArgs args = CallArgsFromVp(argc, vp);
|
||||
if (args.length() != 2 ||
|
||||
args[0].isPrimitive() ||
|
||||
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())) {
|
||||
@ -8218,8 +8228,10 @@ bool
|
||||
Int64::Lo(JSContext* cx, unsigned argc, jsval* vp)
|
||||
{
|
||||
CallArgs args = CallArgsFromVp(argc, vp);
|
||||
if (args.length() != 1 || args[0].isPrimitive() ||
|
||||
!Int64::IsInt64(&args[0].toObject())) {
|
||||
if (args.length() != 1) {
|
||||
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;
|
||||
}
|
||||
@ -8236,8 +8248,10 @@ bool
|
||||
Int64::Hi(JSContext* cx, unsigned argc, jsval* vp)
|
||||
{
|
||||
CallArgs args = CallArgsFromVp(argc, vp);
|
||||
if (args.length() != 1 || args[0].isPrimitive() ||
|
||||
!Int64::IsInt64(&args[0].toObject())) {
|
||||
if (args.length() != 1) {
|
||||
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;
|
||||
}
|
||||
@ -8255,8 +8269,7 @@ Int64::Join(JSContext* cx, unsigned argc, jsval* vp)
|
||||
{
|
||||
CallArgs args = CallArgsFromVp(argc, vp);
|
||||
if (args.length() != 2) {
|
||||
JS_ReportError(cx, "join takes two arguments");
|
||||
return false;
|
||||
return ArgumentLengthError(cx, "Int64.join", "two", "s");
|
||||
}
|
||||
|
||||
int32_t hi;
|
||||
@ -8292,8 +8305,7 @@ UInt64::Construct(JSContext* cx,
|
||||
|
||||
// Construct and return a new UInt64 object.
|
||||
if (args.length() != 1) {
|
||||
JS_ReportError(cx, "UInt64 takes one argument");
|
||||
return false;
|
||||
return ArgumentLengthError(cx, "UInt64 constructor", "one", "");
|
||||
}
|
||||
|
||||
uint64_t u = 0;
|
||||
@ -8356,8 +8368,10 @@ bool
|
||||
UInt64::Compare(JSContext* cx, unsigned argc, jsval* vp)
|
||||
{
|
||||
CallArgs args = CallArgsFromVp(argc, vp);
|
||||
if (args.length() != 2 ||
|
||||
args[0].isPrimitive() ||
|
||||
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())) {
|
||||
@ -8385,8 +8399,10 @@ bool
|
||||
UInt64::Lo(JSContext* cx, unsigned argc, jsval* vp)
|
||||
{
|
||||
CallArgs args = CallArgsFromVp(argc, vp);
|
||||
if (args.length() != 1 || args[0].isPrimitive() ||
|
||||
!UInt64::IsUInt64(&args[0].toObject())) {
|
||||
if (args.length() != 1) {
|
||||
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;
|
||||
}
|
||||
@ -8403,8 +8419,10 @@ bool
|
||||
UInt64::Hi(JSContext* cx, unsigned argc, jsval* vp)
|
||||
{
|
||||
CallArgs args = CallArgsFromVp(argc, vp);
|
||||
if (args.length() != 1 || args[0].isPrimitive() ||
|
||||
!UInt64::IsUInt64(&args[0].toObject())) {
|
||||
if (args.length() != 1) {
|
||||
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;
|
||||
}
|
||||
@ -8422,8 +8440,7 @@ UInt64::Join(JSContext* cx, unsigned argc, jsval* vp)
|
||||
{
|
||||
CallArgs args = CallArgsFromVp(argc, vp);
|
||||
if (args.length() != 2) {
|
||||
JS_ReportError(cx, "join takes two arguments");
|
||||
return false;
|
||||
return ArgumentLengthError(cx, "UInt64.join", "two", "s");
|
||||
}
|
||||
|
||||
uint32_t hi;
|
||||
|
@ -32,3 +32,6 @@ MSG_DEF(CTYPESMSG_PROP_NONSTRING,3, JSEXN_TYPEERR, "property name {0} of {1} is
|
||||
/* data finalizer */
|
||||
MSG_DEF(CTYPESMSG_EMPTY_FIN, 1, JSEXN_TYPEERR, "attempting to convert an empty CDataFinalizer{0}")
|
||||
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_WRONG_ARG_LENGTH,3, JSEXN_TYPEERR, "{0} takes {1} argument{2}")
|
||||
|
9
js/src/jit-test/tests/ctypes/argument-length-abi.js
Normal file
9
js/src/jit-test/tests/ctypes/argument-length-abi.js
Normal file
@ -0,0 +1,9 @@
|
||||
load(libdir + 'asserts.js');
|
||||
|
||||
function test() {
|
||||
assertTypeErrorMessage(() => { ctypes.default_abi.toSource(1); },
|
||||
"ABI.prototype.toSource takes no arguments");
|
||||
}
|
||||
|
||||
if (typeof ctypes === "object")
|
||||
test();
|
15
js/src/jit-test/tests/ctypes/argument-length-array.js
Normal file
15
js/src/jit-test/tests/ctypes/argument-length-array.js
Normal file
@ -0,0 +1,15 @@
|
||||
load(libdir + 'asserts.js');
|
||||
|
||||
function test() {
|
||||
assertTypeErrorMessage(() => { ctypes.ArrayType(); },
|
||||
"ArrayType takes one or two arguments");
|
||||
assertTypeErrorMessage(() => { ctypes.int32_t.array(10)(1, 2); },
|
||||
"size defined ArrayType constructor takes at most one argument");
|
||||
assertTypeErrorMessage(() => { ctypes.int32_t.array()(1, 2); },
|
||||
"size undefined ArrayType constructor takes one argument");
|
||||
assertTypeErrorMessage(() => { ctypes.int32_t.array(10)().addressOfElement(); },
|
||||
"ArrayType.prototype.addressOfElement takes one argument");
|
||||
}
|
||||
|
||||
if (typeof ctypes === "object")
|
||||
test();
|
15
js/src/jit-test/tests/ctypes/argument-length-cdata.js
Normal file
15
js/src/jit-test/tests/ctypes/argument-length-cdata.js
Normal file
@ -0,0 +1,15 @@
|
||||
load(libdir + 'asserts.js');
|
||||
|
||||
function test() {
|
||||
assertTypeErrorMessage(() => { ctypes.int32_t(0).address(1); },
|
||||
"CData.prototype.address takes no arguments");
|
||||
assertTypeErrorMessage(() => { ctypes.char.array(10)().readString(1); },
|
||||
"CData.prototype.readString takes no arguments");
|
||||
assertTypeErrorMessage(() => { ctypes.char.array(10)().readStringReplaceMalformed(1); },
|
||||
"CData.prototype.readStringReplaceMalformed takes no arguments");
|
||||
assertTypeErrorMessage(() => { ctypes.int32_t(0).toSource(1); },
|
||||
"CData.prototype.toSource takes no arguments");
|
||||
}
|
||||
|
||||
if (typeof ctypes === "object")
|
||||
test();
|
11
js/src/jit-test/tests/ctypes/argument-length-ctypes.js
Normal file
11
js/src/jit-test/tests/ctypes/argument-length-ctypes.js
Normal file
@ -0,0 +1,11 @@
|
||||
load(libdir + 'asserts.js');
|
||||
|
||||
function test() {
|
||||
assertTypeErrorMessage(() => { ctypes.cast(); },
|
||||
"ctypes.cast takes two arguments");
|
||||
assertTypeErrorMessage(() => { ctypes.getRuntime(); },
|
||||
"ctypes.getRuntime takes one argument");
|
||||
}
|
||||
|
||||
if (typeof ctypes === "object")
|
||||
test();
|
16
js/src/jit-test/tests/ctypes/argument-length-finalizer.js
Normal file
16
js/src/jit-test/tests/ctypes/argument-length-finalizer.js
Normal file
@ -0,0 +1,16 @@
|
||||
load(libdir + 'asserts.js');
|
||||
|
||||
function test() {
|
||||
assertTypeErrorMessage(() => { ctypes.CDataFinalizer(1); },
|
||||
"CDataFinalizer constructor takes two arguments");
|
||||
|
||||
let fin = ctypes.CDataFinalizer(ctypes.int32_t(0), ctypes.FunctionType(ctypes.default_abi, ctypes.int32_t, [ctypes.int32_t]).ptr(x => x));
|
||||
assertTypeErrorMessage(() => { fin.forget(1); },
|
||||
"CDataFinalizer.prototype.forget takes no arguments");
|
||||
assertTypeErrorMessage(() => { fin.dispose(1); },
|
||||
"CDataFinalizer.prototype.dispose takes no arguments");
|
||||
fin.forget();
|
||||
}
|
||||
|
||||
if (typeof ctypes === "object")
|
||||
test();
|
11
js/src/jit-test/tests/ctypes/argument-length-function.js
Normal file
11
js/src/jit-test/tests/ctypes/argument-length-function.js
Normal file
@ -0,0 +1,11 @@
|
||||
load(libdir + 'asserts.js');
|
||||
|
||||
function test() {
|
||||
assertTypeErrorMessage(() => { ctypes.FunctionType(); },
|
||||
"FunctionType takes two or three arguments");
|
||||
assertTypeErrorMessage(() => { ctypes.FunctionType(ctypes.default_abi, ctypes.void_t, []).ptr({}, 1); },
|
||||
"FunctionType constructor takes one argument");
|
||||
}
|
||||
|
||||
if (typeof ctypes === "object")
|
||||
test();
|
36
js/src/jit-test/tests/ctypes/argument-length-int64.js
Normal file
36
js/src/jit-test/tests/ctypes/argument-length-int64.js
Normal file
@ -0,0 +1,36 @@
|
||||
load(libdir + 'asserts.js');
|
||||
|
||||
function test() {
|
||||
assertTypeErrorMessage(() => { ctypes.Int64(1).toString(1, 2); },
|
||||
"Int64.prototype.toString takes at most one argument");
|
||||
assertTypeErrorMessage(() => { ctypes.Int64(1).toSource(1); },
|
||||
"Int64.prototype.toSource takes no arguments");
|
||||
assertTypeErrorMessage(() => { ctypes.Int64(); },
|
||||
"Int64 constructor takes one argument");
|
||||
assertTypeErrorMessage(() => { ctypes.Int64.compare(); },
|
||||
"Int64.compare takes two arguments");
|
||||
assertTypeErrorMessage(() => { ctypes.Int64.lo(); },
|
||||
"Int64.lo takes one argument");
|
||||
assertTypeErrorMessage(() => { ctypes.Int64.hi(); },
|
||||
"Int64.hi takes one argument");
|
||||
assertTypeErrorMessage(() => { ctypes.Int64.join(); },
|
||||
"Int64.join takes two arguments");
|
||||
|
||||
assertTypeErrorMessage(() => { ctypes.UInt64(1).toString(1, 2); },
|
||||
"UInt64.prototype.toString takes at most one argument");
|
||||
assertTypeErrorMessage(() => { ctypes.UInt64(1).toSource(1); },
|
||||
"UInt64.prototype.toSource takes no arguments");
|
||||
assertTypeErrorMessage(() => { ctypes.UInt64(); },
|
||||
"UInt64 constructor takes one argument");
|
||||
assertTypeErrorMessage(() => { ctypes.UInt64.compare(); },
|
||||
"UInt64.compare takes two arguments");
|
||||
assertTypeErrorMessage(() => { ctypes.UInt64.lo(); },
|
||||
"UInt64.lo takes one argument");
|
||||
assertTypeErrorMessage(() => { ctypes.UInt64.hi(); },
|
||||
"UInt64.hi takes one argument");
|
||||
assertTypeErrorMessage(() => { ctypes.UInt64.join(); },
|
||||
"UInt64.join takes two arguments");
|
||||
}
|
||||
|
||||
if (typeof ctypes === "object")
|
||||
test();
|
11
js/src/jit-test/tests/ctypes/argument-length-pointer.js
Normal file
11
js/src/jit-test/tests/ctypes/argument-length-pointer.js
Normal file
@ -0,0 +1,11 @@
|
||||
load(libdir + 'asserts.js');
|
||||
|
||||
function test() {
|
||||
assertTypeErrorMessage(() => { ctypes.PointerType(); },
|
||||
"PointerType takes one argument");
|
||||
assertTypeErrorMessage(() => { ctypes.int32_t.ptr(1, 2, 3, 4); },
|
||||
"PointerType constructor takes 0, 1, 2, or 3 arguments");
|
||||
}
|
||||
|
||||
if (typeof ctypes === "object")
|
||||
test();
|
11
js/src/jit-test/tests/ctypes/argument-length-primitive.js
Normal file
11
js/src/jit-test/tests/ctypes/argument-length-primitive.js
Normal file
@ -0,0 +1,11 @@
|
||||
load(libdir + 'asserts.js');
|
||||
|
||||
function test() {
|
||||
assertTypeErrorMessage(() => { ctypes.int32_t(1, 2, 3); },
|
||||
"CType constructor takes at most one argument");
|
||||
assertTypeErrorMessage(() => { ctypes.int32_t.array(1, 2); },
|
||||
"CType.prototype.array takes at most one argument");
|
||||
}
|
||||
|
||||
if (typeof ctypes === "object")
|
||||
test();
|
17
js/src/jit-test/tests/ctypes/argument-length-struct.js
Normal file
17
js/src/jit-test/tests/ctypes/argument-length-struct.js
Normal file
@ -0,0 +1,17 @@
|
||||
load(libdir + 'asserts.js');
|
||||
|
||||
function test() {
|
||||
assertTypeErrorMessage(() => { ctypes.StructType(); },
|
||||
"StructType takes one or two arguments");
|
||||
assertTypeErrorMessage(() => { ctypes.StructType("a").define(); },
|
||||
"StructType.prototype.define takes one argument");
|
||||
assertTypeErrorMessage(() => { ctypes.StructType("a", [])(1, 2, 3); },
|
||||
"StructType constructor takes at most one argument");
|
||||
assertTypeErrorMessage(() => { ctypes.StructType("a", [ {"x": ctypes.int32_t }, {"y": ctypes.int32_t }, {"z": ctypes.int32_t }])(1, 2); },
|
||||
"StructType constructor takes 0, 1, or 3 arguments");
|
||||
assertTypeErrorMessage(() => { ctypes.StructType("a", [ {"x": ctypes.int32_t } ])().addressOfField(); },
|
||||
"StructType.prototype.addressOfField takes one argument");
|
||||
}
|
||||
|
||||
if (typeof ctypes === "object")
|
||||
test();
|
@ -300,7 +300,7 @@ function run_abstract_class_tests()
|
||||
}
|
||||
|
||||
function run_Int64_tests() {
|
||||
do_check_throws(function() { ctypes.Int64(); }, Error);
|
||||
do_check_throws(function() { ctypes.Int64(); }, TypeError);
|
||||
|
||||
// Test that classes and prototypes are set up correctly.
|
||||
do_check_class(ctypes.Int64, "Function");
|
||||
@ -334,11 +334,11 @@ function run_Int64_tests() {
|
||||
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(10, 2); }, Error);
|
||||
do_check_throws(function() { i.toString(10, 2); }, TypeError);
|
||||
|
||||
// Test Int64.toSource().
|
||||
do_check_eq(i.toSource(), "ctypes.Int64(\"0\")");
|
||||
do_check_throws(function() { i.toSource(10); }, Error);
|
||||
do_check_throws(function() { i.toSource(10); }, TypeError);
|
||||
|
||||
i = ctypes.Int64("0x28590a1c921def71");
|
||||
do_check_eq(i.toString(), i.toString(10));
|
||||
@ -471,7 +471,7 @@ function run_Int64_tests() {
|
||||
}
|
||||
|
||||
function run_UInt64_tests() {
|
||||
do_check_throws(function() { ctypes.UInt64(); }, Error);
|
||||
do_check_throws(function() { ctypes.UInt64(); }, TypeError);
|
||||
|
||||
// Test that classes and prototypes are set up correctly.
|
||||
do_check_class(ctypes.UInt64, "Function");
|
||||
@ -505,11 +505,11 @@ function run_UInt64_tests() {
|
||||
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(10, 2); }, Error);
|
||||
do_check_throws(function() { i.toString(10, 2); }, TypeError);
|
||||
|
||||
// Test UInt64.toSource().
|
||||
do_check_eq(i.toSource(), "ctypes.UInt64(\"0\")");
|
||||
do_check_throws(function() { i.toSource(10); }, Error);
|
||||
do_check_throws(function() { i.toSource(10); }, TypeError);
|
||||
|
||||
i = ctypes.UInt64("0x28590a1c921def71");
|
||||
do_check_eq(i.toString(), i.toString(10));
|
||||
@ -1372,8 +1372,8 @@ function run_StructType_tests() {
|
||||
ctypes.StructType("t", [{"c": ctypes.int32_t}, {"d": ctypes.int64_t}]),
|
||||
[ "fields" ], [ "define" ], [], [ "addressOfField" ], [ "a", "b" ]);
|
||||
|
||||
do_check_throws(function() { ctypes.StructType(); }, Error);
|
||||
do_check_throws(function() { ctypes.StructType("a", [], 5); }, Error);
|
||||
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);
|
||||
|
||||
@ -1424,8 +1424,8 @@ function run_StructType_tests() {
|
||||
}, TypeError);
|
||||
|
||||
// Check that 'define' works.
|
||||
do_check_throws(function() { opaque_t.define(); }, Error);
|
||||
do_check_throws(function() { opaque_t.define([], 0); }, Error);
|
||||
do_check_throws(function() { opaque_t.define(); }, TypeError);
|
||||
do_check_throws(function() { opaque_t.define([], 0); }, TypeError);
|
||||
do_check_throws(function() { opaque_t.define([{}]); }, Error);
|
||||
do_check_throws(function() { opaque_t.define([{ a: 0 }]); }, Error);
|
||||
do_check_throws(function() {
|
||||
@ -1551,7 +1551,7 @@ function run_StructType_tests() {
|
||||
do_check_eq(g.a, 1);
|
||||
do_check_eq(g.b, 2);
|
||||
do_check_throws(function() { g_t(1); }, TypeError);
|
||||
do_check_throws(function() { g_t(1, 2, 3); }, Error);
|
||||
do_check_throws(function() { g_t(1, 2, 3); }, TypeError);
|
||||
|
||||
for (let field in g)
|
||||
do_check_true(field == "a" || field == "b");
|
||||
@ -1576,9 +1576,9 @@ function run_StructType_tests() {
|
||||
g_a = s.addressOfField("b");
|
||||
do_check_true(g_a.constructor === g_t.ptr);
|
||||
do_check_eq(g_a.contents.a, s.b.a);
|
||||
do_check_throws(function() { s.addressOfField(); }, Error);
|
||||
do_check_throws(function() { s.addressOfField(); }, TypeError);
|
||||
do_check_throws(function() { s.addressOfField("d"); }, Error);
|
||||
do_check_throws(function() { s.addressOfField("a", 2); }, Error);
|
||||
do_check_throws(function() { s.addressOfField("a", 2); }, TypeError);
|
||||
|
||||
do_check_eq(s.toSource(), "s_t(4, {\"a\": 7, \"b\": 2}, 10)");
|
||||
do_check_eq(s.toSource(), s.toString());
|
||||
@ -1657,8 +1657,8 @@ function run_PointerType_tests() {
|
||||
ctypes.PointerType(ctypes.int32_t), ctypes.PointerType(ctypes.int64_t),
|
||||
[ "targetType" ], [], [ "contents" ], [ "isNull", "increment", "decrement" ], []);
|
||||
|
||||
do_check_throws(function() { ctypes.PointerType(); }, Error);
|
||||
do_check_throws(function() { ctypes.PointerType(ctypes.int32_t, 5); }, Error);
|
||||
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);
|
||||
@ -1835,13 +1835,13 @@ function run_FunctionType_tests() {
|
||||
[ "abi", "returnType", "argTypes", "isVariadic" ],
|
||||
undefined, undefined, undefined, undefined);
|
||||
|
||||
do_check_throws(function() { ctypes.FunctionType(); }, Error);
|
||||
do_check_throws(function() { ctypes.FunctionType(); }, TypeError);
|
||||
do_check_throws(function() {
|
||||
ctypes.FunctionType(ctypes.default_abi, ctypes.void_t, [ ctypes.void_t ]);
|
||||
}, Error);
|
||||
do_check_throws(function() {
|
||||
ctypes.FunctionType(ctypes.default_abi, ctypes.void_t, [ ctypes.void_t ], 5);
|
||||
}, Error);
|
||||
}, TypeError);
|
||||
do_check_throws(function() {
|
||||
ctypes.FunctionType(ctypes.default_abi, ctypes.void_t, ctypes.void_t);
|
||||
}, Error);
|
||||
@ -1960,9 +1960,9 @@ function run_ArrayType_tests() {
|
||||
ctypes.ArrayType(ctypes.int32_t, 10), ctypes.ArrayType(ctypes.int64_t),
|
||||
[ "elementType", "length" ], [], [ "length" ], [ "addressOfElement" ]);
|
||||
|
||||
do_check_throws(function() { ctypes.ArrayType(); }, Error);
|
||||
do_check_throws(function() { ctypes.ArrayType(); }, TypeError);
|
||||
do_check_throws(function() { ctypes.ArrayType(null); }, Error);
|
||||
do_check_throws(function() { ctypes.ArrayType(ctypes.int32_t, 1, 5); }, Error);
|
||||
do_check_throws(function() { ctypes.ArrayType(ctypes.int32_t, 1, 5); }, TypeError);
|
||||
do_check_throws(function() { ctypes.ArrayType(ctypes.int32_t, -1); }, Error);
|
||||
|
||||
let name = "g_t";
|
||||
@ -2011,7 +2011,7 @@ function run_ArrayType_tests() {
|
||||
do_check_eq(a2.constructor.length, 5);
|
||||
do_check_eq(a2.length, 5);
|
||||
do_check_eq(a2.constructor.size, g_t.size * 5);
|
||||
do_check_throws(function() { new a2_t(); }, Error);
|
||||
do_check_throws(function() { new a2_t(); }, TypeError);
|
||||
do_check_throws(function() { ctypes.ArrayType(ctypes.ArrayType(g_t)); }, Error);
|
||||
do_check_throws(function() { ctypes.ArrayType(ctypes.ArrayType(g_t), 5); }, Error);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user