Skip to content

Commit

Permalink
Implement nqp::splice.
Browse files Browse the repository at this point in the history
  • Loading branch information
pmurias committed Feb 5, 2015
1 parent 9d92aa8 commit 83b4da9
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/vm/js/QAST/Compiler.nqp
Expand Up @@ -628,6 +628,7 @@ class QAST::OperationsJS {
add_simple_op('pop', $T_OBJ, [$T_OBJ], sub ($array) {"$array.pop()"}, :sideffects);
add_simple_op('push', $T_OBJ, [$T_OBJ, $T_OBJ], sub ($array, $elem) {"$array.push($elem)"}, :sideffects);
add_simple_op('unshift', $T_OBJ, [$T_OBJ, $T_OBJ], sub ($array, $elem) {"$array.unshift($elem)"}, :sideffects);
add_simple_op('splice', $T_OBJ, [$T_OBJ, $T_OBJ, $T_INT, $T_INT], :sideffects);

add_simple_op('iterator', $T_OBJ, [$T_OBJ], :sideffects);

Expand Down
11 changes: 11 additions & 0 deletions src/vm/js/nqp-runtime/core.js
Expand Up @@ -218,3 +218,14 @@ op.curcode = function() {
var current = arguments.callee.caller;
return current.codeRef;
};


// TODO benchmark and pick a fast way of doing this
op.splice = function(target, source, offset, length) {
var args = [offset, length];
for (var i = 0; i < source.length; i++) {
args.push(source[i]);
}
target.splice.apply(target, args);
return target;
}

0 comments on commit 83b4da9

Please sign in to comment.