public static JS.Value ManagedToNative(JSContextPtr cx, object value) { if (value == null) { return(JS.Value.Null); } var s = value as string; if (s != null) { var pString = JSAPI.NewStringCopy(cx, s); return(new JS.Value(pString)); } var a = value as Array; if (a != null) { var va = new JS.ValueArray((uint)a.Length); for (int i = 0, l = a.Length; i < l; i++) { va.Elements[i] = ManagedToNative(cx, a.GetValue(i)); } JS.ValueArrayPtr vaPtr = va; var pArray = JSAPI.NewArrayObject(cx, ref vaPtr); return(new JS.Value(pArray)); } return((JS.Value)Activator.CreateInstance(typeof(JS.Value), value)); }
public static unsafe JSObjectPtr NewError( JSContextPtr cx, ref JS.ValueArrayPtr args ) { var errorPrototype = GetErrorPrototype(cx); var errorConstructor = GetConstructor(cx, &errorPrototype); return(New(cx, &errorConstructor, ref args)); }
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)); } }
private static Rooted <JS.Value> NewError(JSContextPtr cx, params object[] errorArguments) { var jsErrorArgs = new JS.ValueArray((uint)errorArguments.Length); for (int i = 0; i < errorArguments.Length; i++) { jsErrorArgs.Elements[i] = ManagedToNative(cx, errorArguments[i]); } JS.ValueArrayPtr vaPtr = jsErrorArgs; return(new Rooted <JS.Value>( cx, new JS.Value(JSAPI.NewError(cx, ref vaPtr)) )); }
private unsafe static JSObjectPtr CreateArrayImpl( JSContextPtr context, JS.Value[] contents, uint offset, uint count ) { if (count == 0xFFFFFFFF) { count = (uint)(contents.Length - offset); } if ( (count > (contents.Length - offset)) || (offset >= contents.Length) ) throw new ArgumentException("offset/count out of range"); fixed(JS.Value *pContents = &contents[offset]) { var valueArray = new JS.ValueArrayPtr(count, (IntPtr)pContents); return(JSAPI.NewArrayObject(context, ref valueArray)); } }
public JSArray(JSContextPtr context, ref JS.ValueArrayPtr contents) : this(context, JSAPI.NewArrayObject(context, ref contents)) { }