How to use the js2py.base.PyJs.define_own_property function in Js2Py

To help you get started, we’ve selected a few Js2Py examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github PiotrDabkowski / Js2Py / js2py / base.py View on Github external
if not self.delete(
                                str(int(old_len))
                        ):  # if failed to delete set len to current len and reject.
                            new_desc['value'] = Js(old_len + 1)
                            if not new_writable:
                                new_desc['writable'] = False
                            PyJs.define_own_property(self, prop, new_desc)
                            return False
            if not new_writable:
                self.own['length']['writable'] = False
            return True
        elif prop.isdigit():
            index = int(int(prop) % 2**32)
            if index >= old_len and not old_len_desc['writable']:
                return False
            if not PyJs.define_own_property(self, prop, desc):
                return False
            if index >= old_len:
                old_len_desc['value'] = Js(index + 1)
            return True
        else:
            return PyJs.define_own_property(self, prop, desc)
github PiotrDabkowski / Js2Py / js2py / base.py View on Github external
return PyJs.define_own_property(self, prop, desc)
            new_len = desc['value'].to_uint32()
            if new_len != desc['value'].to_number().value:
                raise MakeError('RangeError', 'Invalid range!')
            new_desc = dict((k, v) for k, v in six.iteritems(desc))
            new_desc['value'] = Js(new_len)
            if new_len >= old_len:
                return PyJs.define_own_property(self, prop, new_desc)
            if not old_len_desc['writable']:
                return False
            if 'writable' not in new_desc or new_desc['writable'] == True:
                new_writable = True
            else:
                new_writable = False
                new_desc['writable'] = True
            if not PyJs.define_own_property(self, prop, new_desc):
                return False
            if new_len < old_len:
                # not very efficient for sparse arrays, so using different method for sparse:
                if old_len > 30 * len(self.own):
                    for ele in self.own.keys():
                        if ele.isdigit() and int(ele) >= new_len:
                            if not self.delete(
                                    ele
                            ):  # if failed to delete set len to current len and reject.
                                new_desc['value'] = Js(old_len + 1)
                                if not new_writable:
                                    new_desc['writable'] = False
                                PyJs.define_own_property(self, prop, new_desc)
                                return False
                    old_len = new_len
                else:  # standard method
github PiotrDabkowski / Js2Py / js2py / base.py View on Github external
new_desc['value'] = Js(old_len + 1)
                                if not new_writable:
                                    new_desc['writable'] = False
                                PyJs.define_own_property(self, prop, new_desc)
                                return False
                    old_len = new_len
                else:  # standard method
                    while new_len < old_len:
                        old_len -= 1
                        if not self.delete(
                                str(int(old_len))
                        ):  # if failed to delete set len to current len and reject.
                            new_desc['value'] = Js(old_len + 1)
                            if not new_writable:
                                new_desc['writable'] = False
                            PyJs.define_own_property(self, prop, new_desc)
                            return False
            if not new_writable:
                self.own['length']['writable'] = False
            return True
        elif prop.isdigit():
            index = int(int(prop) % 2**32)
            if index >= old_len and not old_len_desc['writable']:
                return False
            if not PyJs.define_own_property(self, prop, desc):
                return False
            if index >= old_len:
                old_len_desc['value'] = Js(index + 1)
            return True
        else:
            return PyJs.define_own_property(self, prop, desc)
github PiotrDabkowski / Js2Py / js2py / base.py View on Github external
new_writable = False
                new_desc['writable'] = True
            if not PyJs.define_own_property(self, prop, new_desc):
                return False
            if new_len < old_len:
                # not very efficient for sparse arrays, so using different method for sparse:
                if old_len > 30 * len(self.own):
                    for ele in self.own.keys():
                        if ele.isdigit() and int(ele) >= new_len:
                            if not self.delete(
                                    ele
                            ):  # if failed to delete set len to current len and reject.
                                new_desc['value'] = Js(old_len + 1)
                                if not new_writable:
                                    new_desc['writable'] = False
                                PyJs.define_own_property(self, prop, new_desc)
                                return False
                    old_len = new_len
                else:  # standard method
                    while new_len < old_len:
                        old_len -= 1
                        if not self.delete(
                                str(int(old_len))
                        ):  # if failed to delete set len to current len and reject.
                            new_desc['value'] = Js(old_len + 1)
                            if not new_writable:
                                new_desc['writable'] = False
                            PyJs.define_own_property(self, prop, new_desc)
                            return False
            if not new_writable:
                self.own['length']['writable'] = False
            return True
github PiotrDabkowski / Js2Py / js2py / base.py View on Github external
if not self.delete(
                                str(int(old_len))
                        ):  # if failed to delete set len to current len and reject.
                            new_desc['value'] = Js(old_len + 1)
                            if not new_writable:
                                new_desc['writable'] = False
                            PyJs.define_own_property(self, prop, new_desc)
                            return False
            if not new_writable:
                self.own['length']['writable'] = False
            return True
        elif prop.isdigit():
            index = int(int(prop) % 2**32)
            if index >= old_len and not old_len_desc['writable']:
                return False
            if not PyJs.define_own_property(self, prop, desc):
                return False
            if index >= old_len:
                old_len_desc['value'] = Js(index + 1)
            return True
        else:
            return PyJs.define_own_property(self, prop, desc)
github PiotrDabkowski / Js2Py / js2py / base.py View on Github external
if not self.delete(
                                str(int(old_len))
                        ):  # if failed to delete set len to current len and reject.
                            new_desc['value'] = Js(old_len + 1)
                            if not new_writable:
                                new_desc['writable'] = False
                            PyJs.define_own_property(self, prop, new_desc)
                            return False
            if not new_writable:
                self.own['length']['writable'] = False
            return True
        elif prop.isdigit():
            index = int(int(prop) % 2**32)
            if index >= old_len and not old_len_desc['writable']:
                return False
            if not PyJs.define_own_property(self, prop, desc):
                return False
            if index >= old_len:
                old_len_desc['value'] = Js(index + 1)
            return True
        else:
            return PyJs.define_own_property(self, prop, desc)
github PiotrDabkowski / Js2Py / js2py / base.py View on Github external
new_writable = False
                new_desc['writable'] = True
            if not PyJs.define_own_property(self, prop, new_desc):
                return False
            if new_len < old_len:
                # not very efficient for sparse arrays, so using different method for sparse:
                if old_len > 30 * len(self.own):
                    for ele in self.own.keys():
                        if ele.isdigit() and int(ele) >= new_len:
                            if not self.delete(
                                    ele
                            ):  # if failed to delete set len to current len and reject.
                                new_desc['value'] = Js(old_len + 1)
                                if not new_writable:
                                    new_desc['writable'] = False
                                PyJs.define_own_property(self, prop, new_desc)
                                return False
                    old_len = new_len
                else:  # standard method
                    while new_len < old_len:
                        old_len -= 1
                        if not self.delete(
                                str(int(old_len))
                        ):  # if failed to delete set len to current len and reject.
                            new_desc['value'] = Js(old_len + 1)
                            if not new_writable:
                                new_desc['writable'] = False
                            PyJs.define_own_property(self, prop, new_desc)
                            return False
            if not new_writable:
                self.own['length']['writable'] = False
            return True
github PiotrDabkowski / Js2Py / js2py / base.py View on Github external
def define_own_property(self, prop, desc):
        old_len_desc = self.get_own_property('length')
        old_len = old_len_desc[
            'value'].value  #  value is js type so convert to py.
        if prop == 'length':
            if 'value' not in desc:
                return PyJs.define_own_property(self, prop, desc)
            new_len = desc['value'].to_uint32()
            if new_len != desc['value'].to_number().value:
                raise MakeError('RangeError', 'Invalid range!')
            new_desc = dict((k, v) for k, v in six.iteritems(desc))
            new_desc['value'] = Js(new_len)
            if new_len >= old_len:
                return PyJs.define_own_property(self, prop, new_desc)
            if not old_len_desc['writable']:
                return False
            if 'writable' not in new_desc or new_desc['writable'] == True:
                new_writable = True
            else:
                new_writable = False
                new_desc['writable'] = True
            if not PyJs.define_own_property(self, prop, new_desc):
                return False
            if new_len < old_len:
                # not very efficient for sparse arrays, so using different method for sparse:
                if old_len > 30 * len(self.own):
                    for ele in self.own.keys():
                        if ele.isdigit() and int(ele) >= new_len:
                            if not self.delete(
                                    ele
github PiotrDabkowski / Js2Py / js2py / base.py View on Github external
PyJs.define_own_property(self, prop, new_desc)
                            return False
            if not new_writable:
                self.own['length']['writable'] = False
            return True
        elif prop.isdigit():
            index = int(int(prop) % 2**32)
            if index >= old_len and not old_len_desc['writable']:
                return False
            if not PyJs.define_own_property(self, prop, desc):
                return False
            if index >= old_len:
                old_len_desc['value'] = Js(index + 1)
            return True
        else:
            return PyJs.define_own_property(self, prop, desc)
github PiotrDabkowski / Js2Py / js2py / base.py View on Github external
def define_own_property(self, prop, desc):
        old_len_desc = self.get_own_property('length')
        old_len = old_len_desc[
            'value'].value  #  value is js type so convert to py.
        if prop == 'length':
            if 'value' not in desc:
                return PyJs.define_own_property(self, prop, desc)
            new_len = desc['value'].to_uint32()
            if new_len != desc['value'].to_number().value:
                raise MakeError('RangeError', 'Invalid range!')
            new_desc = dict((k, v) for k, v in six.iteritems(desc))
            new_desc['value'] = Js(new_len)
            if new_len >= old_len:
                return PyJs.define_own_property(self, prop, new_desc)
            if not old_len_desc['writable']:
                return False
            if 'writable' not in new_desc or new_desc['writable'] == True:
                new_writable = True
            else:
                new_writable = False
                new_desc['writable'] = True
            if not PyJs.define_own_property(self, prop, new_desc):
                return False