Exemplo n.º 1
0
def setup(global_object):
    from js.builtins import put_native_function, put_property
    from js.object_space import object_space

    #String
    # 15.5.1
    from js.jsobj import W_StringConstructor
    w_String = W_StringConstructor()
    object_space.assign_proto(w_String, object_space.proto_function)
    put_property(w_String, u'length', _w(1), writable=False, enumerable=False, configurable=False)
    put_property(global_object, u'String', w_String)

    # 15.5.4
    w_StringPrototype = W_StringObject(_w(u''))
    object_space.assign_proto(w_StringPrototype, object_space.proto_object)

    # 15.5.3.1
    object_space.proto_string = w_StringPrototype

    put_property(w_String, u'prototype', w_StringPrototype, writable=False, enumerable=False, configurable=False)

    # 15.5.3.2
    put_native_function(w_String, u'fromCharCode', from_char_code, params=[u'char1'])

    # 15.5.4.1
    put_property(w_StringPrototype, u'constructor', w_String)

    # 15.5.4.2
    put_native_function(w_StringPrototype, u'toString', to_string)

    # 15.5.4.3
    put_native_function(w_StringPrototype, u'valueOf', value_of)

    # 15.5.4.4
    put_native_function(w_StringPrototype, u'charAt', char_at, params=[u'pos'])

    # 15.5.4.5
    put_native_function(w_StringPrototype, u'charCodeAt', char_code_at, params=[u'pos'])

    # 15.5.4.6
    put_native_function(w_StringPrototype, u'concat', concat, params=[u'string1'])

    # 15.5.4.7
    put_native_function(w_StringPrototype, u'indexOf', index_of, params=[u'searchstring'])

    # 15.5.4.8
    put_native_function(w_StringPrototype, u'lastIndexOf', last_index_of, params=[u'searchstring'])

    # 15.5.4.14
    put_native_function(w_StringPrototype, u'split', split, params=[u'separator', u'limit'])

    # 15.5.4.15
    put_native_function(w_StringPrototype, u'substring', substring, params=[u'start', u'end'])

    # 15.5.4.16
    put_native_function(w_StringPrototype, u'toLowerCase', to_lower_case)

    # 15.5.4.18
    put_native_function(w_StringPrototype, u'toUpperCase', to_upper_case)
Exemplo n.º 2
0
def setup(global_object):
    from js.builtins import put_native_function, put_property
    from js.jsobj import W_Math
    from js.object_space import object_space

    # 15.8
    w_Math = W_Math()
    object_space.assign_proto(w_Math)
    put_property(global_object, u'Math', w_Math)

    put_native_function(w_Math, u'abs', js_abs, params=[u'x'])
    put_native_function(w_Math, u'floor', floor, params=[u'x'])
    put_native_function(w_Math, u'round', js_round, params=[u'x'])
    put_native_function(w_Math, u'random', js_random)
    put_native_function(w_Math, u'min', js_min, params=[u'value1', u'value2'])
    put_native_function(w_Math, u'max', js_max, params=[u'value1', u'value2'])
    put_native_function(w_Math, u'pow', js_pow, params=[u'x', u'y'])
    put_native_function(w_Math, u'sqrt', js_sqrt, params=[u'x'])
    put_native_function(w_Math, u'log', js_log, params=[u'x'])
    put_native_function(w_Math, u'sin', js_sin, params=[u'x'])
    put_native_function(w_Math, u'tan', js_tan, params=[u'x'])
    put_native_function(w_Math, u'acos', js_acos, params=[u'x'])
    put_native_function(w_Math, u'asin', js_asin, params=[u'x'])
    put_native_function(w_Math, u'atan', js_atan, params=[u'x'])
    put_native_function(w_Math, u'atan2', js_atan2, params=[u'y', u'x'])
    put_native_function(w_Math, u'ceil', js_ceil, params=[u'x'])
    put_native_function(w_Math, u'cos', js_cos, params=[u'x'])
    put_native_function(w_Math, u'exp', js_exp, params=[u'x'])

    # 15.8.1

    # 15.8.1.1
    put_property(w_Math, u'E', _w(E), writable=False, enumerable=False, configurable=False)

    # 15.8.1.2
    put_property(w_Math, u'LN10', _w(LN10), writable=False, enumerable=False, configurable=False)

    # 15.8.1.3
    put_property(w_Math, u'LN2', _w(LN2), writable=False, enumerable=False, configurable=False)

    # 15.8.1.4
    put_property(w_Math, u'LOG2E', _w(LOG2E), writable=False, enumerable=False, configurable=False)

    # 15.8.1.5
    put_property(w_Math, u'LOG10E', _w(LOG10E), writable=False, enumerable=False, configurable=False)

    # 15.8.1.6
    put_property(w_Math, u'PI', _w(PI), writable=False, enumerable=False, configurable=False)

    # 15.8.1.7
    put_property(w_Math, u'SQRT1_2', _w(SQRT1_2), writable=False, enumerable=False, configurable=False)

    # 15.8.1.8
    put_property(w_Math, u'SQRT2', _w(SQRT2), writable=False, enumerable=False, configurable=False)
Exemplo n.º 3
0
def setup(global_object):
    from js.builtins import put_property, put_native_function
    from js.jsobj import W_ArrayConstructor, W__Array
    from js.object_space import object_space

    w_Array = W_ArrayConstructor()
    object_space.assign_proto(w_Array, object_space.proto_function)
    put_property(global_object, u'Array', w_Array)

    # 15.4.4
    w_ArrayPrototype = W__Array()
    object_space.assign_proto(w_ArrayPrototype, object_space.proto_object)
    object_space.proto_array = w_ArrayPrototype

    # 15.4.3.1
    put_property(w_Array,
                 u'prototype',
                 w_ArrayPrototype,
                 writable=False,
                 enumerable=False,
                 configurable=False)

    # 15.4.4.1
    put_property(w_ArrayPrototype, u'constructor', w_Array)

    # 15.4.4.2
    put_native_function(w_ArrayPrototype, u'toString', to_string)

    # 15.4.4.5
    put_native_function(w_ArrayPrototype, u'join', join, params=[u'separator'])

    # 15.4.4.6
    put_native_function(w_ArrayPrototype, u'pop', pop)

    # 15.4.4.7
    put_native_function(w_ArrayPrototype, u'push', push)

    # 15.4.4.8
    put_native_function(w_ArrayPrototype, u'reverse', reverse)

    # 15.4.4.11
    put_native_function(w_ArrayPrototype, u'sort', sort)

    put_native_function(w_ArrayPrototype, u'forEach', for_each)

    put_native_function(w_ArrayPrototype, u'indexOf', index_of)

    put_native_function(w_ArrayPrototype, u'lastIndexOf', last_index_of)

    put_native_function(w_ArrayPrototype, u'shift', shift)

    put_native_function(w_ArrayPrototype, u'slice', slice)
Exemplo n.º 4
0
    def __init__(self, config={}):
        from js.jsobj import W_GlobalObject
        from js.object_space import object_space
        import js.builtins.interpreter

        self.config = InterpreterConfig(config)
        self.global_object = W_GlobalObject()
        object_space.global_object = self.global_object
        object_space.interpreter = self

        js.builtins.setup_builtins(self.global_object)
        js.builtins.interpreter.setup_builtins(self.global_object)

        object_space.assign_proto(self.global_object)
Exemplo n.º 5
0
def setup(global_object):
    from js.builtins import put_property, put_native_function
    from js.jsobj import W_ArrayConstructor, W__Array
    from js.object_space import object_space

    w_Array = W_ArrayConstructor()
    object_space.assign_proto(w_Array, object_space.proto_function)
    put_property(global_object, u'Array', w_Array)

    # 15.4.4
    w_ArrayPrototype = W__Array()
    object_space.assign_proto(w_ArrayPrototype, object_space.proto_object)
    object_space.proto_array = w_ArrayPrototype

    # 15.4.3.1
    put_property(w_Array, u'prototype', w_ArrayPrototype, writable=False, enumerable=False, configurable=False)

    # 15.4.4.1
    put_property(w_ArrayPrototype, u'constructor', w_Array)

    # 15.4.4.2
    put_native_function(w_ArrayPrototype, u'toString', to_string)

    # 15.4.4.5
    put_native_function(w_ArrayPrototype, u'join', join, params=[u'separator'])

    # 15.4.4.6
    put_native_function(w_ArrayPrototype, u'pop', pop)

    # 15.4.4.7
    put_native_function(w_ArrayPrototype, u'push', push)

    # 15.4.4.8
    put_native_function(w_ArrayPrototype, u'reverse', reverse)

    # 15.4.4.11
    put_native_function(w_ArrayPrototype, u'sort', sort)

    put_native_function(w_ArrayPrototype, u'forEach', for_each)

    put_native_function(w_ArrayPrototype, u'indexOf', index_of)

    put_native_function(w_ArrayPrototype, u'lastIndexOf', last_index_of)

    put_native_function(w_ArrayPrototype, u'shift', shift)

    put_native_function(w_ArrayPrototype, u'slice', slice)
Exemplo n.º 6
0
    def Construct(self, args=[]):
        from js.object_space import object_space

        proto = self.get(u'prototype')
        if isinstance(proto, W_BasicObject):
            obj = object_space.new_obj()
            object_space.assign_proto(obj, proto)
        else:
            # would love to test this
            # but I fail to find a case that falls into this
            obj = object_space.new_obj()

        result = self.Call(args, this=obj)
        if isinstance(result, W__Object):
            return result

        return obj
Exemplo n.º 7
0
def setup(global_object):
    from js.builtins import put_property, put_native_function
    from js.object_space import object_space

    # 15.7.2
    from js.jsobj import W_NumberConstructor
    w_Number = W_NumberConstructor()
    object_space.assign_proto(w_Number, object_space.proto_function)
    put_property(global_object, u'Number', w_Number)

    # 15.7.3
    put_property(w_Number, u'length', _w(1), writable=False, enumerable=False, configurable=False)

    # 15.7.4
    w_NumberPrototype = W_NumericObject(_w(0))
    object_space.assign_proto(w_NumberPrototype, object_space.proto_object)
    object_space.proto_number = w_NumberPrototype

    # 15.7.4.1
    put_property(w_NumberPrototype, u'constructor', w_Number)

    # 15.7.4.2
    put_native_function(w_NumberPrototype, u'toString', to_string)

    # 15.7.4.4
    put_native_function(w_NumberPrototype, u'valueOf', value_of)

    # 15.7.3.1
    put_property(w_Number, u'prototype', w_NumberPrototype, writable=False, enumerable=False, configurable=False)

    # 15.7.3.2
    put_property(w_Number, u'MAX_VALUE', w_MAX_VALUE, writable=False, configurable=False, enumerable=False)

    # 15.7.3.3
    put_property(w_Number, u'MIN_VALUE', w_MIN_VALUE, writable=False, configurable=False, enumerable=False)

    # 15.7.3.4
    put_property(w_Number, u'NaN', w_NAN, writable=False, configurable=False, enumerable=False)

    # 15.7.3.5
    put_property(w_Number, u'POSITIVE_INFINITY', w_POSITIVE_INFINITY, writable=False, configurable=False, enumerable=False)

    # 15.7.3.6
    put_property(w_Number, u'NEGATIVE_INFINITY', w_NEGATIVE_INFINITY, writable=False, configurable=False, enumerable=False)
Exemplo n.º 8
0
def setup(global_object):
    from js.builtins import put_property, put_native_function
    from js.object_space import object_space

    # 15.6.2
    from js.jsobj import W_BooleanConstructor
    w_Boolean = W_BooleanConstructor()
    object_space.assign_proto(w_Boolean, object_space.proto_function)
    put_property(global_object, u'Boolean', w_Boolean)

    # 15.6.3
    put_property(w_Boolean,
                 u'length',
                 _w(1),
                 writable=False,
                 enumerable=False,
                 configurable=False)

    # 15.6.4
    w_BooleanPrototype = W_BooleanObject(_w(False))
    object_space.assign_proto(w_BooleanPrototype, object_space.proto_object)

    # 15.6.3.1
    object_space.proto_boolean = w_BooleanPrototype

    # 15.6.3.1
    put_property(w_Boolean,
                 u'prototype',
                 w_BooleanPrototype,
                 writable=False,
                 enumerable=False,
                 configurable=False)

    # 15.6.4.1
    put_property(w_BooleanPrototype, u'constructor', w_Boolean)

    # 15.6.4.2
    put_native_function(w_BooleanPrototype, u'toString', to_string)

    # 15.6.4.3
    put_native_function(w_BooleanPrototype, u'valueOf', value_of)
Exemplo n.º 9
0
def setup(global_object):
    from js.builtins import put_native_function, put_property
    from js.jsobj import W_Math
    from js.object_space import object_space

    # 15.8
    w_Math = W_Math()
    object_space.assign_proto(w_Math)
    put_property(global_object, u'Math', w_Math)

    put_native_function(w_Math, u'abs', js_abs, params=[u'x'])
    put_native_function(w_Math, u'floor', floor, params=[u'x'])
    put_native_function(w_Math, u'round', js_round, params=[u'x'])
    put_native_function(w_Math, u'random', js_random)
    put_native_function(w_Math, u'min', js_min, params=[u'value1', u'value2'])
    put_native_function(w_Math, u'max', js_max, params=[u'value1', u'value2'])
    put_native_function(w_Math, u'pow', js_pow, params=[u'x', u'y'])
    put_native_function(w_Math, u'sqrt', js_sqrt, params=[u'x'])
    put_native_function(w_Math, u'log', js_log, params=[u'x'])
    put_native_function(w_Math, u'sin', js_sin, params=[u'x'])
    put_native_function(w_Math, u'tan', js_tan, params=[u'x'])
    put_native_function(w_Math, u'acos', js_acos, params=[u'x'])
    put_native_function(w_Math, u'asin', js_asin, params=[u'x'])
    put_native_function(w_Math, u'atan', js_atan, params=[u'x'])
    put_native_function(w_Math, u'atan2', js_atan2, params=[u'y', u'x'])
    put_native_function(w_Math, u'ceil', js_ceil, params=[u'x'])
    put_native_function(w_Math, u'cos', js_cos, params=[u'x'])
    put_native_function(w_Math, u'exp', js_exp, params=[u'x'])

    # 15.8.1

    # 15.8.1.1
    put_property(w_Math,
                 u'E',
                 _w(E),
                 writable=False,
                 enumerable=False,
                 configurable=False)

    # 15.8.1.2
    put_property(w_Math,
                 u'LN10',
                 _w(LN10),
                 writable=False,
                 enumerable=False,
                 configurable=False)

    # 15.8.1.3
    put_property(w_Math,
                 u'LN2',
                 _w(LN2),
                 writable=False,
                 enumerable=False,
                 configurable=False)

    # 15.8.1.4
    put_property(w_Math,
                 u'LOG2E',
                 _w(LOG2E),
                 writable=False,
                 enumerable=False,
                 configurable=False)

    # 15.8.1.5
    put_property(w_Math,
                 u'LOG10E',
                 _w(LOG10E),
                 writable=False,
                 enumerable=False,
                 configurable=False)

    # 15.8.1.6
    put_property(w_Math,
                 u'PI',
                 _w(PI),
                 writable=False,
                 enumerable=False,
                 configurable=False)

    # 15.8.1.7
    put_property(w_Math,
                 u'SQRT1_2',
                 _w(SQRT1_2),
                 writable=False,
                 enumerable=False,
                 configurable=False)

    # 15.8.1.8
    put_property(w_Math,
                 u'SQRT2',
                 _w(SQRT2),
                 writable=False,
                 enumerable=False,
                 configurable=False)
Exemplo n.º 10
0
def setup(global_object):
    from js.builtins import put_property, put_native_function
    from js.jsobj import W_DateObject, W_DateConstructor
    from js.object_space import object_space

    ##Date
    # 15.9.5
    w_DatePrototype = W_DateObject(_w(NAN))
    # TODO
    #object_space.assign_proto(w_DatePrototype, object_space.proto_object)
    object_space.proto_date = w_DatePrototype

    put_native_function(w_DatePrototype, u'toString', to_string)

    put_native_function(w_DatePrototype, u'valueOf', value_of)
    put_native_function(w_DatePrototype, u'getTime', get_time)

    put_native_function(w_DatePrototype, u'getFullYear', get_full_year)
    put_native_function(w_DatePrototype, u'getUTCFullYear', get_utc_full_year)

    put_native_function(w_DatePrototype, u'getMonth', get_month)
    put_native_function(w_DatePrototype, u'getUTCMonth', get_utc_month)

    put_native_function(w_DatePrototype, u'getDate', get_date)
    put_native_function(w_DatePrototype, u'getUTCDate', get_utc_date)

    put_native_function(w_DatePrototype, u'getDay', get_day)
    put_native_function(w_DatePrototype, u'getUTCDay', get_utc_day)

    put_native_function(w_DatePrototype, u'getHours', get_hours)
    put_native_function(w_DatePrototype, u'getUTCHours', get_utc_hours)

    put_native_function(w_DatePrototype, u'getMinutes', get_minutes)
    put_native_function(w_DatePrototype, u'getUTCMinutes', get_utc_minutes)

    put_native_function(w_DatePrototype, u'getSeconds', get_seconds)
    put_native_function(w_DatePrototype, u'getUTCSeconds', get_utc_seconds)

    put_native_function(w_DatePrototype, u'getMilliseconds', get_milliseconds)
    put_native_function(w_DatePrototype, u'getUTCMilliseconds',
                        get_utc_milliseconds)

    put_native_function(w_DatePrototype, u'getTimezoneOffset',
                        get_timezone_offset)

    put_native_function(w_DatePrototype, u'setTime', set_time)

    put_native_function(w_DatePrototype, u'setMilliseconds', set_milliseconds)
    put_native_function(w_DatePrototype, u'setUTCMilliseconds',
                        set_utc_milliseconds)

    put_native_function(w_DatePrototype, u'setSeconds', set_seconds)
    put_native_function(w_DatePrototype, u'setUTCSeconds', set_utc_seconds)

    put_native_function(w_DatePrototype, u'setMinutes', set_minutes)
    put_native_function(w_DatePrototype, u'setUTCMinutes', set_utc_minutes)

    put_native_function(w_DatePrototype, u'setHours', set_hours)
    put_native_function(w_DatePrototype, u'setUTCHours', set_utc_hours)

    put_native_function(w_DatePrototype, u'setDate', set_date)
    put_native_function(w_DatePrototype, u'setUTCDate', set_utc_date)

    put_native_function(w_DatePrototype, u'setMonth', set_month)
    put_native_function(w_DatePrototype, u'setUTCMonth', set_utc_month)

    put_native_function(w_DatePrototype, u'setFullYear', set_full_year)
    put_native_function(w_DatePrototype, u'setUTCFullYear', set_utc_full_year)

    put_native_function(w_DatePrototype, u'getYear', get_year)
    put_native_function(w_DatePrototype, u'setYear', set_year)

    put_native_function(w_DatePrototype, u'toUTCString', to_utc_string)
    put_native_function(w_DatePrototype, u'toGMTString', to_gmt_string)

    # 15.9.3
    w_Date = W_DateConstructor()
    object_space.assign_proto(w_Date, object_space.proto_function)
    put_property(global_object, u'Date', w_Date)

    put_property(w_Date,
                 u'prototype',
                 w_DatePrototype,
                 writable=False,
                 enumerable=False,
                 configurable=False)

    put_native_function(w_Date, u'parse', parse)

    put_native_function(w_Date, u'now', now)

    put_native_function(w_Date, u'UTC', parse)

    # 15.9.5.1
    put_property(w_DatePrototype, u'constructor', w_Date)
Exemplo n.º 11
0
def setup(global_object):
    from js.builtins import put_property, put_native_function
    from js.jsobj import W_DateObject, W_DateConstructor
    from js.object_space import object_space

    ##Date
    # 15.9.5
    w_DatePrototype = W_DateObject(_w(NAN))
    # TODO
    #object_space.assign_proto(w_DatePrototype, object_space.proto_object)
    object_space.proto_date = w_DatePrototype

    put_native_function(w_DatePrototype, u'toString', to_string)

    put_native_function(w_DatePrototype, u'valueOf', value_of)
    put_native_function(w_DatePrototype, u'getTime', get_time)

    put_native_function(w_DatePrototype, u'getFullYear', get_full_year)
    put_native_function(w_DatePrototype, u'getUTCFullYear', get_utc_full_year)

    put_native_function(w_DatePrototype, u'getMonth', get_month)
    put_native_function(w_DatePrototype, u'getUTCMonth', get_utc_month)

    put_native_function(w_DatePrototype, u'getDate', get_date)
    put_native_function(w_DatePrototype, u'getUTCDate', get_utc_date)

    put_native_function(w_DatePrototype, u'getDay', get_day)
    put_native_function(w_DatePrototype, u'getUTCDay', get_utc_day)

    put_native_function(w_DatePrototype, u'getHours', get_hours)
    put_native_function(w_DatePrototype, u'getUTCHours', get_utc_hours)

    put_native_function(w_DatePrototype, u'getMinutes', get_minutes)
    put_native_function(w_DatePrototype, u'getUTCMinutes', get_utc_minutes)

    put_native_function(w_DatePrototype, u'getSeconds', get_seconds)
    put_native_function(w_DatePrototype, u'getUTCSeconds', get_utc_seconds)

    put_native_function(w_DatePrototype, u'getMilliseconds', get_milliseconds)
    put_native_function(w_DatePrototype, u'getUTCMilliseconds', get_utc_milliseconds)

    put_native_function(w_DatePrototype, u'getTimezoneOffset', get_timezone_offset)

    put_native_function(w_DatePrototype, u'setTime', set_time)

    put_native_function(w_DatePrototype, u'setMilliseconds', set_milliseconds)
    put_native_function(w_DatePrototype, u'setUTCMilliseconds', set_utc_milliseconds)

    put_native_function(w_DatePrototype, u'setSeconds', set_seconds)
    put_native_function(w_DatePrototype, u'setUTCSeconds', set_utc_seconds)

    put_native_function(w_DatePrototype, u'setMinutes', set_minutes)
    put_native_function(w_DatePrototype, u'setUTCMinutes', set_utc_minutes)

    put_native_function(w_DatePrototype, u'setHours', set_hours)
    put_native_function(w_DatePrototype, u'setUTCHours', set_utc_hours)

    put_native_function(w_DatePrototype, u'setDate', set_date)
    put_native_function(w_DatePrototype, u'setUTCDate', set_utc_date)

    put_native_function(w_DatePrototype, u'setMonth', set_month)
    put_native_function(w_DatePrototype, u'setUTCMonth', set_utc_month)

    put_native_function(w_DatePrototype, u'setFullYear', set_full_year)
    put_native_function(w_DatePrototype, u'setUTCFullYear', set_utc_full_year)

    put_native_function(w_DatePrototype, u'getYear', get_year)
    put_native_function(w_DatePrototype, u'setYear', set_year)

    put_native_function(w_DatePrototype, u'toUTCString', to_utc_string)
    put_native_function(w_DatePrototype, u'toGMTString', to_gmt_string)

    # 15.9.3
    w_Date = W_DateConstructor()
    object_space.assign_proto(w_Date, object_space.proto_function)
    put_property(global_object, u'Date', w_Date)

    put_property(w_Date, u'prototype', w_DatePrototype, writable=False, enumerable=False, configurable=False)

    put_native_function(w_Date, u'parse', parse)

    put_native_function(w_Date, u'now', now)

    put_native_function(w_Date, u'UTC', parse)

    # 15.9.5.1
    put_property(w_DatePrototype, u'constructor', w_Date)
Exemplo n.º 12
0
def setup(global_object):
    from js.builtins import put_native_function, put_property
    from js.object_space import object_space

    #String
    # 15.5.1
    from js.jsobj import W_StringConstructor
    w_String = W_StringConstructor()
    object_space.assign_proto(w_String, object_space.proto_function)
    put_property(w_String,
                 u'length',
                 _w(1),
                 writable=False,
                 enumerable=False,
                 configurable=False)
    put_property(global_object, u'String', w_String)

    # 15.5.4
    w_StringPrototype = W_StringObject(_w(u''))
    object_space.assign_proto(w_StringPrototype, object_space.proto_object)

    # 15.5.3.1
    object_space.proto_string = w_StringPrototype

    put_property(w_String,
                 u'prototype',
                 w_StringPrototype,
                 writable=False,
                 enumerable=False,
                 configurable=False)

    # 15.5.3.2
    put_native_function(w_String,
                        u'fromCharCode',
                        from_char_code,
                        params=[u'char1'])

    # 15.5.4.1
    put_property(w_StringPrototype, u'constructor', w_String)

    # 15.5.4.2
    put_native_function(w_StringPrototype, u'toString', to_string)

    # 15.5.4.3
    put_native_function(w_StringPrototype, u'valueOf', value_of)

    # 15.5.4.4
    put_native_function(w_StringPrototype, u'charAt', char_at, params=[u'pos'])

    # 15.5.4.5
    put_native_function(w_StringPrototype,
                        u'charCodeAt',
                        char_code_at,
                        params=[u'pos'])

    # 15.5.4.6
    put_native_function(w_StringPrototype,
                        u'concat',
                        concat,
                        params=[u'string1'])

    # 15.5.4.7
    put_native_function(w_StringPrototype,
                        u'indexOf',
                        index_of,
                        params=[u'searchstring'])

    # 15.5.4.8
    put_native_function(w_StringPrototype,
                        u'lastIndexOf',
                        last_index_of,
                        params=[u'searchstring'])

    # 15.5.4.14
    put_native_function(w_StringPrototype,
                        u'split',
                        split,
                        params=[u'separator', u'limit'])

    # 15.5.4.15
    put_native_function(w_StringPrototype,
                        u'substring',
                        substring,
                        params=[u'start', u'end'])

    # 15.5.4.16
    put_native_function(w_StringPrototype, u'toLowerCase', to_lower_case)

    # 15.5.4.18
    put_native_function(w_StringPrototype, u'toUpperCase', to_upper_case)
Exemplo n.º 13
0
def setup(global_object):
    from js.builtins import put_property, put_native_function
    from js.object_space import object_space

    # 15.7.2
    from js.jsobj import W_NumberConstructor
    w_Number = W_NumberConstructor()
    object_space.assign_proto(w_Number, object_space.proto_function)
    put_property(global_object, u'Number', w_Number)

    # 15.7.3
    put_property(w_Number,
                 u'length',
                 _w(1),
                 writable=False,
                 enumerable=False,
                 configurable=False)

    # 15.7.4
    w_NumberPrototype = W_NumericObject(_w(0))
    object_space.assign_proto(w_NumberPrototype, object_space.proto_object)
    object_space.proto_number = w_NumberPrototype

    # 15.7.4.1
    put_property(w_NumberPrototype, u'constructor', w_Number)

    # 15.7.4.2
    put_native_function(w_NumberPrototype, u'toString', to_string)

    # 15.7.4.4
    put_native_function(w_NumberPrototype, u'valueOf', value_of)

    # 15.7.3.1
    put_property(w_Number,
                 u'prototype',
                 w_NumberPrototype,
                 writable=False,
                 enumerable=False,
                 configurable=False)

    # 15.7.3.2
    put_property(w_Number,
                 u'MAX_VALUE',
                 w_MAX_VALUE,
                 writable=False,
                 configurable=False,
                 enumerable=False)

    # 15.7.3.3
    put_property(w_Number,
                 u'MIN_VALUE',
                 w_MIN_VALUE,
                 writable=False,
                 configurable=False,
                 enumerable=False)

    # 15.7.3.4
    put_property(w_Number,
                 u'NaN',
                 w_NAN,
                 writable=False,
                 configurable=False,
                 enumerable=False)

    # 15.7.3.5
    put_property(w_Number,
                 u'POSITIVE_INFINITY',
                 w_POSITIVE_INFINITY,
                 writable=False,
                 configurable=False,
                 enumerable=False)

    # 15.7.3.6
    put_property(w_Number,
                 u'NEGATIVE_INFINITY',
                 w_NEGATIVE_INFINITY,
                 writable=False,
                 configurable=False,
                 enumerable=False)
Exemplo n.º 14
0
def setup_builtins(global_object):
    from js.object_space import object_space

    # 15.2.4 Properties of the Object Prototype Object
    from js.jsobj import W_BasicObject
    w_ObjectPrototype = W_BasicObject()
    object_space.proto_object = w_ObjectPrototype

    # 15.3.2
    from js.jsobj import W_FunctionConstructor
    w_Function = W_FunctionConstructor()
    put_property(global_object, u'Function', w_Function)

    # 15.3.4 Properties of the Function Prototype Object
    from js.functions import JsNativeFunction

    import js.builtins.function
    empty_func = JsNativeFunction(js.builtins.function.empty, u'Empty')
    w_FunctionPrototype = object_space.new_func(empty_func)
    object_space.assign_proto(w_FunctionPrototype, object_space.proto_object)
    object_space.proto_function = w_FunctionPrototype

    # 15.3.3
    object_space.assign_proto(w_Function, object_space.proto_function)

    # 15.2 Object Objects
    # 15.2.3 Properties of the Object Constructor
    from js.jsobj import W_ObjectConstructor
    w_Object = W_ObjectConstructor()
    object_space.assign_proto(w_Object, object_space.proto_function)

    put_property(w_Object, u'length', _w(1))

    put_property(global_object, u'Object', w_Object)

    # 15.2.3.1 Object.prototype
    put_property(w_Object, u'prototype', w_ObjectPrototype, writable=False, configurable=False, enumerable=False)

    # 14.2.4.1 Object.prototype.constructor
    put_property(w_ObjectPrototype, u'constructor', w_Object)

    import js.builtins.object
    # 15.2.4.2 Object.prototype.toString()
    put_native_function(w_ObjectPrototype, u'toString', js.builtins.object.to_string)
    put_native_function(w_ObjectPrototype, u'toLocaleString', js.builtins.object.to_string)

    # 15.2.4.3 Object.prototype.valueOf()
    put_native_function(w_ObjectPrototype, u'valueOf', js.builtins.object.value_of)

    # 15.3 Function Objects
    # 15.3.3 Properties of the Function Constructor

    # 15.3.3.1 Function.prototype
    put_property(w_Function, u'prototype', w_FunctionPrototype, writable=False, configurable=False, enumerable=False)

    # 15.3.3.2 Function.length
    put_property(w_Function, u'length', _w(1), writable=False, configurable=False, enumerable=False)

    # 14.3.4.1 Function.prototype.constructor
    put_property(w_FunctionPrototype, u'constructor', w_Function)

    # 15.3.4.2 Function.prototype.toString()
    put_native_function(w_FunctionPrototype, u'toString', js.builtins.function.to_string)

    # 15.3.4.3 Function.prototype.apply
    put_intimate_function(w_FunctionPrototype, u'apply', js.builtins.function.js_apply)

    # 15.3.4.4 Function.prototype.call
    put_intimate_function(w_FunctionPrototype, u'call', js.builtins.function.js_call)

    import js.builtins.boolean
    js.builtins.boolean.setup(global_object)

    import js.builtins.number
    js.builtins.number.setup(global_object)

    import js.builtins.string
    js.builtins.string.setup(global_object)

    import js.builtins.array
    js.builtins.array.setup(global_object)

    import js.builtins.js_math
    js.builtins.js_math.setup(global_object)

    import js.builtins.date
    js.builtins.date.setup(global_object)

    import js.builtins.js_global
    js.builtins.js_global.setup(global_object)