/// <summary> /// Registers a managed function as a property on the target object. /// The managed function is wrapped automatically by a marshalling proxy. /// </summary> /// <returns> /// The function's marshalling proxy that must be retained as long as the function is available to JS. /// </returns> public Managed.NativeToManagedProxy DefineFunction( JSContextPtr context, string name, Delegate @delegate, uint attrs = 0 ) { var wrapped = new Managed.NativeToManagedProxy(@delegate); JSAPI.DefineFunction( context, TransientSelf(), name, wrapped.WrappedMethod, wrapped.ArgumentCount, attrs ); return(wrapped); }
public Rooted <JS.Value> Get() { var root = new Rooted <JS.Value>(Context, JS.Value.Undefined); if (JSAPI.GetPendingException(Context, root)) { return(root); } root.Dispose(); return(null); }
/// <summary> /// Registers a managed JSNative as a property on the target object. /// The JSNative should return true on success and always set a result value. /// </summary> /// <returns> /// A pinning handle for the function that must be retained as long as the function is available to JS. /// </returns> public unsafe Managed.JSNativePin DefineFunction( JSContextPtr context, string name, JSNative call, uint nargs = 0, uint attrs = 0 ) { var wrapped = new Managed.JSNativePin(call); JSAPI.DefineFunction( context, TransientSelf(), name, wrapped.Target, nargs, attrs ); return(wrapped); }
public Rooted <JS.Value> GetProperty(JSContextPtr context, string name) { var result = new Rooted <JS.Value>(context); if (JSAPI.GetProperty(context, TransientSelf(), name, result)) { return(result); } result.Dispose(); return(null); }
public unsafe JSObjectPtr InvokeConstructor( JSContextPtr context, params JS.Value[] arguments ) { fixed(JSFunctionPtr *pThis = &this) fixed(JS.Value * pArgs = arguments) { var argsPtr = new JS.ValueArrayPtr((uint)arguments.Length, (IntPtr)pArgs); return(JSAPI.New(context, (JSObjectPtr *)pThis, ref argsPtr)); } }
public Exception GetManaged() { var root = new Rooted <JS.Value>(Context, JS.Value.Undefined); if (!JSAPI.GetPendingException(Context, root)) { return(null); } var error = new Spidermonkey.Managed.JSError(Context, root.Value.AsObject); return(error.ToException()); }
// Creates a copy internal static unsafe string ToManagedString(JSContextPtr context, JSStringPtr ptr) { uint length; if (JSAPI.StringHasLatin1Chars(ptr)) { var pChars = JSAPI.GetLatin1StringCharsAndLength( context, ref JS.AutoCheckCannotGC.Instance, ptr, out length ); var latin1 = Encoding.GetEncoding("ISO-8859-1"); return(new String((sbyte *)pChars, 0, (int)length, latin1)); } else { var pChars = JSAPI.GetTwoByteStringCharsAndLength( context, ref JS.AutoCheckCannotGC.Instance, ptr, out length ); return(new String((char *)pChars, 0, (int)length)); } }
void IRootable.RemoveRoot(JSContextPtr context, JSRootPtr root) { JSAPI.RemoveObjectRoot(context, root); }
// FIXME: I think this is right since JSFunction derives from JSObject bool IRootable.AddRoot(JSContextPtr context, JSRootPtr root) { return(JSAPI.AddObjectRoot(context, root)); }
public void Clear() { JSAPI.ClearPendingException(Context); }
bool IRootable.AddRoot(JSContextPtr context, JSRootPtr root) { return(JSAPI.AddNamedScriptRoot(context, root, null)); }
void IRootable.RemoveRoot(JSContextPtr context, JSRootPtr root) { JSAPI.RemoveStringRoot(context, root); }
public bool SetProperty(JSContextPtr context, string name, JSHandleValue value) { return(JSAPI.SetProperty(context, TransientSelf(), name, value)); }