我决定了解浏览器是如何处理代码中只有一行的脚本的,这一行是一个例外。
假设我们有这样的例外:
throw Error("custom error");按照规范,ecma262 ThrowStatement返回一个抛出类型的完成记录。执行脚本ScriptEvaluation时:
这就清楚地告诉我们,从ScriptEvaluation返回了一个具有抛出类型的完成记录。
但是ecma262规范并没有说明何时向控制台抛出错误。我需要帮助来了解什么规范是如何从ecma262拦截错误抛出的。
发布于 2019-11-26 05:00:05
您所看到的行为是在WHATWG HTML标准中指定的。
https://html.spec.whatwg.org/multipage/webappapis.html#calling-scripts
1. ...
2. ...
3. Otherwise, rethrow errors is false. Perform the following steps: 1. **Report the exception given by evaluationStatus.[[Value]] for script.**
2. Clean up after running script with settings.
3. Return evaluationStatus.
https://html.spec.whatwg.org/multipage/webappapis.html#runtime-script-errors-in-documents
当用户代理要报告异常E时,用户代理必须报告相关脚本的错误,其中包含脚本的资源中有问题的位置(行号和列号),使用脚本的设置对象指定的全局对象作为目标。如果在此之后仍未处理错误,则可能会将错误报告给开发人员控制台。
而且,ECMAScript实际上没有控制台,这是在https://console.spec.whatwg.org指定的
https://stackoverflow.com/questions/59031259
复制相似问题