Changeset 127774 in webkit for trunk/Source/JavaScriptCore/bytecompiler
- Timestamp:
- Sep 6, 2012, 12:45:35 PM (13 years ago)
- Location:
- trunk/Source/JavaScriptCore/bytecompiler
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/JavaScriptCore/bytecompiler/BytecodeGenerator.cpp
r127698 r127774 34 34 #include "BatchedTransitionOptimizer.h" 35 35 #include "Comment.h" 36 #include "Interpreter.h"37 36 #include "JSActivation.h" 38 37 #include "JSFunction.h" 39 #include " JSNameScope.h"38 #include "Interpreter.h" 40 39 #include "LowLevelInterpreter.h" 40 41 41 #include "StrongInlines.h" 42 42 #include <wtf/text/WTFString.h> … … 325 325 globalObject->removeDirect(*m_globalData, function->ident()); // Newly declared functions overwrite existing properties. 326 326 327 JSValue value = JSFunction::create(exec, FunctionExecutable::create(*m_globalData, function), scope);327 JSValue value = JSFunction::create(exec, makeFunction(exec, function), scope); 328 328 int index = addGlobalVar( 329 329 function->ident(), IsVariable, … … 420 420 } 421 421 422 RegisterID* calleeRegister = resolveCallee(functionBody); // May push to the scope chain and/or add a captured var.423 424 422 const DeclarationStacks::FunctionStack& functionStack = functionBody->functionStack(); 425 423 const DeclarationStacks::VarStack& varStack = functionBody->varStack(); … … 459 457 460 458 codeBlock->m_numCapturedVars = codeBlock->m_numVars; 461 462 459 m_firstLazyFunction = codeBlock->m_numVars; 463 460 for (size_t i = 0; i < functionStack.size(); ++i) { … … 500 497 501 498 preserveLastVar(); 502 503 // We declare the callee's name last because it should lose to a var, function, and/or parameter declaration.504 addCallee(functionBody, calleeRegister);505 499 506 500 if (isConstructor()) { … … 556 550 const DeclarationStacks::FunctionStack& functionStack = evalNode->functionStack(); 557 551 for (size_t i = 0; i < functionStack.size(); ++i) 558 m_codeBlock->addFunctionDecl( FunctionExecutable::create(*m_globalData, functionStack[i]));552 m_codeBlock->addFunctionDecl(makeFunction(m_globalData, functionStack[i])); 559 553 560 554 const DeclarationStacks::VarStack& varStack = evalNode->varStack(); … … 579 573 instructions().append(reg->index()); 580 574 return reg; 581 }582 583 RegisterID* BytecodeGenerator::resolveCallee(FunctionBodyNode* functionBodyNode)584 {585 if (functionBodyNode->ident().isNull())586 return 0;587 588 m_calleeRegister.setIndex(RegisterFile::Callee);589 590 // If non-strict eval is in play, we use a separate object in the scope chain for the callee's name.591 if ((m_codeBlock->usesEval() && !m_codeBlock->isStrictMode()) || m_shouldEmitDebugHooks) {592 emitOpcode(op_push_name_scope);593 instructions().append(addConstant(functionBodyNode->ident()));594 instructions().append(m_calleeRegister.index());595 instructions().append(ReadOnly | DontDelete);596 597 // Put a mirror object in compilation scope, so compile-time variable resolution sees the property name we'll see at runtime.598 m_scope.set(*globalData(),599 JSNameScope::create(600 m_scope->globalObject()->globalExec(),601 functionBodyNode->ident(),602 jsUndefined(),603 ReadOnly | DontDelete,604 m_scope.get()605 )606 );607 return 0;608 }609 610 if (!functionBodyNode->captures(functionBodyNode->ident()))611 return &m_calleeRegister;612 613 // Move the callee into the captured section of the stack.614 return emitMove(addVar(), &m_calleeRegister);615 }616 617 void BytecodeGenerator::addCallee(FunctionBodyNode* functionBodyNode, RegisterID* calleeRegister)618 {619 if (functionBodyNode->ident().isNull())620 return;621 622 // If non-strict eval is in play, we use a separate object in the scope chain for the callee's name.623 if ((m_codeBlock->usesEval() && !m_codeBlock->isStrictMode()) || m_shouldEmitDebugHooks)624 return;625 626 ASSERT(calleeRegister);627 symbolTable().add(functionBodyNode->ident().impl(), SymbolTableEntry(calleeRegister->index(), ReadOnly));628 575 } 629 576 … … 1884 1831 RegisterID* BytecodeGenerator::emitNewFunction(RegisterID* dst, FunctionBodyNode* function) 1885 1832 { 1886 return emitNewFunctionInternal(dst, m_codeBlock->addFunctionDecl( FunctionExecutable::create(*m_globalData, function)), false);1833 return emitNewFunctionInternal(dst, m_codeBlock->addFunctionDecl(makeFunction(m_globalData, function)), false); 1887 1834 } 1888 1835 … … 1891 1838 FunctionOffsetMap::AddResult ptr = m_functionOffsets.add(function, 0); 1892 1839 if (ptr.isNewEntry) 1893 ptr.iterator->second = m_codeBlock->addFunctionDecl( FunctionExecutable::create(*m_globalData, function));1840 ptr.iterator->second = m_codeBlock->addFunctionDecl(makeFunction(m_globalData, function)); 1894 1841 return emitNewFunctionInternal(dst, ptr.iterator->second, true); 1895 1842 } … … 1916 1863 { 1917 1864 FunctionBodyNode* function = n->body(); 1918 unsigned index = m_codeBlock->addFunctionExpr( FunctionExecutable::create(*m_globalData, function));1865 unsigned index = m_codeBlock->addFunctionExpr(makeFunction(m_globalData, function)); 1919 1866 1920 1867 createActivationIfNecessary(); … … 2653 2600 return; 2654 2601 2655 RefPtr<RegisterID> error = emitLoad(newTemporary(), JSValue(createTypeError(scope()->globalObject()->globalExec(), StrictModeReadonlyPropertyWriteError)));2602 RefPtr<RegisterID> error = emitLoad(newTemporary(), createTypeError(scope()->globalObject()->globalExec(), StrictModeReadonlyPropertyWriteError)); 2656 2603 emitThrow(error.get()); 2657 2604 } -
trunk/Source/JavaScriptCore/bytecompiler/BytecodeGenerator.h
r127698 r127774 618 618 619 619 void addParameter(const Identifier&, int parameterIndex); 620 RegisterID* resolveCallee(FunctionBodyNode*); 621 void addCallee(FunctionBodyNode*, RegisterID*); 622 620 623 621 void preserveLastVar(); 624 622 bool shouldAvoidResolveGlobal(); … … 628 626 if (index >= 0) 629 627 return m_calleeRegisters[index]; 630 631 if (index == RegisterFile::Callee)632 return m_calleeRegister;633 628 634 629 ASSERT(m_parameters.size()); … … 642 637 unsigned addConstantBuffer(unsigned length); 643 638 639 FunctionExecutable* makeFunction(ExecState* exec, FunctionBodyNode* body) 640 { 641 return FunctionExecutable::create(exec, body->ident(), body->inferredName(), body->source(), body->usesArguments(), body->parameters(), body->isStrictMode(), body->lineNo(), body->lastLine()); 642 } 643 644 FunctionExecutable* makeFunction(JSGlobalData* globalData, FunctionBodyNode* body) 645 { 646 return FunctionExecutable::create(*globalData, body->ident(), body->inferredName(), body->source(), body->usesArguments(), body->parameters(), body->isStrictMode(), body->lineNo(), body->lastLine()); 647 } 648 644 649 JSString* addStringConstant(const Identifier&); 645 650 … … 712 717 RegisterID m_ignoredResultRegister; 713 718 RegisterID m_thisRegister; 714 RegisterID m_calleeRegister;715 719 RegisterID* m_activationRegister; 716 720 SegmentedVector<RegisterID, 32> m_constantPoolRegisters;
Note:
See TracChangeset
for help on using the changeset viewer.