Пример #1
0
 public BlockScope(ScriptObject parent, String name, int scopeId)
   : base(parent){
   this.scopeId = scopeId;
   JSField field = (JSField)this.parent.GetField(name+":"+this.scopeId, BindingFlags.Public);
   this.name_table[name] = field;
   this.field_table.Add(field);
 }
Пример #2
0
 internal NumberObject(ScriptObject parent, Object value, bool implicitWrapper)
   : base(parent, Typeob.NumberObject) {
   this.baseType = value.GetType();
   this.value = value;
   this.noExpando = implicitWrapper;
   this.implicitWrapper = implicitWrapper;
 }
 public Closure(FunctionObject func) : this(func, null)
 {
     if (func.enclosing_scope is Microsoft.JScript.StackFrame)
     {
         this.enclosing_scope = func.enclosing_scope;
     }
 }
 internal LenientErrorPrototype(LenientFunctionPrototype funcprot, ScriptObject parent, string name) : base(parent, name)
 {
     base.noExpando = false;
     this.name = name;
     Type type = typeof(ErrorPrototype);
     this.toString = new BuiltinFunction("toString", this, type.GetMethod("toString"), funcprot);
 }
Пример #5
0
 internal ArrayObject(ScriptObject prototype, Type subType)
   : base(prototype, subType) {
   this.len = 0;
   this.denseArray = null;
   this.denseArrayLength = 0;
   this.noExpando = false;
 }
 private void AddNameTo(ScriptObject enclosingScope)
 {
     while (enclosingScope is WithObject)
     {
         enclosingScope = enclosingScope.GetParent();
     }
     if (((IActivationObject) enclosingScope).GetLocalField(this.name) == null)
     {
         FieldInfo info;
         if (enclosingScope is ActivationObject)
         {
             if (enclosingScope is FunctionScope)
             {
                 info = ((ActivationObject) enclosingScope).AddNewField(this.name, null, FieldAttributes.Public);
             }
             else
             {
                 info = ((ActivationObject) enclosingScope).AddNewField(this.name, null, FieldAttributes.Static | FieldAttributes.Public);
             }
         }
         else
         {
             info = ((StackFrame) enclosingScope).AddNewField(this.name, null, FieldAttributes.Public);
         }
         JSLocalField field = info as JSLocalField;
         if (field != null)
         {
             field.debugOn = base.context.document.debugOn;
             field.isDefined = true;
         }
         this.field = (JSVariableField) info;
     }
 }
Пример #7
0
 protected NumberObject(ScriptObject parent, Object value)
   : base(parent) {
   this.baseType = value.GetType();
   this.value = value;
   this.noExpando = false;
   this.implicitWrapper = false;
 }
 internal FunctionScope(ScriptObject parent, bool isMethod) : base(parent)
 {
     base.isKnownAtCompileTime = true;
     this.isMethod = isMethod;
     this.mustSaveStackLocals = false;
     if ((parent != null) && (parent is ActivationObject))
     {
         base.fast = ((ActivationObject) parent).fast;
     }
     else
     {
         base.fast = false;
     }
     this.returnVar = null;
     this.owner = null;
     this.isStatic = false;
     this.nested_functions = null;
     this.fields_for_nested_functions = null;
     if (parent is FunctionScope)
     {
         this.ProvidesOuterScopeLocals = new SimpleHashtable(0x10);
     }
     else
     {
         this.ProvidesOuterScopeLocals = null;
     }
     this.closuresMightEscape = false;
 }
Пример #9
0
 internal DateObject(ScriptObject parent, double value)
   : base(parent) {
   this.value = value != value || value > Int64.MaxValue || value < Int64.MinValue
     ? Double.NaN
     : System.Math.Round(value);
   this.noExpando = false;
 }
 internal NumberObject(ScriptObject parent, object value, bool implicitWrapper) : base(parent, typeof(NumberObject))
 {
     this.baseType = Globals.TypeRefs.ToReferenceContext(value.GetType());
     this.value = value;
     base.noExpando = implicitWrapper;
     this.implicitWrapper = implicitWrapper;
 }
 protected NumberObject(ScriptObject parent, object value) : base(parent)
 {
     this.baseType = Globals.TypeRefs.ToReferenceContext(value.GetType());
     this.value = value;
     base.noExpando = false;
     this.implicitWrapper = false;
 }
 internal FunctionObject(string name, ParameterDeclaration[] parameter_declarations, TypeExpression return_type_expr, Block body, FunctionScope own_scope, ScriptObject enclosing_scope, Context funcContext, MethodAttributes attributes, CustomAttributeList customAttributes, bool isMethod) : base(body.Globals.globalObject.originalFunction.originalPrototype, name, parameter_declarations.Length)
 {
     this.parameter_declarations = parameter_declarations;
     int length = parameter_declarations.Length;
     this.formal_parameters = new string[length];
     for (int i = 0; i < length; i++)
     {
         this.formal_parameters[i] = parameter_declarations[i].identifier;
     }
     this.argumentsSlotNumber = 0;
     this.return_type_expr = return_type_expr;
     if (this.return_type_expr != null)
     {
         own_scope.AddReturnValueField();
     }
     this.body = body;
     this.method = null;
     this.parameterInfos = null;
     this.funcContext = funcContext;
     this.own_scope = own_scope;
     this.own_scope.owner = this;
     if ((!(enclosing_scope is ActivationObject) || !((ActivationObject) enclosing_scope).fast) && !isMethod)
     {
         this.argumentsSlotNumber = this.own_scope.GetNextSlotNumber();
         JSLocalField field = (JSLocalField) this.own_scope.AddNewField("arguments", null, FieldAttributes.PrivateScope);
         field.type = new TypeExpression(new ConstantWrapper(Typeob.Object, funcContext));
         field.isDefined = true;
         this.hasArgumentsObject = true;
     }
     else
     {
         this.hasArgumentsObject = false;
     }
     this.implementedIface = null;
     this.implementedIfaceMethod = null;
     this.isMethod = isMethod;
     this.isExpandoMethod = (customAttributes != null) && customAttributes.ContainsExpandoAttribute();
     this.isStatic = this.own_scope.isStatic = (attributes & MethodAttributes.Static) != MethodAttributes.PrivateScope;
     this.suppressIL = false;
     this.noVersionSafeAttributeSpecified = true;
     this.fields = this.own_scope.GetLocalFields();
     this.enclosing_scope = enclosing_scope;
     this.must_save_stack_locals = false;
     this.text = null;
     this.mb = null;
     this.cb = null;
     this.attributes = attributes;
     if (!this.isStatic)
     {
         this.attributes |= MethodAttributes.HideBySig;
     }
     this.globals = body.Globals;
     this.superConstructor = null;
     this.superConstructorCall = null;
     this.customAttributes = customAttributes;
     base.noExpando = false;
     this.clsCompliance = CLSComplianceSpec.NotAttributed;
     this.engineLocal = null;
     this.partiallyEvaluated = false;
 }
 internal FunctionObject(Type t, string name, string method_name, string[] formal_parameters, JSLocalField[] fields, bool must_save_stack_locals, bool hasArgumentsObject, string text, VsaEngine engine) : base(engine.Globals.globalObject.originalFunction.originalPrototype, name, formal_parameters.Length)
 {
     base.engine = engine;
     this.formal_parameters = formal_parameters;
     this.argumentsSlotNumber = 0;
     this.body = null;
     this.method = TypeReflector.GetTypeReflectorFor(Globals.TypeRefs.ToReferenceContext(t)).GetMethod(method_name, BindingFlags.Public | BindingFlags.Static);
     this.parameterInfos = this.method.GetParameters();
     if (!Microsoft.JScript.CustomAttribute.IsDefined(this.method, typeof(JSFunctionAttribute), false))
     {
         this.isMethod = true;
     }
     else
     {
         JSFunctionAttributeEnum attributeValue = ((JSFunctionAttribute) Microsoft.JScript.CustomAttribute.GetCustomAttributes(this.method, typeof(JSFunctionAttribute), false)[0]).attributeValue;
         this.isExpandoMethod = (attributeValue & JSFunctionAttributeEnum.IsExpandoMethod) != JSFunctionAttributeEnum.None;
     }
     this.funcContext = null;
     this.own_scope = null;
     this.fields = fields;
     this.must_save_stack_locals = must_save_stack_locals;
     this.hasArgumentsObject = hasArgumentsObject;
     this.text = text;
     this.attributes = MethodAttributes.Public;
     this.globals = engine.Globals;
     this.superConstructor = null;
     this.superConstructorCall = null;
     this.enclosing_scope = this.globals.ScopeStack.Peek();
     base.noExpando = false;
     this.clsCompliance = CLSComplianceSpec.NotAttributed;
 }
Пример #14
0
 public PackageScope(ScriptObject parent)
   : base(parent) {
   this.fast = true;
   this.name = null;
   this.owner = null;
   this.isKnownAtCompileTime = true;
 }
Пример #15
0
 internal BlockScope(ScriptObject parent)
   : base(parent){
   this.scopeId = BlockScope.counter++;
   this.isKnownAtCompileTime = true;
   this.fast = parent is ActivationObject ? ((ActivationObject)parent).fast : true;
   this.localFieldsForDebugInfo = new ArrayList();
 }
	// Constructor.
	public BuiltinFunction(ScriptObject prototype, String name,
						   MethodInfo method)
			: base(prototype, name)
			{
				this.method = method;
				Object[] attrs = method.GetCustomAttributes
						(typeof(JSFunctionAttribute), false);
				if(attrs == null || attrs.Length == 0)
				{
					this.flags = (JSFunctionAttributeEnum)0;
				}
				else
				{
					this.flags = ((JSFunctionAttribute)(attrs[0]))
							.GetAttributeValue();
				}
				requiredParameters = method.GetParameters().Length;
				lengthValue = requiredParameters;
				if((flags & JSFunctionAttributeEnum.HasThisObject) != 0)
				{
					--lengthValue;
				}
				if((flags & JSFunctionAttributeEnum.HasEngine) != 0)
				{
					--lengthValue;
				}
				if((flags & JSFunctionAttributeEnum.HasVarArgs) != 0)
				{
					--lengthValue;
				}
			}
	// Constructor.
	internal FunctionObject(FunctionPrototype parent, JFunction defn,
							ScriptObject declaringScope)
			: base(parent, defn.name, Support.ExprListLength(defn.fparams))
			{
				this.defn = defn;
				this.declaringScope = declaringScope;
			}
 internal LenientErrorPrototype(LenientFunctionPrototype funcprot, ScriptObject parent, String name)
   : base(parent, name) {
   this.noExpando = false;
   //this.constructor is given a value by the constructor class
   this.name = name;
   Type super = typeof(ErrorPrototype);
   this.toString = new BuiltinFunction("toString", this, super.GetMethod("toString"), funcprot);
 }
Пример #19
0
      public VsaEngine engine; //This is only really useful for ScriptFunctions, IActivation objects and prototype objects. It lives here for the sake of simplicity.
      //Prototype objects do not need the scope stack, so in fast mode, all prototype objects can share a common engine.

      internal ScriptObject(ScriptObject parent){
        this.parent = parent;
        this.wrappedMemberCache = null;
        if (this.parent != null)
          this.engine = parent.engine;
        else
          this.engine = null;
      }
Пример #20
0
 internal WithObject(ScriptObject parent, Object contained_object, bool isSuperType)
   : base(parent) {
   this.contained_object = contained_object;
   this.isKnownAtCompileTime = contained_object is Type ||
                              (contained_object is ClassScope && ((ClassScope)contained_object).noExpando) ||
                              (contained_object is JSObject && ((JSObject)contained_object).noExpando);
   this.isSuperType = isSuperType;
 }
Пример #21
0
 internal VsaNamedItemScope(Object hostObject, ScriptObject parent, VsaEngine engine)
   : base(parent){
   this.namedItem = hostObject;
   if ((this.reflectObj = hostObject as IReflect) == null)
     this.reflectObj = hostObject.GetType();
   this.recursive = false;
   this.engine = engine;
 }
 internal LenientFunctionPrototype(ScriptObject parent) : base(parent)
 {
     base.noExpando = false;
     Type type = typeof(FunctionPrototype);
     this.apply = new BuiltinFunction("apply", this, type.GetMethod("apply"), this);
     this.call = new BuiltinFunction("call", this, type.GetMethod("call"), this);
     this.toString = new BuiltinFunction("toString", this, type.GetMethod("toString"), this);
 }
 internal LenientFunctionPrototype(ScriptObject parent)
   : base(parent) {
   this.noExpando = false;
   //this.constructor is given a value by ObjectConstructor
   Type super = typeof(FunctionPrototype);
   this.apply = new BuiltinFunction("apply", this, super.GetMethod("apply"), this);
   this.call = new BuiltinFunction("call", this, super.GetMethod("call"), this);
   this.toString = new BuiltinFunction("toString", this, super.GetMethod("toString"), this);
 }
 internal ArgumentsObject(ScriptObject parent, Object[] arguments, FunctionObject function, Closure callee, ScriptObject scope, ArgumentsObject caller)
   : base(parent) {
   this.arguments = arguments;
   this.formal_names = function.formal_parameters;
   this.scope = scope;
   this.callee = callee;
   this.caller = caller;
   this.length = arguments.Length;
   this.noExpando = false;
 }
 internal VsaNamedItemScope(object hostObject, ScriptObject parent, VsaEngine engine) : base(parent)
 {
     this.namedItem = hostObject;
     this.reflectObj = hostObject as IReflect;
     if (this.reflectObj == null)
     {
         this.reflectObj = Globals.TypeRefs.ToReferenceContext(hostObject.GetType());
     }
     this.recursive = false;
     base.engine = engine;
 }
Пример #26
0
 internal ArrayWrapper(ScriptObject prototype, Array value, bool implicitWrapper)
   : base(prototype, typeof(ArrayWrapper)) {
   this.value = value;
   this.implicitWrapper = implicitWrapper;
   if (value != null){
     if (value.Rank != 1)
       throw new JScriptException(JSError.TypeMismatch);
     this.len = (uint) value.Length;
   }else
     this.len = 0;
 }
Пример #27
0
 static internal ClassScope ScopeOfClassMemberInitializer(ScriptObject scope) {
   while (scope != null) {
     if (scope is FunctionScope)
       return null;
     ClassScope cscope = scope as ClassScope;
     if (cscope != null)
       return cscope;
     scope = scope.GetParent();
   }
   return null;
 }
Пример #28
0
	// Constructor.
	internal ScriptObject(ScriptObject parent)
			{
				this.parent = parent;
				if(parent != null)
				{
					this.engine = parent.engine;
				}
				else
				{
					this.engine = null;
				}
			}
Пример #29
0
 internal JSObject(ScriptObject parent, Type subType)
   : base(parent) {
   this.memberCache = null;
   this.isASubClass = false;
   this.subClassIR = null;
   Debug.Assert(subType == this.GetType() || this.GetType() == typeof(BuiltinFunction));
   if (subType != Typeob.JSObject){
     this.isASubClass = true;
     this.subClassIR = TypeReflector.GetTypeReflectorFor(subType);
   }
   this.noExpando = this.isASubClass;
   this.name_table = null;
   this.field_table = null;
 }
Пример #30
0
 internal StackFrame(ScriptObject parent, JSLocalField[] fields, Object[] local_vars, Object thisObject)
   : base(parent) {
   this.caller_arguments = null;
   this.fields = fields;
   this.localVars = local_vars;
   this.nestedFunctionScope = null;
   this.thisObject = thisObject;
   if (parent is StackFrame)
     this.closureInstance = ((StackFrame)parent).closureInstance;
   else if (parent is JSObject)
     this.closureInstance = parent;
   else
     this.closureInstance = null;
 }
Пример #31
0
 private void TranslateToILObjectForMember(ILGenerator il, Type obType, bool noValue, MemberInfo mem)
 {
     this.thereIsAnObjectOnTheStack = true;
     if (mem is IWrappedMember)
     {
         object wrappedObject = ((IWrappedMember)mem).GetWrappedObject();
         if (wrappedObject is LenientGlobalObject)
         {
             base.EmitILToLoadEngine(il);
             il.Emit(OpCodes.Call, CompilerGlobals.getLenientGlobalObjectMethod);
         }
         else if ((wrappedObject is Type) || (wrappedObject is ClassScope))
         {
             if (obType.IsAssignableFrom(Typeob.Type))
             {
                 new ConstantWrapper(wrappedObject, null).TranslateToIL(il, Typeob.Type);
             }
             else
             {
                 ScriptObject parent = base.Globals.ScopeStack.Peek();
                 while ((parent is WithObject) || (parent is BlockScope))
                 {
                     parent = parent.GetParent();
                 }
                 if (parent is FunctionScope)
                 {
                     if (((FunctionScope)parent).owner.isMethod)
                     {
                         il.Emit(OpCodes.Ldarg_0);
                     }
                     else
                     {
                         base.EmitILToLoadEngine(il);
                         il.Emit(OpCodes.Call, CompilerGlobals.scriptObjectStackTopMethod);
                         parent = base.Globals.ScopeStack.Peek();
                         while ((parent is WithObject) || (parent is BlockScope))
                         {
                             il.Emit(OpCodes.Call, CompilerGlobals.getParentMethod);
                             parent = parent.GetParent();
                         }
                         il.Emit(OpCodes.Castclass, Typeob.StackFrame);
                         il.Emit(OpCodes.Ldfld, CompilerGlobals.closureInstanceField);
                     }
                 }
                 else if (parent is ClassScope)
                 {
                     il.Emit(OpCodes.Ldarg_0);
                 }
                 for (parent = base.Globals.ScopeStack.Peek(); parent != null; parent = parent.GetParent())
                 {
                     ClassScope scope = parent as ClassScope;
                     if (scope != null)
                     {
                         if (scope.IsSameOrDerivedFrom(obType))
                         {
                             return;
                         }
                         il.Emit(OpCodes.Ldfld, scope.outerClassField);
                     }
                 }
             }
         }
         else
         {
             this.TranslateToILDefaultThisObject(il, this.lexLevel);
             Microsoft.JScript.Convert.Emit(this, il, Typeob.Object, obType);
         }
     }
     else
     {
         ScriptObject obj5 = base.Globals.ScopeStack.Peek();
         while ((obj5 is WithObject) || (obj5 is BlockScope))
         {
             obj5 = obj5.GetParent();
         }
         if (!(obj5 is FunctionScope) || ((FunctionScope)obj5).owner.isMethod)
         {
             il.Emit(OpCodes.Ldarg_0);
             while (obj5 != null)
             {
                 if (obj5 is ClassScope)
                 {
                     ClassScope scope3 = (ClassScope)obj5;
                     if (scope3.IsSameOrDerivedFrom(obType))
                     {
                         return;
                     }
                     il.Emit(OpCodes.Ldfld, scope3.outerClassField);
                 }
                 obj5 = obj5.GetParent();
             }
         }
         else
         {
             base.EmitILToLoadEngine(il);
             il.Emit(OpCodes.Call, CompilerGlobals.scriptObjectStackTopMethod);
             obj5 = base.Globals.ScopeStack.Peek();
             while ((obj5 is WithObject) || (obj5 is BlockScope))
             {
                 il.Emit(OpCodes.Call, CompilerGlobals.getParentMethod);
                 obj5 = obj5.GetParent();
             }
             il.Emit(OpCodes.Castclass, Typeob.StackFrame);
             il.Emit(OpCodes.Ldfld, CompilerGlobals.closureInstanceField);
             while (obj5 != null)
             {
                 if (obj5 is ClassScope)
                 {
                     ClassScope scope2 = (ClassScope)obj5;
                     if (scope2.IsSameOrDerivedFrom(obType))
                     {
                         break;
                     }
                     il.Emit(OpCodes.Castclass, scope2.GetTypeBuilder());
                     il.Emit(OpCodes.Ldfld, scope2.outerClassField);
                 }
                 obj5 = obj5.GetParent();
             }
             il.Emit(OpCodes.Castclass, obType);
         }
     }
 }
 private MemberInfo[] GetMember(String name, BindingFlags bindingAttr, bool calledFromParent)
 {
     if (this.recursive)
     {
         return(new MemberInfo[0]);
     }
     MemberInfo[] result = null;
     if (!this.isComponentScope)
     {
         //Look for an expando
         MemberInfo[] members = base.GetMember(name, bindingAttr | BindingFlags.DeclaredOnly);
         if (members.Length > 0)
         {
             return(members);
         }
         if (this.componentScopes != null)
         {
             for (int i = 0, n = this.componentScopes.Count; i < n; i++)
             {
                 GlobalScope sc = (GlobalScope)this.componentScopes[i];
                 result = sc.GetMember(name, bindingAttr | BindingFlags.DeclaredOnly, true);
                 if (result.Length > 0)
                 {
                     return(result);
                 }
             }
         }
         if (this.globalObject != null)
         {
             result = this.globalObjectTR.GetMember(name, bindingAttr & ~BindingFlags.NonPublic | BindingFlags.Static);
         }
         if (result != null && result.Length > 0)
         {
             return(ScriptObject.WrapMembers(result, this.globalObject));
         }
     }
     else
     {
         //Look for global variables represented as static fields on subclass of GlobalScope. I.e. the script block case.
         result = this.typeReflector.GetMember(name, bindingAttr & ~BindingFlags.NonPublic | BindingFlags.Static);
         int n = result.Length;
         if (n > 0)
         {
             int          toBeHidden = 0;
             MemberInfo[] newResult  = new MemberInfo[n];
             for (int i = 0; i < n; i++)
             {
                 MemberInfo mem = newResult[i] = result[i];
                 if (mem.DeclaringType.IsAssignableFrom(Typeob.GlobalScope))
                 {
                     newResult[i] = null; toBeHidden++;
                 }
                 else if (mem is FieldInfo)
                 {
                     FieldInfo field = (FieldInfo)mem;
                     if (field.IsStatic && field.FieldType == Typeob.Type)
                     {
                         Type t = (Type)field.GetValue(null);
                         if (t != null)
                         {
                             newResult[i] = t;
                         }
                     }
                 }
             }
             if (toBeHidden == 0)
             {
                 return(result);
             }
             if (toBeHidden == n)
             {
                 return(new MemberInfo[0]);
             }
             MemberInfo[] remainingMembers = new MemberInfo[n - toBeHidden];
             int          j = 0;
             foreach (MemberInfo mem in newResult)
             {
                 if (mem != null)
                 {
                     remainingMembers[j++] = mem;
                 }
             }
             return(remainingMembers);
         }
     }
     if (this.parent != null && !calledFromParent && ((bindingAttr & BindingFlags.DeclaredOnly) == 0 || this.isComponentScope))
     {
         this.recursive = true;
         try{
             result = ((ScriptObject)this.parent).GetMember(name, bindingAttr);
         }finally{
             this.recursive = false;
         }
         if (result != null && result.Length > 0)
         {
             return(result);
         }
     }
     return(new MemberInfo[0]);
 }
Пример #33
0
        // internal constructor
        internal MathObject(ScriptObject parent)
            : base(parent)
        {
            EngineInstance inst = EngineInstance.GetEngineInstance(engine);

            Put("E", E,
                PropertyAttributes.DontEnum |
                PropertyAttributes.DontDelete |
                PropertyAttributes.ReadOnly);

            Put("LN10", LN10,
                PropertyAttributes.DontEnum |
                PropertyAttributes.DontDelete |
                PropertyAttributes.ReadOnly);

            Put("LN2", LN2,
                PropertyAttributes.DontEnum |
                PropertyAttributes.DontDelete |
                PropertyAttributes.ReadOnly);

            Put("LOG2E", LOG2E,
                PropertyAttributes.DontEnum |
                PropertyAttributes.DontDelete |
                PropertyAttributes.ReadOnly);

            Put("LOG10E", LOG10E,
                PropertyAttributes.DontEnum |
                PropertyAttributes.DontDelete |
                PropertyAttributes.ReadOnly);

            Put("PI", PI,
                PropertyAttributes.DontEnum |
                PropertyAttributes.DontDelete |
                PropertyAttributes.ReadOnly);

            Put("SQRT1_2", SQRT1_2,
                PropertyAttributes.DontEnum |
                PropertyAttributes.DontDelete |
                PropertyAttributes.ReadOnly);

            Put("SQRT2", SQRT2,
                PropertyAttributes.DontEnum |
                PropertyAttributes.DontDelete |
                PropertyAttributes.ReadOnly);

            AddBuiltin(inst, "abs");
            AddBuiltin(inst, "acos");
            AddBuiltin(inst, "asin");
            AddBuiltin(inst, "atan");
            AddBuiltin(inst, "atan2");
            AddBuiltin(inst, "ceil");
            AddBuiltin(inst, "exp");
            AddBuiltin(inst, "floor");
            AddBuiltin(inst, "log");
            AddBuiltin(inst, "max");
            AddBuiltin(inst, "min");
            AddBuiltin(inst, "pow");
            AddBuiltin(inst, "random");
            AddBuiltin(inst, "round");
            AddBuiltin(inst, "sin");
            AddBuiltin(inst, "sqrt");
            AddBuiltin(inst, "tan");
        }
Пример #34
0
 internal virtual Object Call(Object[] args, Object thisob, ScriptObject enclosing_scope, Closure calleeClosure, Binder binder, CultureInfo culture)
 {
     return(this.Call(args, thisob));
 }
Пример #35
0
 internal override AST PartiallyEvaluate()
 {
     this.BindName();
     if (this.members == null || this.members.Length == 0)
     {
         //Give a warning, unless inside a with statement
         ScriptObject scope = Globals.ScopeStack.Peek();
         while (scope is FunctionScope)
         {
             scope = scope.GetParent();
         }
         if (!(scope is WithObject) || this.isFullyResolved)
         {
             this.context.HandleError(JSError.UndeclaredVariable, this.isFullyResolved && this.Engine.doFast);
         }
     }
     else
     {
         this.ResolveRHValue();
         MemberInfo member = this.member;
         if (member is FieldInfo)
         {
             FieldInfo field = (FieldInfo)member;
             if (field is JSLocalField && !((JSLocalField)field).isDefined)
             {
                 ((JSLocalField)field).isUsedBeforeDefinition = true;
                 this.context.HandleError(JSError.VariableMightBeUnitialized);
             }
             if (field.IsLiteral)
             {
                 Object val = field is JSVariableField ? ((JSVariableField)field).value : field.GetValue(null);
                 if (val is AST)
                 {
                     AST pval = ((AST)val).PartiallyEvaluate();
                     if (pval is ConstantWrapper && this.isFullyResolved)
                     {
                         return(pval);
                     }
                     val = null;
                 }
                 if (!(val is FunctionObject) && this.isFullyResolved)
                 {
                     return(new ConstantWrapper(val, this.context));
                 }
             }
             else if (field.IsInitOnly && field.IsStatic && field.DeclaringType == Typeob.GlobalObject && this.isFullyResolved)
             {
                 return(new ConstantWrapper(field.GetValue(null), this.context));
             }
         }
         else if (member is PropertyInfo)
         {
             PropertyInfo prop = (PropertyInfo)member;
             if (!prop.CanWrite && !(prop is JSProperty) && prop.DeclaringType == Typeob.GlobalObject && this.isFullyResolved)
             {
                 return(new ConstantWrapper(prop.GetValue(null, null), this.context));
             }
         }
         if (member is Type && this.isFullyResolved)
         {
             return(new ConstantWrapper(member, this.context));
         }
     }
     return(this);
 }
Пример #36
0
        public override MemberInfo[] GetMember(String name, BindingFlags bindingAttr)
        {
            MemberInfoList mems  = new MemberInfoList();
            FieldInfo      field = (FieldInfo)(this.name_table[name]);

            if (field != null)
            {
                if (field.IsPublic)
                {
                    if ((bindingAttr & BindingFlags.Public) == 0)
                    {
                        goto parent;
                    }
                }
                else
                {
                    if ((bindingAttr & BindingFlags.NonPublic) == 0)
                    {
                        goto parent;
                    }
                }
                if (field.IsLiteral)
                {
                    Object val = ((JSMemberField)field).value;
                    if (val is FunctionObject)
                    {
                        FunctionObject func = (FunctionObject)val;
                        if (func.isConstructor)
                        {
                            return(new MemberInfo[0]); //Suppress constructors, they are awkward to handle. The compiler always obtains them via GetConstructor
                        }
                        if (func.isExpandoMethod)
                        {
                            if ((bindingAttr & BindingFlags.Instance) == 0)
                            {
                                goto parent;
                            }
                            mems.Add(field);
                        }
                        else
                        {
                            ((JSMemberField)field).AddOverloadedMembers(mems, this, bindingAttr | BindingFlags.DeclaredOnly);
                        }
                        goto parent;
                    }
                    else if (val is JSProperty)
                    {
                        JSProperty prop           = (JSProperty)val;
                        MethodInfo getterOrSetter = prop.getter != null ? prop.getter : prop.setter;
                        if (getterOrSetter.IsStatic)
                        {
                            if ((bindingAttr & BindingFlags.Static) == 0)
                            {
                                goto parent;
                            }
                        }
                        else
                        {
                            if ((bindingAttr & BindingFlags.Instance) == 0)
                            {
                                goto parent;
                            }
                        }
                        mems.Add(prop);
                        goto parent;
                    }
                    else if (val is ClassScope)
                    {
                        if ((bindingAttr & BindingFlags.Instance) != 0)
                        {
                            if (!((ClassScope)val).owner.isStatic)
                            {
                                mems.Add(field);
                                goto parent;
                            }
                        }
                    }
                }
                if (field.IsStatic)
                {
                    if ((bindingAttr & BindingFlags.Static) == 0)
                    {
                        goto parent;
                    }
                }
                else
                {
                    if ((bindingAttr & BindingFlags.Instance) == 0)
                    {
                        goto parent;
                    }
                }
                mems.Add(field);
            }
parent:
            if (this.owner != null && this.owner.isInterface && ((bindingAttr & BindingFlags.DeclaredOnly) == 0))
            {
                return(this.owner.GetInterfaceMember(name));
            }
            if (this.parent != null && ((bindingAttr & BindingFlags.DeclaredOnly) == 0)) //Add any members found on the superclass
            {
                MemberInfo[] supMembers = this.parent.GetMember(name, bindingAttr);
                if (supMembers != null)
                {
                    foreach (MemberInfo mem in supMembers)
                    {
                        if (mem.MemberType == MemberTypes.Field)
                        {
                            field = (FieldInfo)mem;
                            if (!field.IsStatic && !field.IsLiteral && !(field is JSWrappedField))
                            {
                                field = new JSWrappedField(field, this.parent);
                            }
                            mems.Add(field);
                        }
                        else
                        {
                            mems.Add(ScriptObject.WrapMember(mem, this.parent));
                        }
                    }
                }
            }
            return(mems.ToArray());
        }
 internal ErrorPrototype(ScriptObject parent, String name)
     : base(parent)
 {
     this.name = name;
     //this.constructor is given a value by the constructor class
 }
Пример #38
0
 // Initialize the prototype value from a subclass.
 internal void InitPrototype(ScriptObject parent)
 {
     this.prototypeValue =
         new JSPrototypeObject(parent.GetParent(), this);
 }
 internal JSGlobalField(ScriptObject obj, string name, object value, FieldAttributes attributeFlags) : base(name, obj, attributeFlags)
 {
     base.value   = value;
     this.ILField = null;
 }
 internal FunctionScope(ScriptObject parent)
     : this(parent, false)
 {
 }
        public override MemberInfo[] GetMember(String name, BindingFlags bindingAttr)
        {
            FieldInfo field = (FieldInfo)(this.name_table[name]);

            if (field != null)
            {
                return new MemberInfo[] { field }
            }
            ;
            bool         nestedInInstanceMethod = false;
            ScriptObject parent = this.parent;

            //Treat locals of outer functions as if they were locals of this function
            while (parent is FunctionScope)
            {
                FunctionScope fscope = (FunctionScope)parent;

                nestedInInstanceMethod = fscope.isMethod && !fscope.isStatic;
                JSLocalField lfield = (JSLocalField)fscope.name_table[name];
                if (lfield == null)
                {
                    parent = parent.GetParent();
                    continue;
                }
                if (lfield.IsLiteral && !(lfield.value is FunctionObject))
                {
                    return new MemberInfo[] { lfield }
                }
                ;
                JSLocalField f = new JSLocalField(lfield.Name, this, this.field_table.Count, Missing.Value);
                f.outerField = lfield;
                f.debugOn    = lfield.debugOn;
                if (!f.debugOn && this.owner.funcContext.document.debugOn && fscope.owner.funcContext.document.debugOn)
                {
                    //Check to see it is off because outer field is a parameter
                    f.debugOn = Array.IndexOf(fscope.owner.formal_parameters, lfield.Name) >= 0;
                }
                f.isDefined    = lfield.isDefined;
                f.debuggerName = "outer" + "." + f.Name;
                if (lfield.IsLiteral)
                {
                    f.attributeFlags |= FieldAttributes.Literal;
                    f.value           = lfield.value;
                }
                this.AddOuterScopeField(name, f);
                if (this.ProvidesOuterScopeLocals[parent] == null)
                {
                    this.ProvidesOuterScopeLocals[parent] = parent;
                }
                ((FunctionScope)parent).mustSaveStackLocals = true;
                return(new MemberInfo[] { f });
            }
            if (parent is ClassScope && nestedInInstanceMethod)
            {
                //return class members as if they were local to the function. It is more convenient to wrap up instance members
                //at this stage than it is to figure out later that a special case is involved.
                MemberInfo[] members     = parent.GetMember(name, bindingAttr & ~BindingFlags.DeclaredOnly);
                int          n           = members.Length;
                bool         giveBadNews = false;
                for (int i = 0; i < n; i++)
                {
                    MemberInfo member = members[i];
                    switch (member.MemberType)
                    {
                    case MemberTypes.Field:
                        field = (FieldInfo)member;
                        if (field.IsLiteral)
                        {
                            JSMemberField mfield = field as JSMemberField;
                            if (mfield != null && mfield.value is ClassScope && !((ClassScope)mfield.value).owner.IsStatic)
                            {
                                giveBadNews = true;
                            }
                        }
                        if (!field.IsStatic && !field.IsLiteral)
                        {
                            members[i]  = new JSClosureField(field);
                            giveBadNews = true;
                        }
                        break;

                    case MemberTypes.Method:
                        MethodInfo meth = (MethodInfo)member;
                        if (!meth.IsStatic)
                        {
                            members[i]  = new JSClosureMethod(meth);
                            giveBadNews = true;
                        }
                        break;

                    case MemberTypes.Property:
                        PropertyInfo prop      = (PropertyInfo)member;
                        MethodInfo   getMeth   = JSProperty.GetGetMethod(prop, (bindingAttr & BindingFlags.NonPublic) != 0);
                        MethodInfo   setMeth   = JSProperty.GetSetMethod(prop, (bindingAttr & BindingFlags.NonPublic) != 0);
                        bool         nonStatic = false;
                        if (getMeth != null && !getMeth.IsStatic)
                        {
                            nonStatic = true;
                            getMeth   = new JSClosureMethod(getMeth);
                        }
                        if (setMeth != null && !setMeth.IsStatic)
                        {
                            nonStatic = true;
                            setMeth   = new JSClosureMethod(setMeth);
                        }
                        if (nonStatic)
                        {
                            members[i]  = new JSClosureProperty(prop, getMeth, setMeth);
                            giveBadNews = true;
                        }
                        break;
                    }
                }
                if (giveBadNews)
                {
                    this.GiveOuterFunctionsTheBadNews();        //They have to create explicit stack frames
                }
                if (n > 0)
                {
                    return(members);
                }
            }
            if ((bindingAttr & BindingFlags.DeclaredOnly) != 0)
            {
                return(new MemberInfo[0]);
            }
            return(parent.GetMember(name, bindingAttr));
        }
 internal JSObject(ScriptObject parent) : this(parent, true)
 {
 }
Пример #43
0
 internal override AST PartiallyEvaluate()
 {
     this.BindName();
     if ((base.members == null) || (base.members.Length == 0))
     {
         ScriptObject parent = base.Globals.ScopeStack.Peek();
         while (parent is FunctionScope)
         {
             parent = parent.GetParent();
         }
         if (!(parent is WithObject) || base.isFullyResolved)
         {
             base.context.HandleError(JSError.UndeclaredVariable, base.isFullyResolved && base.Engine.doFast);
         }
     }
     else
     {
         base.ResolveRHValue();
         MemberInfo member = base.member;
         if (member is FieldInfo)
         {
             FieldInfo field = (FieldInfo)member;
             if ((field is JSLocalField) && !((JSLocalField)field).isDefined)
             {
                 ((JSLocalField)field).isUsedBeforeDefinition = true;
                 base.context.HandleError(JSError.VariableMightBeUnitialized);
             }
             if (!field.IsLiteral)
             {
                 if ((field.IsInitOnly && field.IsStatic) && ((field.DeclaringType == Typeob.GlobalObject) && base.isFullyResolved))
                 {
                     return(new ConstantWrapper(field.GetValue(null), base.context));
                 }
             }
             else
             {
                 object obj3 = (field is JSVariableField) ? ((JSVariableField)field).value : TypeReferences.GetConstantValue(field);
                 if (obj3 is AST)
                 {
                     AST ast = ((AST)obj3).PartiallyEvaluate();
                     if ((ast is ConstantWrapper) && base.isFullyResolved)
                     {
                         return(ast);
                     }
                     obj3 = null;
                 }
                 if (!(obj3 is FunctionObject) && base.isFullyResolved)
                 {
                     return(new ConstantWrapper(obj3, base.context));
                 }
             }
         }
         else if (member is PropertyInfo)
         {
             PropertyInfo info3 = (PropertyInfo)member;
             if ((!info3.CanWrite && !(info3 is JSProperty)) && ((info3.DeclaringType == Typeob.GlobalObject) && base.isFullyResolved))
             {
                 return(new ConstantWrapper(info3.GetValue(null, null), base.context));
             }
         }
         if ((member is Type) && base.isFullyResolved)
         {
             return(new ConstantWrapper(member, base.context));
         }
     }
     return(this);
 }
 internal MathObject(ScriptObject parent)
     : base(parent)
 {
 }
Пример #45
0
        private void BindName()
        {
            int          num         = 0;
            int          num2        = 0;
            ScriptObject parent      = base.Globals.ScopeStack.Peek();
            BindingFlags bindingAttr = BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Static | BindingFlags.Instance | BindingFlags.DeclaredOnly;
            bool         flag        = false;
            bool         flag2       = false;

            while (parent != null)
            {
                MemberInfo[] member = null;
                WithObject   obj3   = parent as WithObject;
                if ((obj3 != null) && flag2)
                {
                    member = obj3.GetMember(base.name, bindingAttr, false);
                }
                else
                {
                    member = parent.GetMember(base.name, bindingAttr);
                }
                base.members = member;
                if (member.Length > 0)
                {
                    break;
                }
                if (parent is WithObject)
                {
                    base.isFullyResolved = base.isFullyResolved && ((WithObject)parent).isKnownAtCompileTime;
                    num++;
                }
                else if (parent is ActivationObject)
                {
                    base.isFullyResolved = base.isFullyResolved && ((ActivationObject)parent).isKnownAtCompileTime;
                    if ((parent is BlockScope) || ((parent is FunctionScope) && ((FunctionScope)parent).mustSaveStackLocals))
                    {
                        num++;
                    }
                    if (parent is ClassScope)
                    {
                        if (flag)
                        {
                            flag2 = true;
                        }
                        if (((ClassScope)parent).owner.isStatic)
                        {
                            bindingAttr &= ~BindingFlags.Instance;
                            flag         = true;
                        }
                    }
                }
                else if (parent is StackFrame)
                {
                    num++;
                }
                num2++;
                parent = parent.GetParent();
            }
            if (base.members.Length > 0)
            {
                this.lexLevel     = num;
                this.evalLexLevel = num2;
            }
        }
 internal DateObject(ScriptObject parent, double value) : base(parent)
 {
     this.value     = (((value != value) || (value > 9.2233720368547758E+18)) || (value < -9.2233720368547758E+18)) ? double.NaN : Math.Round(value);
     base.noExpando = false;
 }
Пример #47
0
 // Constructor.
 public GlobalField(FieldAttributes attributes, String name,
                    ScriptObject obj, Object value)
     : base(attributes, name, obj, value)
 {
     // Nothing to do here.
 }
 internal FunctionPrototype(ScriptObject parent) : base(parent)
 {
 }
Пример #49
0
 internal WithObject(ScriptObject parent, Object contained_object)
     : this(parent, contained_object, false)
 {
 }
 internal JSPrototypeObject(ScriptObject parent, ScriptFunction constructor)
     : base(parent, typeof(JSPrototypeObject))
 {
     this.constructor = constructor;
     this.noExpando   = false;
 }
        internal VariableDeclaration(Context context, Lookup identifier, TypeExpression type, AST initializer, FieldAttributes attributes, CustomAttributeList customAttributes)
            : base(context)
        {
            if (initializer != null)
            {
                this.context.UpdateWith(initializer.context);
            }
            else if (type != null)
            {
                this.context.UpdateWith(type.context);
            }
            this.identifier  = identifier;
            this.type        = type;
            this.initializer = initializer;
            ScriptObject current_scope = (ScriptObject)Globals.ScopeStack.Peek();

            while (current_scope is WithObject) //Can only happen at run time and only if there is an eval
            {
                current_scope = current_scope.GetParent();
            }
            String name = this.identifier.ToString();

            if (current_scope is ClassScope)
            {
                if (name == ((ClassScope)current_scope).name)
                {
                    identifier.context.HandleError(JSError.CannotUseNameOfClass);
                    name = name + " var";
                }
            }
            else
            {
                if (attributes != (FieldAttributes)0)
                {
                    this.context.HandleError(JSError.NotInsideClass);
                    attributes = FieldAttributes.Public;
                }
                else
                {
                    attributes |= FieldAttributes.Public;
                }
            }
            FieldInfo field = ((IActivationObject)current_scope).GetLocalField(name);

            if (field != null)
            {
                if (field.IsLiteral || current_scope is ClassScope || type != null)
                {
                    identifier.context.HandleError(JSError.DuplicateName, true);
                }
                this.type = type = null;
            }
            if (current_scope is ActivationObject)
            {
                if (field == null || field is JSVariableField)
                {
                    this.field = ((ActivationObject)current_scope).AddFieldOrUseExistingField(this.identifier.ToString(), Missing.Value, attributes);
                }
                else
                {
                    this.field = ((ActivationObject)current_scope).AddNewField(this.identifier.ToString(), null, attributes);
                }
            }
            else
            {
                this.field = ((StackFrame)current_scope).AddNewField(this.identifier.ToString(), null, attributes | FieldAttributes.Static);
            }
            this.field.type             = type;
            this.field.customAttributes = customAttributes;
            this.field.originalContext  = context;
            if (this.field is JSLocalField)
            {
                // emit debug info for the local only if this block of code is in a section that has debug set
                ((JSLocalField)this.field).debugOn = this.identifier.context.document.debugOn;
            }
            this.completion = new Completion();
        }
Пример #52
0
 internal ActivationObject(ScriptObject parent)
     : base(parent)
 {
     this.name_table  = new SimpleHashtable(32);
     this.field_table = new ArrayList();
 }
Пример #53
0
        protected override void TranslateToILObject(ILGenerator il, Type obType, bool noValue)
        {
            this.thereIsAnObjectOnTheStack = true;
            if (this.member is IWrappedMember)
            {
                Object obj = ((IWrappedMember)this.member).GetWrappedObject();
                if (obj is LenientGlobalObject)
                {
                    this.EmitILToLoadEngine(il);
                    il.Emit(OpCodes.Call, CompilerGlobals.getLenientGlobalObjectMethod);
                }
                else if (obj is Type || obj is ClassScope)
                {
                    if (obType.IsAssignableFrom(Typeob.Type))
                    {
                        (new ConstantWrapper(obj, null)).TranslateToIL(il, Typeob.Type);
                        return;
                    }
                    //this.name is the name of an instance member of the superclass of the class (or an outer class) in which this expression appears
                    //get class instance on stack
                    ScriptObject scope = Globals.ScopeStack.Peek();
                    while (scope is WithObject || scope is BlockScope)
                    {
                        scope = scope.GetParent();
                    }
                    if (scope is FunctionScope)
                    {
                        FunctionObject func = ((FunctionScope)scope).owner;
                        if (func.isMethod)
                        {
                            il.Emit(OpCodes.Ldarg_0);
                        }
                        else //Need to get the StackFrame.closureInstance on the stack
                        {
                            this.EmitILToLoadEngine(il);
                            il.Emit(OpCodes.Call, CompilerGlobals.scriptObjectStackTopMethod);
                            scope = this.Globals.ScopeStack.Peek();
                            while (scope is WithObject || scope is BlockScope)
                            {
                                il.Emit(OpCodes.Call, CompilerGlobals.getParentMethod);
                                scope = scope.GetParent();
                            }
                            il.Emit(OpCodes.Castclass, CompilerGlobals.stackFrameClass);
                            il.Emit(OpCodes.Ldfld, CompilerGlobals.closureInstanceField);
                        }
                    }
                    else if (scope is ClassScope)
                    {
                        il.Emit(OpCodes.Ldarg_0); //Inside instance initializer
                    }

                    //If dealing with a member of an outer class, get the outer class instance on the stack
                    scope = Globals.ScopeStack.Peek();
                    while (scope != null)
                    {
                        ClassScope csc = scope as ClassScope;
                        if (csc != null) //Might be dealing with a reference from within a nested class to an instance member of an outer class
                        {
                            if (csc.IsSameOrDerivedFrom(obType))
                            {
                                break;
                            }
                            il.Emit(OpCodes.Ldfld, csc.outerClassField);
                        }
                        scope = scope.GetParent();
                    }
                }
                else
                {
                    this.TranslateToILDefaultThisObject(il, this.lexLevel);
                    Convert.Emit(this, il, Typeob.Object, obType);
                }
            }
            else
            {
                ScriptObject scope = Globals.ScopeStack.Peek();
                while (scope is WithObject || scope is BlockScope)
                {
                    scope = scope.GetParent();
                }
                if (scope is FunctionScope)
                {
                    FunctionObject func = ((FunctionScope)scope).owner;
                    if (!func.isMethod) //Need to get the StackFrame.closureInstance on the stack
                    {
                        this.EmitILToLoadEngine(il);
                        il.Emit(OpCodes.Call, CompilerGlobals.scriptObjectStackTopMethod);
                        scope = this.Globals.ScopeStack.Peek();
                        while (scope is WithObject || scope is BlockScope)
                        {
                            il.Emit(OpCodes.Call, CompilerGlobals.getParentMethod);
                            scope = scope.GetParent();
                        }
                        il.Emit(OpCodes.Castclass, CompilerGlobals.stackFrameClass);
                        il.Emit(OpCodes.Ldfld, CompilerGlobals.closureInstanceField);
                        while (scope != null)
                        {
                            if (scope is ClassScope) //Might be dealing with a reference from within a nested class to an instance member of an outer class
                            {
                                ClassScope csc = (ClassScope)scope;
                                if (csc.IsSameOrDerivedFrom(obType))
                                {
                                    break;
                                }
                                il.Emit(OpCodes.Castclass, csc.GetTypeBuilder());
                                il.Emit(OpCodes.Ldfld, csc.outerClassField);
                            }
                            scope = scope.GetParent();
                        }
                        il.Emit(OpCodes.Castclass, obType);
                        return;
                    }
                }
                il.Emit(OpCodes.Ldarg_0);
                while (scope != null)
                {
                    if (scope is ClassScope) //Might be dealing with a reference from within a nested class to an instance member of an outer class
                    {
                        ClassScope csc = (ClassScope)scope;
                        if (csc.IsSameOrDerivedFrom(obType))
                        {
                            break;
                        }
                        il.Emit(OpCodes.Ldfld, csc.outerClassField);
                    }
                    scope = scope.GetParent();
                }
            }
        }
Пример #54
0
 // Constructor.
 internal JSPrototypeObject(ScriptObject parent, Object constructor)
     : base(parent)
 {
     this.constructor = constructor;
 }
Пример #55
0
        internal override void TranslateToIL(ILGenerator il, Type rtype)
        {
            //This assumes that rtype == Void.class.
            bool savedInsideProtectedRegion = compilerGlobals.InsideProtectedRegion;

            compilerGlobals.InsideProtectedRegion = true;
            compilerGlobals.BreakLabelStack.Push(compilerGlobals.BreakLabelStack.Peek(0));
            compilerGlobals.ContinueLabelStack.Push(compilerGlobals.ContinueLabelStack.Peek(0));
            il.BeginExceptionBlock();
            if (this.finally_block != null)
            {
                if (this.finallyHasControlFlowOutOfIt)
                {
                    il.BeginExceptionBlock();
                }
                if (this.handler != null)
                {
                    il.BeginExceptionBlock();
                }
            }
            this.body.TranslateToIL(il, Typeob.Void);
            if (this.tryEndContext != null)
            {
                this.tryEndContext.EmitLineInfo(il);
            }
            if (this.handler != null)
            {
                if (this.type == null)
                {
                    il.BeginCatchBlock(Typeob.Exception);
                    this.handler.context.EmitLineInfo(il);
                    this.EmitILToLoadEngine(il);
                    il.Emit(OpCodes.Call, CompilerGlobals.jScriptExceptionValueMethod);
                }
                else
                {
                    Type filterType = this.type.ToType();
                    if (Typeob.Exception.IsAssignableFrom(filterType))
                    {
                        il.BeginCatchBlock(filterType);
                        this.handler.context.EmitLineInfo(il);
                    }
                    else
                    {
                        il.BeginExceptFilterBlock();
                        this.handler.context.EmitLineInfo(il);
                        this.EmitILToLoadEngine(il);
                        il.Emit(OpCodes.Call, CompilerGlobals.jScriptExceptionValueMethod);
                        il.Emit(OpCodes.Isinst, filterType);
                        il.Emit(OpCodes.Ldnull);
                        il.Emit(OpCodes.Cgt_Un);
                        il.BeginCatchBlock(null);
                        this.EmitILToLoadEngine(il);
                        il.Emit(OpCodes.Call, CompilerGlobals.jScriptExceptionValueMethod);
                        Convert.Emit(this, il, Typeob.Object, filterType);
                    }
                }
                Object tok = this.field is JSVariableField ? ((JSVariableField)this.field).GetMetaData() : this.field;
                if (tok is LocalBuilder)
                {
                    il.Emit(OpCodes.Stloc, (LocalBuilder)tok);
                }
                else if (tok is FieldInfo)
                {
                    il.Emit(OpCodes.Stsfld, (FieldInfo)tok);
                }
                else
                {
                    Convert.EmitLdarg(il, (short)tok);
                }

                if (this.handler_scope != null)
                {
                    if (!this.handler_scope.isKnownAtCompileTime) //I.e. eval or nested func
                    {
                        this.EmitILToLoadEngine(il);
                        il.Emit(OpCodes.Ldstr, this.fieldName);
                        ConstantWrapper.TranslateToILInt(il, this.handler_scope.scopeId);
                        il.Emit(OpCodes.Call, Typeob.Try.GetMethod("PushHandlerScope"));
                        Globals.ScopeStack.Push(this.handler_scope);
                        il.BeginExceptionBlock();
                    }
                    il.BeginScope(); // so that we can emit local scoped information for the handler variable
                    if (this.context.document.debugOn)
                    {
                        this.handler_scope.EmitLocalInfoForFields(il);
                    }
                }
                this.handler.TranslateToIL(il, Typeob.Void);
                if (this.handler_scope != null)
                {
                    il.EndScope();
                    if (!this.handler_scope.isKnownAtCompileTime) //I.e. eval or nested func
                    {
                        il.BeginFinallyBlock();
                        this.EmitILToLoadEngine(il);
                        il.Emit(OpCodes.Call, CompilerGlobals.popScriptObjectMethod);
                        il.Emit(OpCodes.Pop);
                        Globals.ScopeStack.Pop();
                        il.EndExceptionBlock();
                    }
                }
                il.EndExceptionBlock();
            }
            if (this.finally_block != null)
            {
                bool savedInsideFinally   = compilerGlobals.InsideFinally;
                int  savedFinallyStackTop = compilerGlobals.FinallyStackTop;
                compilerGlobals.InsideFinally   = true;
                compilerGlobals.FinallyStackTop = compilerGlobals.BreakLabelStack.Size();
                il.BeginFinallyBlock();
                this.finally_block.TranslateToIL(il, Typeob.Void);
                il.EndExceptionBlock();
                compilerGlobals.InsideFinally   = savedInsideFinally;
                compilerGlobals.FinallyStackTop = savedFinallyStackTop;
                if (this.finallyHasControlFlowOutOfIt)
                {
                    il.BeginCatchBlock(Typeob.BreakOutOfFinally);
                    il.Emit(OpCodes.Ldfld, Typeob.BreakOutOfFinally.GetField("target"));
                    // don't need to go to 0 in the loop because 0 is the outmost block (i.e. function body)
                    // and that would generate a JIT assert because the jump is sometimes outside the function
                    for (int i = compilerGlobals.BreakLabelStack.Size() - 1, n = i; i > 0; i--)
                    {
                        il.Emit(OpCodes.Dup);
                        ConstantWrapper.TranslateToILInt(il, i);
                        Label lab = il.DefineLabel();
                        il.Emit(OpCodes.Blt_S, lab);
                        il.Emit(OpCodes.Pop);
                        if (savedInsideFinally && i < savedFinallyStackTop)
                        {
                            il.Emit(OpCodes.Rethrow);
                        }
                        else
                        {
                            il.Emit(OpCodes.Leave, (Label)compilerGlobals.BreakLabelStack.Peek(n - i));
                        }
                        il.MarkLabel(lab);
                    }
                    il.Emit(OpCodes.Pop);
                    il.BeginCatchBlock(Typeob.ContinueOutOfFinally);
                    il.Emit(OpCodes.Ldfld, Typeob.ContinueOutOfFinally.GetField("target"));
                    // don't need to go to 0 in the loop because 0 is the outmost block (i.e. function body)
                    for (int i = compilerGlobals.ContinueLabelStack.Size() - 1, n = i; i > 0; i--)
                    {
                        il.Emit(OpCodes.Dup);
                        ConstantWrapper.TranslateToILInt(il, i);
                        Label lab = il.DefineLabel();
                        il.Emit(OpCodes.Blt_S, lab);
                        il.Emit(OpCodes.Pop);
                        if (savedInsideFinally && i < savedFinallyStackTop)
                        {
                            il.Emit(OpCodes.Rethrow);
                        }
                        else
                        {
                            il.Emit(OpCodes.Leave, (Label)compilerGlobals.ContinueLabelStack.Peek(n - i));
                        }
                        il.MarkLabel(lab);
                    }
                    il.Emit(OpCodes.Pop);
                    ScriptObject scope = Globals.ScopeStack.Peek();
                    while (scope != null && !(scope is FunctionScope))
                    {
                        scope = scope.GetParent();
                    }
                    if (scope != null && !savedInsideFinally)
                    {
                        il.BeginCatchBlock(Typeob.ReturnOutOfFinally);
                        il.Emit(OpCodes.Pop);
                        il.Emit(OpCodes.Leave, ((FunctionScope)scope).owner.returnLabel);
                    }
                    il.EndExceptionBlock();
                }
            }
            compilerGlobals.InsideProtectedRegion = savedInsideProtectedRegion;
            compilerGlobals.BreakLabelStack.Pop();
            compilerGlobals.ContinueLabelStack.Pop();
        }
Пример #56
0
        private void SetValue(Object obj, Object value, BindingFlags invokeAttr, Binder binder, CultureInfo locale, ScriptObject scope)
        {
            if (this.IsStatic || this.IsLiteral)
            {
                if ((this.IsLiteral || this.IsInitOnly) && !(this.value is Missing))
                {
                    throw new JScriptException(JSError.AssignmentToReadOnly);
                }
                goto setValue;
            }
            if (this.obj != obj)
            {
                if (obj is JSObject)
                {
                    FieldInfo field = ((JSObject)obj).GetField(this.Name, BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);
                    if (field != null)
                    {
                        field.SetValue(obj, value, invokeAttr, binder, locale);
                        return;
                    }
                }
                throw new TargetException();
            }
            if (!this.IsPublic && (scope == null || !this.IsAccessibleFrom(scope)))
            {
                if (((JSObject)this.obj).noExpando)
                {
                    throw new JScriptException(JSError.NotAccessible, new Context(new DocumentContext("", null), this.Name));
                }
                else
                {
                    this.expandoValue = value;
                }
                return;
            }
setValue:
            if (this.type != null)
            {
                this.value = Convert.Coerce(value, this.type);
            }
            else
            {
                this.value = value;
            }
        }
Пример #57
0
 protected BooleanObject(ScriptObject prototype, Type subType)
 {
     throw new NotImplementedException();
 }
Пример #58
0
 internal bool IsAccessibleFrom(ScriptObject scope)
 {
     return(((JSMemberField)this.field).IsAccessibleFrom(scope));
 }
        private MemberInfo[] GetLocalMember(string name, BindingFlags bindingAttr, bool wrapMembers)
        {
            MemberInfo[] members = null;
            FieldInfo    info    = (this.name_table == null) ? null : ((FieldInfo)this.name_table[name]);

            if ((info == null) && this.isASubClass)
            {
                if (this.memberCache != null)
                {
                    members = (MemberInfo[])this.memberCache[name];
                    if (members != null)
                    {
                        return(members);
                    }
                }
                bindingAttr &= ~BindingFlags.NonPublic;
                members      = this.subClassIR.GetMember(name, bindingAttr);
                if (members.Length == 0)
                {
                    members = this.subClassIR.GetMember(name, (bindingAttr & ~BindingFlags.Instance) | BindingFlags.Static);
                }
                int length = members.Length;
                if (length > 0)
                {
                    int num2 = 0;
                    foreach (MemberInfo info2 in members)
                    {
                        if (IsHiddenMember(info2))
                        {
                            num2++;
                        }
                    }
                    if ((num2 > 0) && (((length != 1) || !(this is ObjectPrototype)) || (name != "ToString")))
                    {
                        MemberInfo[] infoArray2 = new MemberInfo[length - num2];
                        int          num3       = 0;
                        foreach (MemberInfo info3 in members)
                        {
                            if (!IsHiddenMember(info3))
                            {
                                infoArray2[num3++] = info3;
                            }
                        }
                        members = infoArray2;
                    }
                }
                if (((members == null) || (members.Length == 0)) && (((bindingAttr & BindingFlags.Public) != BindingFlags.Default) && ((bindingAttr & BindingFlags.Instance) != BindingFlags.Default)))
                {
                    BindingFlags flags = ((bindingAttr & BindingFlags.IgnoreCase) | BindingFlags.Public) | BindingFlags.Instance;
                    if (this is StringObject)
                    {
                        members = TypeReflector.GetTypeReflectorFor(Typeob.String).GetMember(name, flags);
                    }
                    else if (this is NumberObject)
                    {
                        members = TypeReflector.GetTypeReflectorFor(((NumberObject)this).baseType).GetMember(name, flags);
                    }
                    else if (this is BooleanObject)
                    {
                        members = TypeReflector.GetTypeReflectorFor(Typeob.Boolean).GetMember(name, flags);
                    }
                    else if (this is StringConstructor)
                    {
                        members = TypeReflector.GetTypeReflectorFor(Typeob.String).GetMember(name, (flags | BindingFlags.Static) & ~BindingFlags.Instance);
                    }
                    else if (this is BooleanConstructor)
                    {
                        members = TypeReflector.GetTypeReflectorFor(Typeob.Boolean).GetMember(name, (flags | BindingFlags.Static) & ~BindingFlags.Instance);
                    }
                    else if (this is ArrayWrapper)
                    {
                        members = TypeReflector.GetTypeReflectorFor(Typeob.Array).GetMember(name, flags);
                    }
                }
                if ((members != null) && (members.Length > 0))
                {
                    if (wrapMembers)
                    {
                        members = ScriptObject.WrapMembers(members, this);
                    }
                    if (this.memberCache == null)
                    {
                        this.memberCache = new SimpleHashtable(0x20);
                    }
                    this.memberCache[name] = members;
                    return(members);
                }
            }
            if (((bindingAttr & BindingFlags.IgnoreCase) != BindingFlags.Default) && ((members == null) || (members.Length == 0)))
            {
                members = null;
                IDictionaryEnumerator enumerator = this.name_table.GetEnumerator();
                while (enumerator.MoveNext())
                {
                    if (string.Compare(enumerator.Key.ToString(), name, StringComparison.OrdinalIgnoreCase) == 0)
                    {
                        info = (FieldInfo)enumerator.Value;
                        break;
                    }
                }
            }
            if (info != null)
            {
                return(new MemberInfo[] { info });
            }
            if (members == null)
            {
                members = new MemberInfo[0];
            }
            return(members);
        }
 internal NumberObject(ScriptObject parent, Type baseType) : base(parent)
 {
     this.baseType  = baseType;
     this.value     = 0.0;
     base.noExpando = false;
 }