a56874d3eb
This CL implements early SyntaxErrors for regular expressions. Early errors are thrown when a malformed pattern is parsed, rather than when the code first runs. We do this by having the JS parser call into the regexp parser when a regexp pattern is found. Regexps are expected to be relatively rare, small, and cheap to parse - that's why we currently accept that the regexp parser does unnecessary work (e.g. creating the AST structures). If needed, we can optimize in the future. Ideas: - Split up the regexp parser to avoid useless work for syntax validation. - Preserve parser results to avoid reparsing later. Bug: v8:896 Change-Id: I3d1ec18c980ba94439576ac3764138552418b85d Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3106647 Commit-Queue: Jakob Gruber <jgruber@chromium.org> Reviewed-by: Leszek Swirski <leszeks@chromium.org> Reviewed-by: Patrick Thier <pthier@chromium.org> Cr-Commit-Position: refs/heads/main@{#76502}
13 lines
368 B
JavaScript
13 lines
368 B
JavaScript
// Copyright 2014 the V8 project authors. All rights reserved.
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
// found in the LICENSE file.
|
|
|
|
Error.prepareStackTrace = function (a,b) { return b; };
|
|
|
|
try {
|
|
eval("/(invalid regexp/;");
|
|
assertUnreachable();
|
|
} catch (e) {
|
|
assertEquals("[object global]", e.stack[0].getThis().toString());
|
|
}
|