Esempio n. 1
0
        public static Completion ThrowRangeError(string message)
        {
            Completion errorInstance = NewErrorInstance(message, i => i.RangeErrorConstructor);

            if (errorInstance.IsAbrupt())
            {
                return(errorInstance);
            }
            return(Throw(errorInstance.value));
        }
        public Completion CreateGlobalFunctionBinding(string n, IValue v, bool d)
        {
            var existingPropComp = ObjectRecord.BindingObject.GetOwnProperty(n);

            if (existingPropComp.IsAbrupt())
            {
                return(existingPropComp.WithEmptyBool());
            }
            var existingProp = existingPropComp.Other;
            PropertyDescriptor desc;

            if (existingProp == null || existingProp.Configurable.GetValueOrDefault())
            {
                desc = new PropertyDescriptor(v, true, true, d);
            }
            else
            {
                desc = new PropertyDescriptor()
                {
                    Value = v
                }
            };
            Completion comp = ObjectRecord.BindingObject.DefinePropertyOrThrow(n, desc);

            if (comp.IsAbrupt())
            {
                return(comp);
            }
            //TODO mark n as initialized in ObjectRecord
            comp = ObjectRecord.BindingObject.Set(n, v, false);
            if (comp.IsAbrupt())
            {
                return(comp);
            }
            if (!VarNames.Contains(n))
            {
                VarNames.Add(n);
            }
            return(Completion.NormalCompletion());
        }
Esempio n. 3
0
        private Completion InitializeHostDefinedRealm()
        {
            var realm      = JSInterpreter.Realm.CreateRealm();
            var newContext = new ExecutionContext(realm);

            PushExecutionStack(newContext);
            realm.SetRealmGlobalObject(null, null);
            Completion globalObj = realm.SetDefaultGlobalBindings();

            if (globalObj.IsAbrupt())
            {
                return(globalObj);
            }
            // implementation-defined global object properties
            return(Completion.NormalCompletion());
        }