Inheritance: ScriptObject, IEnumerable, IExpando
 internal virtual Object Construct(Object[] args){
   JSObject newob = new JSObject(null, false);
   newob.SetParent(this.GetPrototypeForConstructedObject());
   Object result = this.Call(args, newob);
   if (result is ScriptObject || (this is BuiltinFunction && ((BuiltinFunction)this).method.Name.Equals("CreateInstance")))
     return result;
   return newob;
 }
 internal virtual object Construct(object[] args)
 {
     JSObject thisob = new JSObject(null, false);
     thisob.SetParent(this.GetPrototypeForConstructedObject());
     object obj3 = this.Call(args, thisob);
     if (!(obj3 is ScriptObject) && (!(this is BuiltinFunction) || !((BuiltinFunction) this).method.Name.Equals("CreateInstance")))
     {
         return thisob;
     }
     return obj3;
 }
Exemple #3
0
 internal JSObject(ScriptObject parent, bool checkSubType)
   : base(parent) {
   this.memberCache = null;
   this.isASubClass = false;
   this.subClassIR = null;
   if (checkSubType){
     Type subType = this.GetType();
     Debug.Assert(subType != typeof(BuiltinFunction));
     if (subType != Typeob.JSObject){
       this.isASubClass = true;
       this.subClassIR = TypeReflector.GetTypeReflectorFor(subType);
     }
   }else
     Debug.Assert(this.GetType() == Typeob.JSObject);
   this.noExpando = this.isASubClass;
   this.name_table = null;
   this.field_table = null;
   this.outer_class_instance = null;
 }
Exemple #4
0
        private PayloadObject parseJsonObject(JSObject jsObject)
        {
            PayloadObject payloadObject = new PayloadObject(this);

            FieldInfo[] fields = jsObject.GetFields(BindingFlags.Default);

            for (int i = 0; i < fields.Length; i++)
            {
                JSField field = (JSField)fields[i];
                var value = field.GetValue(field);

                if (value is ArrayObject)
                {
                    PayloadObject payloadNestedParentObject = new PayloadObject(this);
                    payloadNestedParentObject.Name = field.Name;

                    ArrayObject nestedPayloadObjects = (ArrayObject)field.GetValue(field);
                    payloadNestedParentObject.PayloadObjects.AddRange(this.ParseJsonArray(nestedPayloadObjects));

                    foreach (PayloadObject po in payloadNestedParentObject.PayloadObjects)
                    {
                        po.Name = field.Name;
                    }

                    payloadObject.PayloadObjects.Add(payloadNestedParentObject);
                }
                else if (value is JSObject)
                {
                    if (field.Name == "__metadata")
                    {
                        payloadObject.Uri = this.GetArrayString(field, "uri");
                        payloadObject.Type = this.GetArrayString(field, "type");

                        string etag = this.GetArrayString(field, "etag");
                        if (etag != null)
                        {
                            payloadObject.ETag = etag;
                        }
                    }
                    else
                    {
                        JSField firstChild = this.GetArrayField(field, 0);

                        if (firstChild != null && firstChild.Name == v2JsonResultsField)
                        {
                            PayloadObject payloadNestedParentObject = new PayloadObject(this);
                            payloadNestedParentObject.Name = field.Name;

                            ArrayObject nestedPayloadObjects = (ArrayObject)firstChild.GetValue(firstChild);
                            payloadNestedParentObject.PayloadObjects.AddRange(this.ParseJsonArray(nestedPayloadObjects));

                            foreach (PayloadObject po in payloadNestedParentObject.PayloadObjects)
                            {
                                po.Name = field.Name;
                            }

                            payloadObject.PayloadObjects.Add(payloadNestedParentObject);
                        }
                        else if (firstChild != null && firstChild.Name == "__deferred") // Deferred reference/collection
                        {
                            PayloadObject deferredObject = new PayloadObject(this);
                            deferredObject.Name = field.Name;
                            deferredObject.Uri = this.GetArrayString(firstChild, "uri");
                            deferredObject.Deferred = true;

                            payloadObject.PayloadObjects.Add(deferredObject);
                        }
                        else if (firstChild != null && firstChild.Name == "__mediaresource")
                        {
                            PayloadNamedStream stream = new PayloadNamedStream();
                            stream.Name = field.Name;
                            stream.ContentType = this.GetArrayString(firstChild, "content-type");
                            stream.EditLink = this.GetArrayString(firstChild, "edit_media");
                            stream.SelfLink = this.GetArrayString(firstChild, "media_src");
                            stream.ETag = this.GetArrayString(firstChild, "etag");
                            payloadObject.NamedStreams.Add(stream);
                        }
                        else
                        {
                            JSObject objectValue = (JSObject)field.GetValue(field);
                            var objectValueFields = objectValue.GetFields(BindingFlags.Default);
                            if (objectValueFields.Any(f => f.Name == "__metadata" && GetArrayString((JSField)f, "uri") != null))
                            {
                                PayloadObject referencePayloadObject = parseJsonObject(objectValue);
                                referencePayloadObject.Name = field.Name;
                                referencePayloadObject.Reference = true;

                                payloadObject.PayloadObjects.Add(referencePayloadObject);
                            }
                            else
                            {
                                PayloadComplexProperty payloadProperty = this.parseComplexObject(payloadObject, field);    // Complex object
                                payloadObject.PayloadProperties.Add(payloadProperty);
                            }
                        }
                    }
                }
                else
                {
                    PayloadProperty payloadProperty = this.parseSimpleObject(payloadObject, field);
                    payloadObject.PayloadProperties.Add(payloadProperty);
                }
            }

            return payloadObject;
        }
Exemple #5
0
 private List<PayloadObject> ParseSingleJsonObject(JSObject jsonData)
 {
     List<PayloadObject> payloadObjects = new List<PayloadObject>();
     payloadObjects.Add(this.parseJsonObject(jsonData));
     return payloadObjects;
 }
	public override Object Eval(VsaEngine engine)
#line 62 "./Nodes/JExpr.tc"
	{
		// Create a new instance of "Object".
		JSObject value = new JSObject(EngineInstance.GetEngineInstance(engine)
											.GetObjectPrototype());
	
		// Evaluate and add the properties.
		JExprListElem elem = first;
		while(elem != null)
		{
			value.Put(Convert.ToString(elem.name), elem.expr.Eval(engine));
			elem = elem.next;
		}
	
		// Return the object to the caller.
		return value;
	}
 internal object Construct(JSObject thisob, object[] args)
 {
     JSObject obj2 = new JSObject(null, false);
     obj2.SetParent(base.GetPrototypeForConstructedObject());
     obj2.outer_class_instance = thisob;
     object obj3 = this.Call(args, obj2);
     if (obj3 is ScriptObject)
     {
         return obj3;
     }
     return obj2;
 }
	// Perform a constructor call on this object.
	internal virtual Object Construct(VsaEngine engine, Object[] args)
			{
				JSObject obj = new JSObject(GetPrototypeForConstructedObject());
				Object result = Call(engine, obj, args);
				if(result is ScriptObject)
				{
					return result;
				}
				else
				{
					return obj;
				}
			}
Exemple #9
0
 internal Object Construct(JSObject thisob, Object[] args){
   JSObject newob = new JSObject(null, false);
   newob.SetParent(this.GetPrototypeForConstructedObject());
   newob.outer_class_instance = thisob;
   Object result = this.Call(args, newob);
   if (result is ScriptObject) return result;
   return newob;
 }
 internal static object smartToString(JSObject thisObj)
 {
     JSObject obj = (JSObject) thisObj;
     object val = obj.GetDefaultValue (typeof (string), true);
     if (val == thisObj)
         return toString (thisObj);
     else
         return Convert.ToString (val);
 }
		// Constructor.
		public PropertyEnumerator(JSObject obj)
				{
					this.obj = obj;
					this.prop = obj.properties;
					this.current = null;
				}
	// Constructor.
	internal GlobalObject(VsaEngine engine)
			{
				// Record the engine for later.
				this.engine = engine;

				// Create the actual storage value, with no prototype.
				globalObject = new JSObject(null, engine);

				// Get the instance object for the engine.
				EngineInstance inst = EngineInstance.GetEngineInstance(engine);

				// Add all of the properties to the global object.
				AddBuiltin(inst, "CollectGarbage");
				AddBuiltin(inst, "decodeURI");
				AddBuiltin(inst, "decodeURIComponent");
				AddBuiltin(inst, "encodeURI");
				AddBuiltin(inst, "encodeURIComponent");
				AddBuiltin(inst, "escape");
				AddBuiltin(inst, "eval");
				AddBuiltin(inst, "GetObject");
				AddBuiltin(inst, "isFinite");
				AddBuiltin(inst, "isNaN");
				AddBuiltin(inst, "parseFloat");
				AddBuiltin(inst, "parseInt");
				AddBuiltin(inst, "ScriptEngine");
				AddBuiltin(inst, "ScriptEngineBuildVersion");
				AddBuiltin(inst, "ScriptEngineMajorVersion");
				AddBuiltin(inst, "ScriptEngineMinorVersion");
				AddBuiltin(inst, "unescape");
				globalObject.Put("Infinity", Double.PositiveInfinity,
								 PropertyAttributes.DontEnum |
								 PropertyAttributes.DontDelete);
				globalObject.Put("NaN", Double.NaN,
								 PropertyAttributes.DontEnum |
								 PropertyAttributes.DontDelete);
				globalObject.Put("undefined", null,
								 PropertyAttributes.DontEnum |
								 PropertyAttributes.DontDelete);
#if false
				AddProperty("ActiveXObject", ActiveXObject);
#endif
				AddProperty("Array", Array);
#if false
				AddProperty("Boolean", Boolean);
				AddProperty("Date", Date);
				AddProperty("Enumerator", Enumerator);
				AddProperty("Error", Error);
				AddProperty("EvalError", EvalError);
#endif
				AddProperty("Function", Function);
				AddProperty("Math", Math);
				AddProperty("Number", Number);
				AddProperty("Object", Object);
#if false
				AddProperty("RangeError", RangeError);
				AddProperty("ReferenceError", ReferenceError);
				AddProperty("RegExp", RegExp);
#endif
				AddProperty("String", String);
#if false
				AddProperty("SyntaxError", SyntaxError);
				AddProperty("TypeError", TypeError);
				AddProperty("URIError", URIError);
				AddProperty("VBArray", VBArray);
#endif
			}