Backed out changeset 07d1058b745e (bug 891107)

This commit is contained in:
Tooru Fujisawa 2016-03-13 04:54:18 +09:00
Родитель 6e4d9110ce
Коммит da7b7e3756
4 изменённых файлов: 24 добавлений и 92 удалений

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

@ -1732,33 +1732,6 @@ NonPrimitiveError(JSContext* cx, HandleObject typeObj)
return false;
}
static bool
NonStringBaseError(JSContext* cx, HandleValue thisVal)
{
JSAutoByteString valBytes;
const char* valStr = CTypesToSourceForError(cx, thisVal, valBytes);
if (!valStr)
return false;
JS_ReportErrorNumber(cx, GetErrorMessage, nullptr,
CTYPESMSG_NON_STRING_BASE, valStr);
return false;
}
static bool
NullPointerError(JSContext* cx, const char* action, HandleObject obj)
{
JSAutoByteString valBytes;
RootedValue val(cx, ObjectValue(*obj));
const char* valStr = CTypesToSourceForError(cx, val, valBytes);
if (!valStr)
return false;
JS_ReportErrorNumber(cx, GetErrorMessage, nullptr,
CTYPESMSG_NULL_POINTER, action, valStr);
return false;
}
static bool
PropNameNonStringError(JSContext* cx, HandleId id, HandleValue actual,
ConversionType convType,
@ -1826,20 +1799,6 @@ TypeOverflow(JSContext* cx, const char* expected, HandleValue actual)
return false;
}
static bool
UndefinedSizePointerError(JSContext* cx, const char* action, HandleObject obj)
{
JSAutoByteString valBytes;
RootedValue val(cx, ObjectValue(*obj));
const char* valStr = CTypesToSourceForError(cx, val, valBytes);
if (!valStr)
return false;
JS_ReportErrorNumber(cx, GetErrorMessage, nullptr,
CTYPESMSG_UNDEFINED_SIZE, action, valStr);
return false;
}
static bool
VariadicArgumentTypeError(JSContext* cx, uint32_t index, HandleValue actual)
{
@ -5184,7 +5143,7 @@ PointerType::IsNull(JSContext* cx, unsigned argc, Value* vp)
bool
PointerType::OffsetBy(JSContext* cx, const CallArgs& args, int offset)
{
RootedObject obj(cx, JS_THIS_OBJECT(cx, args.base()));
JSObject* obj = JS_THIS_OBJECT(cx, args.base());
if (!obj)
return false;
if (!CData::IsCData(obj)) {
@ -5208,7 +5167,8 @@ PointerType::OffsetBy(JSContext* cx, const CallArgs& args, int offset)
RootedObject baseType(cx, PointerType::GetBaseType(typeObj));
if (!CType::IsSizeDefined(baseType)) {
return UndefinedSizePointerError(cx, "modify", obj);
JS_ReportError(cx, "cannot modify pointer of undefined size");
return false;
}
size_t elementSize = CType::GetSize(baseType);
@ -5244,12 +5204,14 @@ PointerType::ContentsGetter(JSContext* cx, const JS::CallArgs& args)
RootedObject obj(cx, &args.thisv().toObject());
RootedObject baseType(cx, GetBaseType(CData::GetCType(obj)));
if (!CType::IsSizeDefined(baseType)) {
return UndefinedSizePointerError(cx, "get contents of", obj);
JS_ReportError(cx, "cannot get contents of undefined size");
return false;
}
void* data = *static_cast<void**>(CData::GetData(obj));
if (data == nullptr) {
return NullPointerError(cx, "read contents of", obj);
JS_ReportError(cx, "cannot read contents of null pointer");
return false;
}
RootedValue result(cx);
@ -5266,12 +5228,14 @@ PointerType::ContentsSetter(JSContext* cx, const JS::CallArgs& args)
RootedObject obj(cx, &args.thisv().toObject());
RootedObject baseType(cx, GetBaseType(CData::GetCType(obj)));
if (!CType::IsSizeDefined(baseType)) {
return UndefinedSizePointerError(cx, "set contents of", obj);
JS_ReportError(cx, "cannot set contents of undefined size");
return false;
}
void* data = *static_cast<void**>(CData::GetData(obj));
if (data == nullptr) {
return NullPointerError(cx, "write contents to", obj);
JS_ReportError(cx, "cannot write contents to null pointer");
return false;
}
args.rval().setUndefined();
@ -7774,7 +7738,8 @@ ReadStringCommon(JSContext* cx, InflateUTF8Method inflateUTF8, unsigned argc,
baseType = PointerType::GetBaseType(typeObj);
data = *static_cast<void**>(CData::GetData(obj));
if (data == nullptr) {
return NullPointerError(cx, "read contents of", obj);
JS_ReportError(cx, "cannot read contents of null pointer");
return false;
}
break;
case TYPE_array:
@ -7783,7 +7748,8 @@ ReadStringCommon(JSContext* cx, InflateUTF8Method inflateUTF8, unsigned argc,
maxLength = ArrayType::GetLength(typeObj);
break;
default:
return TypeError(cx, "PointerType or ArrayType", args.thisv());
JS_ReportError(cx, "not a PointerType or ArrayType");
return false;
}
// Convert the string buffer, taking care to determine the correct string
@ -7817,7 +7783,9 @@ ReadStringCommon(JSContext* cx, InflateUTF8Method inflateUTF8, unsigned argc,
break;
}
default:
return NonStringBaseError(cx, args.thisv());
JS_ReportError(cx,
"base type is not an 8-bit or 16-bit integer or character type");
return false;
}
if (!result)

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

@ -65,8 +65,3 @@ MSG_DEF(CTYPESMSG_VARG_TYPE_ERROR,2, JSEXN_TYPEERR, "variadic argument {0} must
/* ctype */
MSG_DEF(CTYPESMSG_CANNOT_CONSTRUCT,1, JSEXN_TYPEERR, "cannot construct from {0}")
/* pointer */
MSG_DEF(CTYPESMSG_UNDEFINED_SIZE,2, JSEXN_TYPEERR, "cannot {0} pointer of undefined size {1}")
MSG_DEF(CTYPESMSG_NULL_POINTER, 2, JSEXN_TYPEERR, "cannot {0} null pointer {1}")
MSG_DEF(CTYPESMSG_NON_STRING_BASE,1, JSEXN_TYPEERR, "base type {0} is not an 8-bit or 16-bit integer or character type")

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

@ -1,31 +0,0 @@
load(libdir + 'asserts.js');
function test() {
let p = ctypes.StructType("foo").ptr(0);
assertTypeErrorMessage(() => { p.increment(); },
"cannot modify pointer of undefined size foo.ptr(ctypes.UInt64(\"0x0\"))");
assertTypeErrorMessage(() => { p.decrement(); },
"cannot modify pointer of undefined size foo.ptr(ctypes.UInt64(\"0x0\"))");
assertTypeErrorMessage(() => { let a = p.contents; },
"cannot get contents of pointer of undefined size foo.ptr(ctypes.UInt64(\"0x0\"))");
assertTypeErrorMessage(() => { p.contents = 1; },
"cannot set contents of pointer of undefined size foo.ptr(ctypes.UInt64(\"0x0\"))");
let p2 = ctypes.int32_t.ptr(0);
assertTypeErrorMessage(() => { let a = p2.contents; },
"cannot read contents of null pointer ctypes.int32_t.ptr(ctypes.UInt64(\"0x0\"))");
assertTypeErrorMessage(() => { p2.contents = 1; },
"cannot write contents to null pointer ctypes.int32_t.ptr(ctypes.UInt64(\"0x0\"))");
assertTypeErrorMessage(() => { p2.readString(); },
"cannot read contents of null pointer ctypes.int32_t.ptr(ctypes.UInt64(\"0x0\"))");
assertTypeErrorMessage(() => { ctypes.int32_t(0).readString(); },
"expected PointerType or ArrayType, got ctypes.int32_t(0)");
assertTypeErrorMessage(() => { ctypes.int32_t(0).address().readString(); },
/base type ctypes\.int32_t\.ptr\(ctypes\.UInt64\(\"[x0-9A-Fa-f]+\"\)\) is not an 8-bit or 16-bit integer or character type/);
}
if (typeof ctypes === "object")
test();

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

@ -1691,8 +1691,8 @@ function run_PointerType_tests() {
let p = p_t();
do_check_throws(function() { p.value; }, TypeError);
do_check_eq(ptrValue(p), 0);
do_check_throws(function() { p.contents; }, TypeError);
do_check_throws(function() { p.contents = g; }, TypeError);
do_check_throws(function() { p.contents; }, Error);
do_check_throws(function() { p.contents = g; }, Error);
p = p_t(5);
do_check_eq(ptrValue(p), 5);
p = p_t(ctypes.UInt64(10));
@ -1708,10 +1708,10 @@ function run_PointerType_tests() {
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; }, TypeError);
do_check_throws(function() { f.contents = 0; }, TypeError);
do_check_throws(function() { f.contents; }, Error);
do_check_throws(function() { f.contents = 0; }, Error);
f = f_t(5);
do_check_throws(function() { f.contents = 0; }, TypeError);
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); }, TypeError);
@ -1754,7 +1754,7 @@ function run_PointerType_tests() {
// but that the former cannot be dereferenced.
let z_t = ctypes.int32_t.array().ptr;
do_check_eq(ptrValue(z_t()), 0);
do_check_throws(function() { z_t().contents }, TypeError);
do_check_throws(function() { z_t().contents }, Error);
z_t = ctypes.int32_t.array(0).ptr;
do_check_eq(ptrValue(z_t()), 0);
let z = ctypes.int32_t.array(0)().address();