internal static CefV8Value Invoke(CefV8Context context, XrayObject target, CefListValue args) { CefV8Value func = target.Value; CefV8Value thisArg = CastCefValueToCefV8Value(context, args.GetValue(3), out bool isNewThisArg); int size = (int)(args.GetSize() - 4); var xraylist = new List <int>(size); var fnArgs = new CefV8Value[size]; try { for (int i = 0; i < fnArgs.Length; i++) { int index = (i + 4); fnArgs[i] = CastCefValueToCefV8Value(context, args.GetValue(index), out bool isNew); if (!isNew) { xraylist.Add(index); } } return(func.ExecuteFunction(thisArg, fnArgs)); } finally { for (int i = 0; i < fnArgs.Length; i++) { if (!xraylist.Contains(i)) { fnArgs[i].Dispose(); } } } }
public static void Set(CefV8Context context, XrayObject target, CefListValue args) { CefV8Value thisArg = GetSafeThisArg(context, target); CefV8Value value = CastCefValueToCefV8Value(context, args.GetValue(4), out bool isNotXray); thisArg.SetValueByKey(args.GetString(3), value, CefV8PropertyAttribute.None); if (isNotXray) { value.Dispose(); } }
internal unsafe static object CastCefV8ValueToDotnetType(CefV8Context context, CefV8Value value, out bool isXray) { isXray = false; if (value == null) { return(null); } if (!value.IsValid) { throw new InvalidCastException(); } switch (value.Type) { case CefV8ValueType.Undefined: return(V8Undefined.Value); case CefV8ValueType.Null: return(null); case CefV8ValueType.Bool: return(value.GetBoolValue()); case CefV8ValueType.Int: // TYPE_INT, TYPE_UINT case CefV8ValueType.UInt: return(value.GetIntValue()); case CefV8ValueType.Double: return(value.GetDoubleValue()); case CefV8ValueType.Date: return(value.GetDateValue().ToDateTime()); case CefV8ValueType.String: return(value.GetStringValue()); case CefV8ValueType.Object: isXray = true; if (value.IsArray) //TYPE_OBJECT (array) { throw new NotImplementedException(); } if (value.IsArrayBuffer) //TYPE_OBJECT (arraybuffer) { throw new NotImplementedException(); } return(XrayObject.Wrap(context, value).CreateHandle()); } throw new NotImplementedException(); }
public static long Get(CefV8Context context, XrayObject target, CefListValue args, out CefV8Value value) { CefV8Value thisArg = GetSafeThisArg(context, target); CefValue arg3 = args.GetValue(3); CefValueType valueType = arg3.Type; if (valueType == CefValueType.Int) { value = thisArg.GetValueByIndex(arg3.GetInt()); return(0); } string name = arg3.GetString(); value = thisArg.GetValue(name); return(0); }
internal CefV8Value ToCefV8Value(CefFrame frame) { switch (this.dataType) { case XrayDataType.Date: return(new CefV8Value(DateTime.FromBinary(iRaw))); case XrayDataType.Object: case XrayDataType.Function: XrayObject xray = this.GetTarget(frame); if (xray == null) { throw new InvalidCastException(); } return(xray.Value); } throw new NotSupportedException(); }
internal static CefV8Value InvokeMember(CefV8Context context, XrayObject target, CefListValue args) { CefV8Value thisArg = GetSafeThisArg(context, target); CefV8Value func = thisArg.GetValue(args.GetString(3)); if (!func.IsFunction) { func.Dispose(); throw new MissingMethodException(); } int size = (int)(args.GetSize() - 4); var xraylist = new List <int>(size); var fnArgs = new CefV8Value[size]; try { for (int i = 0; i < fnArgs.Length; i++) { int index = (i + 4); fnArgs[i] = CastCefValueToCefV8Value(context, args.GetValue(index), out bool isNew); if (!isNew) { xraylist.Add(index); } } return(func.ExecuteFunction(thisArg, fnArgs)); } finally { func.Dispose(); for (int i = 0; i < fnArgs.Length; i++) { if (!xraylist.Contains(i)) { fnArgs[i].Dispose(); } } } }
private object GetPropertyInternal(XrayHandle self, string name) { if (!CefApi.CurrentlyOn(CefThreadId.Renderer)) { using (var callTask = new V8CallTask(() => GetPropertyInternal(self, name))) { if (!CefApi.PostTask(CefThreadId.Renderer, callTask)) { throw new InvalidOperationException(); } return(callTask.GetResult()); } } XrayObject target = self.GetTarget(this.Frame); if (!target.Context.Enter()) { throw new InvalidOperationException(); } object retval; try { CefV8Value value = target.Value.GetValueByKey(name); retval = CastCefV8ValueToDotnetType(target.Context, value, out bool isxray); if (!isxray) { value.Dispose(); } } finally { target.Context.Exit(); } return(retval); }
private bool SetPropertyInternal(XrayHandle self, string name, object value) { if (!CefApi.CurrentlyOn(CefThreadId.Renderer)) { using (var callTask = new V8CallTask(() => SetPropertyInternal(self, name, value))) { if (!CefApi.PostTask(CefThreadId.Renderer, callTask)) { throw new InvalidOperationException(); } return((bool)callTask.GetResult()); } } XrayObject target = self.GetTarget(this.Frame); if (target is null || !target.Context.Enter()) { throw new InvalidOperationException(); } bool result; try { CefV8Value v8value = CastDotnetTypeToCefV8Value(target.Context, value, out bool isNotXray); result = target.Value.SetValueByKey(name, v8value, CefV8PropertyAttribute.None); if (isNotXray) { v8value.Dispose(); } } finally { target.Context.Exit(); } return(result); }
public static XrayObject Wrap(CefV8Context context, CefV8Value value) { List <XrayObject> roots; lock (XrayRoots) { if (!XrayRoots.TryGetValue(context, out roots)) { throw new InvalidOperationException("Unexpected context."); } } foreach (XrayObject obj in roots) { if (value == obj._value) { return(obj); } } var xray = new XrayObject(context, value); roots.Add(xray); return(xray); }
internal unsafe static CefValue CastCefV8ValueToCefValue(CefV8Context context, CefV8Value value, out bool isXray) { isXray = false; if (value == null) { return(null); } if (!value.IsValid) { throw new InvalidCastException(); } CefValue v; switch (value.Type) { case CefV8ValueType.Undefined: v = new CefValue(); v.SetBinary(new byte[1]); return(v); case CefV8ValueType.Null: v = new CefValue(); v.SetNull(); return(v); case CefV8ValueType.Bool: v = new CefValue(); v.SetBool(value.GetBoolValue()); return(v); case CefV8ValueType.Int: // TYPE_INT, TYPE_UINT case CefV8ValueType.UInt: v = new CefValue(); v.SetInt(value.GetIntValue()); return(v); case CefV8ValueType.Double: v = new CefValue(); v.SetDouble(value.GetDoubleValue()); return(v); case CefV8ValueType.Date: v = new CefValue(); v.SetBinary(XrayHandle.FromDateTime(value.GetDateValue().ToDateTime()).ToCfxBinaryValue()); return(v); case CefV8ValueType.String: v = new CefValue(); if (!value.CopyV8StringToCefValue(v)) { throw new CefRuntimeException("Can't copy the string."); } return(v); case CefV8ValueType.Object: isXray = true; if (value.IsArray) //TYPE_OBJECT (array) { throw new NotImplementedException(); } if (value.IsArrayBuffer) //TYPE_OBJECT (arraybuffer) { throw new NotImplementedException(); } v = new CefValue(); v.SetBinary(XrayObject.Wrap(context, value).CreateHandle().ToCfxBinaryValue()); return(v); } throw new NotImplementedException(); }
private object InvokeInternal(XrayHandle self, object[] args) { if (args is null || args.Length == 0) { throw new ArgumentOutOfRangeException(nameof(args)); } if (!CefApi.CurrentlyOn(CefThreadId.Renderer)) { using (var callTask = new V8CallTask(() => InvokeInternal(self, args))) { if (!CefApi.PostTask(CefThreadId.Renderer, callTask)) { throw new InvalidOperationException(); } return((bool)callTask.GetResult()); } } XrayObject target = self.GetTarget(this.Frame); if (target is null || !target.Context.Enter()) { throw new InvalidOperationException(); } object retval; try { CefV8Value func = target.Value; CefV8Value thisArg = CastDotnetTypeToCefV8Value(target.Context, args[0], out bool isNewThisArg); CefV8Value value; int size = args.Length - 1; var xraylist = new List <int>(size); var fnArgs = new CefV8Value[size]; try { for (int i = 0; i < fnArgs.Length; i++) { int index = (i + 1); fnArgs[i] = CastDotnetTypeToCefV8Value(target.Context, args[index], out bool isNew); if (!isNew) { xraylist.Add(index); } } value = func.ExecuteFunction(thisArg, fnArgs); } finally { for (int i = 0; i < fnArgs.Length; i++) { if (!xraylist.Contains(i)) { fnArgs[i].Dispose(); } } } retval = CastCefV8ValueToDotnetType(target.Context, value, out bool isxray); if (!isxray) { value.Dispose(); } } finally { target.Context.Exit(); } return(retval); }
public object InvokeMemberInternal(XrayHandle self, string name, object[] args) { if (args is null) { throw new ArgumentNullException(nameof(args)); } if (!CefApi.CurrentlyOn(CefThreadId.Renderer)) { using (var callTask = new V8CallTask(() => InvokeMemberInternal(self, name, args))) { if (!CefApi.PostTask(CefThreadId.Renderer, callTask)) { throw new InvalidOperationException(); } return((bool)callTask.GetResult()); } } XrayObject target = self.GetTarget(this.Frame); if (target is null || !target.Context.Enter()) { throw new InvalidOperationException(); } object retval; try { CefV8Value thisArg = target.Value; CefV8Value func = thisArg.GetValueByKey(name); if (!func.IsFunction) { func.Dispose(); throw new MissingMethodException(string.Format("'{0} is not a function.'", name)); } CefV8Value value; var xraylist = new List <int>(args.Length); var fnArgs = new CefV8Value[args.Length]; try { for (int i = 0; i < fnArgs.Length; i++) { fnArgs[i] = CastDotnetTypeToCefV8Value(target.Context, args[i], out bool isNew); if (!isNew) { xraylist.Add(i); } } value = func.ExecuteFunction(thisArg, fnArgs); } finally { for (int i = 0; i < fnArgs.Length; i++) { if (!xraylist.Contains(i)) { fnArgs[i].Dispose(); } } } retval = CastCefV8ValueToDotnetType(target.Context, value, out bool isxray); if (!isxray) { value.Dispose(); } } finally { target.Context.Exit(); } return(retval); }
private static CefV8Value GetSafeThisArg(CefV8Context context, XrayObject target) { return(target?.Value ?? context.GetGlobal()); }