예제 #1
0
        public static JSValue _DoFile(JSContext ctx, JSValue this_obj, int argc, JSValue[] argv)
        {
            if (argc < 1 || !argv[0].IsString())
            {
                return(JSApi.JS_ThrowInternalError(ctx, "path expected"));
            }
            var path = JSApi.GetString(ctx, argv[0]);

            if (string.IsNullOrEmpty(path))
            {
                return(JSApi.JS_ThrowInternalError(ctx, "invalid path"));
            }

            //TODO: use runtime.EvalFile instead

            var context      = ScriptEngine.GetContext(ctx);
            var runtime      = context.GetRuntime();
            var fileSystem   = runtime.GetFileSystem();
            var resolvedPath = runtime.ResolveFilePath("", path);

            if (resolvedPath == null)
            {
                return(JSApi.JS_ThrowInternalError(ctx, "file not found:" + path));
            }
            var source = fileSystem.ReadAllBytes(resolvedPath);

            return(ScriptRuntime.EvalSource(ctx, source, resolvedPath, true));
        }
예제 #2
0
        public object EvalSource(byte[] source, string fileName, Type returnType)
        {
            var jsValue = ScriptRuntime.EvalSource(_ctx, source, fileName, false);

            if (JSApi.JS_IsException(jsValue))
            {
                var ex = _ctx.GetExceptionString();
                throw new JSException(ex, fileName);
            }
            object retObject;

            Values.js_get_var(_ctx, jsValue, returnType, out retObject);
            JSApi.JS_FreeValue(_ctx, jsValue);
            return(retObject);
        }
예제 #3
0
        public void EvalSourceFree(byte[] source, string fileName, Action <JSContext, JSValue> onEvalReturn)
        {
            var jsValue = ScriptRuntime.EvalSource(_ctx, source, fileName, false);

            if (JSApi.JS_IsException(jsValue))
            {
                _ctx.print_exception();
            }
            else
            {
                onEvalReturn(_ctx, jsValue);
            }

            JSApi.JS_FreeValue(_ctx, jsValue);
        }