Esempio n. 1
0
        public Completion GetValue()
        {
            if (IsAbrupt())
            {
                return(this);
            }
            if (!(value is ReferenceValue reference))
            {
                return(this);
            }

            var @base = reference.baseValue;

            if (reference.IsUnresolvableReference())
            {
                return(Completion.ThrowReferenceError($"cannot get {reference.referencedName} from unresolvable reference"));
            }
            if (reference.IsPropertyReference())
            {
                if (reference.HasPrimitiveBase())
                {
                    @base = (@base as IValue) !.ToObject().value !;
                }
                var obj = @base as Object;
                return(obj !.InternalGet(reference.referencedName, reference.GetThisValue()));
            }
            if (!(@base is EnvironmentRecord envRec))
            {
                throw new InvalidOperationException("Completion.GetValue: baseValue is not a recognized IReferenceable");
            }
            return(envRec.GetBindingValue(reference.referencedName, reference.strict));
        }
Esempio n. 2
0
 public override Completion GetBindingValue(string name, bool strict)
 {
     if (!bindings.ContainsKey(name))
     {
         throw new InvalidOperationException("Spec 8.1.1.1.6 step 2");
     }
     if (bindings[name].Value == null)
     {
         return(Completion.ThrowReferenceError($"binding {name} does not exist."));
     }
     return(Completion.NormalCompletion(bindings[name].Value));
 }
 public Completion GetThisBinding()
 {
     if (ThisBindingStatus == ThisBindingStatus.Lexical)
     {
         throw new InvalidOperationException("Spec 8.1.1.3.4 step 2");
     }
     if (ThisBindingStatus == ThisBindingStatus.Uninitialized)
     {
         return(Completion.ThrowReferenceError("'this' value is not initialized"));
     }
     return(Completion.NormalCompletion(ThisValue));
 }
 public Completion BindThisValue(IValue value)
 {
     if (ThisBindingStatus == ThisBindingStatus.Lexical)
     {
         throw new InvalidOperationException("FunctionEnvironmentRecord.BindThisValue: ThisBindingStatus must not be Lexical");
     }
     if (ThisBindingStatus == ThisBindingStatus.Initialized)
     {
         return(Completion.ThrowReferenceError("'this' value is already initialized"));
     }
     ThisValue         = value;
     ThisBindingStatus = ThisBindingStatus.Initialized;
     return(Completion.NormalCompletion(value));
 }
Esempio n. 5
0
        public override Completion GetBindingValue(string name, bool strict)
        {
            var valueComp = BindingObject.HasProperty(name);

            if (valueComp.IsAbrupt())
            {
                return(valueComp);
            }
            var value = valueComp.Other;

            if (!value)
            {
                if (!strict)
                {
                    return(Completion.NormalCompletion(UndefinedValue.Instance));
                }
                else
                {
                    return(Completion.ThrowReferenceError($"No value {name} defined."));
                }
            }
            return(BindingObject.Get(name));
        }
Esempio n. 6
0
        public override Completion SetMutableBinding(string name, IValue value, bool strict)
        {
            if (!bindings.ContainsKey(name))
            {
                if (strict)
                {
                    return(Completion.ThrowReferenceError($"binding {name} does not exist."));
                }
                CreateMutableBinding(name, true);
                InitializeBinding(name, value);
                return(Completion.NormalCompletion());
            }
            var binding = bindings[name];

            if (binding.strict.GetValueOrDefault(false))
            {
                strict = true;
            }
            if (binding.Value == null)
            {
                return(Completion.ThrowReferenceError($"{name} has not been initialized yet."));
            }
            else if (binding.mutable)
            {
                binding.Value = value;
            }
            else
            {
                // attempt to change value of immutable binding
                if (strict)
                {
                    return(Completion.ThrowTypeError("attempt to change value of immutable binding"));
                }
            }
            return(Completion.NormalCompletion());
        }