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
def split(this, args): from js.object_space import isundefined this.check_object_coercible() separator = get_arg(args, 0, None) limit = get_arg(args, 1) string = this.to_string() if isundefined(limit): import math lim = int(math.pow(2, 32) - 1) else: lim = limit.ToUInt32() if lim == 0 or separator is None: return [string] r = separator.to_string() if r == u'': i = 0 splitted = [] while i < len(string): splitted += [string[i]] i += 1 return splitted else: splitted = _rsplit(string, r, lim) return splitted
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)
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)
def sort_compare(obj, j, k, comparefn=newundefined()): from js.object_space import isundefined j_string = j k_string = k has_j = obj.has_property(j) has_k = obj.has_property(k) if has_j is False and has_k is False: return 0 if has_j is False: return 1 if has_k is False: return -1 x = obj.get(j_string) y = obj.get(k_string) if isundefined(x) and isundefined(y): return 0 if isundefined(x): return 1 if isundefined(y): return -1 if not isundefined(comparefn): if not comparefn.is_callable(): from js.exception import JsTypeError raise JsTypeError(u'') from js.jsobj import W_BasicFunction assert isinstance(comparefn, W_BasicFunction) res = comparefn.Call(args=[x, y], this=newundefined()) return res.ToInteger() x_string = x.to_string() y_string = y.to_string() if x_string < y_string: return -1 if x_string > y_string: return 1 return 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
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