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

Side by Side Diff: src/scopes.cc

Issue 1135243004: [es6] Support super.property in eval and arrow functions (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: i have no idea Created 5 years, 7 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 unified diff | Download patch
OLDNEW
1 // Copyright 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "src/v8.h" 5 #include "src/v8.h"
6 6
7 #include "src/accessors.h" 7 #include "src/accessors.h"
8 #include "src/bootstrapper.h" 8 #include "src/bootstrapper.h"
9 #include "src/messages.h" 9 #include "src/messages.h"
10 #include "src/parser.h" 10 #include "src/parser.h"
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after
147 147
148 148
149 void Scope::SetDefaults(ScopeType scope_type, Scope* outer_scope, 149 void Scope::SetDefaults(ScopeType scope_type, Scope* outer_scope,
150 Handle<ScopeInfo> scope_info, 150 Handle<ScopeInfo> scope_info,
151 FunctionKind function_kind) { 151 FunctionKind function_kind) {
152 outer_scope_ = outer_scope; 152 outer_scope_ = outer_scope;
153 scope_type_ = scope_type; 153 scope_type_ = scope_type;
154 function_kind_ = function_kind; 154 function_kind_ = function_kind;
155 block_scope_is_class_scope_ = false; 155 block_scope_is_class_scope_ = false;
156 scope_name_ = ast_value_factory_->empty_string(); 156 scope_name_ = ast_value_factory_->empty_string();
157 dynamics_ = NULL; 157 dynamics_ = nullptr;
158 receiver_ = NULL; 158 receiver_ = nullptr;
159 new_target_ = nullptr; 159 new_target_ = nullptr;
160 function_ = NULL; 160 function_ = nullptr;
161 arguments_ = NULL; 161 arguments_ = nullptr;
162 illegal_redecl_ = NULL; 162 home_object_ = nullptr;
163 illegal_redecl_ = nullptr;
163 scope_inside_with_ = false; 164 scope_inside_with_ = false;
164 scope_contains_with_ = false; 165 scope_contains_with_ = false;
165 scope_calls_eval_ = false; 166 scope_calls_eval_ = false;
166 scope_uses_arguments_ = false; 167 scope_uses_arguments_ = false;
167 scope_uses_super_property_ = false; 168 scope_uses_super_property_ = false;
168 asm_module_ = false; 169 asm_module_ = false;
169 asm_function_ = outer_scope != NULL && outer_scope->asm_module_; 170 asm_function_ = outer_scope != NULL && outer_scope->asm_module_;
170 // Inherit the language mode from the parent scope. 171 // Inherit the language mode from the parent scope.
171 language_mode_ = outer_scope != NULL ? outer_scope->language_mode_ : SLOPPY; 172 language_mode_ = outer_scope != NULL ? outer_scope->language_mode_ : SLOPPY;
172 outer_scope_calls_sloppy_eval_ = false; 173 outer_scope_calls_sloppy_eval_ = false;
173 inner_scope_calls_eval_ = false; 174 inner_scope_calls_eval_ = false;
174 inner_scope_uses_arguments_ = false; 175 inner_scope_uses_arguments_ = false;
175 inner_scope_uses_super_property_ = false;
176 force_eager_compilation_ = false; 176 force_eager_compilation_ = false;
177 force_context_allocation_ = (outer_scope != NULL && !is_function_scope()) 177 force_context_allocation_ = (outer_scope != NULL && !is_function_scope())
178 ? outer_scope->has_forced_context_allocation() : false; 178 ? outer_scope->has_forced_context_allocation() : false;
179 num_var_or_const_ = 0; 179 num_var_or_const_ = 0;
180 num_stack_slots_ = 0; 180 num_stack_slots_ = 0;
181 num_heap_slots_ = 0; 181 num_heap_slots_ = 0;
182 num_modules_ = 0; 182 num_modules_ = 0;
183 module_var_ = NULL, 183 module_var_ = NULL,
184 rest_parameter_ = NULL; 184 rest_parameter_ = NULL;
185 rest_index_ = -1; 185 rest_index_ = -1;
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after
330 if (is_function_scope() && !is_arrow_scope()) { 330 if (is_function_scope() && !is_arrow_scope()) {
331 // Declare 'arguments' variable which exists in all non arrow functions. 331 // Declare 'arguments' variable which exists in all non arrow functions.
332 // Note that it might never be accessed, in which case it won't be 332 // Note that it might never be accessed, in which case it won't be
333 // allocated during variable allocation. 333 // allocated during variable allocation.
334 variables_.Declare(this, 334 variables_.Declare(this,
335 ast_value_factory_->arguments_string(), 335 ast_value_factory_->arguments_string(),
336 VAR, 336 VAR,
337 Variable::ARGUMENTS, 337 Variable::ARGUMENTS,
338 kCreatedInitialized); 338 kCreatedInitialized);
339 } 339 }
340
341 if (is_function_scope() && !is_arrow_scope() &&
342 (IsConciseMethod(function_kind_) || IsConstructor(function_kind_) ||
343 IsAccessorFunction(function_kind_))) {
344 // TODO(arv): uses_super_property.
345 // Declare '.home_object' variable which exists in all methods.
346 // Note that it might never be accessed, in which case it won't be
347 // allocated during variable allocation.
348 variables_.Declare(this, ast_value_factory_->home_object_string(), VAR,
349 Variable::NORMAL, kCreatedInitialized);
350 }
340 } 351 }
341 352
342 353
343 Scope* Scope::FinalizeBlockScope() { 354 Scope* Scope::FinalizeBlockScope() {
344 DCHECK(is_block_scope()); 355 DCHECK(is_block_scope());
345 DCHECK(internals_.is_empty()); 356 DCHECK(internals_.is_empty());
346 DCHECK(temps_.is_empty()); 357 DCHECK(temps_.is_empty());
347 DCHECK(params_.is_empty()); 358 DCHECK(params_.is_empty());
348 359
349 if (num_var_or_const() > 0) return this; 360 if (num_var_or_const() > 0) return this;
(...skipping 564 matching lines...) Expand 10 before | Expand all | Expand 10 after
914 } 925 }
915 if (scope_inside_with_) Indent(n1, "// scope inside 'with'\n"); 926 if (scope_inside_with_) Indent(n1, "// scope inside 'with'\n");
916 if (scope_contains_with_) Indent(n1, "// scope contains 'with'\n"); 927 if (scope_contains_with_) Indent(n1, "// scope contains 'with'\n");
917 if (scope_calls_eval_) Indent(n1, "// scope calls 'eval'\n"); 928 if (scope_calls_eval_) Indent(n1, "// scope calls 'eval'\n");
918 if (scope_uses_arguments_) Indent(n1, "// scope uses 'arguments'\n"); 929 if (scope_uses_arguments_) Indent(n1, "// scope uses 'arguments'\n");
919 if (scope_uses_super_property_) 930 if (scope_uses_super_property_)
920 Indent(n1, "// scope uses 'super' property\n"); 931 Indent(n1, "// scope uses 'super' property\n");
921 if (inner_scope_uses_arguments_) { 932 if (inner_scope_uses_arguments_) {
922 Indent(n1, "// inner scope uses 'arguments'\n"); 933 Indent(n1, "// inner scope uses 'arguments'\n");
923 } 934 }
924 if (inner_scope_uses_super_property_)
925 Indent(n1, "// inner scope uses 'super' property\n");
926 if (outer_scope_calls_sloppy_eval_) { 935 if (outer_scope_calls_sloppy_eval_) {
927 Indent(n1, "// outer scope calls 'eval' in sloppy context\n"); 936 Indent(n1, "// outer scope calls 'eval' in sloppy context\n");
928 } 937 }
929 if (inner_scope_calls_eval_) Indent(n1, "// inner scope calls 'eval'\n"); 938 if (inner_scope_calls_eval_) Indent(n1, "// inner scope calls 'eval'\n");
930 if (num_stack_slots_ > 0) { Indent(n1, "// "); 939 if (num_stack_slots_ > 0) { Indent(n1, "// ");
931 PrintF("%d stack slots\n", num_stack_slots_); } 940 PrintF("%d stack slots\n", num_stack_slots_); }
932 if (num_heap_slots_ > 0) { Indent(n1, "// "); 941 if (num_heap_slots_ > 0) { Indent(n1, "// ");
933 PrintF("%d heap slots\n", num_heap_slots_); } 942 PrintF("%d heap slots\n", num_heap_slots_); }
934 943
935 // Print locals. 944 // Print locals.
(...skipping 335 matching lines...) Expand 10 before | Expand all | Expand 10 after
1271 if (inner->scope_calls_eval_ || inner->inner_scope_calls_eval_) { 1280 if (inner->scope_calls_eval_ || inner->inner_scope_calls_eval_) {
1272 inner_scope_calls_eval_ = true; 1281 inner_scope_calls_eval_ = true;
1273 } 1282 }
1274 // If the inner scope is an arrow function, propagate the flags tracking 1283 // If the inner scope is an arrow function, propagate the flags tracking
1275 // usage of arguments/super/this, but do not propagate them out from normal 1284 // usage of arguments/super/this, but do not propagate them out from normal
1276 // functions. 1285 // functions.
1277 if (!inner->is_function_scope() || inner->is_arrow_scope()) { 1286 if (!inner->is_function_scope() || inner->is_arrow_scope()) {
1278 if (inner->scope_uses_arguments_ || inner->inner_scope_uses_arguments_) { 1287 if (inner->scope_uses_arguments_ || inner->inner_scope_uses_arguments_) {
1279 inner_scope_uses_arguments_ = true; 1288 inner_scope_uses_arguments_ = true;
1280 } 1289 }
1281 if (inner->scope_uses_super_property_ ||
1282 inner->inner_scope_uses_super_property_) {
1283 inner_scope_uses_super_property_ = true;
1284 }
1285 } 1290 }
1286 if (inner->force_eager_compilation_) { 1291 if (inner->force_eager_compilation_) {
1287 force_eager_compilation_ = true; 1292 force_eager_compilation_ = true;
1288 } 1293 }
1289 if (asm_module_ && inner->scope_type() == FUNCTION_SCOPE) { 1294 if (asm_module_ && inner->scope_type() == FUNCTION_SCOPE) {
1290 inner->asm_function_ = true; 1295 inner->asm_function_ = true;
1291 } 1296 }
1292 } 1297 }
1293 } 1298 }
1294 1299
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
1382 // In strict mode 'arguments' does not alias formal parameters. 1387 // In strict mode 'arguments' does not alias formal parameters.
1383 // Therefore in strict mode we allocate parameters as if 'arguments' 1388 // Therefore in strict mode we allocate parameters as if 'arguments'
1384 // were not used. 1389 // were not used.
1385 uses_sloppy_arguments = is_sloppy(language_mode()); 1390 uses_sloppy_arguments = is_sloppy(language_mode());
1386 } 1391 }
1387 1392
1388 if (rest_parameter_ && !MustAllocate(rest_parameter_)) { 1393 if (rest_parameter_ && !MustAllocate(rest_parameter_)) {
1389 rest_parameter_ = NULL; 1394 rest_parameter_ = NULL;
1390 } 1395 }
1391 1396
1397 Variable* home_object_var =
1398 LookupLocal(ast_value_factory_->home_object_string());
1399 if (home_object_var != nullptr && uses_super_property() &&
1400 MustAllocate(home_object_var)) {
1401 // TODO(arv): super() uses a SuperReference so it generates a VariableProxy
1402 // for the .home_object which makes it look like we need to allocate the
1403 // home_object_var.
1404 // Consider splitting the AST node into 2 different nodes since the
1405 // semantics is just so different.
1406 home_object_ = home_object_var;
1407 }
1408
1392 // The same parameter may occur multiple times in the parameters_ list. 1409 // The same parameter may occur multiple times in the parameters_ list.
1393 // If it does, and if it is not copied into the context object, it must 1410 // If it does, and if it is not copied into the context object, it must
1394 // receive the highest parameter index for that parameter; thus iteration 1411 // receive the highest parameter index for that parameter; thus iteration
1395 // order is relevant! 1412 // order is relevant!
1396 for (int i = params_.length() - 1; i >= 0; --i) { 1413 for (int i = params_.length() - 1; i >= 0; --i) {
1397 Variable* var = params_[i]; 1414 Variable* var = params_[i];
1398 if (var == rest_parameter_) continue; 1415 if (var == rest_parameter_) continue;
1399 1416
1400 DCHECK(var->scope() == this); 1417 DCHECK(var->scope() == this);
1401 if (uses_sloppy_arguments || has_forced_context_allocation()) { 1418 if (uses_sloppy_arguments || has_forced_context_allocation()) {
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
1547 (function_ != NULL && function_->proxy()->var()->IsStackLocal() ? 1 : 0); 1564 (function_ != NULL && function_->proxy()->var()->IsStackLocal() ? 1 : 0);
1548 } 1565 }
1549 1566
1550 1567
1551 int Scope::ContextLocalCount() const { 1568 int Scope::ContextLocalCount() const {
1552 if (num_heap_slots() == 0) return 0; 1569 if (num_heap_slots() == 0) return 0;
1553 return num_heap_slots() - Context::MIN_CONTEXT_SLOTS - 1570 return num_heap_slots() - Context::MIN_CONTEXT_SLOTS -
1554 (function_ != NULL && function_->proxy()->var()->IsContextSlot() ? 1 : 0); 1571 (function_ != NULL && function_->proxy()->var()->IsContextSlot() ? 1 : 0);
1555 } 1572 }
1556 } } // namespace v8::internal 1573 } } // namespace v8::internal
OLDNEW
« src/ast-numbering.cc ('K') | « src/scopes.h ('k') | src/x64/full-codegen-x64.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698