Commit 70e6ffcc authored by Maya Lekova's avatar Maya Lekova Committed by Commit Bot

Revert "[parser] Optimize directive parsing especially for preparser"

This reverts commit 9d34fa0c.

Reason for revert: Breaking test-parsing tests, see
https://ci.chromium.org/p/v8/builders/luci.v8.ci/V8%20Linux%20gcc%204.8/22942
https://ci.chromium.org/p/v8/builders/luci.v8.ci/V8%20Win64%20-%20msvc/5731

Original change's description:
> [parser] Optimize directive parsing especially for preparser
> 
> - Avoid allocating AstRawString in the preparser
> - Use fast LiteralEquals to compare the directive.
> 
> Bug: chromium:901250
> Change-Id: I178aca812f6c0ffa28d7f48b707316a5a99a2ac0
> Reviewed-on: https://chromium-review.googlesource.com/c/1314570
> Commit-Queue: Toon Verwaest <verwaest@chromium.org>
> Reviewed-by: Igor Sheludko <ishell@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#57217}

TBR=ishell@chromium.org,verwaest@chromium.org

Change-Id: I47381358c5a8e9c39fe2af6e72481ebfe9d74a55
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Bug: chromium:901250
Reviewed-on: https://chromium-review.googlesource.com/c/1314577Reviewed-by: 's avatarMaya Lekova <mslekova@chromium.org>
Commit-Queue: Maya Lekova <mslekova@chromium.org>
Cr-Commit-Position: refs/heads/master@{#57218}
parent 9d34fa0c
......@@ -235,6 +235,8 @@ class AstBigInt {
F(this_function, ".this_function") \
F(throw, "throw") \
F(undefined, "undefined") \
F(use_asm, "use asm") \
F(use_strict, "use strict") \
F(value, "value")
class AstStringConstants final {
......
......@@ -4589,25 +4589,16 @@ ParserBase<Impl>::ParseStatementList(StatementListT body,
DCHECK(!impl()->IsNull(body));
while (peek() == Token::STRING) {
bool use_strict = false;
bool use_asm = false;
while (peek() == Token::STRING && (scanner()->HasLineTerminatorAfterNext() ||
Token::IsAutoSemicolon(PeekAhead()))) {
const AstRawString* symbol = scanner()->NextSymbol(ast_value_factory_);
Scanner::Location token_loc = scanner()->peek_location();
if (scanner()->NextLiteralEquals("use strict")) {
use_strict = true;
} else if (scanner()->NextLiteralEquals("use asm")) {
use_asm = true;
}
StatementT stat = ParseStatementListItem();
body->Add(stat, zone_);
may_abort = false;
if (!impl()->IsStringLiteral(stat)) break;
if (use_strict) {
// The length of the token is used to distinguish between strings literals
// that evaluate equal to directives but contain either escape sequences
// (e.g., "use \x73trict") or line continuations (e.g., "use \(newline)
// strict").
if (symbol == ast_value_factory()->use_strict_string() &&
token_loc.end_pos - token_loc.beg_pos == sizeof("use strict") + 1) {
// Directive "use strict" (ES5 14.1).
RaiseLanguageMode(LanguageMode::kStrict);
if (!scope()->HasSimpleParameters()) {
......@@ -4619,7 +4610,8 @@ ParserBase<Impl>::ParseStatementList(StatementListT body,
"use strict");
return kLazyParsingComplete;
}
} else if (use_asm) {
} else if (symbol == ast_value_factory()->use_asm_string() &&
token_loc.end_pos - token_loc.beg_pos == sizeof("use asm") + 1) {
// Directive "use asm".
impl()->SetAsmModule();
} else {
......@@ -4628,6 +4620,9 @@ ParserBase<Impl>::ParseStatementList(StatementListT body,
// as appropriate. Ditto usages below.
RaiseLanguageMode(LanguageMode::kSloppy);
}
StatementT stat = ParseStatementListItem();
body->Add(stat, zone());
may_abort = false;
}
// Allocate a target stack to use for this set of source elements. This way,
......
......@@ -260,8 +260,9 @@ class Scanner {
Location(int b, int e) : beg_pos(b), end_pos(e) { }
Location() : beg_pos(0), end_pos(0) { }
int length() const { return end_pos - beg_pos; }
bool IsValid() const { return beg_pos >= 0 && end_pos >= beg_pos; }
bool IsValid() const {
return beg_pos >= 0 && end_pos >= beg_pos;
}
static Location invalid() { return Location(-1, -1); }
......@@ -365,20 +366,6 @@ class Scanner {
CurrentMatchesContextualEscaped(Token::LET);
}
template <size_t N>
bool NextLiteralEquals(const char (&s)[N]) {
DCHECK_EQ(Token::STRING, peek());
// The length of the token is used to make sure the literal equals without
// taking escape sequences (e.g., "use \x73trict") or line continuations
// (e.g., "use \(newline) strict") into account.
if (!is_next_literal_one_byte()) return false;
if (peek_location().length() != N + 1) return false;
Vector<const uint8_t> next = next_literal_one_byte_string();
const char* chars = reinterpret_cast<const char*>(next.start());
return next.length() == N - 1 && strncmp(s, chars, N - 1) == 0;
}
UnicodeCache* unicode_cache() const { return unicode_cache_; }
// Returns the location of the last seen octal literal.
......
// Copyright 2018 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.
function f([a]) {
"use strict";
}
*%(basename)s:6: SyntaxError: Illegal 'use strict' directive in function with non-simple parameter list
"use strict";
^^^^^^^^^^^^
SyntaxError: Illegal 'use strict' directive in function with non-simple parameter list
// Copyright 2018 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.
function f() {
'use strict'
in Number
}
f.arguments
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment