Skip to content

Commit e6b249f

Browse files
committed
[js] Implement taking int64 and uint64 arguments
1 parent d4d4d23 commit e6b249f

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed

src/vm/js/nqp-runtime/runtime.js

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -540,6 +540,48 @@ exports.arg_i = function(ctx, contedArg) {
540540
}
541541
};
542542

543+
exports.arg_i64 = function(ctx, contedArg) {
544+
if (contedArg instanceof NativeIntArg) {
545+
return BigInt(contedArg.value);
546+
} else if (contedArg instanceof NativeUIntArg) {
547+
return BigInt(contedArg.value);
548+
} else if (contedArg instanceof NativeNumArg) {
549+
throw new NQPException('Expected native int64 argument, but got num');
550+
} else if (contedArg instanceof NativeStrArg) {
551+
throw new NQPException('Expected native int64 argument, but got str');
552+
}
553+
554+
const arg = contedArg.$$decont(ctx);
555+
if (arg instanceof NQPInt) {
556+
return BigInt(arg.value);
557+
} else if (arg.$$getInt64) {
558+
return BigInt(arg.$$getInt64());
559+
} else {
560+
throw new NQPException('Expected native int64 argument, but got something else');
561+
}
562+
};
563+
564+
exports.arg_u64 = function(ctx, contedArg) {
565+
if (contedArg instanceof NativeIntArg) {
566+
return BigInt.asUintN(64, contedArg.value);
567+
} else if (contedArg instanceof NativeUIntArg) {
568+
return BigInt(contedArg.value);
569+
} else if (contedArg instanceof NativeNumArg) {
570+
throw new NQPException('Expected native uint64 argument, but got num');
571+
} else if (contedArg instanceof NativeStrArg) {
572+
throw new NQPException('Expected native uint64 argument, but got str');
573+
}
574+
575+
const arg = contedArg.$$decont(ctx);
576+
if (arg instanceof NQPInt) {
577+
return BigInt.asUintN(64, BigInt(arg.value));
578+
} else if (arg.$$getUint64) {
579+
return BigInt(arg.$$getUint64());
580+
} else {
581+
throw new NQPException('Expected native uint64 argument, but got something else');
582+
}
583+
};
584+
543585
exports.arg_n = function(ctx, contedArg) {
544586
if (contedArg instanceof NativeNumArg) {
545587
return contedArg.value;

0 commit comments

Comments
 (0)