Example #1
0
        public override JSValue Invoke(JSContext ctx, JSValue this_obj, int argc, JSValue[] argv)
        {
            if (!_ctor.IsPublic && !_type.privateAccess)
            {
                return(JSApi.JS_ThrowInternalError(ctx, "constructor is inaccessible due to its protection level"));
            }

            var parameters = _ctor.GetParameters();
            var nArgs      = argc;
            var args       = new object[nArgs];

            for (var i = 0; i < nArgs; i++)
            {
                if (!Values.js_get_var(ctx, argv[i], parameters[i].ParameterType, out args[i]))
                {
                    return(JSApi.JS_ThrowInternalError(ctx, "failed to cast val"));
                }
            }

            if (_crossbind)
            {
                UnityEngine.Debug.LogFormat($"_js_crossbind_constructor {_type}");
                return(Values._js_crossbind_constructor(ctx, this_obj));
            }

            var inst = _ctor.Invoke(args);
            var val  = Values.NewBridgeClassObject(ctx, this_obj, inst, _type.id, false);

            return(val);
        }
Example #2
0
 public static JSValue CrossBindConstructor(JSContext ctx, JSValue new_target, int argc, JSValue[] argv, int magic)
 {
     try
     {
         if (argc == 0)
         {
             return(Values._js_crossbind_constructor(ctx, new_target));
         }
         throw new NoSuitableMethodException("constructor", argc);
     }
     catch (Exception exception)
     {
         return(JSApi.ThrowException(ctx, exception));
     }
 }
Example #3
0
 public override JSValue Invoke(JSContext ctx, JSValue this_obj, int argc, JSValue[] argv)
 {
     return(Values._js_crossbind_constructor(ctx, this_obj));
 }