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

Side by Side Diff: src/parsing/pattern-rewriter.cc

Issue 1768973002: [debugger] break at each initialization in a multiple var declaration. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 4 years, 9 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
« no previous file with comments | « no previous file | test/cctest/test-debug.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 the V8 project authors. All rights reserved. 1 // Copyright 2015 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/ast/ast.h" 5 #include "src/ast/ast.h"
6 #include "src/messages.h" 6 #include "src/messages.h"
7 #include "src/parsing/parameter-initializer-rewriter.h" 7 #include "src/parsing/parameter-initializer-rewriter.h"
8 #include "src/parsing/parser.h" 8 #include "src/parsing/parser.h"
9 9
10 namespace v8 { 10 namespace v8 {
(...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after
223 ZoneList<Expression*>* arguments = 223 ZoneList<Expression*>* arguments =
224 new (zone()) ZoneList<Expression*>(3, zone()); 224 new (zone()) ZoneList<Expression*>(3, zone());
225 // We have at least 1 parameter. 225 // We have at least 1 parameter.
226 arguments->Add( 226 arguments->Add(
227 factory()->NewStringLiteral(name, descriptor_->declaration_pos), 227 factory()->NewStringLiteral(name, descriptor_->declaration_pos),
228 zone()); 228 zone());
229 CallRuntime* initialize; 229 CallRuntime* initialize;
230 230
231 if (IsImmutableVariableMode(descriptor_->mode)) { 231 if (IsImmutableVariableMode(descriptor_->mode)) {
232 arguments->Add(value, zone()); 232 arguments->Add(value, zone());
233 value = NULL; // zap the value to avoid the unnecessary assignment
234
235 // Construct the call to Runtime_InitializeConstGlobal 233 // Construct the call to Runtime_InitializeConstGlobal
236 // and add it to the initialization statement block. 234 // and add it to the initialization statement block.
237 // Note that the function does different things depending on 235 // Note that the function does different things depending on
238 // the number of arguments (1 or 2). 236 // the number of arguments (1 or 2).
239 initialize = 237 initialize = factory()->NewCallRuntime(Runtime::kInitializeConstGlobal,
240 factory()->NewCallRuntime(Runtime::kInitializeConstGlobal, arguments, 238 arguments, value->position());
241 descriptor_->initialization_pos); 239 value = NULL; // zap the value to avoid the unnecessary assignment
242 } else { 240 } else {
243 // Add language mode. 241 // Add language mode.
244 // We may want to pass singleton to avoid Literal allocations. 242 // We may want to pass singleton to avoid Literal allocations.
245 LanguageMode language_mode = initialization_scope->language_mode(); 243 LanguageMode language_mode = initialization_scope->language_mode();
246 arguments->Add(factory()->NewNumberLiteral(language_mode, 244 arguments->Add(
247 descriptor_->declaration_pos), 245 factory()->NewNumberLiteral(language_mode, RelocInfo::kNoPosition),
248 zone()); 246 zone());
249 247
250 // Be careful not to assign a value to the global variable if 248 // Be careful not to assign a value to the global variable if
251 // we're in a with. The initialization value should not 249 // we're in a with. The initialization value should not
252 // necessarily be stored in the global object in that case, 250 // necessarily be stored in the global object in that case,
253 // which is why we need to generate a separate assignment node. 251 // which is why we need to generate a separate assignment node.
254 if (value != NULL && !descriptor_->scope->inside_with()) { 252 if (value != NULL && !descriptor_->scope->inside_with()) {
255 arguments->Add(value, zone()); 253 arguments->Add(value, zone());
256 value = NULL; // zap the value to avoid the unnecessary assignment
257 // Construct the call to Runtime_InitializeVarGlobal 254 // Construct the call to Runtime_InitializeVarGlobal
258 // and add it to the initialization statement block. 255 // and add it to the initialization statement block.
259 initialize = 256 initialize = factory()->NewCallRuntime(Runtime::kInitializeVarGlobal,
260 factory()->NewCallRuntime(Runtime::kInitializeVarGlobal, arguments, 257 arguments, value->position());
261 descriptor_->declaration_pos); 258 value = NULL; // zap the value to avoid the unnecessary assignment
262 } else { 259 } else {
263 initialize = NULL; 260 initialize = NULL;
264 } 261 }
265 } 262 }
266 263
267 if (initialize != NULL) { 264 if (initialize != NULL) {
268 block_->statements()->Add( 265 block_->statements()->Add(
269 factory()->NewExpressionStatement(initialize, initialize->position()), 266 factory()->NewExpressionStatement(initialize, initialize->position()),
270 zone()); 267 zone());
271 } 268 }
272 } else if (value != nullptr && (descriptor_->mode == CONST_LEGACY || 269 } else if (value != nullptr && (descriptor_->mode == CONST_LEGACY ||
273 IsLexicalVariableMode(descriptor_->mode))) { 270 IsLexicalVariableMode(descriptor_->mode))) {
274 // Constant initializations always assign to the declared constant which 271 // Constant initializations always assign to the declared constant which
275 // is always at the function scope level. This is only relevant for 272 // is always at the function scope level. This is only relevant for
276 // dynamically looked-up variables and constants (the 273 // dynamically looked-up variables and constants (the
277 // start context for constant lookups is always the function context, 274 // start context for constant lookups is always the function context,
278 // while it is the top context for var declared variables). Sigh... 275 // while it is the top context for var declared variables). Sigh...
279 // For 'let' and 'const' declared variables in harmony mode the 276 // For 'let' and 'const' declared variables in harmony mode the
280 // initialization also always assigns to the declared variable. 277 // initialization also always assigns to the declared variable.
281 DCHECK_NOT_NULL(proxy); 278 DCHECK_NOT_NULL(proxy);
282 DCHECK_NOT_NULL(proxy->var()); 279 DCHECK_NOT_NULL(proxy->var());
283 DCHECK_NOT_NULL(value); 280 DCHECK_NOT_NULL(value);
284 // Add break location for destructured sub-pattern. 281 // Add break location for destructured sub-pattern.
285 int pos = 282 int pos = IsSubPattern() ? pattern->position() : value->position();
286 IsSubPattern() ? pattern->position() : descriptor_->initialization_pos;
287 Assignment* assignment = 283 Assignment* assignment =
288 factory()->NewAssignment(Token::INIT, proxy, value, pos); 284 factory()->NewAssignment(Token::INIT, proxy, value, pos);
289 block_->statements()->Add( 285 block_->statements()->Add(
290 factory()->NewExpressionStatement(assignment, pos), zone()); 286 factory()->NewExpressionStatement(assignment, pos), zone());
291 value = NULL; 287 value = NULL;
292 } 288 }
293 289
294 // Add an assignment node to the initialization statement block if we still 290 // Add an assignment node to the initialization statement block if we still
295 // have a pending initialization value. 291 // have a pending initialization value.
296 if (value != NULL) { 292 if (value != NULL) {
297 DCHECK(descriptor_->mode == VAR); 293 DCHECK(descriptor_->mode == VAR);
298 // 'var' initializations are simply assignments (with all the consequences 294 // 'var' initializations are simply assignments (with all the consequences
299 // if they are inside a 'with' statement - they may change a 'with' object 295 // if they are inside a 'with' statement - they may change a 'with' object
300 // property). 296 // property).
301 VariableProxy* proxy = initialization_scope->NewUnresolved(factory(), name); 297 VariableProxy* proxy = initialization_scope->NewUnresolved(factory(), name);
302 // Add break location for destructured sub-pattern. 298 // Add break location for destructured sub-pattern.
303 int pos = 299 int pos = IsSubPattern() ? pattern->position() : value->position();
304 IsSubPattern() ? pattern->position() : descriptor_->initialization_pos;
305 Assignment* assignment = 300 Assignment* assignment =
306 factory()->NewAssignment(Token::INIT, proxy, value, pos); 301 factory()->NewAssignment(Token::INIT, proxy, value, pos);
307 block_->statements()->Add( 302 block_->statements()->Add(
308 factory()->NewExpressionStatement(assignment, pos), zone()); 303 factory()->NewExpressionStatement(assignment, pos), zone());
309 } 304 }
310 } 305 }
311 306
312 307
313 Variable* Parser::PatternRewriter::CreateTempVar(Expression* value) { 308 Variable* Parser::PatternRewriter::CreateTempVar(Expression* value) {
314 auto temp = scope()->NewTemporary(ast_value_factory()->empty_string()); 309 auto temp = scope()->NewTemporary(ast_value_factory()->empty_string());
(...skipping 305 matching lines...) Expand 10 before | Expand all | Expand 10 after
620 NOT_A_PATTERN(TryFinallyStatement) 615 NOT_A_PATTERN(TryFinallyStatement)
621 NOT_A_PATTERN(UnaryOperation) 616 NOT_A_PATTERN(UnaryOperation)
622 NOT_A_PATTERN(VariableDeclaration) 617 NOT_A_PATTERN(VariableDeclaration)
623 NOT_A_PATTERN(WhileStatement) 618 NOT_A_PATTERN(WhileStatement)
624 NOT_A_PATTERN(WithStatement) 619 NOT_A_PATTERN(WithStatement)
625 NOT_A_PATTERN(Yield) 620 NOT_A_PATTERN(Yield)
626 621
627 #undef NOT_A_PATTERN 622 #undef NOT_A_PATTERN
628 } // namespace internal 623 } // namespace internal
629 } // namespace v8 624 } // namespace v8
OLDNEW
« no previous file with comments | « no previous file | test/cctest/test-debug.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698