public static string GetJsString(IntPtr es, long v) { var strPtr = MBApi.jsToTempStringW(es, v); string str = Marshal.PtrToStringUni(strPtr); return(str); }
/// <summary> /// 转换到string /// </summary> /// <param name="jsExecState"></param> /// <returns></returns> public string ToString(IntPtr jsExecState) { IntPtr pStr = MBApi.jsToTempStringW(jsExecState, Value); if (pStr == IntPtr.Zero) { return(null); } return(Marshal.PtrToStringUni(pStr)); }
public static object ToValue(this long value, IntPtr es) { if (value == 0) { return(null); } jsType type = MBApi.jsTypeOf(value); switch (type) { case jsType.NULL: case jsType.UNDEFINED: return(null); case jsType.NUMBER: return(MBApi.jsToDouble(es, value)); case jsType.BOOLEAN: return(MBApi.jsToBoolean(es, value)); case jsType.STRING: return(MBApi.jsToTempStringW(es, value).ToStringW()); case jsType.FUNCTION: return(new JsFunc(new JsFuncWapper(value, es).Call)); case jsType.ARRAY: var len = MBApi.jsGetLength(es, value); var array = new object[len]; for (var i = 0; i < array.Length; i++) { array[i] = MBApi.jsGetAt(es, value, i).ToValue(es); } return(array); case jsType.OBJECT: var ptr = MBApi.jsGetKeys(es, value); var jskeys = (jsKeys)Marshal.PtrToStructure(ptr, typeof(jsKeys)); var keys = Utils.PtrToStringArray(jskeys.keys, jskeys.length); var exp = new ExpandoObject(); var map = (IDictionary <string, object>)exp; foreach (var k in keys) { map.Add(k, MBApi.jsGet(es, value, k).ToValue(es)); } return(exp); default: throw new NotSupportedException(); } }