public static CefV8Value ToCefV8Value(this JavaScriptValue source) { switch (source.ValueType) { case JavaScriptValueType.Null: return(CefV8Value.CreateNull()); case JavaScriptValueType.Bool: return(CefV8Value.CreateBool(source.GetBool())); case JavaScriptValueType.Int: return(CefV8Value.CreateInt(source.GetInt())); case JavaScriptValueType.Double: return(CefV8Value.CreateDouble(source.GetDouble())); case JavaScriptValueType.String: return(CefV8Value.CreateString(source.GetString())); case JavaScriptValueType.DateTime: return(CefV8Value.CreateDate(source.GetDateTime())); case JavaScriptValueType.Property: break; case JavaScriptValueType.Function: break; case JavaScriptValueType.Object: var obj = CefV8Value.CreateObject(); foreach (var key in source.Keys) { var retval = source.GetValue(key)?.ToCefV8Value(); if (retval != null) { obj.SetValue(key, retval); } } return(obj); case JavaScriptValueType.Array: var result = new List <CefV8Value>(); for (int i = 0; i < source.ArrayLength; i++) { var retval = source.GetValue(i)?.ToCefV8Value(); if (retval != null) { result.Add(retval); } } var array = CefV8Value.CreateArray(result.Count); for (int i = 0; i < result.Count; i++) { array.SetValue(i, result[i]); } return(array); } return(null); }
public void Test_GetSimpleValue_Bool_True() { Test(() => { object res = null; bool ok = _CefV8_Converter.GetSimpleValue(CefV8Value.CreateBool(true).Convert(), out res); ok.Should().BeTrue(); res.Should().Be(true); }); }
public static CefV8Value ConvertToV8Value(object o) { if (o == null) { return(CefV8Value.CreateUndefined()); } if (o is bool) { return(CefV8Value.CreateBool((bool)o)); } if (o is DateTime) { return(CefV8Value.CreateDate((DateTime)o)); } if (o is double) { return(CefV8Value.CreateDouble((double)o)); } if (o is int) { return(CefV8Value.CreateInt((int)o)); } if (o is string) { return(CefV8Value.CreateString((string)o)); } if (o is uint) { return(CefV8Value.CreateUInt((uint)o)); } if (o is Array) { var a = (Array)o; var rtn = CefV8Value.CreateArray(a.Length); for (int i = 0; i < a.Length; i++) { rtn.SetValue(i, ConvertToV8Value(a.GetValue(i))); } return(rtn); } if (o is System.Collections.IList) { var a = (System.Collections.IList)o; var rtn = CefV8Value.CreateArray(a.Count); for (int i = 0; i < a.Count; i++) { rtn.SetValue(i, ConvertToV8Value(a[i])); } return(rtn); } throw new NotSupportedException("??"); }
public static CefV8Value ConvertToV8Value(dynamic result) { if (result != null) { if (result is bool) { return(CefV8Value.CreateBool(result)); } else if (result is DateTime) { return(CefV8Value.CreateDate(result)); } else if (result is double) { return(CefV8Value.CreateDouble(result)); } else if (result is int) { return(CefV8Value.CreateInt(result)); } else if (result is string) { return(CefV8Value.CreateString(result)); } else if (result is uint) { return(CefV8Value.CreateUInt(result)); } else if (result is Array) { var source = (Array)result; var destination = CefV8Value.CreateArray(source.Length); for (int x = 0; x < source.Length; x++) { destination.SetValue(x, ConvertToV8Value(source.GetValue(x))); } return(destination); } else if (result is System.Collections.IList) { var source = (System.Collections.IList)result; var destination = CefV8Value.CreateArray(source.Count); for (int x = 0; x < source.Count; x++) { destination.SetValue(x, ConvertToV8Value(source[x])); } return(destination); } //else throw new NotSupportedException("V8 Value"); } return(CefV8Value.CreateNull()); }
public static CefV8Value ConvertToJsValue(object?value) { if (value is null) { return(CefV8Value.CreateNull()); } return(value switch { CefV8Value v => v, string s => CefV8Value.CreateString(s), bool b => CefV8Value.CreateBool(b), Exception ex => MakeJsRejection(ex), _ => throw new NotImplementedException() });
private void BasicUpdateObject(CefV8Value res, bool?readOnly = null) { if (res == null) { return; } SetAttribute(res, NeutroniumConstants.ObjectId, CefV8Value.CreateUInt(_Count++)); if (!readOnly.HasValue) { return; } SetAttribute(res, NeutroniumConstants.ReadOnlyFlag, CefV8Value.CreateBool(readOnly.Value)); }
public static CefV8Value CreateValue(object value) { if (value == null) { return(CefV8Value.CreateNull()); } if (value is bool) { return(CefV8Value.CreateBool((bool)value)); } if (value is double) { return(CefV8Value.CreateDouble((double)value)); } if (value is float) { return(CefV8Value.CreateDouble((double)(float)value)); } if (value is int) { return(CefV8Value.CreateInt((int)value)); } var s = value as string; if (s != null) { return(CefV8Value.CreateString(s)); } if (value is uint) { return(CefV8Value.CreateUInt((uint)value)); } var list = value as IList; if (list == null) { return(CefV8Value.CreateUndefined()); } var val = list; var arr = CefV8Value.CreateArray(val.Count); for (var i = 0; i < val.Count; i++) { arr.SetValue(i, CreateValue(val[i])); } return(arr); }
public static CefV8Value CreateValue(object value) { if (value == null) { return(CefV8Value.CreateNull()); } if (value is bool) { return(CefV8Value.CreateBool((bool)value)); } if (value is double) { return(CefV8Value.CreateDouble((double)value)); } if (value is float) { return(CefV8Value.CreateDouble((double)(float)value)); } if (value is int) { return(CefV8Value.CreateInt((int)value)); } if (value is string) { return(CefV8Value.CreateString((string)value)); } if (value is uint) { return(CefV8Value.CreateUInt((uint)value)); } if (value is IList) { IList val = (IList)value; var arr = CefV8Value.CreateArray(val.Count); for (int i = 0; i < val.Count; i++) { arr.SetValue(i, CreateValue(val[i])); } return(arr); } return(CefV8Value.CreateUndefined()); }
private CefV8Value InvokeMethod(MethodInfo method, List <object> args, Type type) { if (method != null) { if (type == typeof(bool)) { return(CefV8Value.CreateBool((bool)method.Invoke(this, args.ToArray()))); } else if (type == typeof(DateTime)) { return(CefV8Value.CreateDate((DateTime)method.Invoke(this, args.ToArray()))); } else if (type == typeof(double)) { return(CefV8Value.CreateDouble((double)method.Invoke(this, args.ToArray()))); } else if (type == typeof(int)) { return(CefV8Value.CreateInt((int)method.Invoke(this, args.ToArray()))); } else if (type == typeof(string)) { return(CefV8Value.CreateString((string)method.Invoke(this, args.ToArray()))); } else if (type == typeof(uint)) { return(CefV8Value.CreateUInt((uint)method.Invoke(this, args.ToArray()))); } else if (type == typeof(string[]) || type == typeof(int[]) || type == typeof(double[]) || type == typeof(DateTime[]) || type == typeof(bool[]) || type == typeof(uint[]) || type == typeof(Enum[])) { return(Extension.ConvertToV8Value(method.Invoke(this, args.ToArray()))); } } return(null); }
private CefV8Value InvokeContructor(ConstructorInfo constructor, List <object> args, Type type) { if (constructor != null) { if (type == typeof(bool)) { return(CefV8Value.CreateBool((bool)constructor.Invoke(args.ToArray()))); } else if (type == typeof(DateTime)) { return(CefV8Value.CreateDate((DateTime)constructor.Invoke(args.ToArray()))); } else if (type == typeof(double)) { return(CefV8Value.CreateDouble((double)constructor.Invoke(args.ToArray()))); } else if (type == typeof(int)) { return(CefV8Value.CreateInt((int)constructor.Invoke(args.ToArray()))); } else if (type == typeof(string)) { return(CefV8Value.CreateString((string)constructor.Invoke(args.ToArray()))); } else if (type == typeof(uint)) { return(CefV8Value.CreateUInt((uint)constructor.Invoke(args.ToArray()))); } else if (type == typeof(string[]) || type == typeof(int[]) || type == typeof(double[]) || type == typeof(DateTime[]) || type == typeof(bool[]) || type == typeof(uint[]) || type == typeof(Enum[])) { return(Extension.ConvertToV8Value(constructor.Invoke(args.ToArray()))); } } return(null); }
static CefV8_Factory() { Register <string>((source) => CefV8Value.CreateString(source)); Register <Int64>((source) => CefV8Value.CreateDouble((double)source)); Register <UInt64>((source) => CefV8Value.CreateDouble((double)source)); Register <float>((source) => CefV8Value.CreateDouble((double)source)); Register <Int32>((source) => CefV8Value.CreateInt(source)); Register <Int16>((source) => CefV8Value.CreateInt((int)source)); Register <UInt32>((source) => CefV8Value.CreateUInt(source)); Register <UInt16>((source) => CefV8Value.CreateUInt((UInt32)source)); //check two way and convertion back Register <char>((source) => CefV8Value.CreateString(new StringBuilder().Append(source).ToString())); Register <double>((source) => CefV8Value.CreateDouble(source)); Register <decimal>((source) => CefV8Value.CreateDouble((double)source)); Register <bool>((source) => CefV8Value.CreateBool(source)); Register <DateTime>((source) => CefV8Value.CreateDate(source)); }
public static CefV8Value ToCef(object nativeObject, Type type) { if (nativeObject == null) { if (type != null && type == typeof(void)) { return(CefV8Value.CreateUndefined()); } return(CefV8Value.CreateNull()); } if (nativeObject is bool) { return(CefV8Value.CreateBool((bool)nativeObject)); } var stringValue = nativeObject as string; if (stringValue != null) { return(CefV8Value.CreateString(stringValue)); } if (nativeObject is int || nativeObject is byte || nativeObject is ushort || nativeObject is sbyte || nativeObject is short || nativeObject is char) { return(CefV8Value.CreateInt(Convert.ToInt32(nativeObject))); } if (nativeObject is double || nativeObject is decimal || nativeObject is long || nativeObject is uint || nativeObject is ulong || nativeObject is float) { return(CefV8Value.CreateDouble(Convert.ToDouble(nativeObject))); } var nativeArray = nativeObject as Array; if (nativeArray != null) { var cefArray = CefV8Value.CreateArray(nativeArray.Length); for (var i = 0; i < nativeArray.Length; i++) { var nativeArrayItem = nativeArray.GetValue(i); var cefArrayItem = ToCef(nativeArrayItem, null); cefArray.SetValue(i, cefArrayItem); } return(cefArray); } var jsonToken = nativeObject as JToken; if (jsonToken != null) { return(CefJsonValueConverter.ToCef(jsonToken)); } if (type == null) { type = nativeObject.GetType(); } var typeConverter = GetTypeConverter(type); if (typeConverter != null) { return(typeConverter.ToCef(nativeObject)); } throw new Exception(string.Format("Cannot convert '{0}' object from CLR to CEF.", type.FullName)); }
public object Deserialize(CefValue value, Type targetType, ObjectSerializer objectSerializer) { if (!CanHandle(value, targetType)) { throw new InvalidOperationException(); } var valueType = value.GetValueType(); if (valueType == CefValueType.String) { return(CefV8Value.CreateString(value.GetString())); } if (valueType == CefValueType.Int) { return(CefV8Value.CreateInt(value.GetInt())); } if (valueType == CefValueType.Double) { return(CefV8Value.CreateDouble(value.GetDouble())); } if (value.IsType(CefTypes.Int64)) { return(CefV8Value.CreateDouble(value.GetInt64())); } if (value.IsType(CefTypes.Time)) { return(CefV8Value.CreateDate(value.GetTime())); } if (valueType == CefValueType.Bool) { return(CefV8Value.CreateBool(value.GetBool())); } if (valueType == CefValueType.List) { using (var list = value.GetList()) { if (list.Count > 0) { var array = CefV8Value.CreateArray(list.Count); for (var i = 0; i < list.Count; i++) { using (var cefValue = list.GetValue(i)) { array.SetValue(i, (CefV8Value)objectSerializer.Deserialize(cefValue, typeof(CefV8Value))); } } return(array); } } } if (valueType == CefValueType.Dictionary) { using (var dictionary = value.GetDictionary()) using (var valDict = dictionary.GetDictionary(ObjectSerializer.ValuePropertyName)) { var typeId = dictionary.GetString(ObjectSerializer.TypeIdPropertyName); if (typeId == ObjectSerializer.DictionaryTypeId) { var obj = CefV8Value.CreateObject(); foreach (var key in valDict.GetKeys()) { obj.SetValue(key, (CefV8Value)objectSerializer.Deserialize(valDict.GetValue(key), typeof(CefV8Value))); } return(obj); } else { var deserialized = objectSerializer.Deserialize(value, typeof(object)); if (deserialized is ObjectDescriptor descriptor) { return(new ObjectBinder(descriptor, objectSerializer, functionCallPromiseRegistry).BindToNew()); } } } } return(CefV8Value.CreateNull()); }
protected override bool Execute(string name, CefV8Value obj, CefV8Value[] arguments, out CefV8Value returnValue, out string exception) { if (name == _config.JSQueryFunction) { if (arguments.Length != 1 || !arguments[0].IsObject) { returnValue = null; exception = "Invalid arguments; expecting a single object"; return(true); } var arg = arguments[0]; var requestVal = arg.GetValue(CefMessageRouter.MemberRequest); if (requestVal == null || !requestVal.IsString) { returnValue = null; exception = "Invalid arguments; object member '" + CefMessageRouter.MemberRequest + "' is required and must " + "have type string"; return(true); } CefV8Value successVal = null; if (arg.HasValue(CefMessageRouter.MemberOnSuccess)) { successVal = arg.GetValue(CefMessageRouter.MemberOnSuccess); if (!successVal.IsFunction) { returnValue = null; exception = "Invalid arguments; object member '" + CefMessageRouter.MemberOnSuccess + "' must have type " + "function"; return(true); } } CefV8Value failureVal = null; if (arg.HasValue(CefMessageRouter.MemberOnFailure)) { failureVal = arg.GetValue(CefMessageRouter.MemberOnFailure); if (!failureVal.IsFunction) { returnValue = null; exception = "Invalid arguments; object member '" + CefMessageRouter.MemberOnFailure + "' must have type " + "function"; return(true); } } CefV8Value persistentVal = null; if (arg.HasValue(CefMessageRouter.MemberPersistent)) { persistentVal = arg.GetValue(CefMessageRouter.MemberPersistent); if (!persistentVal.IsBool) { returnValue = null; exception = "Invalid arguments; object member '" + CefMessageRouter.MemberPersistent + "' must have type " + "boolean"; return(true); } } var context = CefV8Context.GetCurrentContext(); var contextId = GetIDForContext(context); var frameId = context.GetFrame().Identifier; var persistent = (persistentVal != null && persistentVal.GetBoolValue()); var requestId = _router.SendQuery(context.GetBrowser(), frameId, contextId, requestVal.GetStringValue(), persistent, successVal, failureVal); returnValue = CefV8Value.CreateInt(requestId); exception = null; return(true); } else if (name == _config.JSCancelFunction) { if (arguments.Length != 1 || !arguments[0].IsInt) { returnValue = null; exception = "Invalid arguments; expecting a single integer"; return(true); } var result = false; var requestId = arguments[0].GetIntValue(); if (requestId != CefMessageRouter.ReservedId) { CefV8Context context = CefV8Context.GetCurrentContext(); var contextId = GetIDForContext(context); var frameId = context.GetFrame().Identifier; result = _router.SendCancel(context.GetBrowser(), frameId, contextId, requestId); } returnValue = CefV8Value.CreateBool(result); exception = null; return(true); } returnValue = null; exception = null; return(false); }
/// <summary> /// Handle execution of the function identified by |name|. |object| is the /// receiver ('this' object) of the function. |arguments| is the list of /// arguments passed to the function. If execution succeeds set |retval| to the /// function return value. If execution fails set |exception| to the exception /// that will be thrown. Return true if execution was handled. /// </summary> /// <param name="name">The name of the function to execute.</param> /// <param name="obj">The receiver ('this' object) of the function.</param> /// <param name="arguments">The list of arguments passed to the function</param> /// <param name="returnValue">If execution succeeds set |retval| to the function return value.</param> /// <param name="exception">If execution fails set |exception| to the exception that will be thrown.</param> /// <returns>Return true if execution was handled.</returns> protected override bool Execute(string name, CefV8Value obj, CefV8Value[] arguments, out CefV8Value returnValue, out string exception) { if (string.IsNullOrEmpty(name)) { returnValue = CefV8Value.CreateUndefined(); exception = "Unknown event name"; return(false); } exception = null; returnValue = null; try { switch (name) { case MethodNameAddListener: case MethodNameRemoveListener: { if (arguments == null || arguments.Length != 1 || !arguments[0].IsFunction) { exception = "Expected a callback as the only argument"; } else { var context = CefV8Context.GetCurrentContext(); // TODO should this be disposed? var v8Callback = arguments[0]; switch (name) { case MethodNameAddListener: _plugin.AddEventListener(context, _eventName, v8Callback); break; case MethodNameRemoveListener: _plugin.RemoveEventListener(context, _eventName, v8Callback); break; } return(true); } break; } case MethodNameHasListener: { if (arguments == null || arguments.Length != 1 || !arguments[0].IsFunction) { exception = "Expected a callback as the only argument"; } else { var v8Callback = arguments[0]; var hasListener = _plugin.HasEventListener(_eventName, v8Callback); returnValue = CefV8Value.CreateBool(hasListener); return(true); } break; } case MethodNameHasListeners: { var hasListener = _plugin.HasEventListeners(_eventName); returnValue = CefV8Value.CreateBool(hasListener); return(true); } } } catch (Exception ex) { Logger.Error("Execution of plugin event method {0} {1} {2} failed: {3}", _plugin.Descriptor.PluginId, _eventName, name, ex); exception = ex.Message; } returnValue = CefV8Value.CreateUndefined(); return(false); }
public static CefV8Value ToCef(JToken jsonToken) { switch (jsonToken.Type) { case JTokenType.Object: { var jObject = (JObject)jsonToken; var plainObject = CefV8Value.CreateObject(null); foreach (var jsonProperty in jObject.Properties()) { plainObject.SetValue(jsonProperty.Name, ToCef(jsonProperty.Value), CefV8PropertyAttribute.None); } return(plainObject); } case JTokenType.Array: { var jArray = (JArray)jsonToken; var arrayValue = CefV8Value.CreateArray(jArray.Count); for (var i = 0; i < jArray.Count; i++) { arrayValue.SetValue(i, ToCef(jArray[i])); } return(arrayValue); } case JTokenType.Integer: { var jsonValue = (JValue)jsonToken; if (jsonValue.Value is long) { return(CefV8Value.CreateDouble((double)jsonToken)); } return(CefV8Value.CreateInt((int)jsonToken)); } case JTokenType.Float: return(CefV8Value.CreateDouble((double)jsonToken)); case JTokenType.Guid: case JTokenType.Uri: case JTokenType.String: return(CefV8Value.CreateString((string)jsonToken)); case JTokenType.Boolean: return(CefV8Value.CreateBool((bool)jsonToken)); case JTokenType.Null: return(CefV8Value.CreateNull()); case JTokenType.Undefined: return(CefV8Value.CreateUndefined()); case JTokenType.Date: return(CefV8Value.CreateDate((DateTime)jsonToken)); case JTokenType.Raw: case JTokenType.Bytes: case JTokenType.TimeSpan: case JTokenType.Property: case JTokenType.Comment: case JTokenType.Constructor: case JTokenType.None: throw new NotSupportedException(); default: throw new ArgumentOutOfRangeException(); } }
public IJavascriptObject CreateBool(bool value) { return(new CefV8_JavascriptObject(CefV8Value.CreateBool(value))); }
public CefV8Value AsV8Value() { CefV8Value result = null; if (this.Value is IList) { var v = (IList)this.Value; result = CefV8Value.CreateArray(v.Count); for (var i = 0; i < v.Count; i++) { result.SetValue(i, new JSValue(v[i]).AsV8Value()); } } else if (this.Value is Boolean) { result = CefV8Value.CreateBool((Boolean)this.Value); } else if (this.Value is DateTime) { result = CefV8Value.CreateDate((DateTime)this.Value); } else if (this.Value is Single || this.Value is Double || this.Value is Decimal || this.Value is UInt64 || this.Value is Int64) { result = CefV8Value.CreateDouble((Double)this.Value); } else if (this.Value is CefV8Handler) { result = CefV8Value.CreateFunction(null, (CefV8Handler)this.Value); } else if (this.Value is SByte || this.Value is Int16 || this.Value is Int32) { result = CefV8Value.CreateInt((Int32)this.Value); } else if (this.Value == null) { result = CefV8Value.CreateNull(); } else if (this.Value is IDictionary) { var v = (IDictionary)this.Value; Debug.Assert(v.Keys.Count == v.Values.Count); var vKeys = new String[v.Keys.Count]; var vValues = new CefV8Value[v.Values.Count]; result = CefV8Value.CreateObject(null); for (var i = 0; i < vKeys.Length; i++) { result.SetValue(vKeys[i], new JSValue(vValues[i]).AsV8Value(), CefV8PropertyAttribute.None); } } else if (this.Value is String) { result = CefV8Value.CreateString((String)this.Value); } else if (this.Value is Byte || this.Value is UInt16 || this.Value is UInt32) { result = CefV8Value.CreateUInt((UInt32)this.Value); } if (result == null) { result = CefV8Value.CreateUndefined(); } return(result); }
private static ICefV8Value CreateBoolValue(bool b) { return(new CefV8ValueImpl(CefV8Value.CreateBool(b))); }
protected override bool Execute(string name, CefV8Value obj, CefV8Value[] arguments, out CefV8Value returnValue, out string exception) { try { if (name == "Log") { var message = arguments[0].GetStringValue(); #if DIAGNOSTICS Cef.Logger.Info(LogTarget.Default, message); #endif returnValue = null; } else if (name == "ReturnVoid") { returnValue = null; } else if (name == "ReturnVoidAndDisposeThis") { returnValue = null; if (obj != null) { obj.Dispose(); obj = null; } } else if (name == "ReturnUndefined") { returnValue = CefV8Value.CreateUndefined(); } else if (name == "ReturnNull") { returnValue = CefV8Value.CreateNull(); } else if (name == "ReturnBool") { returnValue = CefV8Value.CreateBool(true); } else if (name == "ReturnInt") { returnValue = CefV8Value.CreateInt(12345678); } else if (name == "ReturnDouble") { returnValue = CefV8Value.CreateDouble(1234.5678); } else if (name == "ReturnDate") { returnValue = CefV8Value.CreateDate(DateTime.UtcNow); } else if (name == "ReturnString") { returnValue = CefV8Value.CreateString("Some string, passed to CEF!"); } else if (name == "ReturnArray") { var array = CefV8Value.CreateArray(3); array.SetValue(0, CefV8Value.CreateInt(123)); array.SetValue(1, CefV8Value.CreateString("hello!")); array.SetValue(2, CefV8Value.CreateBool(false)); returnValue = array; } else if (name == "ReturnObject") { var obj1 = CefV8Value.CreateObject(); obj1.SetValue("index", CefV8Value.CreateInt(123)); obj1.SetValue("reply", CefV8Value.CreateString("hello!")); obj1.SetValue("success", CefV8Value.CreateBool(false)); returnValue = obj1; } else if (name == "ReturnComplexArray") { var obj1 = CefV8Value.CreateObject(); obj1.SetValue("index", CefV8Value.CreateInt(123)); obj1.SetValue("reply", CefV8Value.CreateString("hello!")); obj1.SetValue("success", CefV8Value.CreateBool(false)); var array = CefV8Value.CreateArray(5); array.SetValue(0, CefV8Value.CreateInt(123)); array.SetValue(1, CefV8Value.CreateString("hello!")); array.SetValue(2, CefV8Value.CreateBool(false)); array.SetValue(3, obj1); array.SetValue(4, CefV8Value.CreateString("hello2!")); obj1 = CefV8Value.CreateObject(); obj1.SetValue("index", CefV8Value.CreateInt(123)); obj1.SetValue("reply", CefV8Value.CreateString("hello!")); obj1.SetValue("success", CefV8Value.CreateBool(false)); var obj2 = CefV8Value.CreateObject(); obj2.SetValue("i'm still", CefV8Value.CreateString("alive")); obj1.SetValue("inner", obj2); array.SetValue(5, obj1); returnValue = array; } else if (name == "ReturnComplexObject") { var obj1 = CefV8Value.CreateObject(); obj1.SetValue("index", CefV8Value.CreateInt(123)); obj1.SetValue("reply", CefV8Value.CreateString("hello!")); obj1.SetValue("success", CefV8Value.CreateBool(false)); var obj2 = CefV8Value.CreateObject(); obj2.SetValue("i'm still", CefV8Value.CreateString("alive")); obj1.SetValue("inner", obj2); obj2.Dispose(); // force to dispose object wrapper and underlying v8 persistent handle. // note, that obj2 will passed in obj before, but it anyway safe to destroy obj2 handle, // 'cause v8 api internally always open handles. returnValue = obj1; } else if (name == "SubtractIntImplicit") { var a = arguments[0].GetIntValue(); var b = arguments[1].GetIntValue(); returnValue = CefV8Value.CreateInt(a - b); } else if (name == "SubtractIntExplicit") { if (!arguments[0].IsInt) { throw new ArgumentException("arg0"); } var a = arguments[0].GetIntValue(); if (!arguments[1].IsInt) { throw new ArgumentException("arg1"); } var b = arguments[1].GetIntValue(); returnValue = CefV8Value.CreateInt(a - b); } else if (name == "Dump") { returnValue = CefV8Value.CreateString(Dump(arguments)); } else if (name == "get_PrivateWorkingSet") { var result = Process.GetCurrentProcess().PrivateMemorySize64 / (1024.0 * 1024.0); returnValue = CefV8Value.CreateDouble(result); } else if (name == "leakTestV8Func") { var handler = new TestV8Handler(); for (var i = 0; i < 100000; i++) { var x = CefV8Value.CreateFunction("LeakTest", handler); x.Dispose(); } returnValue = CefV8Value.CreateBool(true); } else { returnValue = null; exception = null; return(false); } exception = null; return(true); } catch (Exception ex) { returnValue = null; exception = ex.ToString(); return(true); } }