Commit Graph

486 Commits

Author SHA1 Message Date
verwaest
22cb3cba18 Allocate script scopes using a separate constructor
This avoids checking for outer_scope == nullptr in Scope::Scope

BUG=v8:5209

Review-Url: https://codereview.chromium.org/2266973002
Cr-Commit-Position: refs/heads/master@{#38812}
2016-08-23 10:09:40 +00:00
adamk
232a33602b [async functions] Disallow 'await' in arrow params inside async functions
The following code was previously accepted:

  async function f() {
    let g = (await) => {};
  }

But per the spec, using 'await' is disallowed in arrow parameters
by an early error rule (just as 'yield' is disallowed in arrow
params inside generators).

There was special logic in ParseUnaryExpression which seems to have been
there only to allow that case. Having removed it, we get a SyntaxError in
the right cases anyway when ParseUnaryExpression chokes on whatever
illegal token follows 'await' in the cases this code previously handled.

Also removes the unnecessary AsyncBindingPatternProduction enum value.

R=caitp@igalia.com, littledan@chromium.org
BUG=v8:4483

Review-Url: https://codereview.chromium.org/2258313002
Cr-Commit-Position: refs/heads/master@{#38802}
2016-08-22 19:03:35 +00:00
adamk
253d4e8464 Disallow 'await' in object literal shorthand position
Also lots of cleanup around the checking for 'await' as an identifier
throughout the parser and preparser.

R=caitp@igalia.com, littledan@chromium.org
BUG=v8:4483,v8:5298

Review-Url: https://codereview.chromium.org/2267493002
Cr-Commit-Position: refs/heads/master@{#38798}
2016-08-22 18:04:01 +00:00
marja
f9d6076115 Cleanup: Move ParseInfo to a separate file.
This makes us able to get rid of dependencies to parser.h from places
which only need the ParseInfo, and also gets rid of the curious Parser
<-> Compiler circular dependency.

Also IWYUd where necessary.

BUG=

Review-Url: https://codereview.chromium.org/2268513002
Cr-Commit-Position: refs/heads/master@{#38777}
2016-08-22 11:33:58 +00:00
gsathya
fc52e32361 [parser] Allow duplicate __proto__ keys in patterns
This patch subsumes CoverInitializedNameProduction to create an ObjectLiteralProduction which is now used to report the duplicate proto error as well.

This patch also changes ObjectLiteralChecker::CheckProperty
to record an ObjectLiteralProduction error instead of
bailing out immediately. Once we realize that we're in a
pattern, we rewind the error, otherwise we report the
error.

BUG=v8:5121

Review-Url: https://codereview.chromium.org/2255353002
Cr-Commit-Position: refs/heads/master@{#38764}
2016-08-20 01:01:51 +00:00
lpy
0c95efb7b7 Fix not throwing error when redefine eval or arguments in strict mode.
Currently when redefining eval or arguments in non-simple parameter list and
destructuring binding, V8 doesn't throw any error, this patch fixes it.

BUG=v8:5201
LOG=N

Review-Url: https://codereview.chromium.org/2185223002
Cr-Commit-Position: refs/heads/master@{#38762}
2016-08-19 19:48:17 +00:00
verwaest
4484bb41b5 Introduce ModuleScope subclass of DeclarationScope
This moves the module_descriptor_ field to that subclass, as well as other module-only methods.

BUG=v8:5209

Review-Url: https://codereview.chromium.org/2252223002
Cr-Commit-Position: refs/heads/master@{#38703}
2016-08-18 08:51:05 +00:00
vogelheim
c677f81381 Scanner::LiteralBuffer usage cleanup.
1, restrict use of LiteralBuffers to the tokens that actually need it.
  - E.g., previously the Token::FUNCTION would have a literal buffer
    containing "function", which was never actually used.
  - This eliminates copies of the string data for every call to
    PeekAhead or SetBookmark.
2, document & enforce the "secret" Scanner API contract w/ DCHECK
  - Document & check the correspondence of token value and literal buffer.
  - Document & check preconditions for calling PeekAhead, ScanRegExp*,
    ScanTemplate*.

BUG=v8:4947

Review-Url: https://codereview.chromium.org/2240513003
Cr-Commit-Position: refs/heads/master@{#38677}
2016-08-17 10:08:59 +00:00
caitp
a9e470797b [parser] improve inferred function names for async arrow functions
No longer include the "async" keyword, or an async arrow function's single
identifier parameter as part of its inferred name.

BUG=v8:5281, v8:4483
R=adamk@chromium.org, littledan@chromium.org, marja@chromium.org

Review-Url: https://codereview.chromium.org/2235423003
Cr-Commit-Position: refs/heads/master@{#38627}
2016-08-12 22:47:11 +00:00
adamk
73b0f15714 Function name variable does not need a VariableDeclaration
This changes Scope::function_ (for holding the name binding
for named function expression) from a VariableDeclaration
to a Variable. No work is done when visiting this declaration,
since it's kCreatedInitialized, so we can treat it like
other function-specific variables.

This simplifies a wide variety of code, and centralizes
the logic for constructing the variable inside scopes.cc.
This may one day make it easier to eliminate the CONST_LEGACY
VariableMode.

R=neis@chromium.org, verwaest@chromium.org
BUG=v8:5209

Review-Url: https://codereview.chromium.org/2232633002
Cr-Commit-Position: refs/heads/master@{#38558}
2016-08-10 18:45:53 +00:00
neis
b2ff10c43d [modules] Detect all indirect exports and represent them as such.
BUG=v8:1569

Review-Url: https://codereview.chromium.org/2223893004
Cr-Commit-Position: refs/heads/master@{#38538}
2016-08-10 12:18:27 +00:00
neis
29e85e36f3 [modules] Split imports into regular and special, store regular ones in a map.
BUG=v8:1569

Review-Url: https://codereview.chromium.org/2224333002
Cr-Commit-Position: refs/heads/master@{#38532}
2016-08-10 11:42:13 +00:00
neis
a126da4369 [modules] Mark namespace variables as kCreatedInitialized.
R=adamk@chromium.org
BUG=

Review-Url: https://codereview.chromium.org/2210533002
Cr-Commit-Position: refs/heads/master@{#38430}
2016-08-08 10:27:16 +00:00
neis
4df91581d1 [modules] Introduce new VariableLocation for module imports/exports.
Introduces a new VariableLocation MODULE for variables that live in a
module's export table.  Scope analysis sets this for the approriate variables.
Not yet supported by any backend.

Also, treats all imports as CONST bindings (including namespace imports), rather
than having new special variable modes.

BUG=

Review-Url: https://codereview.chromium.org/2199283002
Cr-Commit-Position: refs/heads/master@{#38426}
2016-08-08 09:49:27 +00:00
verwaest
4943f72272 Remove bool result from analyze since it's always true
This also gets rid of the pending_error_handler field on DeclarationScope which wasn't actually used.

BUG=v8:5209

Review-Url: https://codereview.chromium.org/2218083002
Cr-Commit-Position: refs/heads/master@{#38400}
2016-08-05 18:59:57 +00:00
verwaest
ff1c3cdb18 Separate Scope into DeclarationScope and Scope
This reduces peak zone memory usage by ~10% on codeload and ~5% on mandreel.

BUG=v8:5209

Committed: https://crrev.com/2648162dcfff622f8587cea2faa8c3af56456968
Review-Url: https://codereview.chromium.org/2209573002
Cr-Original-Commit-Position: refs/heads/master@{#38367}
Cr-Commit-Position: refs/heads/master@{#38390}
2016-08-05 14:34:04 +00:00
machenbach
2b6675c350 Revert of Separate Scope into DeclarationScope and Scope (patchset #13 id:240001 of https://codereview.chromium.org/2209573002/ )
Reason for revert:
[Sheriff] Make leak checker unhappy:
https://build.chromium.org/p/client.v8/builders/V8%20Linux64%20-%20debug/builds/10959

Original issue's description:
> Separate Scope into DeclarationScope and Scope
>
> This reduces peak zone memory usage by ~10% on codeload and ~5% on mandreel.
>
> BUG=v8:5209
>
> Committed: https://crrev.com/2648162dcfff622f8587cea2faa8c3af56456968
> Cr-Commit-Position: refs/heads/master@{#38367}

TBR=marja@chromium.org,mstarzinger@chromium.org,ahaas@chromium.org,adamk@chromium.org,verwaest@chromium.org
# Skipping CQ checks because original CL landed less than 1 days ago.
NOPRESUBMIT=true
NOTREECHECKS=true
NOTRY=true
BUG=v8:5209

Review-Url: https://codereview.chromium.org/2212383003
Cr-Commit-Position: refs/heads/master@{#38380}
2016-08-05 12:37:23 +00:00
verwaest
2648162dcf Separate Scope into DeclarationScope and Scope
This reduces peak zone memory usage by ~10% on codeload and ~5% on mandreel.

BUG=v8:5209

Review-Url: https://codereview.chromium.org/2209573002
Cr-Commit-Position: refs/heads/master@{#38367}
2016-08-05 10:17:54 +00:00
jgruber
a53d468747 Properly handle exceptions in cctests
Thrown exceptions must be handled before another exception is thrown.
This fixes all remaining test failures exposed by not clearing pending
exceptions in JSEntryStub.

BUG=v8:5259

Review-Url: https://codereview.chromium.org/2207923002
Cr-Commit-Position: refs/heads/master@{#38324}
2016-08-04 07:22:11 +00:00
jochen
7036d96b57 Add a mode to completely deserialize scope chains
This will allow for the background parser to parse inner functions

BUG=v8:5215
R=marja@chromium.org,verwaest@chromium.org

Review-Url: https://codereview.chromium.org/2198043002
Cr-Commit-Position: refs/heads/master@{#38291}
2016-08-03 13:31:04 +00:00
adamk
56f9754387 Remove --harmony-exponentiation-operator flag
It's shipped in M52.

R=caitp@igalia.com, littledan@chromium.org

Review-Url: https://codereview.chromium.org/2203843002
Cr-Commit-Position: refs/heads/master@{#38256}
2016-08-02 17:17:35 +00:00
jochen
a661f61123 Implement a character stream for external one byte streams
In contrast to the generic stream, this character stream works without
accessing the heap, and can be used on a background thread.

BUG=v8:5215
R=vogelheim@chromium.org,marja@chromium.org

Review-Url: https://codereview.chromium.org/2184393002
Cr-Commit-Position: refs/heads/master@{#38154}
2016-07-29 06:13:38 +00:00
jochen
37ba8f961b Replace SmartArrayPointer<T> with unique_ptr<T[]>
R=bmeurer@chromium.org
BUG=

Review-Url: https://codereview.chromium.org/2173403002
Cr-Commit-Position: refs/heads/master@{#38007}
2016-07-25 10:27:47 +00:00
adamk
f77d1bfc36 Remove redundant Scope book-keeping
The uses_arguments() bool is not needed for correct
behavior, since that same information is available after scope analysis
based on whether we allocated the Scope::arguments_ var.

BUG=v8:5209

Review-Url: https://codereview.chromium.org/2168293002
Cr-Commit-Position: refs/heads/master@{#37990}
2016-07-22 23:50:53 +00:00
verwaest
f04fd635b6 Turn ZoneList inner_scopes into a linked list
Replace the zonelist with a link from a scope to any of its inner scopes, and a link to any sibling scope.
This makes scopes that track inner scopes use roughly the same amount of space as previously scopes without inner scopes would use for the empty zonelist (pointer to the memory + length field, which, granted could be slightly smaller on 64bit).

BUG=v8:5209

Review-Url: https://codereview.chromium.org/2162143005
Cr-Commit-Position: refs/heads/master@{#37941}
2016-07-21 11:25:56 +00:00
verwaest
13cbf54522 Inline Scope::Initialize into the only constructor that's always called right before
This additionally makes the invariant obvious that outer_scope==nullptr+is_with_scope is impossible.

BUG=v8:5209

Review-Url: https://codereview.chromium.org/2165923002
Cr-Commit-Position: refs/heads/master@{#37902}
2016-07-20 12:19:51 +00:00
verwaest
e8e09ca725 Remove ast_value_factory_ and usages from scope
This frees up a field in Scope and untangles scope a little from the parser.

BUG=v8:5209

Review-Url: https://codereview.chromium.org/2160943004
Cr-Commit-Position: refs/heads/master@{#37887}
2016-07-20 08:08:39 +00:00
neis
0e000a87f1 [modules] AST and parser rework.
Highlights:
- Record all imports and exports in the ModuleDescriptor.
- Remove ImportDeclaration; instead, introduce a new variable kind for imports.
- Set name on default exported anonymous functions.

Still to do: declaration of namespace imports.

BUG=v8:1569

Review-Url: https://codereview.chromium.org/2108193003
Cr-Commit-Position: refs/heads/master@{#37815}
2016-07-18 07:29:28 +00:00
littledan
117fda1401 [parser] report errors for invalid binding patterns in async formal parameters
BUG=v8:4483, v8:5190

R=caitp@igalia.com, nikolaos@chromium.org

Review-Url: https://codereview.chromium.org/2139063002
Cr-Commit-Position: refs/heads/master@{#37691}
2016-07-12 19:50:09 +00:00
jwolfe
b8668fa846 Recognize HTMLCloseComment after multiline comment
When the scanner finds a '-->', it's either part of an HTMLCloseComment
or a '--' followed by a '>'. Previously, only a preceding newline would
make it an HTMLCloseComment. Now, a preceding multiline comment also
makes it an HTMLCloseComment. The effect is that now the following is
not a SyntaxError:

x/*
*/-->this is now a comment

BUG=v8:5142
LOG=y

Review-Url: https://codereview.chromium.org/2119763003
Cr-Commit-Position: refs/heads/master@{#37656}
2016-07-11 20:05:24 +00:00
neis
9f5f31800e [modules] Refactor parsing of anonymous declarations in default exports.
BUG=

Review-Url: https://codereview.chromium.org/2111153002
Cr-Commit-Position: refs/heads/master@{#37474}
2016-07-01 09:21:32 +00:00
jwolfe
1ac0965542 Allow trailing commas in function parameter lists
Add a flag harmony_trailing_commas_in_parameters that allows trailing
commas in function parameter declaration lists and function call
parameter lists. Trailing commas are allowed in parenthetical lists like
`(a, b, c,)` only if the next token is `=>`, thereby making it an arrow
function declaration. Only 1 trailing comma is allowed, not `(a,,)`. A
trailing comma must follow a non-rest parameter, so `(,)` and `(...a,)`
are still SyntaxErrors. However, a trailing comma is allowed after a
spread parameter, e.g. `a(...b,);`.

Add parser tests for all of the above.

BUG=v8:5051
LOG=y

Review-Url: https://codereview.chromium.org/2094463002
Cr-Commit-Position: refs/heads/master@{#37355}
2016-06-29 01:39:10 +00:00
caitpotter88
4efd20ab57 [parser] report error for shorthand property "await" in async arrow formals
In addition to recording the BindingPattern error, also record an
AsyncArrowFormalParameters error for shorthand property "await" in object
literals.

BUG=v8:4483, v8:5148
R=littledan@chromium.org, jwolfe@igalia.com, adamk@chromium.org, nikolaos@chromium.org

Review-Url: https://codereview.chromium.org/2100623002
Cr-Commit-Position: refs/heads/master@{#37302}
2016-06-27 21:12:19 +00:00
caitpotter88
4bb1f70e66 [parser] don't report error for CoverInitializedNames in async arrow formals
BUG=v8:4483, v8:5148
R=littledan@chromium.org, adamk@chromium.org, jwolfe@igalia.com, nikolaos@chromium.org

Review-Url: https://codereview.chromium.org/2091313002
Cr-Commit-Position: refs/heads/master@{#37260}
2016-06-25 00:39:11 +00:00
caitpotter88
e45fba811f [parser] only parse async arrow function when necessary
Previously, an async arrow function would be parsed if any valid
ConditionalExpression began with the identifier "async", and its following token
was on the same line.

So for example, `async.bar foo => 1` was parsed as a valid async arrow function.
This patch corrects this behaviour by asserting that the following token is a
valid arrow parameters start.

BUG=v8:4483
R=littledan@chromium.org, henrique.ferreiro@gmail.com

Review-Url: https://codereview.chromium.org/2089733002
Cr-Commit-Position: refs/heads/master@{#37154}
2016-06-21 19:48:15 +00:00
oleksandr.chekhovskyi
2f6be682ac Parser: Report use counts once per feature
Reporting use counts by invoking a callback once per occurrence has
a large overhead cost in certain situations, for example when it needs
to be dispatched to a different thread (which is the case for Web Workers).

Parsing large scripts can produce a lot of occurrences (strict/sloppy mode
once per function).

Chromium (the only known user of UseCounters so far) does not actually care
about number of occurrences, but simply whether they happened at least once.
This commit changes behavior to report features at most once, which dramatically
improves performance for impacted use cases, and should not affect the only
known real world usage.

R=littledan@chromium.org
BUG=chromium:614775

Review-Url: https://codereview.chromium.org/2062203002
Cr-Commit-Position: refs/heads/master@{#36979}
2016-06-14 21:41:31 +00:00
littledan
6390282f96 Improve strictness of Annex B 3.3 for generators and async functions
Annex B 3.3 applies only for ordinary FunctionDeclarations, not
GeneratorDeclarations or AsyncFunctionDeclarations. This patch
- Skips applying Annex B 3.3 to async functions
- Adds a flag to refrain from applying it to generators
- UseCounter for how often duplicate function in block occurs
  with generators (unclear how to measure need for hoisting from block)

BUG=v8:4806

Review-Url: https://codereview.chromium.org/1995863002
Cr-Commit-Position: refs/heads/master@{#36557}
2016-05-27 18:23:20 +00:00
mike
d0c65f93bf [parser] Relex restriction on reserved words
Some IdentifierNames are only included in the set of FutureReservedWords
for strict mode code. Outside of strict mode, these IdentifierNames may
be used as Identifiers. Notably, this includes their use as
BindingIdentifiers in LexicalBindings.

From ES2015 12.1.1 Static Semantics: Early Errors (Identifiers):

> It is a Syntax Error if this phrase is contained in strict mode code
> and the StringValue of IdentifierName is: "implements", "interface",
> "let", "package", "private", "protected", "public", "static", or
> "yield".

http://www.ecma-international.org/ecma-262/6.0/#sec-identifiers-static-semantics-early-errors

Due to a error in its heuristic for disambiguating the `let` token, V8
does not currently allow any of the strict-mode-only FutureReservedWords
to be used as a BindingIdentifier outside of strict mode.

Update V8's heuristic for disambiguating the `let` keyword to account
for strict mode, enabling these IdentifierNames to be used

BUG=v8:4918
LOG=N
R=adamk@chromium.org

Review-Url: https://codereview.chromium.org/1891453005
Cr-Commit-Position: refs/heads/master@{#36296}
2016-05-17 21:14:01 +00:00
caitpotter88
0d43421a22 [esnext] implement frontend changes for async/await proposal
BUG=v8:4483
LOG=Y
R=littledan@chromium.org, adamk@chromium.org

Review-Url: https://codereview.chromium.org/1841543003
Cr-Commit-Position: refs/heads/master@{#36261}
2016-05-16 23:19:02 +00:00
adamk
0783a6fc27 Further expand parsing tests around yield in generator/arrow parameters
No bugs found, but the additional coverage of arrows as default param
initializers in a generator param list seems good to have.

R=littledan@chromium.org

Review-Url: https://codereview.chromium.org/1949293002
Cr-Commit-Position: refs/heads/master@{#36089}
2016-05-06 19:31:50 +00:00
adamk
40b3626e45 Disallow yield in computed property names of class expressions in params
R=littledan@chromium.org
BUG=v8:4974
LOG=n

Review-Url: https://codereview.chromium.org/1949223002
Cr-Commit-Position: refs/heads/master@{#36047}
2016-05-04 23:25:25 +00:00
nikolaos
0d1687b9df Add support for disabling the preparser when testing modules
R=adamk@chromium.org
BUG=
LOG=N

Review-Url: https://codereview.chromium.org/1952473003
Cr-Commit-Position: refs/heads/master@{#36035}
2016-05-04 17:22:20 +00:00
adamk
9e9abcfff4 Properly disallow 'yield' in class expressions and arrow parameters
Yield expressions are not allowed in formal parameter initializers of
generators, but we weren't properly catching the case where the yield
expression appeared in the 'extends' clause of a class expression.

They also aren't allowed in arrow functions, which we were failing to
catch due to not looking at the obscurely-named "FormalParameterInitializerError"
bit of ExpressionClassifier.

This patch passes along an ExpressionClassifier when parsing class
expressions and accumulates the proper error for that case.

For the arrow function case, the fix is simply to check for the
"formal parameter initializer" error once we know we've parsed
an arrow function. The error message used for this has also
been made specific to yield expressions.

Tests are added both for the error case and the non-error cases (where
yield is used in such a position inside the class body).

BUG=v8:4966, v8:4968, v8:4974
LOG=n

Review-Url: https://codereview.chromium.org/1941823003
Cr-Commit-Position: refs/heads/master@{#35957}
2016-05-03 01:57:48 +00:00
mike
efe5b72d02 [parser] Enforce module-specific identifier restriction
Restrict the use of the `await` token as an identifier when parsing
source text as module code.

From
http://www.ecma-international.org/ecma-262/6.0/#sec-future-reserved-words:

> 11.6.2.2 Future Reserved Words
>
> The following tokens are reserved for used as keywords in future
> language extensions.
>
> Syntax
>
>     FutureReservedWord ::
>         enum
>         await
>
> await is only treated as a FutureReservedWord when Module is the goal
> symbol of the syntactic grammar.

BUG=v8:4767
LOG=N
R=adamk@chromium.org

Review-Url: https://codereview.chromium.org/1723313002
Cr-Commit-Position: refs/heads/master@{#35914}
2016-04-29 18:14:48 +00:00
adamk
f1a0f054fb Several tiny cleanups in test-parsing.cc
R=littledan@chromium.org

Review-Url: https://codereview.chromium.org/1926133003
Cr-Commit-Position: refs/heads/master@{#35890}
2016-04-29 06:44:18 +00:00
littledan
63b935428c Disallow generator declarations in certain locations
The legacy function declaration locations from Annex B 3.2 and 3.4 do not
apply for generator declarations. This patch cracks down on those usages,
which is tested for by new incoming test262 tests.

BUG=v8:4824
LOG=Y
R=adamk

Review-Url: https://codereview.chromium.org/1900033003
Cr-Commit-Position: refs/heads/master@{#35835}
2016-04-27 19:18:38 +00:00
adamk
967a04634d Forward accept_IN to ParseYieldExpression
This allows "yield 'x' in o" as an expression in a generator.

R=ishell@chromium.org
BUG=v8:4945
LOG=n

Review URL: https://codereview.chromium.org/1916183003

Cr-Commit-Position: refs/heads/master@{#35798}
2016-04-26 17:24:49 +00:00
adamk
739947880c Widen --harmony-for-in flag to throw errors in PreParser
The first version of --harmony-for-in avoided throwing PreParser
errors in order to retain use counting. This patch threads
use_counts_ through to the PreParser to allow use counting in
the PreParser while also throwing errors for this case.

Also slightly refactored the Parser code to do a little less
code duplication.

BUG=v8:4942
LOG=y

Review URL: https://codereview.chromium.org/1913203002

Cr-Commit-Position: refs/heads/master@{#35780}
2016-04-26 00:29:50 +00:00
mike
b86ec74395 [modules] Infer strict mode from within scope object
Refactor the Scope object to automatically enable strict mode when
initialized as a "module" scope, relieving the caller of this
responsibility.

BUG=v8:4941
LOG=N
R=adamk@chromium.org

Review URL: https://codereview.chromium.org/1906923002

Cr-Commit-Position: refs/heads/master@{#35730}
2016-04-22 13:38:15 +00:00
mike
43fa3e65c9 [modules] Treat top-level functions as lexical
[15.2.1.11 Static Semantics:
LexicallyDeclaredNames](https://tc39.github.io/ecma262/#sec-module-semantics-static-semantics-lexicallydeclarednames)
(in contrast with its definition for StatementListItem) makes no
explicit provision for HoistableDeclarations. This means that function
declarations are treated as lexically scoped in module code, as
described in section 15.2.1.11's informative note:

> At the top level of a function, or script, function declarations are
> treated like var declarations rather than like lexical declarations.

BUG=v8:4884
LOG=N
R=adamk@chromium.org

Review URL: https://codereview.chromium.org/1851673007

Cr-Commit-Position: refs/heads/master@{#35633}
2016-04-19 17:53:03 +00:00