JavaScript 中所有可能的错误类型的列表?
List of all possible error types in JavaScript?
ECMAScript 规范定义的所有 可能错误是否有任何测试suite/list?我目前正在编写一个 JavaScript 运行时,我想要一些奇怪的错误,所以我需要从引擎中解析它们并进行相应的处理。
如果重要的话,引擎是 Graal.jS。
问候 - Yush。
Is there any list of all possible errors defined by the ECMAScript spec?
当然,可能的错误类型列表在 ECMAScript 规范中。但您似乎只对 SyntaxError
特别感兴趣。
Is there any list of all possible syntax errors in JavaScript?
没有。 ECMAScript 规范不强制要求为语法错误提供任何特定的错误消息。任何引擎都可以自带,也可以实现语法扩展。
The engine is Graal.jS, if that matters.
是的,这很重要。 Graal.js 自己实现了一些 syntax extensions. As for the list of possible parser error messages, you probably best look into the source code of the parser。
这是我从提到的文件中提取的错误列表(用正则表达式 /(?<=throw error\().*?(?=,[^,]*\);)/g
弄脏了):
ECMAErrors.getMessage("syntax.error.redeclare.variable", varNode.getName().getName())
AbstractParser.message("arguments.in.field.initializer")
AbstractParser.message(MESSAGE_INVALID_LVALUE)
AbstractParser.message(MESSAGE_INVALID_LVALUE)
AbstractParser.message(MESSAGE_INVALID_LVALUE)
AbstractParser.message(MESSAGE_INVALID_LVALUE)
String.format("unexpected node in AssignmentPattern: %s"
String.format("nullish coalescing operator cannot immediately contain, or be contained within
AbstractParser.message("use.strict.non.simple.param")
AbstractParser.message(MESSAGE_EXPECTED_STMT, "function declaration")
AbstractParser.message(MESSAGE_EXPECTED_STMT, "let declaration")
AbstractParser.message(MESSAGE_EXPECTED_STMT, "const declaration")
AbstractParser.message(MESSAGE_EXPECTED_STMT, "class declaration")
AbstractParser.message(MESSAGE_EXPECTED_STMT, "async function declaration")
AbstractParser.message("invalid.private.ident")
AbstractParser.message("multiple.constructors")
AbstractParser.message("invalid.private.ident")
AbstractParser.message("unexpected.token"
AbstractParser.message("invalid.private.ident")
ECMAErrors.getMessage("syntax.error.redeclare.variable", classElement.getPrivateName())
AbstractParser.message("invalid.private.ident")
AbstractParser.message("generator.constructor")
AbstractParser.message("accessor.constructor")
AbstractParser.message("async.constructor")
AbstractParser.message("static.prototype.method")
AbstractParser.message("private.constructor.method")
AbstractParser.message("constructor.field")
AbstractParser.message("static.prototype.field")
AbstractParser.message(MESSAGE_ESCAPED_KEYWORD, ident.getName())
expectMessage(IDENT, ident.getToken())
AbstractParser.message(MESSAGE_ESCAPED_KEYWORD, ident.getName())
expectMessage(IDENT, ident.getToken())
AbstractParser.message(MESSAGE_ESCAPED_KEYWORD, ident.getName())
AbstractParser.message("strict.name", ident.getName(), contextString)
AbstractParser.message("missing.destructuring.assignment")
AbstractParser.message("missing.const.assignment"
ECMAErrors.getMessage("syntax.error.redeclare.variable", name)
AbstractParser.message(MESSAGE_INVALID_LVALUE)
"Rest element must be last"
"Unexpected element after rest element"
AbstractParser.message(MESSAGE_INVALID_LVALUE)
"Unexpected element after rest element"
"Expected a valid binding identifier"
"Expected a valid binding identifier"
String.format("unexpected node in BindingPattern: %s"
AbstractParser.message("invalid.for.await.of")
AbstractParser.message("missing.const.assignment"
AbstractParser.message("missing.destructuring.assignment")
AbstractParser.message("for.each.without.in")
AbstractParser.message("many.vars.in.for.in.loop", isForOf || isForAwaitOf ? "of" : "in")
AbstractParser.message("for.in.loop.initializer", isForOf || isForAwaitOf ? "of" : "in")
AbstractParser.message("not.lvalue.for.in.loop", isForOf || isForAwaitOf ? "of" : "in")
AbstractParser.message("undefined.label", ident.getName())
AbstractParser.message("illegal.continue.stmt")
AbstractParser.message("undefined.label", ident.getName())
AbstractParser.message("illegal.break.stmt")
AbstractParser.message("unexpected.token"
AbstractParser.message("strict.no.with")
AbstractParser.message("duplicate.label", ident.getName())
AbstractParser.message(MESSAGE_EXPECTED_OPERAND
AbstractParser.message("missing.catch.or.finally")
AbstractParser.message("strict.no.nonoctaldecimal")
AbstractParser.message("strict.no.octal")
AbstractParser.message(MESSAGE_EXPECTED_OPERAND
AbstractParser.message("expected.comma"
AbstractParser.message("expected.property.id"
AbstractParser.message("expected.comma"
AbstractParser.message("multiple.proto.key")
AbstractParser.message(MESSAGE_PROPERTY_REDEFINITON, property.getKeyName())
AbstractParser.message(MESSAGE_PROPERTY_REDEFINITON, property.getKeyName())
AbstractParser.message(MESSAGE_PROPERTY_REDEFINITON, property.getKeyName())
AbstractParser.message(MESSAGE_PROPERTY_REDEFINITON, property.getKeyName())
AbstractParser.message("strict.no.nonoctaldecimal")
AbstractParser.message("strict.no.octal")
AbstractParser.message("expected.target")
AbstractParser.message(MESSAGE_EXPECTED_OPERAND, IMPORT.getName())
AbstractParser.message("unexpected.token"
AbstractParser.message("invalid.super")
AbstractParser.message("unexpected.import.meta")
AbstractParser.message("unexpected.ident", meta)
AbstractParser.message(MESSAGE_EXPECTED_OPERAND, IMPORT.getName())
AbstractParser.message(MESSAGE_EXPECTED_STMT, "generator function declaration")
JSErrorType.SyntaxError, AbstractParser.message("strict.no.func.decl.here")
JSErrorType.SyntaxError, AbstractParser.message("no.func.decl.here")
AbstractParser.message("strict.param.redefinition", duplicateParameter.getName())
AbstractParser.message("unexpected.token"
AbstractParser.message("unexpected.token"
AbstractParser.message("strict.cant.delete.ident", ident.getName())
AbstractParser.message("strict.cant.delete.private")
AbstractParser.message(MESSAGE_INVALID_ARROW_PARAMETER)
AbstractParser.message(MESSAGE_INVALID_ARROW_PARAMETER)
AbstractParser.message("expected.arrow.parameter")
AbstractParser.message(MESSAGE_INVALID_ARROW_PARAMETER)
AbstractParser.message(MESSAGE_INVALID_ARROW_PARAMETER)
AbstractParser.message(MESSAGE_INVALID_ARROW_PARAMETER)
AbstractParser.message(MESSAGE_INVALID_ARROW_PARAMETER)
AbstractParser.message(MESSAGE_INVALID_ARROW_PARAMETER)
AbstractParser.message("unterminated.template.expression")
ECMAErrors.getMessage("syntax.error.redeclare.variable", ident.getName())
AbstractParser.message("duplicate.import.assertion", assertionKey)
AbstractParser.message("expected.binding.identifier")
AbstractParser.message("invalid.export")
expectMessage(IDENT, reservedWordToken)
AbstractParser.message("new.target.in.function")
ECMAScript 规范定义的所有 可能错误是否有任何测试suite/list?我目前正在编写一个 JavaScript 运行时,我想要一些奇怪的错误,所以我需要从引擎中解析它们并进行相应的处理。
如果重要的话,引擎是 Graal.jS。
问候 - Yush。
Is there any list of all possible errors defined by the ECMAScript spec?
当然,可能的错误类型列表在 ECMAScript 规范中。但您似乎只对 SyntaxError
特别感兴趣。
Is there any list of all possible syntax errors in JavaScript?
没有。 ECMAScript 规范不强制要求为语法错误提供任何特定的错误消息。任何引擎都可以自带,也可以实现语法扩展。
The engine is Graal.jS, if that matters.
是的,这很重要。 Graal.js 自己实现了一些 syntax extensions. As for the list of possible parser error messages, you probably best look into the source code of the parser。
这是我从提到的文件中提取的错误列表(用正则表达式 /(?<=throw error\().*?(?=,[^,]*\);)/g
弄脏了):
ECMAErrors.getMessage("syntax.error.redeclare.variable", varNode.getName().getName())
AbstractParser.message("arguments.in.field.initializer")
AbstractParser.message(MESSAGE_INVALID_LVALUE)
AbstractParser.message(MESSAGE_INVALID_LVALUE)
AbstractParser.message(MESSAGE_INVALID_LVALUE)
AbstractParser.message(MESSAGE_INVALID_LVALUE)
String.format("unexpected node in AssignmentPattern: %s"
String.format("nullish coalescing operator cannot immediately contain, or be contained within
AbstractParser.message("use.strict.non.simple.param")
AbstractParser.message(MESSAGE_EXPECTED_STMT, "function declaration")
AbstractParser.message(MESSAGE_EXPECTED_STMT, "let declaration")
AbstractParser.message(MESSAGE_EXPECTED_STMT, "const declaration")
AbstractParser.message(MESSAGE_EXPECTED_STMT, "class declaration")
AbstractParser.message(MESSAGE_EXPECTED_STMT, "async function declaration")
AbstractParser.message("invalid.private.ident")
AbstractParser.message("multiple.constructors")
AbstractParser.message("invalid.private.ident")
AbstractParser.message("unexpected.token"
AbstractParser.message("invalid.private.ident")
ECMAErrors.getMessage("syntax.error.redeclare.variable", classElement.getPrivateName())
AbstractParser.message("invalid.private.ident")
AbstractParser.message("generator.constructor")
AbstractParser.message("accessor.constructor")
AbstractParser.message("async.constructor")
AbstractParser.message("static.prototype.method")
AbstractParser.message("private.constructor.method")
AbstractParser.message("constructor.field")
AbstractParser.message("static.prototype.field")
AbstractParser.message(MESSAGE_ESCAPED_KEYWORD, ident.getName())
expectMessage(IDENT, ident.getToken())
AbstractParser.message(MESSAGE_ESCAPED_KEYWORD, ident.getName())
expectMessage(IDENT, ident.getToken())
AbstractParser.message(MESSAGE_ESCAPED_KEYWORD, ident.getName())
AbstractParser.message("strict.name", ident.getName(), contextString)
AbstractParser.message("missing.destructuring.assignment")
AbstractParser.message("missing.const.assignment"
ECMAErrors.getMessage("syntax.error.redeclare.variable", name)
AbstractParser.message(MESSAGE_INVALID_LVALUE)
"Rest element must be last"
"Unexpected element after rest element"
AbstractParser.message(MESSAGE_INVALID_LVALUE)
"Unexpected element after rest element"
"Expected a valid binding identifier"
"Expected a valid binding identifier"
String.format("unexpected node in BindingPattern: %s"
AbstractParser.message("invalid.for.await.of")
AbstractParser.message("missing.const.assignment"
AbstractParser.message("missing.destructuring.assignment")
AbstractParser.message("for.each.without.in")
AbstractParser.message("many.vars.in.for.in.loop", isForOf || isForAwaitOf ? "of" : "in")
AbstractParser.message("for.in.loop.initializer", isForOf || isForAwaitOf ? "of" : "in")
AbstractParser.message("not.lvalue.for.in.loop", isForOf || isForAwaitOf ? "of" : "in")
AbstractParser.message("undefined.label", ident.getName())
AbstractParser.message("illegal.continue.stmt")
AbstractParser.message("undefined.label", ident.getName())
AbstractParser.message("illegal.break.stmt")
AbstractParser.message("unexpected.token"
AbstractParser.message("strict.no.with")
AbstractParser.message("duplicate.label", ident.getName())
AbstractParser.message(MESSAGE_EXPECTED_OPERAND
AbstractParser.message("missing.catch.or.finally")
AbstractParser.message("strict.no.nonoctaldecimal")
AbstractParser.message("strict.no.octal")
AbstractParser.message(MESSAGE_EXPECTED_OPERAND
AbstractParser.message("expected.comma"
AbstractParser.message("expected.property.id"
AbstractParser.message("expected.comma"
AbstractParser.message("multiple.proto.key")
AbstractParser.message(MESSAGE_PROPERTY_REDEFINITON, property.getKeyName())
AbstractParser.message(MESSAGE_PROPERTY_REDEFINITON, property.getKeyName())
AbstractParser.message(MESSAGE_PROPERTY_REDEFINITON, property.getKeyName())
AbstractParser.message(MESSAGE_PROPERTY_REDEFINITON, property.getKeyName())
AbstractParser.message("strict.no.nonoctaldecimal")
AbstractParser.message("strict.no.octal")
AbstractParser.message("expected.target")
AbstractParser.message(MESSAGE_EXPECTED_OPERAND, IMPORT.getName())
AbstractParser.message("unexpected.token"
AbstractParser.message("invalid.super")
AbstractParser.message("unexpected.import.meta")
AbstractParser.message("unexpected.ident", meta)
AbstractParser.message(MESSAGE_EXPECTED_OPERAND, IMPORT.getName())
AbstractParser.message(MESSAGE_EXPECTED_STMT, "generator function declaration")
JSErrorType.SyntaxError, AbstractParser.message("strict.no.func.decl.here")
JSErrorType.SyntaxError, AbstractParser.message("no.func.decl.here")
AbstractParser.message("strict.param.redefinition", duplicateParameter.getName())
AbstractParser.message("unexpected.token"
AbstractParser.message("unexpected.token"
AbstractParser.message("strict.cant.delete.ident", ident.getName())
AbstractParser.message("strict.cant.delete.private")
AbstractParser.message(MESSAGE_INVALID_ARROW_PARAMETER)
AbstractParser.message(MESSAGE_INVALID_ARROW_PARAMETER)
AbstractParser.message("expected.arrow.parameter")
AbstractParser.message(MESSAGE_INVALID_ARROW_PARAMETER)
AbstractParser.message(MESSAGE_INVALID_ARROW_PARAMETER)
AbstractParser.message(MESSAGE_INVALID_ARROW_PARAMETER)
AbstractParser.message(MESSAGE_INVALID_ARROW_PARAMETER)
AbstractParser.message(MESSAGE_INVALID_ARROW_PARAMETER)
AbstractParser.message("unterminated.template.expression")
ECMAErrors.getMessage("syntax.error.redeclare.variable", ident.getName())
AbstractParser.message("duplicate.import.assertion", assertionKey)
AbstractParser.message("expected.binding.identifier")
AbstractParser.message("invalid.export")
expectMessage(IDENT, reservedWordToken)
AbstractParser.message("new.target.in.function")