Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(265)

Unified Diff: src/scopes.h

Issue 883823002: Implement proper scoping for "this" in arrow functions Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Make sure an unresolved VariableProxy for "this" is not considered a valid LHS Created 5 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: src/scopes.h
diff --git a/src/scopes.h b/src/scopes.h
index 98a3014dbcbcad75ee4b9080c9c20ab89888c5e7..67b52134ca13531266365084960d5f38ea253166 100644
--- a/src/scopes.h
+++ b/src/scopes.h
@@ -145,13 +145,14 @@ class Scope: public ZoneObject {
VariableProxy* NewUnresolved(AstNodeFactory* factory,
const AstRawString* name,
Interface* interface = Interface::NewValue(),
- int position = RelocInfo::kNoPosition) {
+ int position = RelocInfo::kNoPosition,
+ bool is_this = false) {
wingo 2015/02/04 10:02:13 Boolean parameters are an antipattern, especially
aperez 2015/02/04 21:00:42 Acknowledged. Even better: the actual name of the
// Note that we must not share the unresolved variables with
// the same name because they may be removed selectively via
// RemoveUnresolved().
DCHECK(!already_resolved());
VariableProxy* proxy =
- factory->NewVariableProxy(name, false, interface, position);
+ factory->NewVariableProxy(name, is_this, interface, position);
unresolved_.Add(proxy, zone_);
return proxy;
}
@@ -222,9 +223,6 @@ class Scope: public ZoneObject {
scope_uses_super_constructor_call_ = true;
}
- // Inform the scope that the corresponding code uses "this".
- void RecordThisUsage() { scope_uses_this_ = true; }
-
// Set the strict mode flag (unless disabled by a global flag).
void SetStrictMode(StrictMode strict_mode) { strict_mode_ = strict_mode; }
@@ -328,9 +326,8 @@ class Scope: public ZoneObject {
return inner_scope_uses_super_constructor_call_;
}
// Does this scope access "this".
- bool uses_this() const { return scope_uses_this_; }
+ bool uses_this() const { return receiver_->is_used(); }
// Does any inner scope access "this".
- bool inner_uses_this() const { return inner_scope_uses_this_; }
// ---------------------------------------------------------------------------
// Accessors.
@@ -342,7 +339,14 @@ class Scope: public ZoneObject {
StrictMode strict_mode() const { return strict_mode_; }
// The variable corresponding the 'this' value.
- Variable* receiver() { return receiver_; }
+ Variable* receiver() {
+ DCHECK(has_this_declaration());
wingo 2015/02/04 10:02:13 DCHECK(receiver_) also perhaps?
aperez 2015/02/04 21:00:42 Acknowledged.
+ return receiver_;
+ }
+
+ bool has_this_declaration() const {
+ return !is_arrow_scope() && is_declaration_scope();
+ }
// The variable holding the function literal for named function
// literals, or NULL. Only valid for function scopes.
@@ -516,8 +520,6 @@ class Scope: public ZoneObject {
bool scope_uses_super_property_;
// This scope uses "super" constructor ('super(..)').
bool scope_uses_super_constructor_call_;
- // This scope uses "this".
- bool scope_uses_this_;
// This scope contains an "use asm" annotation.
bool asm_module_;
// This scope's outer context is an asm module.
@@ -534,7 +536,6 @@ class Scope: public ZoneObject {
bool inner_scope_uses_arguments_;
bool inner_scope_uses_super_property_;
bool inner_scope_uses_super_constructor_call_;
- bool inner_scope_uses_this_;
bool force_eager_compilation_;
bool force_context_allocation_;
@@ -634,6 +635,8 @@ class Scope: public ZoneObject {
void AllocateStackSlot(Variable* var);
void AllocateHeapSlot(Variable* var);
void AllocateParameterLocals();
+ void AllocateParameter(Variable* var, int index);
+ void AllocateReceiver();
void AllocateNonParameterLocal(Variable* var);
void AllocateNonParameterLocals();
void AllocateVariablesRecursively();

Powered by Google App Engine
This is Rietveld 408576698