Skip to content

Commit 2199a7f

Browse files
committed
[js] Implement nqp::existspos.
1 parent 5ab6d35 commit 2199a7f

File tree

3 files changed

+2
-8
lines changed

3 files changed

+2
-8
lines changed

src/vm/js/Operations.nqp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -920,7 +920,7 @@ class QAST::OperationsJS {
920920
add_simple_op('existskey', $T_BOOL, [$T_OBJ, $T_STR], :method_call);
921921
add_simple_op('deletekey', $T_OBJ, [$T_OBJ, $T_STR], :method_call, :side_effects);
922922

923-
add_simple_op('existspos', $T_BOOL, [$T_OBJ, $T_INT]);
923+
add_simple_op('existspos', $T_BOOL, [$T_OBJ, $T_INT], :method_call);
924924

925925
for <ceil floor abs log sqrt exp sin acos cos atan tan asin sinh cosh tanh> -> $func {
926926
add_simple_op($func ~ '_n', $T_NUM, [$T_NUM], sub ($arg) {"Math.$func($arg)"});

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

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -191,12 +191,6 @@ exports.op.ishash = function(obj) {
191191
return obj instanceof Hash || (obj._STable && obj._STable.REPR instanceof reprs.VMHash) ? 1 : 0;
192192
};
193193

194-
op.existspos = function(array, idx) {
195-
if (array.$$existspos) return array.$$existspos(idx);
196-
if (idx < 0) idx += array.length;
197-
return array.hasOwnProperty(idx) ? 1 : 0;
198-
};
199-
200194
op.create = function(obj) {
201195
return obj._STable.REPR.allocate(obj._STable);
202196
};

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1058,7 +1058,7 @@ class VMArray extends REPR {
10581058

10591059
$$existspos(index) {
10601060
if (index < 0) index += this.array.length;
1061-
return this.array.hasOwnProperty(index) ? 1 : 0;
1061+
return (this.array[index] === Null || this.array[index] === undefined) ? 0 : 1;
10621062
}
10631063

10641064
$$setelems(elems) {

0 commit comments

Comments
 (0)