protected override void Execute() { var message = BridgeMessage.Create(JS_OBJECT_MAPPING_MESSAGE); var args = JavaScriptValue.CreateObject(); foreach (var obj in jsbridge.RegisteredJavaScriptObjects) { if (obj.Value != null) { args.SetValue(obj.Key, obj.Value); } } message.Arguments.Add(MessageValue.CreateString(args.ToDefinition())); jsbridge.SendProcessMessage(frame, message); jsbridge.IsObjectsMapped = true; }
public static JavaScriptValue ToJSValue(this CefV8Value source) { if (source == null || !source.IsValid) { throw new ArgumentNullException(); } JavaScriptValue target; if (source.IsFunction) { var context = CefV8Context.GetEnteredContext(); var info = new JavaScriptRenderSideFunction(context, source); JavaScriptObjectRepository.RenderSideFunctions.Add(info); target = JavaScriptValue.CreateFunction(info); } else if (source.IsArray) { target = JavaScriptValue.CreateArray(); for (int i = 0; i < source.GetArrayLength(); i++) { var item = source.GetValue(i); if (item != null && item.IsValid) { target.AddArrayValue(item.ToJSValue()); } } } else if (source.IsObject) { target = JavaScriptValue.CreateObject(); foreach (var key in source.GetKeys()) { var item = source.GetValue(key); if (item != null && item.IsValid) { target.SetValue(key, item.ToJSValue()); } } } else if (source.IsBool) { target = JavaScriptValue.CreateBool(source.GetBoolValue()); } else if (source.IsDate) { target = JavaScriptValue.CreateDateTime(source.GetDateValue()); } else if (source.IsDouble) { target = JavaScriptValue.CreateNumber(source.GetDoubleValue()); } else if (source.IsInt) { target = JavaScriptValue.CreateNumber(source.GetIntValue()); } else if (source.IsUInt) { target = JavaScriptValue.CreateNumber(source.GetUIntValue()); } else if (source.IsString) { target = JavaScriptValue.CreateString(source.GetStringValue()); } else { target = JavaScriptValue.CreateNull(); } return(target); }