public FieldSetterCodeGen(CodeGenerator cg, FieldBindingInfo bindingInfo)
        {
            this.cg          = cg;
            this.bindingInfo = bindingInfo;

            var caller        = this.cg.AppendGetThisCS(bindingInfo);
            var fieldInfo     = bindingInfo.fieldInfo;
            var declaringType = fieldInfo.DeclaringType;
            var fieldType     = this.cg.bindingManager.GetCSTypeFullName(fieldInfo.FieldType);

            this.cg.cs.AppendLine("{0} value;", fieldType);
            var getter = this.cg.bindingManager.GetScriptObjectGetter(fieldInfo.FieldType, "ctx", "arg_val", "value");

            this.cg.cs.AppendLine("if (!{0})", getter);
            using (this.cg.cs.Block())
            {
                this.cg.cs.AppendLine("throw new ParameterException(typeof({0}), 0);", fieldType);
            }
            this.cg.cs.AppendLine("{0}.{1} = value;", caller, fieldInfo.Name);
            if (declaringType.IsValueType && !fieldInfo.IsStatic)
            {
                // 非静态结构体字段修改, 尝试替换实例
                this.cg.cs.AppendLine($"js_rebind_this(ctx, this_obj, {caller});");
            }
            this.cg.cs.AppendLine("return JSApi.JS_UNDEFINED;");
        }
        public FieldGetterCodeGen(CodeGenerator cg, FieldBindingInfo bindingInfo)
        {
            this.cg          = cg;
            this.bindingInfo = bindingInfo;

            var caller = this.cg.AppendGetThisCS(bindingInfo);

            this.cg.cs.AppendLine("var ret = {0}.{1};", caller, bindingInfo.fieldInfo.Name);
            var pusher = this.cg.AppendValuePusher(bindingInfo.fieldInfo.FieldType, "ret");

            this.cg.cs.AppendLine("return {0};", pusher);
        }
Beispiel #3
0
 public string AppendGetThisCS(FieldBindingInfo bindingInfo)
 {
     return(AppendGetThisCS(bindingInfo.isStatic, bindingInfo.fieldInfo.DeclaringType));
 }