Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
return PyJs.define_own_property(self, prop, desc, False)
new_len = to_uint32(desc['value'])
if new_len != to_number(desc['value']):
raise MakeError('RangeError', 'Invalid range!')
new_desc = dict((k, v) for k, v in six.iteritems(desc))
new_desc['value'] = float(new_len)
if new_len >= old_len:
return PyJs.define_own_property(self, prop, new_desc, False)
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, False):
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'] = old_len + 1.
if not new_writable:
new_desc['writable'] = False
PyJs.define_own_property(
self, prop, new_desc, False)
return False
old_len = new_len
): # if failed to delete set len to current len and reject.
new_desc['value'] = old_len + 1.
if not new_writable:
new_desc['writable'] = False
PyJs.define_own_property(self, prop, new_desc,
False)
return False
if not new_writable:
self.own['length']['writable'] = False
return True
elif prop.isdigit():
index = to_uint32(prop)
if index >= old_len and not old_len_desc['writable']:
return False
if not PyJs.define_own_property(self, prop, desc, False):
return False
if index >= old_len:
old_len_desc['value'] = index + 1.
return True
else:
return PyJs.define_own_property(self, prop, desc, False)
if not new_writable:
new_desc['writable'] = False
PyJs.define_own_property(
self, prop, new_desc, False)
return False
old_len = new_len
else: # standard method
while new_len < old_len:
old_len -= 1
if not self.delete(
unicode(int(old_len))
): # if failed to delete set len to current len and reject.
new_desc['value'] = old_len + 1.
if not new_writable:
new_desc['writable'] = False
PyJs.define_own_property(self, prop, new_desc,
False)
return False
if not new_writable:
self.own['length']['writable'] = False
return True
elif prop.isdigit():
index = to_uint32(prop)
if index >= old_len and not old_len_desc['writable']:
return False
if not PyJs.define_own_property(self, prop, desc, False):
return False
if index >= old_len:
old_len_desc['value'] = index + 1.
return True
else:
return False
if not new_writable:
self.own['length']['writable'] = False
return True
elif prop.isdigit():
index = to_uint32(prop)
if index >= old_len and not old_len_desc['writable']:
return False
if not PyJs.define_own_property(self, prop, desc, False):
return False
if index >= old_len:
old_len_desc['value'] = index + 1.
return True
else:
return PyJs.define_own_property(self, prop, desc, False)
def define_own_property(self, prop, desc, throw):
assert type(desc.get('value')) != int
old_len_desc = self.get_own_property('length')
old_len = old_len_desc['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, False)
new_len = to_uint32(desc['value'])
if new_len != to_number(desc['value']):
raise MakeError('RangeError', 'Invalid range!')
new_desc = dict((k, v) for k, v in six.iteritems(desc))
new_desc['value'] = float(new_len)
if new_len >= old_len:
return PyJs.define_own_property(self, prop, new_desc, False)
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, False):
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
def define_own_property(self, prop, desc, throw):
assert type(desc.get('value')) != int
old_len_desc = self.get_own_property('length')
old_len = old_len_desc['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, False)
new_len = to_uint32(desc['value'])
if new_len != to_number(desc['value']):
raise MakeError('RangeError', 'Invalid range!')
new_desc = dict((k, v) for k, v in six.iteritems(desc))
new_desc['value'] = float(new_len)
if new_len >= old_len:
return PyJs.define_own_property(self, prop, new_desc, False)
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, False):
return False