예제 #1
0
def test_array_iprop():
    d = DataProperty(42, True, True, True)
    a = W__Array()
    a._set_iprop(23, d)
    assert a._get_iprop(23) is d
    assert a._get_prop(u'23') is d
    assert a.get(u'23') == 42
예제 #2
0
def setup(global_object):
    from js.builtins import put_property, put_native_function
    from js.jsobj import W_ArrayConstructor, W__Array
    from js.object_space import object_space

    w_Array = W_ArrayConstructor()
    object_space.assign_proto(w_Array, object_space.proto_function)
    put_property(global_object, u'Array', w_Array)

    # 15.4.4
    w_ArrayPrototype = W__Array()
    object_space.assign_proto(w_ArrayPrototype, object_space.proto_object)
    object_space.proto_array = w_ArrayPrototype

    # 15.4.3.1
    put_property(w_Array,
                 u'prototype',
                 w_ArrayPrototype,
                 writable=False,
                 enumerable=False,
                 configurable=False)

    # 15.4.4.1
    put_property(w_ArrayPrototype, u'constructor', w_Array)

    # 15.4.4.2
    put_native_function(w_ArrayPrototype, u'toString', to_string)

    # 15.4.4.5
    put_native_function(w_ArrayPrototype, u'join', join, params=[u'separator'])

    # 15.4.4.6
    put_native_function(w_ArrayPrototype, u'pop', pop)

    # 15.4.4.7
    put_native_function(w_ArrayPrototype, u'push', push)

    # 15.4.4.8
    put_native_function(w_ArrayPrototype, u'reverse', reverse)

    # 15.4.4.11
    put_native_function(w_ArrayPrototype, u'sort', sort)

    put_native_function(w_ArrayPrototype, u'forEach', for_each)

    put_native_function(w_ArrayPrototype, u'indexOf', index_of)

    put_native_function(w_ArrayPrototype, u'lastIndexOf', last_index_of)

    put_native_function(w_ArrayPrototype, u'shift', shift)

    put_native_function(w_ArrayPrototype, u'slice', slice)
예제 #3
0
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
예제 #4
0
def test_array_w_put():
    a = W__Array()
    a.w_put(_w(23), 42)
    assert a.get(u'23') == 42
    assert a.w_get(_w(23)) == 42
    assert a.w_get(_w(u'23')) == 42
예제 #5
0
def test_array_w_get():
    d = DataProperty(42, True, True, True)
    a = W__Array()
    a._set_iprop(23, d)
    assert a.w_get(_w(23)) == 42
    assert a.w_get(_w(u'23')) == 42
예제 #6
0
def test_array_get():
    a = W__Array()
    a._set_prop(u'23', DataProperty(42, True, True, True))
    assert a.get(u'23') == 42
예제 #7
0
 def new_array(self, length=_w(0)):
     from js.jsobj import W__Array
     obj = W__Array(length)
     self.assign_proto(obj)
     return obj