Author: Andrews Medina <[email protected]>
Branch: 
Changeset: r393:4a574c8049ff
Date: 2013-05-20 01:44 -0300
http://bitbucket.org/pypy/lang-js/changeset/4a574c8049ff/

Log:    implemented [].slice

diff --git a/js/builtins/array.py b/js/builtins/array.py
--- a/js/builtins/array.py
+++ b/js/builtins/array.py
@@ -48,6 +48,24 @@
 
     put_native_function(w_ArrayPrototype, u'shift', shift)
 
+    put_native_function(w_ArrayPrototype, u'slice', slice)
+
+
+@w_return
+def slice(this, args):
+    o = this.ToObject()
+    from_index = get_arg(args, 0).ToUInt32()
+    to_index = get_arg(args, 1).ToUInt32()
+
+    n = []
+
+    i = 0
+    for k in xrange(from_index, to_index):
+        n.append(o.get(unicode(str(k))))
+        i += 1
+
+    return _w(n)
+
 
 # 15.4.4.7
 @w_return
diff --git a/test/test_array.py b/test/test_array.py
--- a/test/test_array.py
+++ b/test/test_array.py
@@ -1,6 +1,10 @@
 from test.test_interp import assertv, assertp
 
 
+def test_array_slice(capsys):
+    assertp("var a = [2, 5, 9, 2]; print(a.slice(1,3));", "5,9", capsys)
+
+
 def test_array_shift(capsys):
     assertp("var a = [2, 5, 9, 2]; print(a.shift());", "2", capsys)
     assertp("var a = [2, 5, 9, 2]; a.shift(); print(a);", "5,9,2", capsys)
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to