Skip to content

Commit 34bfa2c

Browse files
committed
[js] Fix nqp::uname and make it call the uname command
1 parent a20a24f commit 34bfa2c

File tree

2 files changed

+18
-3
lines changed

2 files changed

+18
-3
lines changed

src/vm/js/Operations.nqp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1907,6 +1907,8 @@ class QAST::OperationsJS {
19071907

19081908
add_simple_op('getrusage', $T_OBJ, [$T_OBJ], :side_effects);
19091909

1910+
add_simple_op('uname', $T_OBJ, [], :side_effects);
1911+
19101912
add_simple_op('cpucores', $T_INT, []);
19111913

19121914
add_simple_op('unicmp_s', $T_INT, [$T_STR, $T_STR, $T_INT, $T_INT, $T_INT]);

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

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ const Null = require('./null.js');
2626
const NQPInt = require('./nqp-int.js');
2727
const NQPStr = require('./nqp-str.js');
2828

29+
const BOOT = require('./BOOT.js');
30+
2931
function boolish(bool) {
3032
return bool ? 1 : 0;
3133
}
@@ -606,10 +608,21 @@ op.getppid = function() {
606608
return process.ppid;
607609
};
608610

611+
function uname(flag) {
612+
const result = child_process.spawnSync('uname', [flag]);
613+
if (result.error) {
614+
return "";
615+
} else {
616+
return result.stdout.toString().replace(/\n$/, '');
617+
}
618+
}
619+
609620
op.uname = function() {
610621
let sysname = os.type();
611622
let release = os.release();
612-
let version = "";
613-
let machine = "";
614-
return [sysname, release, version, machine];
623+
let version = uname('-v');
624+
let machine = uname('-m');
625+
626+
const stable = BOOT.StrArray.$$STable;
627+
return stable.REPR.allocateFromArray(stable, [sysname, release, version, machine]);
615628
};

0 commit comments

Comments
 (0)