<s> import ctypes <EOL> import types <EOL> from appvalidator . constants import MAX_STR_SIZE <EOL> from appvalidator . python . copy import deepcopy <EOL> import instanceactions <EOL> import utils <EOL> from jstypes import JSArray , JSContext , JSGlobal , JSLiteral , JSObject <EOL> NUMERIC_TYPES = ( int , long , float , complex ) <EOL> NUMERIC_OPERATORS = ( "<STR_LIT:->" , "<STR_LIT:*>" , "<STR_LIT:/>" , "<STR_LIT:%>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT:|>" , "<STR_LIT>" , "<STR_LIT:&>" ) <EOL> NUMERIC_OPERATORS += tuple ( "<STR_LIT>" % op for op in NUMERIC_OPERATORS ) <EOL> def BlockStatement ( traverser , node ) : <EOL> traverser . contexts . append ( JSContext ( "<STR_LIT>" , traverser = traverser ) ) <EOL> for child in node [ "<STR_LIT:body>" ] : <EOL> traverser . traverse_node ( child ) <EOL> traverser . contexts . pop ( ) <EOL> return False <EOL> def ExpressionStatement ( traverser , node ) : <EOL> return traverser . traverse_node ( node [ "<STR_LIT>" ] ) <EOL> def WithStatement ( traverser , node ) : <EOL> obj = traverser . traverse_node ( node [ "<STR_LIT:object>" ] ) <EOL> traverser . contexts . append ( obj ) <EOL> traverser . traverse_node ( node [ "<STR_LIT:body>" ] ) <EOL> traverser . contexts . pop ( ) <EOL> return False <EOL> def _function ( traverser , node ) : <EOL> """<STR_LIT>""" <EOL> current_contexts = traverser . contexts [ : ] <EOL> def wrap ( ) : <EOL> traverser . function_collection . append ( [ ] ) <EOL> traverser . _debug ( "<STR_LIT>" ) <EOL> traverser . this_stack . append ( JSObject ( traverser = traverser ) ) <EOL> traverser . contexts = current_contexts <EOL> params = { } <EOL> for param in node [ "<STR_LIT>" ] : <EOL> if param [ "<STR_LIT:type>" ] == "<STR_LIT>" : <EOL> params [ param [ "<STR_LIT:name>" ] ] = lambda : JSObject ( traverser = traverser ) <EOL> else : <EOL> pass <EOL> context = JSContext ( data = params , traverser = traverser ) <EOL> traverser . contexts . append ( context ) <EOL> traverser . traverse_node ( node [ "<STR_LIT:body>" ] ) <EOL> func_coll = traverser . function_collection . pop ( ) <EOL> for func in func_coll : <EOL> func ( ) <EOL> traverser . contexts . pop ( ) <EOL> traverser . _debug ( "<STR_LIT>" ) <EOL> traverser . this_stack . pop ( ) <EOL> if traverser . function_collection : <EOL> traverser . function_collection [ - <NUM_LIT:1> ] . append ( wrap ) <EOL> else : <EOL> wrap ( traverser , node ) <EOL> output = JSObject ( traverser = traverser , callable_ = True ) <EOL> output . TYPEOF = "<STR_LIT>" <EOL> return output <EOL> def FunctionDeclaration ( traverser , node ) : <EOL> me = _function ( traverser , node ) <EOL> traverser . _declare_variable ( node [ "<STR_LIT:id>" ] [ "<STR_LIT:name>" ] , me ) <EOL> return me <EOL> FunctionExpression = _function <EOL> def VariableDeclaration ( traverser , node ) : <EOL> traverser . _debug ( "<STR_LIT>" ) <EOL> traverser . debug_level += <NUM_LIT:1> <EOL> for declaration in node [ "<STR_LIT>" ] : <EOL> if declaration [ "<STR_LIT:id>" ] [ "<STR_LIT:type>" ] == "<STR_LIT>" : <EOL> vars = [ ] <EOL> for element in declaration [ "<STR_LIT:id>" ] [ "<STR_LIT>" ] : <EOL> if element is None or element [ "<STR_LIT:type>" ] != "<STR_LIT>" : <EOL> vars . append ( None ) <EOL> continue <EOL> vars . append ( element [ "<STR_LIT:name>" ] ) <EOL> if declaration [ "<STR_LIT>" ] is None : <EOL> for var in filter ( None , vars ) : <EOL> traverser . _declare_variable ( <EOL> var , JSObject ( traverser = traverser ) ) <EOL> elif declaration [ "<STR_LIT>" ] [ "<STR_LIT:type>" ] == "<STR_LIT>" : <EOL> for value in declaration [ "<STR_LIT>" ] [ "<STR_LIT>" ] : <EOL> if vars [ <NUM_LIT:0> ] : <EOL> traverser . _declare_variable ( <EOL> vars [ <NUM_LIT:0> ] , traverser . traverse_node ( value ) ) <EOL> vars = vars [ <NUM_LIT:1> : ] <EOL> elif declaration [ "<STR_LIT>" ] [ "<STR_LIT:type>" ] == "<STR_LIT>" : <EOL> assigner = traverser . traverse_node ( declaration [ "<STR_LIT>" ] ) <EOL> for value , var in zip ( assigner . elements , vars ) : <EOL> traverser . _declare_variable ( var , value ) <EOL> elif declaration [ "<STR_LIT:id>" ] [ "<STR_LIT:type>" ] == "<STR_LIT>" : <EOL> init = traverser . traverse_node ( declaration [ "<STR_LIT>" ] ) <EOL> def _proc_objpattern ( init_obj , properties ) : <EOL> for prop in properties : <EOL> if prop [ "<STR_LIT:key>" ] [ "<STR_LIT:type>" ] == "<STR_LIT>" : <EOL> prop_name = prop [ "<STR_LIT:key>" ] [ "<STR_LIT:value>" ] <EOL> elif prop [ "<STR_LIT:key>" ] [ "<STR_LIT:type>" ] == "<STR_LIT>" : <EOL> prop_name = prop [ "<STR_LIT:key>" ] [ "<STR_LIT:name>" ] <EOL> else : <EOL> continue <EOL> if prop [ "<STR_LIT:value>" ] [ "<STR_LIT:type>" ] == "<STR_LIT>" : <EOL> traverser . _declare_variable ( <EOL> prop [ "<STR_LIT:value>" ] [ "<STR_LIT:name>" ] , <EOL> init_obj . get ( traverser , prop_name ) ) <EOL> elif prop [ "<STR_LIT:value>" ] [ "<STR_LIT:type>" ] == "<STR_LIT>" : <EOL> _proc_objpattern ( init_obj . get ( traverser , prop_name ) , <EOL> prop [ "<STR_LIT:value>" ] [ "<STR_LIT>" ] ) <EOL> if init is not None : <EOL> _proc_objpattern ( init_obj = init , <EOL> properties = declaration [ "<STR_LIT:id>" ] [ "<STR_LIT>" ] ) <EOL> else : <EOL> var_name = declaration [ "<STR_LIT:id>" ] [ "<STR_LIT:name>" ] <EOL> traverser . _debug ( "<STR_LIT>" % var_name ) <EOL> traverser . _debug ( "<STR_LIT>" % node [ "<STR_LIT>" ] ) <EOL> var = traverser . traverse_node ( declaration [ "<STR_LIT>" ] ) <EOL> var . const = node [ "<STR_LIT>" ] == "<STR_LIT>" <EOL> traverser . _declare_variable ( var_name , var , type_ = node [ "<STR_LIT>" ] ) <EOL> traverser . debug_level -= <NUM_LIT:1> <EOL> return True <EOL> def ThisExpression ( traverser , node ) : <EOL> if not traverser . this_stack : <EOL> from predefinedentities import global_identity <EOL> return traverser . _build_global ( "<STR_LIT>" , global_identity ) <EOL> return traverser . this_stack [ - <NUM_LIT:1> ] or JSGlobal ( traverser = traverser ) <EOL> def ArrayExpression ( traverser , node ) : <EOL> return JSArray ( [ traverser . traverse_node ( x ) for x in node [ "<STR_LIT>" ] or [ ] ] ) <EOL> def ObjectExpression ( traverser , node ) : <EOL> var = JSObject ( traverser = traverser ) <EOL> for prop in node [ "<STR_LIT>" ] : <EOL> if prop [ "<STR_LIT:type>" ] == "<STR_LIT>" : <EOL> var_name = "<STR_LIT>" <EOL> else : <EOL> key = prop [ "<STR_LIT:key>" ] <EOL> if key [ "<STR_LIT:type>" ] == "<STR_LIT>" : <EOL> var_name = key [ "<STR_LIT:value>" ] <EOL> elif isinstance ( key [ "<STR_LIT:name>" ] , basestring ) : <EOL> var_name = key [ "<STR_LIT:name>" ] <EOL> else : <EOL> if "<STR_LIT>" in key [ "<STR_LIT:name>" ] : <EOL> name = key [ "<STR_LIT:name>" ] <EOL> else : <EOL> name = { "<STR_LIT>" : key [ "<STR_LIT:name>" ] } <EOL> var_name = _get_member_exp_property ( traverser , name ) <EOL> var_value = traverser . traverse_node ( prop [ "<STR_LIT:value>" ] ) <EOL> var . set ( var_name , var_value , traverser ) <EOL> return var <EOL> def _expr_unary_typeof ( wrapper ) : <EOL> """<STR_LIT>""" <EOL> if wrapper . callable : <EOL> return "<STR_LIT>" <EOL> elif isinstance ( wrapper , JSGlobal ) : <EOL> if "<STR_LIT>" in wrapper . global_data : <EOL> return wrapper . global_data [ "<STR_LIT>" ] <EOL> if ( "<STR_LIT>" in wrapper . global_data and <EOL> "<STR_LIT:value>" not in wrapper . global_data ) : <EOL> return "<STR_LIT>" <EOL> if wrapper . global_data . get ( "<STR_LIT>" , False ) : <EOL> return "<STR_LIT>" <EOL> return wrapper . TYPEOF <EOL> UNARY_OPERATORS = { <EOL> "<STR_LIT:->" : lambda e , t : - <NUM_LIT:1> * utils . get_as_num ( e . get_literal_value ( t ) ) , <EOL> "<STR_LIT:+>" : lambda e , t : utils . get_as_num ( e . get_literal_value ( t ) ) , <EOL> "<STR_LIT:!>" : lambda e , t : not e . get_literal_value ( t ) , <EOL> "<STR_LIT>" : lambda e , t : - <NUM_LIT:1> * ( utils . get_as_num ( e . get_literal_value ( t ) ) + <NUM_LIT:1> ) , <EOL> } <EOL> def UnaryExpression ( traverser , node ) : <EOL> operator = node [ "<STR_LIT>" ] <EOL> arg = traverser . traverse_node ( node [ "<STR_LIT>" ] ) <EOL> if ( isinstance ( arg , JSGlobal ) and <EOL> "<STR_LIT>" in arg . global_data and <EOL> not ( operator == "<STR_LIT>" and "<STR_LIT>" in arg . global_data ) ) : <EOL> arg = JSLiteral ( <EOL> utils . evaluate_lambdas ( traverser , arg . global_data [ "<STR_LIT>" ] ) , <EOL> traverser = traverser ) <EOL> if operator in UNARY_OPERATORS : <EOL> traverser . _debug ( "<STR_LIT>" % operator ) <EOL> return JSLiteral ( UNARY_OPERATORS [ node [ "<STR_LIT>" ] ] ( arg , traverser ) , <EOL> traverser = traverser ) <EOL> elif operator == "<STR_LIT>" : <EOL> traverser . _debug ( "<STR_LIT>" ) <EOL> from predefinedentities import resolve_entity <EOL> return JSGlobal ( resolve_entity ( traverser , "<STR_LIT>" ) , <EOL> traverser = traverser ) <EOL> elif operator == "<STR_LIT>" : <EOL> traverser . _debug ( "<STR_LIT>" ) <EOL> return JSLiteral ( _expr_unary_typeof ( arg ) ) <EOL> else : <EOL> traverser . _debug ( "<STR_LIT>" ) <EOL> return JSObject ( traverser = traverser ) <EOL> BINARY_OPERATORS = { <EOL> "<STR_LIT>" : lambda l , r , gl , gr : l == r or gl == gr , <EOL> "<STR_LIT>" : lambda l , r , * a : l != r , <EOL> "<STR_LIT>" : lambda l , r , * a : l == r , <EOL> "<STR_LIT>" : lambda l , r , * a : type ( l ) != type ( r ) or l != r , <EOL> "<STR_LIT:>>" : lambda l , r , * a : l > r , <EOL> "<STR_LIT:<>" : lambda l , r , * a : l < r , <EOL> "<STR_LIT>" : lambda l , r , * a : l <= r , <EOL> "<STR_LIT>" : lambda l , r , * a : l >= r , <EOL> "<STR_LIT>" : lambda l , r , gl , gr : int ( gl ) << int ( gr ) , <EOL> "<STR_LIT>" : lambda l , r , gl , gr : int ( gl ) >> int ( gr ) , <EOL> "<STR_LIT>" : lambda l , r , gl , gr : float ( abs ( int ( gl ) ) >> int ( gr ) ) , <EOL> "<STR_LIT:+>" : lambda l , r , * a : l + r , <EOL> "<STR_LIT:->" : lambda l , r , gl , gr : gl - gr , <EOL> "<STR_LIT:*>" : lambda l , r , gl , gr : gl * gr , <EOL> "<STR_LIT:/>" : lambda l , r , gl , gr : <NUM_LIT:0> if gr == <NUM_LIT:0> else ( gl / gr ) , <EOL> "<STR_LIT:%>" : lambda l , r , gl , gr : <NUM_LIT:0> if gr == <NUM_LIT:0> else ( gl % gr ) , <EOL> } <EOL> def BinaryExpression ( traverser , node ) : <EOL> traverser . debug_level += <NUM_LIT:1> <EOL> operator = node [ "<STR_LIT>" ] <EOL> traverser . _debug ( "<STR_LIT>" % operator ) <EOL> traverser . _debug ( "<STR_LIT>" ) <EOL> traverser . debug_level += <NUM_LIT:1> <EOL> if ( node [ "<STR_LIT:left>" ] [ "<STR_LIT:type>" ] == "<STR_LIT>" and <EOL> "<STR_LIT>" not in node [ "<STR_LIT:left>" ] ) : <EOL> left = BinaryExpression ( traverser , node [ "<STR_LIT:left>" ] ) <EOL> node [ "<STR_LIT:left>" ] [ "<STR_LIT>" ] = left <EOL> else : <EOL> left = traverser . traverse_node ( node [ "<STR_LIT:left>" ] ) <EOL> traverser . _debug ( "<STR_LIT>" , - <NUM_LIT:1> ) <EOL> if ( operator == "<STR_LIT>" and <EOL> node [ "<STR_LIT:right>" ] [ "<STR_LIT:type>" ] == "<STR_LIT>" and <EOL> node [ "<STR_LIT:right>" ] [ "<STR_LIT:name>" ] == "<STR_LIT>" ) : <EOL> traverser . debug_level -= <NUM_LIT:1> <EOL> return JSLiteral ( True , traverser = traverser ) <EOL> else : <EOL> right = traverser . traverse_node ( node [ "<STR_LIT:right>" ] ) <EOL> traverser . debug_level -= <NUM_LIT:1> <EOL> left = left . get_literal_value ( traverser ) <EOL> right_wrap = right <EOL> right = right . get_literal_value ( traverser ) <EOL> gleft = utils . get_as_num ( left ) <EOL> gright = utils . get_as_num ( right ) <EOL> if operator in ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ) : <EOL> if left is None or right is None or gright < <NUM_LIT:0> : <EOL> return JSLiteral ( False , traverser = traverser ) <EOL> elif abs ( gleft ) == float ( '<STR_LIT>' ) or abs ( gright ) == float ( '<STR_LIT>' ) : <EOL> return utils . get_NaN ( traverser ) <EOL> output = None <EOL> if operator in BINARY_OPERATORS : <EOL> if operator == "<STR_LIT:+>" : <EOL> if left is None : <EOL> left = "<STR_LIT>" <EOL> if right is None : <EOL> right = "<STR_LIT>" <EOL> if ( isinstance ( left , types . StringTypes ) or <EOL> isinstance ( right , types . StringTypes ) ) : <EOL> left = utils . get_as_str ( left ) <EOL> right = utils . get_as_str ( right ) <EOL> output = BINARY_OPERATORS [ operator ] ( left , right , gleft , gright ) <EOL> elif operator == "<STR_LIT>" : <EOL> return JSLiteral ( right_wrap . has_var ( left , traverser = traverser ) , <EOL> traverser = traverser ) <EOL> if isinstance ( output , types . StringTypes ) and len ( output ) > MAX_STR_SIZE : <EOL> output = output [ : MAX_STR_SIZE ] <EOL> return JSLiteral ( output , traverser = traverser ) <EOL> ASSIGNMENT_OPERATORS = { <EOL> "<STR_LIT:=>" : lambda l , r , * a : r , <EOL> "<STR_LIT>" : lambda l , r , gl , gr : l + r , <EOL> "<STR_LIT>" : lambda l , r , gl , gr : gl - gr , <EOL> "<STR_LIT>" : lambda l , r , gl , gr : gl * gr , <EOL> "<STR_LIT>" : lambda l , r , gl , gr : <NUM_LIT:0> if gr == <NUM_LIT:0> else ( gl / gr ) , <EOL> "<STR_LIT>" : lambda l , r , gl , gr : <NUM_LIT:0> if gr == <NUM_LIT:0> else ( gl % gr ) , <EOL> "<STR_LIT>" : lambda l , r , gl , gr : int ( gl ) << int ( gr ) , <EOL> "<STR_LIT>" : lambda l , r , gl , gr : int ( gl ) >> int ( gr ) , <EOL> "<STR_LIT>" : lambda l , r , gl , gr : float ( <EOL> ctypes . c_uint ( int ( gl ) ) . value >> int ( gr ) ) , <EOL> "<STR_LIT>" : lambda l , r , gl , gr : int ( gl ) | int ( gr ) , <EOL> "<STR_LIT>" : lambda l , r , gl , gr : int ( gl ) ^ int ( gr ) , <EOL> "<STR_LIT>" : lambda l , r , gl , gr : int ( gl ) & int ( gr ) , <EOL> } <EOL> def AssignmentExpression ( traverser , node ) : <EOL> traverser . _debug ( "<STR_LIT>" ) <EOL> traverser . debug_level += <NUM_LIT:1> <EOL> traverser . _debug ( "<STR_LIT>" ) <EOL> right = traverser . traverse_node ( node [ "<STR_LIT:right>" ] ) <EOL> traverser . _debug ( "<STR_LIT>" ) <EOL> orig_left = left = traverser . traverse_node ( node [ "<STR_LIT:left>" ] ) <EOL> operator = node [ "<STR_LIT>" ] <EOL> def set_lvalue ( value ) : <EOL> node_left = node [ "<STR_LIT:left>" ] <EOL> traverser . _debug ( "<STR_LIT>" % node_left [ "<STR_LIT:type>" ] ) <EOL> global_overwrite = False <EOL> readonly_value = True <EOL> if node_left [ "<STR_LIT:type>" ] == "<STR_LIT>" : <EOL> global_overwrite = traverser . _is_global ( node_left [ "<STR_LIT:name>" ] ) <EOL> if global_overwrite : <EOL> from predefinedentities import GLOBAL_ENTITIES <EOL> global_dict = GLOBAL_ENTITIES [ node_left [ "<STR_LIT:name>" ] ] <EOL> readonly_value = global_dict . get ( "<STR_LIT>" , False ) <EOL> traverser . _declare_variable ( node_left [ "<STR_LIT:name>" ] , value , type_ = "<STR_LIT>" ) <EOL> elif node_left [ "<STR_LIT:type>" ] == "<STR_LIT>" : <EOL> member_object = MemberExpression ( traverser , node_left [ "<STR_LIT:object>" ] , <EOL> instantiate = True ) <EOL> member_property = _get_member_exp_property ( traverser , node_left ) <EOL> traverser . _debug ( "<STR_LIT>" % member_property ) <EOL> if member_object is None : <EOL> member_object = JSObject ( ) <EOL> member_object . set ( member_property , value , traverser ) <EOL> if operator == "<STR_LIT:=>" : <EOL> set_lvalue ( right ) <EOL> return right <EOL> elif operator not in ASSIGNMENT_OPERATORS : <EOL> traverser . _debug ( "<STR_LIT>" , <NUM_LIT:1> ) <EOL> return left <EOL> if left . const : <EOL> traverser . err . warning ( <EOL> err_id = ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ) , <EOL> warning = "<STR_LIT>" , <EOL> description = "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" , <EOL> filename = traverser . filename , <EOL> line = traverser . line , <EOL> column = traverser . position , <EOL> context = traverser . context ) <EOL> return JSObject ( traverser = traverser ) <EOL> traverser . _debug ( "<STR_LIT>" ) <EOL> traverser . debug_level -= <NUM_LIT:1> <EOL> if ( operator in NUMERIC_OPERATORS and <EOL> not isinstance ( left . get_literal_value ( traverser ) or <NUM_LIT:0> , NUMERIC_TYPES ) ) : <EOL> set_lvalue ( utils . get_NaN ( traverser ) ) <EOL> return left <EOL> gleft , gright = utils . get_as_num ( left ) , utils . get_as_num ( right ) <EOL> traverser . _debug ( "<STR_LIT>" % operator ) <EOL> if operator in ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ) and gright < <NUM_LIT:0> : <EOL> set_lvalue ( JSLiteral ( <NUM_LIT:0> , traverser = traverser ) ) <EOL> return left <EOL> elif ( operator in ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ) and <EOL> ( abs ( gleft ) == float ( '<STR_LIT>' ) or abs ( gright ) == float ( '<STR_LIT>' ) ) ) : <EOL> set_lvalue ( utils . get_NaN ( traverser ) ) <EOL> return left <EOL> if operator == '<STR_LIT>' : <EOL> lit_left = left . get_literal_value ( traverser ) <EOL> lit_right = right . get_literal_value ( traverser ) <EOL> if lit_left is None : <EOL> lit_left = <NUM_LIT:0> <EOL> if lit_right is None : <EOL> lit_right = <NUM_LIT:0> <EOL> if ( isinstance ( lit_left , types . StringTypes ) or <EOL> isinstance ( lit_right , types . StringTypes ) ) : <EOL> left = utils . get_as_str ( lit_left ) <EOL> right = utils . get_as_str ( lit_right ) <EOL> else : <EOL> left , right = lit_left , lit_right <EOL> output = ASSIGNMENT_OPERATORS [ operator ] ( left , right , gleft , gright ) <EOL> if isinstance ( output , types . StringTypes ) and len ( output ) > MAX_STR_SIZE : <EOL> output = output [ : MAX_STR_SIZE ] <EOL> traverser . _debug ( "<STR_LIT>" % output , <NUM_LIT:1> ) <EOL> set_lvalue ( JSLiteral ( output , traverser = traverser ) ) <EOL> return orig_left <EOL> def NewExpression ( traverser , node ) : <EOL> args = [ traverser . traverse_node ( arg ) for arg in node [ "<STR_LIT>" ] ] <EOL> elem = traverser . traverse_node ( node [ "<STR_LIT>" ] ) <EOL> if not isinstance ( elem , JSGlobal ) : <EOL> return elem <EOL> traverser . _debug ( "<STR_LIT>" ) <EOL> global_data = dict ( elem . global_data ) <EOL> global_data . update ( overwritable = True , readonly = False ) <EOL> temp = JSGlobal ( global_data , traverser = traverser ) <EOL> temp . data = deepcopy ( elem . data ) if elem . data else { } <EOL> if "<STR_LIT>" in temp . global_data : <EOL> new_temp = temp . global_data [ "<STR_LIT>" ] ( node , args , traverser ) <EOL> if new_temp is not None : <EOL> traverser . _debug ( "<STR_LIT>" ) <EOL> new_temp . TYPEOF = "<STR_LIT:object>" <EOL> return new_temp <EOL> elif "<STR_LIT>" in temp . global_data : <EOL> new_temp = temp . global_data [ "<STR_LIT>" ] ( <EOL> wrapper = node , arguments = args , traverser = traverser ) <EOL> if new_temp is not None : <EOL> return new_temp <EOL> return temp <EOL> def CallExpression ( traverser , node ) : <EOL> args = [ traverser . traverse_node ( a ) for a in node [ "<STR_LIT>" ] ] <EOL> member = traverser . traverse_node ( node [ "<STR_LIT>" ] ) <EOL> if ( node [ "<STR_LIT>" ] [ "<STR_LIT:type>" ] == "<STR_LIT>" and <EOL> node [ "<STR_LIT>" ] [ "<STR_LIT>" ] [ "<STR_LIT:type>" ] == "<STR_LIT>" ) : <EOL> identifier_name = node [ "<STR_LIT>" ] [ "<STR_LIT>" ] [ "<STR_LIT:name>" ] <EOL> if identifier_name in instanceactions . INSTANCE_DEFINITIONS : <EOL> traverser . _debug ( '<STR_LIT>' ) <EOL> result = instanceactions . INSTANCE_DEFINITIONS [ identifier_name ] ( <EOL> args , traverser , <EOL> traverser . traverse_node ( node [ "<STR_LIT>" ] [ "<STR_LIT:object>" ] ) ) <EOL> if result is not None : <EOL> return result <EOL> if isinstance ( member , JSGlobal ) and "<STR_LIT>" in member . global_data : <EOL> traverser . _debug ( "<STR_LIT>" ) <EOL> output = member . global_data [ "<STR_LIT>" ] ( <EOL> wrapper = member , arguments = args , traverser = traverser ) <EOL> if output is not None : <EOL> return output <EOL> return JSObject ( traverser = traverser ) <EOL> def _get_member_exp_property ( traverser , node ) : <EOL> """<STR_LIT>""" <EOL> if node [ "<STR_LIT>" ] [ "<STR_LIT:type>" ] == "<STR_LIT>" and not node [ "<STR_LIT>" ] : <EOL> return unicode ( node [ "<STR_LIT>" ] [ "<STR_LIT:name>" ] ) <EOL> else : <EOL> eval_exp = traverser . traverse_node ( node [ "<STR_LIT>" ] ) <EOL> return utils . get_as_str ( eval_exp . get_literal_value ( traverser ) ) <EOL> def MemberExpression ( traverser , node , instantiate = False ) : <EOL> "<STR_LIT>" <EOL> traverser . _debug ( "<STR_LIT>" % node [ "<STR_LIT:type>" ] ) <EOL> if node [ "<STR_LIT:type>" ] == "<STR_LIT>" : <EOL> base = MemberExpression ( traverser , node [ "<STR_LIT:object>" ] , instantiate ) <EOL> identifier = _get_member_exp_property ( traverser , node ) <EOL> traverser . _debug ( "<STR_LIT>" % identifier ) <EOL> return base . get ( traverser , identifier , instantiate = instantiate ) <EOL> elif node [ "<STR_LIT:type>" ] == "<STR_LIT>" : <EOL> traverser . _debug ( "<STR_LIT>" % node [ "<STR_LIT:name>" ] ) <EOL> if instantiate and not traverser . _is_defined ( node [ "<STR_LIT:name>" ] ) : <EOL> output = JSObject ( traverser = traverser ) <EOL> traverser . contexts [ <NUM_LIT:0> ] . set ( node [ "<STR_LIT:name>" ] , output ) <EOL> else : <EOL> output = traverser . _seek_variable ( node [ "<STR_LIT:name>" ] ) <EOL> return output <EOL> else : <EOL> traverser . _debug ( "<STR_LIT>" ) <EOL> return traverser . traverse_node ( node ) <EOL> def Literal ( traverser , node ) : <EOL> """<STR_LIT>""" <EOL> value = node [ "<STR_LIT:value>" ] <EOL> if isinstance ( value , dict ) : <EOL> return JSObject ( traverser = traverser ) <EOL> return JSLiteral ( value , traverser = traverser ) <EOL> def Identifier ( traverser , node ) : <EOL> "<STR_LIT>" <EOL> return traverser . _seek_variable ( node [ "<STR_LIT:name>" ] ) <EOL> def node ( branches = None , action = None , returns = False ) : <EOL> return branches or ( ) , action , returns <EOL> DEFINITIONS = { <EOL> "<STR_LIT>" : node ( ) , <EOL> "<STR_LIT>" : node ( ) , <EOL> "<STR_LIT>" : node ( branches = ( "<STR_LIT:body>" , ) ) , <EOL> "<STR_LIT>" : node ( branches = ( "<STR_LIT:body>" , ) , action = BlockStatement ) , <EOL> "<STR_LIT>" : node ( branches = ( "<STR_LIT>" , ) , <EOL> action = ExpressionStatement , <EOL> returns = True ) , <EOL> "<STR_LIT>" : node ( branches = ( "<STR_LIT:test>" , "<STR_LIT>" , "<STR_LIT>" ) ) , <EOL> "<STR_LIT>" : node ( branches = ( "<STR_LIT:body>" , ) ) , <EOL> "<STR_LIT>" : node ( ) , <EOL> "<STR_LIT>" : node ( ) , <EOL> "<STR_LIT>" : node ( branches = ( "<STR_LIT:body>" , "<STR_LIT:object>" ) , action = WithStatement ) , <EOL> "<STR_LIT>" : node ( branches = ( "<STR_LIT>" , "<STR_LIT>" ) ) , <EOL> "<STR_LIT>" : node ( branches = ( "<STR_LIT>" , ) ) , <EOL> "<STR_LIT>" : node ( branches = ( "<STR_LIT>" , ) ) , <EOL> "<STR_LIT>" : node ( branches = ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , <EOL> "<STR_LIT>" ) ) , <EOL> "<STR_LIT>" : node ( branches = ( "<STR_LIT:test>" , "<STR_LIT:body>" ) ) , <EOL> "<STR_LIT>" : node ( branches = ( "<STR_LIT:test>" , "<STR_LIT:body>" ) ) , <EOL> "<STR_LIT>" : node ( branches = ( "<STR_LIT>" , "<STR_LIT:test>" , "<STR_LIT>" , "<STR_LIT:body>" ) ) , <EOL> "<STR_LIT>" : node ( branches = ( "<STR_LIT:left>" , "<STR_LIT:right>" , "<STR_LIT:body>" ) ) , <EOL> "<STR_LIT>" : node ( branches = ( "<STR_LIT:left>" , "<STR_LIT:right>" , "<STR_LIT:body>" ) ) , <EOL> "<STR_LIT>" : node ( branches = ( "<STR_LIT:body>" , ) , <EOL> action = FunctionDeclaration ) , <EOL> "<STR_LIT>" : node ( branches = ( "<STR_LIT>" , ) , <EOL> action = VariableDeclaration ) , <EOL> "<STR_LIT>" : node ( action = ThisExpression , returns = True ) , <EOL> "<STR_LIT>" : node ( branches = ( "<STR_LIT>" , ) , action = ArrayExpression , <EOL> returns = True ) , <EOL> "<STR_LIT>" : node ( branches = ( "<STR_LIT>" , ) , <EOL> action = ObjectExpression , returns = True ) , <EOL> "<STR_LIT>" : node ( branches = ( "<STR_LIT:body>" , ) , <EOL> action = FunctionExpression , returns = True ) , <EOL> "<STR_LIT>" : node ( branches = ( "<STR_LIT>" , ) , returns = True ) , <EOL> "<STR_LIT>" : node ( branches = ( "<STR_LIT>" , ) , action = UnaryExpression , <EOL> returns = True ) , <EOL> "<STR_LIT>" : node ( branches = ( "<STR_LIT:left>" , "<STR_LIT:right>" ) , <EOL> action = BinaryExpression , returns = True ) , <EOL> "<STR_LIT>" : node ( branches = ( "<STR_LIT:left>" , "<STR_LIT:right>" ) , <EOL> action = AssignmentExpression , returns = True ) , <EOL> "<STR_LIT>" : node ( branches = ( "<STR_LIT>" , ) , returns = True ) , <EOL> "<STR_LIT>" : node ( branches = ( "<STR_LIT:left>" , "<STR_LIT:right>" ) , returns = True ) , <EOL> "<STR_LIT>" : node ( branches = ( "<STR_LIT:test>" , "<STR_LIT>" , "<STR_LIT>" ) , <EOL> returns = True ) , <EOL> "<STR_LIT>" : node ( branches = ( "<STR_LIT>" , "<STR_LIT>" ) , <EOL> action = NewExpression , returns = True ) , <EOL> "<STR_LIT>" : node ( branches = ( "<STR_LIT>" , "<STR_LIT>" ) , <EOL> action = CallExpression , returns = True ) , <EOL> "<STR_LIT>" : node ( branches = ( "<STR_LIT:object>" , "<STR_LIT>" ) , <EOL> action = MemberExpression , returns = True ) , <EOL> "<STR_LIT>" : node ( branches = ( "<STR_LIT>" ) , returns = True ) , <EOL> "<STR_LIT>" : node ( branches = ( "<STR_LIT:body>" , "<STR_LIT>" ) , returns = True ) , <EOL> "<STR_LIT>" : node ( branches = ( "<STR_LIT:body>" , "<STR_LIT>" ) , returns = True ) , <EOL> "<STR_LIT>" : node ( ) , <EOL> "<STR_LIT>" : node ( ) , <EOL> "<STR_LIT>" : node ( branches = ( "<STR_LIT:test>" , "<STR_LIT>" ) ) , <EOL> "<STR_LIT>" : node ( branches = ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT:body>" ) , returns = True ) , <EOL> "<STR_LIT>" : node ( branches = ( "<STR_LIT:left>" , "<STR_LIT:right>" ) , returns = True ) , <EOL> "<STR_LIT>" : node ( action = Literal , returns = True ) , <EOL> "<STR_LIT>" : node ( action = Identifier , returns = True ) , <EOL> "<STR_LIT>" : node ( returns = True ) , <EOL> "<STR_LIT>" : node ( returns = True ) , <EOL> "<STR_LIT>" : node ( returns = True ) , <EOL> "<STR_LIT>" : node ( returns = True ) , <EOL> "<STR_LIT>" : node ( returns = True ) , <EOL> } </s>
