Merge pull request #979 from brendandahl/return-check2

Thoroughly check return values.
This commit is contained in:
Myk Melez 2015-01-30 18:30:51 -08:00
Родитель c2466cc3b2 8c3cc1889e
Коммит d7ccc1e539
3 изменённых файлов: 12 добавлений и 14 удалений

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

@ -82,17 +82,14 @@ module J2ME {
* Debugging helper to make sure native methods were implemented correctly.
*/
function checkReturnValue(methodInfo: MethodInfo, returnValue: any) {
if (returnValue instanceof Promise) {
console.error("You forgot to call asyncImpl():", methodInfo.implKey);
} else if (methodInfo.getReturnKind() === Kind.Void && returnValue) {
console.error("You returned something in a void method:", methodInfo.implKey);
} else if (methodInfo.getReturnKind() !== Kind.Void && (returnValue === undefined) &&
!U) {
console.error("You returned undefined in a non-void method:", methodInfo.implKey);
} else if (typeof returnValue === "string") {
console.error("You returned a non-wrapped string:", methodInfo.implKey);
} else if (returnValue === true || returnValue === false) {
console.error("You returned a JS boolean:", methodInfo.implKey);
if (U) {
if (typeof returnValue !== "undefined") {
assert(false, "Expected undefined return value during unwind, got " + returnValue);
}
return;
}
if (!(getKindCheck(methodInfo.getReturnKind())(returnValue))) {
assert(false, "Expected " + Kind[methodInfo.getReturnKind()] + " return value, got " + returnValue);
}
}

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

@ -659,4 +659,5 @@
exports.fromNumber = fromNumber;
exports.fromBits = fromBits;
exports.fromString = fromString;
exports.constructor = Long;
})(typeof exports === "undefined" ? this.Long = {} : exports);

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

@ -102,11 +102,11 @@ module J2ME {
case Kind.Int:
return (x) => (x | 0) === x;
case Kind.Float:
return (x) => Math.fround(x) === x;
return (x) => isNaN(x) || Math.fround(x) === x;
case Kind.Long:
return (x) => x instanceof Long;
return (x) => x instanceof Long.constructor;
case Kind.Double:
return (x) => (+x) === x;
return (x) => isNaN(x) || (+x) === x;
case Kind.Reference:
return (x) => x === null || x instanceof Object;
case Kind.Void: