示例#1
0
        public static unsafe Rooted <JS.Value> ManagedToNativeException(JSContextPtr cx, Exception managedException)
        {
            var errorRoot = NewError(cx, managedException.Message);
            var errorObj  = errorRoot.Value.AsObject;

            var existingStackRoot = new Rooted <JS.Value>(cx);

            JSAPI.GetProperty(
                cx, &errorObj, "stack", existingStackRoot
                );
            var existingStackText = existingStackRoot.Value.ToManagedString(cx);

            JSAPI.SetProperty(
                cx, &errorObj, "stack",
                new JSString(
                    cx,
                    managedException.StackTrace +
                    "\n//---- JS-to-native boundary ----//\n" +
                    existingStackText
                    )
                );

            if (managedException.InnerException != null)
            {
                var inner = ManagedToNativeException(cx, managedException.InnerException);

                JSAPI.SetProperty(cx, &errorObj, "innerException", inner);
            }

            return(errorRoot);
        }