Changeset 38047 in webkit for trunk/JavaScriptCore/VM/CodeGenerator.cpp
- Timestamp:
- Oct 31, 2008, 12:59:08 PM (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/JavaScriptCore/VM/CodeGenerator.cpp
r37991 r38047 205 205 , m_dynamicScopeDepth(0) 206 206 , m_codeType(GlobalCode) 207 , m_continueDepth(0)208 207 , m_nextGlobal(-1) 209 208 , m_globalData(&scopeChain.globalObject()->globalExec()->globalData()) … … 283 282 , m_dynamicScopeDepth(0) 284 283 , m_codeType(FunctionCode) 285 , m_continueDepth(0)286 284 , m_globalData(&scopeChain.globalObject()->globalExec()->globalData()) 287 285 , m_lastOpcodeID(op_end) … … 354 352 , m_dynamicScopeDepth(0) 355 353 , m_codeType(EvalCode) 356 , m_continueDepth(0)357 354 , m_globalData(&scopeChain.globalObject()->globalExec()->globalData()) 358 355 , m_lastOpcodeID(op_end) … … 450 447 newRegister(); 451 448 return &m_calleeRegisters.last(); 449 } 450 451 PassRefPtr<LabelScope> CodeGenerator::newLabelScope(LabelScope::Type type, const Identifier* name) 452 { 453 // Reclaim free label scopes. 454 while (m_labelScopes.size() && !m_labelScopes.last().refCount()) 455 m_labelScopes.removeLast(); 456 457 // Allocate new label scope. 458 LabelScope scope(type, name, scopeDepth(), newLabel(), type == LabelScope::Loop ? newLabel() : 0); // Only loops have continue targets. 459 m_labelScopes.append(scope); 460 return &m_labelScopes.last(); 452 461 } 453 462 … … 1357 1366 } 1358 1367 1359 void CodeGenerator::pushJumpContext(LabelStack* labels, LabelID* continueTarget, LabelID* breakTarget, bool isValidUnlabeledBreakTarget) 1360 { 1361 JumpContext context = { labels, continueTarget, breakTarget, scopeDepth(), isValidUnlabeledBreakTarget }; 1362 m_jumpContextStack.append(context); 1363 if (continueTarget) 1364 m_continueDepth++; 1365 } 1366 1367 void CodeGenerator::popJumpContext() 1368 { 1369 ASSERT(m_jumpContextStack.size()); 1370 if (m_jumpContextStack.last().continueTarget) 1371 m_continueDepth--; 1372 m_jumpContextStack.removeLast(); 1373 } 1374 1375 JumpContext* CodeGenerator::jumpContextForContinue(const Identifier& label) 1376 { 1377 if(!m_jumpContextStack.size()) 1368 LabelScope* CodeGenerator::breakTarget(const Identifier& name) 1369 { 1370 // Reclaim free label scopes. 1371 while (m_labelScopes.size() && !m_labelScopes.last().refCount()) 1372 m_labelScopes.removeLast(); 1373 1374 if (!m_labelScopes.size()) 1378 1375 return 0; 1379 1376 1380 if (label.isEmpty()) { 1381 for (int i = m_jumpContextStack.size() - 1; i >= 0; i--) { 1382 JumpContext* scope = &m_jumpContextStack[i]; 1383 if (scope->continueTarget) 1377 // We special-case the following, which is a syntax error in Firefox: 1378 // label: 1379 // break; 1380 if (name.isEmpty()) { 1381 for (int i = m_labelScopes.size() - 1; i >= 0; --i) { 1382 LabelScope* scope = &m_labelScopes[i]; 1383 if (scope->type() != LabelScope::NamedLabel) { 1384 ASSERT(scope->breakTarget()); 1384 1385 return scope; 1386 } 1385 1387 } 1386 1388 return 0; 1387 1389 } 1388 1390 1389 for (int i = m_jumpContextStack.size() - 1; i >= 0; i--) { 1390 JumpContext* scope = &m_jumpContextStack[i]; 1391 if (scope->labels->contains(label)) 1391 for (int i = m_labelScopes.size() - 1; i >= 0; --i) { 1392 LabelScope* scope = &m_labelScopes[i]; 1393 if (scope->name() && *scope->name() == name) { 1394 ASSERT(scope->breakTarget()); 1392 1395 return scope; 1396 } 1393 1397 } 1394 1398 return 0; 1395 1399 } 1396 1400 1397 JumpContext* CodeGenerator::jumpContextForBreak(const Identifier& label) 1398 { 1399 if(!m_jumpContextStack.size()) 1401 LabelScope* CodeGenerator::continueTarget(const Identifier& name) 1402 { 1403 // Reclaim free label scopes. 1404 while (m_labelScopes.size() && !m_labelScopes.last().refCount()) 1405 m_labelScopes.removeLast(); 1406 1407 if (!m_labelScopes.size()) 1400 1408 return 0; 1401 1409 1402 if (label.isEmpty()) { 1403 for (int i = m_jumpContextStack.size() - 1; i >= 0; i--) { 1404 JumpContext* scope = &m_jumpContextStack[i]; 1405 if (scope->isValidUnlabeledBreakTarget) 1410 if (name.isEmpty()) { 1411 for (int i = m_labelScopes.size() - 1; i >= 0; --i) { 1412 LabelScope* scope = &m_labelScopes[i]; 1413 if (scope->type() == LabelScope::Loop) { 1414 ASSERT(scope->continueTarget()); 1406 1415 return scope; 1416 } 1407 1417 } 1408 1418 return 0; 1409 1419 } 1410 1420 1411 for (int i = m_jumpContextStack.size() - 1; i >= 0; i--) { 1412 JumpContext* scope = &m_jumpContextStack[i]; 1413 if (scope->labels->contains(label)) 1414 return scope; 1421 // Continue to the loop nested nearest to the label scope that matches 1422 // 'name'. 1423 LabelScope* result = 0; 1424 for (int i = m_labelScopes.size() - 1; i >= 0; --i) { 1425 LabelScope* scope = &m_labelScopes[i]; 1426 if (scope->type() == LabelScope::Loop) { 1427 ASSERT(scope->continueTarget()); 1428 result = scope; 1429 } 1430 if (scope->name() && *scope->name() == name) 1431 return result; // may be 0 1415 1432 } 1416 1433 return 0;
Note:
See TracChangeset
for help on using the changeset viewer.