private int GetOwnPropertyNamesImpl(JSContext cx, JSPropertyEnum **props, out int len, JSValue obj) { len = 0; *props = null; JSPropertyEnum[] names = null; int error; try { error = ((JSGetOwnPropertyNamesDelegate)_callbacks.get_own_property_names)(cx, out names, obj); if (error == 0) { if (names != null && names.Length > 0) { *props = (JSPropertyEnum *)js_malloc(cx, sizeof(JSPropertyEnum) * names.Length); if (props == null) { FreePropEnum(cx, names, props); error = -1; } else { len = names.Length; for (int i = 0; i < names.Length; i++) { *(*props + i) = names[i]; } } } } } catch (OutOfMemoryException) { FreePropEnum(cx, names, props); JS_ThrowOutOfMemory(cx); error = -1; } catch (Exception ex) { FreePropEnum(cx, names, props); Utils.ReportException(cx, ex); error = -1; } return(error); }
private static void FreePropEnum(JSContext ctx, JSPropertyEnum[] props, JSPropertyEnum **ptab) { if (*ptab != null) { IntPtr mem = new IntPtr(*ptab); * ptab = null; js_free(ctx, mem); } if (props == null) { return; } for (int i = 0; i < props.Length; i++) { JS_FreeAtom(ctx, props[i].atom); } }