def test_get_identifier_reference(self):
        lex_env = DeclarativeEnvironment()

        env_rec = lex_env.environment_record
        env_rec.create_mutuable_binding(u'foo', True)

        ref = lex_env.get_identifier_reference(u'foo')
        assert ref.base_env == env_rec
        assert ref.referenced == 'foo'
    def test_get_identifier_reference_from_parent(self):
        outer_lex_env = DeclarativeEnvironment()
        outer_env_rec = outer_lex_env.environment_record
        outer_env_rec.create_mutuable_binding(u'foo', True)

        lex_env = DeclarativeEnvironment(outer_lex_env)

        ref = lex_env.get_identifier_reference(u'foo')
        assert ref.base_env == outer_env_rec
        assert ref.referenced == 'foo'
Exemplo n.º 3
0
    def __init__(self, code, formal_parameters=[], argv=[], this=newundefined(), strict=False, scope=None, w_func=None):
        from js.jsobj import W_BasicObject
        from js.object_space import object_space, isnull_or_undefined

        stack_size = code.estimated_stack_size()
        env_size = code.env_size() + 1  # neet do add one for the arguments object

        ExecutionContext.__init__(self, stack_size, env_size)

        self._code_ = code
        self._argument_values_ = argv
        self._strict_ = strict
        self._scope_ = scope
        self._w_func_ = w_func
        self._calling_context_ = None

        from js.lexical_environment import DeclarativeEnvironment
        localEnv = DeclarativeEnvironment(scope, env_size, False)
        self._lexical_environment_ = localEnv
        self._variable_environment_ = localEnv

        if strict:
            self._this_binding_ = this
        else:
            if this is None or isnull_or_undefined(this):
                self._this_binding_ = object_space.global_object
            else:
                assert isinstance(this, W_BasicObject)

                if this.klass() is not 'Object':
                    self._this_binding_ = this.ToObject()
                else:
                    self._this_binding_ = this

        self.declaration_binding_initialization()
Exemplo n.º 4
0
    def test_foo7(self):
        symbol_map = SymbolMap()
        var_idx_a = symbol_map.add_variable(u'a')
        var_idx_b = symbol_map.add_symbol(u'b')

        code = JsCode(symbol_map)
        code.emit('LOAD_VARIABLE', var_idx_a, u'a')
        code.emit('LOAD_VARIABLE', var_idx_b, u'b')
        code.emit('ADD')
        code.emit('STORE', var_idx_b, u'b')
        code.emit('RETURN')

        outer_env = DeclarativeEnvironment()
        outer_env_rec = outer_env.environment_record

        f = JsFunction(u'foo', code)

        ctx = FunctionExecutionContext(f, scope=outer_env)

        lex_env = ctx.variable_environment()
        env_rec = lex_env.environment_record

        env_rec.set_mutable_binding(u'a', _w(21), False)

        outer_env_rec.create_mutuable_binding(u'b', True)
        outer_env_rec.set_mutable_binding(u'b', _w(21), False)

        res = f.run(ctx)

        assert env_rec.get_binding_value(u'a') == _w(21)
        assert outer_env_rec.get_binding_value(u'b') == _w(42)
        assert res.value == _w(42)
    def test_get_identifier_reference_overwrite_parent(self):
        outer_lex_env = DeclarativeEnvironment()
        outer_env_rec = outer_lex_env.environment_record
        outer_env_rec.create_mutuable_binding(u'foo', True)

        obj = W_BasicObject()
        lex_env = ObjectEnvironment(obj, outer_lex_env)
        env_rec = lex_env.environment_record
        env_rec.create_mutuable_binding(u'foo', True)

        ref = lex_env.get_identifier_reference(u'foo')
        assert ref.base_env == env_rec
        assert ref.referenced == u'foo'
Exemplo n.º 6
0
    def __init__(self, code, calling_context=None):
        stack_size = code.estimated_stack_size()

        _DynamicExecutionContext.__init__(self, stack_size)
        self._code_ = code
        self._strict_ = code.strict

        if not calling_context:
            raise NotImplementedError()
        else:
            self._this_binding_ = calling_context.this_binding()
            self._variable_environment_ = calling_context.variable_environment()
            self._lexical_environment_ = calling_context.lexical_environment()
        if self._strict_:
            from js.lexical_environment import DeclarativeEnvironment
            strict_var_env = DeclarativeEnvironment(self._lexical_environment_)
            self._variable_environment_ = strict_var_env
            self._lexical_environment_ = strict_var_env

        self.declaration_binding_initialization()
Exemplo n.º 7
0
    def __init__(self, code, catchparam, exception_value, parent_context):
        self._code_ = code
        self._strict_ = code.strict
        self._parent_context_ = parent_context

        stack_size = code.estimated_stack_size()
        #env_size = code.env_size() + 1  # neet do add one for the arguments object

        _DynamicExecutionContext.__init__(self, stack_size)

        parent_env = parent_context.lexical_environment()

        from js.lexical_environment import DeclarativeEnvironment
        local_env = DeclarativeEnvironment(parent_env)
        local_env_rec = local_env.environment_record
        local_env_rec.create_mutuable_binding(catchparam, True)
        local_env_rec.set_mutable_binding(catchparam, exception_value, False)

        self._lexical_environment_ = local_env
        self._variable_environment_ = local_env

        self.declaration_binding_initialization()
    def test_get_identifier_reference_empty(self):
        lex_env = DeclarativeEnvironment()
        ref = lex_env.get_identifier_reference(u'foo')

        assert ref.base_value is None
        assert ref.referenced == u'foo'