Esempio n. 1
0
        public static string GetString(JSContext ctx, JSValue val)
        {
            size_t len;
            var    pstr = JSApi.JS_ToCStringLen(ctx, out len, val);

            if (pstr == IntPtr.Zero)
            {
                return(null);
            }

            var str = JSApi.GetString(ctx, pstr, len);

            JSApi.JS_FreeCString(ctx, pstr);
            return(str);
        }
Esempio n. 2
0
        public unsafe string GetString(JSValue jsValue)
        {
            size_t len;
            var    ptr = JSApi.JS_ToCStringLen(this, out len, jsValue);

            if (ptr != IntPtr.Zero)
            {
                try
                {
                    if (len > 0)
                    {
                        var str_ = Encoding.UTF8.GetString((byte *)ptr.ToPointer(), len);
                        return(str_);
                    }
                }
                finally
                {
                    JSApi.JS_FreeCString(this, ptr);
                }
            }

            return(null);
        }