コード例 #1
0
ファイル: jsobj.py プロジェクト: ProgVal/rpython-langjs
    def can_put(self, p):
        from js.object_space import isundefined, isnull_or_undefined
        desc = self.get_own_property(p)
        if desc is not None:
            if is_accessor_descriptor(desc) is True:
                if isundefined(desc.setter):
                    return False
                else:
                    return True
            return desc.writable

        proto = self.prototype()

        if isnull_or_undefined(proto):
            return self.extensible()

        assert isinstance(proto, W_BasicObject)
        inherited = proto.get_property(p)
        if inherited is None:
            return self.extensible()

        if is_accessor_descriptor(inherited) is True:
            if isundefined(inherited.setter):
                return False
            else:
                return True
        else:
            if self.extensible() is False:
                return False
            else:
                return inherited.writable
コード例 #2
0
ファイル: jsobj.py プロジェクト: ProgVal/rpython-langjs
 def Call(self, args=[], this=None, calling_context=None):
     from js.object_space import _w, isnull_or_undefined
     if len(args) >= 1 and not isnull_or_undefined(args[0]):
         boolval = args[0].to_boolean()
         return _w(boolval)
     else:
         return _w(False)
コード例 #3
0
    def __init__(self, code, formal_parameters=[], argv=[], this=newundefined(), strict=False, scope=None, w_func=None):
        from js.jsobj import W_BasicObject
        from js.object_space import object_space, isnull_or_undefined

        stack_size = code.estimated_stack_size()
        env_size = code.env_size() + 1  # neet do add one for the arguments object

        ExecutionContext.__init__(self, stack_size, env_size)

        self._code_ = code
        self._argument_values_ = argv
        self._strict_ = strict
        self._scope_ = scope
        self._w_func_ = w_func
        self._calling_context_ = None

        from js.lexical_environment import DeclarativeEnvironment
        localEnv = DeclarativeEnvironment(scope, env_size, False)
        self._lexical_environment_ = localEnv
        self._variable_environment_ = localEnv

        if strict:
            self._this_binding_ = this
        else:
            if this is None or isnull_or_undefined(this):
                self._this_binding_ = object_space.global_object
            else:
                assert isinstance(this, W_BasicObject)

                if this.klass() is not 'Object':
                    self._this_binding_ = this.ToObject()
                else:
                    self._this_binding_ = this

        self.declaration_binding_initialization()
コード例 #4
0
ファイル: function.py プロジェクト: ProgVal/rpython-langjs
def js_apply(ctx):
    from js.object_space import isnull_or_undefined
    func = ctx.this_binding()
    args = ctx.argv()

    this_arg = get_arg(args, 0)
    arg_array = get_arg(args, 1)

    if isnull_or_undefined(arg_array):
        res = func.Call(args=[], this=this_arg, calling_context=ctx)
        compl = NormalCompletion(value=_w(res))
        return compl

    from js.jsobj import W_BasicObject
    if not isinstance(arg_array, W_BasicObject):
        raise JsTypeError(u'')

    length = arg_array.get(u'length')
    n = length.ToUInt32()
    arg_list = []
    index = 0
    while index < n:
        index_name = unicode(str(index))
        next_arg = arg_array.get(index_name)
        arg_list.append(next_arg)
        index += 1

    res = func.Call(args=arg_list, this=this_arg, calling_context=ctx)
    compl = NormalCompletion(value=_w(res))
    return compl
コード例 #5
0
ファイル: jsobj.py プロジェクト: ProgVal/rpython-langjs
    def Call(self, args=[], this=None, calling_context=None):
        from js.object_space import _w, isnull_or_undefined, isundefined

        if len(args) >= 1 and not isnull_or_undefined(args[0]):
            return _w(args[0].ToNumber())
        elif len(args) >= 1 and isundefined(args[0]):
            return _w(NAN)
        else:
            return _w(0.0)
コード例 #6
0
ファイル: array.py プロジェクト: andrewsmedina/lang-js
def join(this, args):
    from js.object_space import isundefined

    separator = get_arg(args, 0)

    o = this.ToObject()
    len_val = o.get(u'length')
    length = len_val.ToUInt32()

    if isundefined(separator):
        sep = u','
    else:
        sep = separator.to_string()

    if length == 0:
        return u''

    element0 = o.get(u'0')
    if isnull_or_undefined(element0):
        r = u''
    else:
        r = element0.to_string()

    k = 1

    while(k < length):
        s = r + sep
        element = o.get(unicode(str(k)))
        if isnull_or_undefined(element):
            _next = u''
        else:
            _next = element.to_string()
        r = s + _next
        k += 1

    return r
コード例 #7
0
def join(this, args):
    from js.object_space import isundefined

    separator = get_arg(args, 0)

    o = this.ToObject()
    len_val = o.get(u'length')
    length = len_val.ToUInt32()

    if isundefined(separator):
        sep = u','
    else:
        sep = separator.to_string()

    if length == 0:
        return u''

    element0 = o.get(u'0')
    if isnull_or_undefined(element0):
        r = u''
    else:
        r = element0.to_string()

    k = 1

    while (k < length):
        s = r + sep
        element = o.get(unicode(str(k)))
        if isnull_or_undefined(element):
            _next = u''
        else:
            _next = element.to_string()
        r = s + _next
        k += 1

    return r
コード例 #8
0
ファイル: jsobj.py プロジェクト: ProgVal/rpython-langjs
    def _named_properties_dict(self):
        from js.object_space import isnull_or_undefined
        my_d = {}
        for i in self._property_map_.keys():
            my_d[i] = None

        proto = self.prototype()
        if not isnull_or_undefined(proto):
            assert isinstance(proto, W_BasicObject)
            proto_d = proto._named_properties_dict()
        else:
            proto_d = {}

        my_d.update(proto_d)

        return my_d
コード例 #9
0
ファイル: jsobj.py プロジェクト: ProgVal/rpython-langjs
    def has_instance(self, v):
        from js.object_space import isnull_or_undefined
        if not isinstance(v, W_BasicObject):
            return False

        o = self.get(u'prototype')

        if not isinstance(o, W_BasicObject):
            raise JsTypeError(u'has_instance')

        while True:
            assert isinstance(v, W_BasicObject)
            v = v.prototype()
            if isnull_or_undefined(v):
                return False
            if v == o:
                return True
コード例 #10
0
ファイル: jsobj.py プロジェクト: ProgVal/rpython-langjs
    def _can_idx_put(self, idx):
        from js.object_space import isundefined, isnull_or_undefined
        prop = self._get_iprop(idx)

        if prop is None:
            desc = None
        else:
            desc = prop.to_property_descriptor()

        #desc = self._get_own_idx_property(idx)
        if desc is not None:
            if is_accessor_descriptor(desc) is True:
                if isundefined(desc.setter):
                    return Descr(False, desc, None, prop)
                else:
                    return Descr(True, desc, None, prop)
            return Descr(desc.writable, desc, None, prop)

        proto = self.prototype()

        if isnull_or_undefined(proto):
            return Descr(self.extensible(), None, None, prop)

        assert isinstance(proto, W_BasicObject)

        if isinstance(proto, W__Array):
            inherited = proto._get_idx_property(idx)
        else:
            p = unicode(str(idx))
            inherited = proto.get_property(p)

        if inherited is None:
            return Descr(self.extensible(), None, None, prop)

        if is_accessor_descriptor(inherited) is True:
            if isundefined(inherited.setter):
                return Descr(False, None, inherited, prop)
            else:
                return Descr(True, None, inherited, prop)
        else:
            if self.extensible() is False:
                return Descr(False, None, inherited, prop)
            else:
                return Descr(inherited.writable, None, inherited, prop)
コード例 #11
0
ファイル: jsobj.py プロジェクト: ProgVal/rpython-langjs
    def Call(self, args=[], this=None, calling_context=None):
        from js.object_space import isnull_or_undefined
        from js.builtins import get_arg
        value = get_arg(args, 0)

        if isinstance(value, W_BasicObject):
            return value
        if isinstance(value, W_String):
            return value.ToObject()
        if isinstance(value, W_Boolean):
            return value.ToObject()
        if isinstance(value, W_Number):
            return value.ToObject()

        assert isnull_or_undefined(value)

        from js.object_space import object_space
        obj = object_space.new_obj()
        return obj