Reviewers: wingo,
Description:
Cleanups needed for this-scoping in arrow functions
This patch provides a series of changes needed to implement proper
scoping of "this" in arrow functions in a followup patch. To implement
the scoping, all references to "this" will be initially unresolved
variables (like every other variable), which will be resolved later
on during the variable resolution pass. Arrow scopes will not have
have "this" declared, so accessing "this" from one will resolve to
the one captured from the outer scope like for any other variable.
* Add Scope::has_this_declaration(): This is a simple accessor that
returns "true" for the scopes which declare "this", which is all
the declaration scopes except arrow functions. This will be used
to know which scopes have to declare "this". It can already be
used in code generation to skip patching up the receiver for those
scopes which do not have one.
* Remove Variable::IsValidReference(), and the Variable::is_valid_ref_
member: This was "false" only for "this", and for internal variables.
For the first, VariableProxy::is_this() can be used for the check
instead; and for internal variables, it is guaranteed they they will
not be written to (because the V8 code does not do it, and they are
not accessible from JavaScript).
The reasong to remove this is that the existing implementation of
VariableProxy::IsValidReferenceExpression() was using the
Variable::IsValidReference() method from the proxied variable,
which does will not work anymore before variable resolution when
the references to "this" are changed to be unresolved variables.
* The "bool is_this" parameter of VariableProxy() constructor is
changed to use Variable::Kind. This will allow to later on adding
a parameter to create unresolved variables of any kind, which in
turn will be used to make references to "this" initially unresolved,
and use the existing variable resolution mechanics for "this".
Also, boolean parameters tend to result in poor APIs: enums convey
more information when reading code, and allow for further extension
to more than two values in the future.
BUG=v8:2700
LOG=Y
Please review this at https://codereview.chromium.org/1024703004/
Base URL: https://chromium.googlesource.com/v8/v8.git@master
Affected files (+50, -56 lines):
M src/arm/full-codegen-arm.cc
M src/arm/lithium-codegen-arm.cc
M src/arm64/full-codegen-arm64.cc
M src/arm64/lithium-codegen-arm64.cc
M src/ast.h
M src/ast.cc
M src/ia32/full-codegen-ia32.cc
M src/ia32/lithium-codegen-ia32.cc
M src/parser.cc
M src/scopes.h
M src/scopes.cc
M src/variables.h
M src/variables.cc
M src/x64/full-codegen-x64.cc
M src/x64/lithium-codegen-x64.cc
--
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev
---
You received this message because you are subscribed to the Google Groups "v8-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.