source: webkit/trunk/JavaScriptCore/parser/Parser.cpp@ 43375

Last change on this file since 43375 was 43375, checked in by [email protected], 16 years ago

2009-05-07 Geoffrey Garen <[email protected]>

Reviewed by Cameron Zwarich.


Fixed a minor sequencing error introduced by recent Parser speedups.

  • parser/Parser.cpp: (JSC::Parser::parse):
  • parser/Parser.h: (JSC::Parser::parse): (JSC::Parser::reparse): Shrink the parsedObjects vector after allocating the root node, to avoid leaving a stray node in the vector, since that's a slight memory leak, and it causes problems during JSGlobalData teardown.
  • runtime/JSGlobalData.cpp: (JSC::JSGlobalData::~JSGlobalData): ASSERT that we're not being torn down while we think we're still parsing, since that would cause lots of bad memory references during our destruction.
  • Property svn:eol-style set to native
File size: 3.4 KB
Line 
1/*
2 * Copyright (C) 1999-2001 Harri Porten ([email protected])
3 * Copyright (C) 2001 Peter Kelly ([email protected])
4 * Copyright (C) 2003, 2006, 2007, 2008, 2009 Apple Inc. All rights reserved.
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Library General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Library General Public License for more details.
15 *
16 * You should have received a copy of the GNU Library General Public License
17 * along with this library; see the file COPYING.LIB. If not, write to
18 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19 * Boston, MA 02110-1301, USA.
20 *
21 */
22
23#include "config.h"
24#include "Parser.h"
25
26#include "Debugger.h"
27#include "Lexer.h"
28#include <wtf/HashSet.h>
29#include <wtf/Vector.h>
30#include <memory>
31
32using std::auto_ptr;
33
34#ifndef yyparse
35extern int jscyyparse(void*);
36#endif
37
38namespace JSC {
39
40void Parser::parse(JSGlobalData* globalData, int* errLine, UString* errMsg)
41{
42 ASSERT(!m_sourceElements);
43
44 int defaultErrLine;
45 UString defaultErrMsg;
46
47 if (!errLine)
48 errLine = &defaultErrLine;
49 if (!errMsg)
50 errMsg = &defaultErrMsg;
51
52 *errLine = -1;
53 *errMsg = 0;
54
55 Lexer& lexer = *globalData->lexer;
56 lexer.setCode(*m_source);
57
58 int parseError = jscyyparse(globalData);
59 bool lexError = lexer.sawError();
60 int lineNumber = lexer.lineNumber();
61 lexer.clear();
62
63 if (parseError || lexError) {
64 *errLine = lineNumber;
65 *errMsg = "Parse error";
66 m_sourceElements.clear();
67 }
68}
69
70void Parser::reparseInPlace(JSGlobalData* globalData, FunctionBodyNode* functionBodyNode)
71{
72 ASSERT(!functionBodyNode->data());
73
74 m_source = &functionBodyNode->source();
75 globalData->lexer->setIsReparsing();
76 parse(globalData, 0, 0);
77 ASSERT(m_sourceElements);
78
79 functionBodyNode->adoptData(std::auto_ptr<ScopeNodeData>(new ScopeNodeData(m_sourceElements.get(),
80 m_varDeclarations ? &m_varDeclarations->data : 0,
81 m_funcDeclarations ? &m_funcDeclarations->data : 0,
82 m_numConstants)));
83 bool usesArguments = functionBodyNode->usesArguments();
84 functionBodyNode->setFeatures(m_features);
85 if (usesArguments && !functionBodyNode->usesArguments())
86 functionBodyNode->setUsesArguments();
87
88 m_source = 0;
89 m_sourceElements = 0;
90 m_varDeclarations = 0;
91 m_funcDeclarations = 0;
92}
93
94void Parser::didFinishParsing(SourceElements* sourceElements, ParserRefCountedData<DeclarationStacks::VarStack>* varStack,
95 ParserRefCountedData<DeclarationStacks::FunctionStack>* funcStack, CodeFeatures features, int lastLine, int numConstants)
96{
97 m_sourceElements = sourceElements;
98 m_varDeclarations = varStack;
99 m_funcDeclarations = funcStack;
100 m_features = features;
101 m_lastLine = lastLine;
102 m_numConstants = numConstants;
103}
104
105} // namespace JSC
Note: See TracBrowser for help on using the repository browser.