Ejemplo n.º 1
0
        public static unsafe bool EvaluateScript(
            JSContextPtr cx,
            JSHandleObject scope,
            string chars,
            string filename,
            uint lineno,
            JSMutableHandleValue rval
            )
        {
            fixed(char *pChars = chars)
            fixed(char *pFilename = filename)
            {
                byte *pFilenameBytes = null;

                if (filename != null)
                {
                    byte *temp = stackalloc byte[filename.Length + 1];
                    pFilenameBytes = temp;

                    Encoding.ASCII.GetBytes(
                        pFilename, filename.Length,
                        pFilenameBytes, filename.Length
                        );
                }

                return(EvaluateUCScript(
                           cx, scope,
                           (IntPtr)pChars, chars.Length,
                           (IntPtr)pFilenameBytes, lineno,
                           rval
                           ));
            }
        }
Ejemplo n.º 2
0
 public static unsafe bool SetProperty(
     JSContextPtr cx,
     JSHandleObject obj,
     string name,
     JSHandleValue vp
     ) {
     fixed(char *pName = name)
     return(SetUCProperty(cx, obj, (IntPtr)pName, (uint)name.Length, vp));
 }
Ejemplo n.º 3
0
        public Rooted <JS.Value> InvokeFunction(
            JSContextPtr context,
            JSHandleObject thisReference,
            params JS.Value[] arguments
            )
        {
            var thisValue = new JS.Value(this);

            return(thisValue.InvokeFunction(context, thisReference, arguments));
        }
Ejemplo n.º 4
0
 public static unsafe JSFunctionPtr DefineFunction(
     JSContextPtr cx,
     JSHandleObject obj,
     string name,
     JSNative call,
     uint nargs, uint attrs
     ) {
     fixed(char *pName = name)
     return(DefineUCFunction(
                cx, obj, (IntPtr)pName, (uint)name.Length, call, nargs, attrs
                ));
 }
Ejemplo n.º 5
0
 public static unsafe bool CompileScript(
     JSContextPtr cx,
     JSHandleObject obj,
     string chars,
     JSCompileOptions options,
     JSMutableHandleScript script
     ) {
     fixed(char *pChars = chars)
     return(CompileUCScript(
                cx, obj,
                (IntPtr)pChars, (uint)chars.Length,
                options,
                script
                ));
 }
Ejemplo n.º 6
0
        public static unsafe bool CompileFunction(
            JSContextPtr cx, JSHandleObject obj,
            string name,
            UInt32 nargs, string[] argnames,
            string chars,
            JSCompileOptions options,
            JSMutableHandleFunction fun
            )
        {
            if (argnames == null)
            {
                argnames = new string[0];
            }

            if (nargs != argnames.Length)
            {
                throw new ArgumentException("Wrong number of argument names", "nargs");
            }
            char **argNameBuffers = stackalloc char *[argnames.Length];

            for (int i = 0; i < argnames.Length; i++)
            {
                argNameBuffers[i] = (char *)Marshal.StringToHGlobalAnsi(argnames[i]);
            }

            try {
                fixed(char *pChars = chars)
                return(CompileUCFunction(
                           cx, obj,
                           name, nargs, (IntPtr)argNameBuffers,
                           (IntPtr)pChars, (uint)chars.Length,
                           options,
                           fun
                           ));
            } finally {
                for (int i = 0; i < argnames.Length; i++)
                {
                    Marshal.FreeHGlobal((IntPtr)argNameBuffers[i]);
                }
            }
        }
Ejemplo n.º 7
0
 unsafe static JSHandleObject() {
     fixed(JSObjectPtr *pZero = &ZeroPtr)
     Zero = new JSHandleObject(pZero);
 }