{"record":{"id":"100b83bae8eaa582","repo":"babalae/better-genshin-impact","slug":"javascript-output","errorCode":null,"errorMessage":"JavaScript没有设置Output输出","messagePattern":"JavaScript没有设置Output输出","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"BetterGenshinImpact/GameTask/AutoArtifactSalvage/AutoArtifactSalvageTask.cs","lineNumber":485,"sourceCode":"                engine.Interrupt();\n            }\n            catch (Exception ex)\n            {\n                Console.WriteLine($\"中断失败: {ex.Message}\");\n            }\n        });\n        try\n        {\n            // 传入输入参数\n            engine.Script.ArtifactStat = artifact;\n\n            // 执行JavaScript代码\n            await Task.Run(() => engine.Execute(javaScript));\n\n            // 检查是否有输出\n            if (!engine.Script.propertyIsEnumerable(\"Output\"))\n            {\n                throw new InvalidOperationException(\"JavaScript没有设置Output输出\");\n            }\n\n            if (engine.Script.Output is not bool)\n            {\n                throw new InvalidOperationException(\"JavaScript的Output输出不是布尔类型\");\n            }\n\n            return (bool)engine.Script.Output;\n        }\n        catch (ScriptInterruptedException)\n        {\n            logger.LogWarning(\"脚本执行超出3秒限制，请使用正确的JS代码（JavaScript execution timeout!）\");\n            throw;\n        }\n        catch (ScriptEngineException ex)\n        {\n            throw new Exception($\"JavaScript execution error: {ex.Message}\", ex);\n        }","sourceCodeStart":467,"sourceCodeEnd":503,"githubUrl":"https://github.com/babalae/better-genshin-impact/blob/a7cb36712dcb409be610257d877fcea3597e9d6b/BetterGenshinImpact/GameTask/AutoArtifactSalvage/AutoArtifactSalvageTask.cs#L467-L503","documentation":"Thrown by IsMatchJavaScript after engine.Execute(javaScript) succeeds but engine.Script.propertyIsEnumerable('Output') returns false. ClearScript exposes host/global properties through engine.Script; the user's JS must assign a global 'Output' variable. Its absence means the script never set a result.","triggerScenarios":"User JS declared Output inside a function scope or as a const in a module (not global); JS threw before reaching the assignment (but Execute did not surface it); script used 'let Output' which ClearScript may not expose as enumerable; script assigned to a misspelled name (e.g. 'output').","commonSituations":"Custom artifact-filter JS authored without reading the Output contract; JS ported from Node where module-scope vars are global; ClearScript V8 flag differences (DisableGlobalMembers is set, so only explicit globals are visible).","solutions":["Ensure the JS sets a top-level 'var Output = ...;' or 'Output = ...;' (no let/const inside a block).","Confirm the assignment runs unconditionally on the last line, after all logic.","Test the JS in isolation with the same ArtifactStat input.","Document that Output must be a global boolean and provide a template script."],"exampleFix":"// before (user JS)\nfunction decide(a) { return a.level >= 20; }\n// (Output never set globally)\n// after\nfunction decide(a) { return a.level >= 20; }\nOutput = decide(ArtifactStat); // top-level global, boolean","handlingStrategy":"validation","validationCode":"bool HasGlobalOutput(string js) => Regex.IsMatch(js, @\"(^|[^\\w.])Output\\s*=\", RegexOptions.Multiline);","typeGuard":null,"tryCatchPattern":"try { return await IsMatchJavaScript(artifact, js, logger); }\ncatch (InvalidOperationException ex) when (ex.Message.Contains(\"Output\"))\n{ logger.LogError(\"JS 未设置全局 Output 布尔输出\"); throw; }","preventionTips":["Document that Output must be a top-level global boolean.","Provide a JS template that ends with 'Output = ...;'.","Lint the JS for a top-level Output assignment before executing."],"tags":["game-task","javascript","clearscript","configuration"],"backgroundTag":null,"analyzedSha":"a7cb36712dcb409be610257d877fcea3597e9d6b","analyzedAt":"2026-08-13T16:44:57.548Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}