Exemplo n.º 1
0
 internal void SetMember(string identifier, SObject data)
 {
     Members[identifier].Data = data;
 }
Exemplo n.º 2
0
 internal void AddMember(string idenfifier, SObject data)
 {
     Members.Add(idenfifier, new SVariable(idenfifier, data));
 }
Exemplo n.º 3
0
 internal override SObject ExecuteMethod(ScriptProcessor processor, string methodName, SObject caller, SObject This, SObject[] parameters)
 {
     if (Members.ContainsKey(methodName))
     {
         if (Members[methodName].Data.TypeOf() == LiteralTypeFunction)
         {
             return(((SFunction)Members[methodName].Data).Call(processor, caller, this, parameters));
         }
         else
         {
             return(processor.ErrorHandler.ThrowError(ErrorType.TypeError, ErrorHandler.MessageTypeNotAFunction, methodName));
         }
     }
     else if (Prototype != null && Prototype.HasMember(processor, methodName))
     {
         return(Prototype.ExecuteMethod(processor, methodName, caller, This, parameters));
     }
     else if (SuperClass != null)
     {
         return(SuperClass.ExecuteMethod(processor, methodName, caller, This, parameters));
     }
     else
     {
         return(processor.ErrorHandler.ThrowError(ErrorType.TypeError, ErrorHandler.MessageTypeNotAFunction, methodName));
     }
 }
Exemplo n.º 4
0
        internal override void SetMember(ScriptProcessor processor, SObject accessor, bool isIndexer, SObject value)
        {
            if (isIndexer)
            {
                if (Prototype.GetIndexerSetFunction() != IndexerSetFunction)
                {
                    IndexerSetFunction = Prototype.GetIndexerSetFunction();
                }
            }

            if (isIndexer && accessor.TypeOf() == LiteralTypeNumber && IndexerSetFunction != null)
            {
                IndexerSetFunction.Call(processor, this, this, new[] { accessor, value });
            }
            else
            {
                var accessorAsString = accessor as SString;
                var memberName       = accessorAsString != null ? accessorAsString.Value : accessor.ToString(processor).Value;

                if (Members.ContainsKey(PropertySetPrefix + memberName)) // setter property
                {
                    ((SFunction)Members[PropertySetPrefix + memberName].Data).Call(processor, this, this, new[] { value });
                }
                if (Members.ContainsKey(memberName))
                {
                    Members[memberName].Data = value;
                }
                else if (Prototype != null && Prototype.HasMember(processor, memberName) && !Prototype.IsStaticMember(memberName))
                {
                    // This is the case when new members got added to the prototype, and we haven't copied them over to the instance yet.
                    // So we do that now, and then set the value of that member:
                    AddMember(memberName, value);
                }
                else
                {
                    SuperClass?.SetMember(processor, accessor, isIndexer, value);
                }
            }
        }
Exemplo n.º 5
0
        internal override SObject ExecuteMethod(ScriptProcessor processor, string methodName, SObject caller, SObject This, SObject[] parameters)
        {
            if (processor.Context.HasCallback(CallbackType.ExecuteMethod))
            {
                var callback = (DExecuteMethod)processor.Context.GetCallback(CallbackType.ExecuteMethod);
                var task     = Task <SObject> .Factory.StartNew(() => callback(processor, ModuleName, methodName, parameters));

                task.Wait();

                return(task.Result);
            }
            else
            {
                processor.ErrorHandler.ThrowError(ErrorType.ApiError, ErrorHandler.MessageApiNotSupported);
                return(processor.Undefined);
            }
        }
Exemplo n.º 6
0
 internal override void SetMember(ScriptProcessor processor, SObject accessor, bool isIndexer, SObject value)
 {
     if (processor.Context.HasCallback(CallbackType.SetMember))
     {
         var callback = (DSetMember)processor.Context.GetCallback(CallbackType.SetMember);
         var task     = Task.Factory.StartNew(() => callback(processor, ModuleName, accessor, isIndexer, value));
         task.Wait();
     }
     else
     {
         processor.ErrorHandler.ThrowError(ErrorType.ApiError, ErrorHandler.MessageApiNotSupported);
     }
 }