зеркало из https://github.com/mozilla/pluotsorbet.git
Merge pull request #979 from brendandahl/return-check2
Thoroughly check return values.
This commit is contained in:
Коммит
d7ccc1e539
|
@ -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);
|
||||
|
|
6
types.ts
6
types.ts
|
@ -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:
|
||||
|
|
Загрузка…
Ссылка в новой задаче