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
                ));
 }
Exemple #2
0
        static JSCompileOptions()
        {
            GetElement = getElement;
            GetElementAttributeName = getElementAttributeName;
            GetIntroductionScript   = getIntroductionScript;

            DefaultVTable = new VTable {
                element = Marshal.GetFunctionPointerForDelegate(GetElement),
                elementAttributeName = Marshal.GetFunctionPointerForDelegate(GetElementAttributeName),
                introductionScript   = Marshal.GetFunctionPointerForDelegate(GetIntroductionScript),
            };

            pDefaultVTable = Marshal.AllocHGlobal(Marshal.SizeOf(DefaultVTable));
            Marshal.StructureToPtr(DefaultVTable, pDefaultVTable, false);

            Default = new JSCompileOptions();
        }
        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]);
                }
            }
        }