def put_value(v_completion: Completion, w_completion: Completion) -> Completion: if v_completion.is_abrupt(): return v_completion v = v_completion.value if w_completion.is_abrupt(): return w_completion w = w_completion.value if not isinstance(v, Reference): return ThrowCompletion(value('new ReferenceError')) # FIXME base = get_base(v) if is_unresolvable_reference(v) is Value.true: if is_strict_reference(v) is Value.true: return ThrowCompletion(value('new ReferenceError')) # FIXME # https://tc39.es/ecma262/#sec-putvalue raise NotImplementedError() if is_property_reference(v) is Value.true: if has_primitive_base(v) is Value.true: assert type_of(get_base(v)) not in ('undefined', 'null') # https://tc39.es/ecma262/#sec-putvalue raise NotImplementedError() # https://tc39.es/ecma262/#sec-putvalue raise NotImplementedError() assert isinstance(v, EnvironmentRecord) return base.set_mutable_binding(get_referenced_name(v), w, is_strict_reference(v))
def bind_this_value(self, val: Value) -> 'Completion': assert self.this_binding_status != ThisBindingStatus.LEXICAL if self.this_binding_status == ThisBindingStatus.INITIALIZED: return ThrowCompletion(value('new ReferenceError')) # FIXME self.this_value = val self.this_binding_status = ThisBindingStatus.INITIALIZED return NormalCompletion(val)
def get_binding_value(self, name: Value, strict: Value) -> Completion: assert strict is Value.true assert name in self.bindings or name in self.indirect_bindings if name in self.indirect_bindings: binding = self.indirect_bindings[name] m = binding.module_record n2 = binding.name2 target_env = m.environment if target_env is None: return ThrowCompletion(value('new ReferenceError')) # FIXME target_er = target_env.environment_record return target_er.get_binding_value(n2, Value.true) binding2 = self.bindings[name] if not binding2.initialized: return ThrowCompletion(value('new ReferenceError')) # FIXME return NormalCompletion(binding2.value)
def resolve_binding(name: Value, env: Optional[LexicalEnvironment] = None, strict: bool = False) -> Reference: if not env: assert surrounding_agent is not None env = surrounding_agent.running_execution_context.lexical_environment assert isinstance(env, LexicalEnvironment) ref = get_identifier_reference(env, name, value(strict)) assert isinstance(ref, Reference) return ref
def get_value(v_completion: Completion) -> Completion: if v_completion.is_abrupt(): return v_completion v = v_completion.value if not isinstance(v, Reference): return NormalCompletion(v) base = get_base(v) if is_unresolvable_reference(v) is Value.true: return ThrowCompletion(value('new TypeError')) # FIXME if is_property_reference(v) is Value.true: if has_primitive_base(v) is Value.true: assert type_of(v.base) not in ('null', 'undefined') # https://tc39.es/ecma262/#sec-getvalue raise NotImplementedError() raise NotImplementedError() assert isinstance(base, EnvironmentRecord) return base.get_binding_value(get_referenced_name(v), is_strict_reference(v))
def is_super_reference(ref: Reference) -> Value: return value(isinstance(ref, SuperReference))
def is_unresolvable_reference(ref: Reference) -> Value: return value(ref.base is Value.undefined)
def is_property_reference(ref: Reference) -> Completion: return NormalCompletion( value( type_of(ref.base) == 'object' or has_primitive_base(ref) is Value.true))
def has_primitive_base(ref: Reference) -> Value: return value(isinstance(ref.base, Value) and ref.base.is_primitive())
def get_this_binding(self) -> 'Completion': assert self.this_binding_status != ThisBindingStatus.LEXICAL if self.this_binding_status == ThisBindingStatus.UNINITIALIZED: return ThrowCompletion(value('new ReferenceError')) # FIXME return NormalCompletion(self.this_value)
def has_super_binding(self) -> 'Completion': if self.this_binding_status == ThisBindingStatus.LEXICAL: return NormalCompletion(Value.false) return NormalCompletion(value(self.home_object is not Value.undefined))
def has_this_binding(self) -> Value: return value(self.this_binding_status != ThisBindingStatus.LEXICAL)
def has_var_declaration(self, name: Value) -> Completion: return NormalCompletion(value(name in self.var_names))
def create_immutable_binding(self, name: Value, strict: Value) -> Completion: if self.declarative_record.has_binding(name) is Value.true: return ThrowCompletion(value('new TypeError')) # FIXME return self.declarative_record.create_immutable_binding(name, strict)
def test_value(self): self.assertIs(value(True), Value.true) self.assertIs(value(False), Value.false) self.assertIs(value(None), Value.null) self.assertIs(value(UNDEFINED), Value.undefined) self.assertIs(value(), Value.undefined)