Example #1
0
 def Call(self, ctx, args=[], this=None):
     if len(args) >= 1 and not isnull_or_undefined(args[0]):
         return W_FloatNumber(args[0].ToNumber(ctx))
     elif len(args) >= 1 and args[0] is w_Undefined:
         return W_FloatNumber(NAN)
     else:
         return W_FloatNumber(0.0)
Example #2
0
 def Call(self, ctx, args=[], this=None):
     if len(args) >= 1:
         if isnull_or_undefined(args[0]):
             thisArg = ctx.get_global()
         else:
             thisArg = args[0]
         callargs = args[1:]
     else:
         thisArg = ctx.get_global()
         callargs = []
     return this.Call(ctx, callargs, this = thisArg)
Example #3
0
    def Call(self, ctx, args=[], this=None):
        try:
            if isnull_or_undefined(args[0]):
                thisArg = ctx.get_global()
            else:
                thisArg = args[0].ToObject(ctx)
        except IndexError:
            thisArg = ctx.get_global()

        try:
            arrayArgs = args[1]
            if isinstance(arrayArgs, W_ListObject):
                callargs = arrayArgs.tolist()
            elif isnull_or_undefined(arrayArgs):
                callargs = []
            else:
                raise JsTypeError('arrayArgs is not an Array or Arguments object')
        except IndexError:
            callargs = []
        return this.Call(ctx, callargs, this=thisArg)
Example #4
0
def common_join(ctx, this, sep=','):
    length = this.Get(ctx, 'length').ToUInt32(ctx)
    l = []
    i = 0
    while i < length:
        item = this.Get(ctx, str(i))
        if isnull_or_undefined(item):
            item_string = ''
        else:
            item_string = item.ToString(ctx)
        l.append(item_string)
        i += 1

    return sep.join(l)
Example #5
0
 def Construct(self, ctx, args=[]):
     if len(args) >= 1 and not isnull_or_undefined(args[0]):
         Value = W_FloatNumber(args[0].ToNumber(ctx))
         return create_object(ctx, 'Number', Value = Value)
     return create_object(ctx, 'Number', Value = W_FloatNumber(0.0))
Example #6
0
 def Construct(self, ctx, args=[]):
     if len(args) >= 1 and not isnull_or_undefined(args[0]):
         Value = newbool(args[0].ToBoolean())
         return create_object(ctx, 'Boolean', Value = Value)
     return create_object(ctx, 'Boolean', Value = newbool(False))
Example #7
0
 def Call(self, ctx, args=[], this=None):
     if len(args) >= 1 and not isnull_or_undefined(args[0]):
         return newbool(args[0].ToBoolean())
     else:
         return newbool(False)
Example #8
0
 def Call(self, ctx, args=[], this=None):
     if len(args) >= 1 and not isnull_or_undefined(args[0]):
         return args[0].ToObject(ctx)
     else:
         return self.Construct(ctx)