Author: Andrews Medina <[email protected]>
Branch:
Changeset: r383:477e94f31216
Date: 2013-05-13 00:49 -0300
http://bitbucket.org/pypy/lang-js/changeset/477e94f31216/
Log: fixed [].sort() and obj.put behaviour.
diff --git a/js/builtins/array.py b/js/builtins/array.py
--- a/js/builtins/array.py
+++ b/js/builtins/array.py
@@ -40,6 +40,8 @@
# 15.4.4.11
put_native_function(w_ArrayPrototype, u'sort', sort)
+ put_native_function(w_ArrayPrototype, u'forEach', for_each)
+
# 15.4.4.7
@w_return
@@ -162,10 +164,17 @@
lower = lower + 1
+@w_return
+def for_each(this):
+ obj = this
+ length = this.get(u'length').ToUInt32()
+ return this
+
+
# 15.4.4.11
@w_return
def sort(this, args):
- obj = this
+ obj = this.ToObject()
length = this.get(u'length').ToUInt32()
comparefn = get_arg(args, 0)
diff --git a/js/jsobj.py b/js/jsobj.py
--- a/js/jsobj.py
+++ b/js/jsobj.py
@@ -324,7 +324,7 @@
own_desc = self.get_own_property(p)
if is_data_descriptor(own_desc) is True:
- value_desc = PropertyDescriptor(value=v)
+ value_desc = PropertyDescriptor(value=v, writable=True)
self.define_own_property(p, value_desc, throw)
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,12 @@
from test.test_interp import assertv, assertp
+def test_sort(capsys):
+ assertp("var x = [5,2]; print(x.sort());", '2,5', capsys)
+ assertp("var x = [1,2,3]; print(x.sort());", '1,2,3', capsys)
+ assertp("var x = [4,3,2,1]; print(x.sort());", '1,2,3,4', capsys)
+
+
def test_array_push(capsys):
assertv("var x = []; x.push(42); x.length;", 1)
assertv("var x = []; x.push(42); x[0];", 42)
diff --git a/test/test_w_array.py b/test/test_w_array.py
--- a/test/test_w_array.py
+++ b/test/test_w_array.py
@@ -3,6 +3,14 @@
from js.object_space import _w
+def test_array_put_change_index():
+ a = W__Array()
+ a.put(u'0', 42)
+ assert a.get(u'0') == 42
+ a.put(u'0', 43)
+ assert a.get(u'0') == 43
+
+
def test_array_get():
a = W__Array()
a._set_prop(u'23', DataProperty(42, True, True, True))
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit