source: webkit/trunk/JavaScriptCore/kjs/interpreter.cpp@ 34412

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

Reviewed by Darin.

Combine per-thread objects into one, to make it easier to support legacy clients (for
which they shouldn't be really per-thread).

No change on SunSpider total.

  • kjs/JSGlobalData.cpp: Added. (KJS::JSGlobalData::JSGlobalData): (KJS::JSGlobalData::~JSGlobalData): (KJS::JSGlobalData::threadInstance):
  • kjs/JSGlobalData.h: Added. This class encapsulates all data that should be per-thread (or shared between legacy clients). It will also keep a Heap pointer, but right now, Heap (Collector) methods are all static.
  • kjs/identifier.h: (KJS::Identifier::Identifier): Added a constructor explicitly taking JSGlobalData to access IdentifierTable. Actually, all of them should, but this will be a separate patch.
  • kjs/identifier.cpp: (KJS::IdentifierTable::literalTable): (KJS::createIdentifierTable): (KJS::deleteIdentifierTable): (KJS::Identifier::add): (KJS::Identifier::addSlowCase): Combined IdentifierTable and LiteralIdentifierTable into a single class for simplicity.
  • kjs/grammar.y: kjsyyparse now takes JSGlobalData, not just a Lexer.
  • kjs/nodes.cpp: (KJS::Node::Node): (KJS::EvalFunctionCallNode::emitCode): (KJS::ScopeNode::ScopeNode): Changed to access Lexer and Parser via JSGlobalData::threadInstance(). This is also a temporary measure, they will need to use JSGlobalData explicitly.
  • VM/CodeGenerator.cpp: (KJS::CodeGenerator::CodeGenerator):
  • VM/CodeGenerator.h:
  • VM/Machine.cpp: (KJS::callEval):
  • kjs/CommonIdentifiers.cpp: (KJS::CommonIdentifiers::CommonIdentifiers):
  • kjs/CommonIdentifiers.h:
  • kjs/DebuggerCallFrame.cpp: (KJS::DebuggerCallFrame::evaluate):
  • kjs/ExecState.cpp: (KJS::ExecState::ExecState):
  • kjs/ExecState.h: (KJS::ExecState::globalData): (KJS::ExecState::identifierTable): (KJS::ExecState::propertyNames): (KJS::ExecState::emptyList): (KJS::ExecState::lexer): (KJS::ExecState::parser): (KJS::ExecState::arrayTable): (KJS::ExecState::dateTable): (KJS::ExecState::mathTable): (KJS::ExecState::numberTable): (KJS::ExecState::RegExpImpTable): (KJS::ExecState::RegExpObjectImpTable): (KJS::ExecState::stringTable):
  • kjs/InitializeThreading.cpp: (KJS::initializeThreadingOnce):
  • kjs/JSGlobalObject.cpp: (KJS::JSGlobalObject::init):
  • kjs/JSGlobalObject.h: (KJS::JSGlobalObject::JSGlobalObjectData::JSGlobalObjectData): (KJS::JSGlobalObject::head): (KJS::JSGlobalObject::globalData):
  • kjs/Parser.cpp: (KJS::Parser::parse):
  • kjs/Parser.h:
  • kjs/function.cpp: (KJS::FunctionImp::getParameterName): (KJS::IndexToNameMap::unMap): (KJS::globalFuncEval):
  • kjs/function_object.cpp: (KJS::FunctionObjectImp::construct):
  • kjs/interpreter.cpp: (KJS::Interpreter::checkSyntax): (KJS::Interpreter::evaluate):
  • kjs/lexer.cpp: (kjsyylex):
  • kjs/lexer.h:
  • kjs/testkjs.cpp: (prettyPrintScript): Updated for the above changes. Most of threadInstance uses here will need to be replaced with explicitly passed pointers to support legacy JSC clients.
  • 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, 2007 Apple Inc.
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 "interpreter.h"
25
26#include "ExecState.h"
27#include "JSGlobalObject.h"
28#include "Machine.h"
29#include "Parser.h"
30#include "debugger.h"
31#include <profiler/Profiler.h>
32#include <stdio.h>
33
34#if !PLATFORM(WIN_OS)
35#include <unistd.h>
36#endif
37
38namespace KJS {
39
40Completion Interpreter::checkSyntax(ExecState* exec, const UString& sourceURL, int startingLineNumber, const UString& code)
41{
42 return checkSyntax(exec, sourceURL, startingLineNumber, UStringSourceProvider::create(code));
43}
44
45Completion Interpreter::checkSyntax(ExecState* exec, const UString& sourceURL, int startingLineNumber, PassRefPtr<SourceProvider> source)
46{
47 JSLock lock;
48
49 int errLine;
50 UString errMsg;
51
52 RefPtr<ProgramNode> progNode = exec->parser()->parse<ProgramNode>(exec, sourceURL, startingLineNumber, source, 0, &errLine, &errMsg);
53 if (!progNode)
54 return Completion(Throw, Error::create(exec, SyntaxError, errMsg, errLine, 0, sourceURL));
55 return Completion(Normal);
56}
57
58Completion Interpreter::evaluate(ExecState* exec, ScopeChain& scopeChain, const UString& sourceURL, int startingLineNumber, const UString& code, JSValue* thisV)
59{
60 return evaluate(exec, scopeChain, sourceURL, startingLineNumber, UStringSourceProvider::create(code), thisV);
61}
62
63Completion Interpreter::evaluate(ExecState* exec, ScopeChain& scopeChain, const UString& sourceURL, int startingLineNumber, PassRefPtr<SourceProvider> source, JSValue* thisValue)
64{
65 JSLock lock;
66
67 // parse the source code
68 int sourceId;
69 int errLine;
70 UString errMsg;
71
72 RefPtr<ProgramNode> programNode = exec->parser()->parse<ProgramNode>(exec, sourceURL, startingLineNumber, source, &sourceId, &errLine, &errMsg);
73
74 // no program node means a syntax error occurred
75 if (!programNode)
76 return Completion(Throw, Error::create(exec, SyntaxError, errMsg, errLine, sourceId, sourceURL));
77
78 JSObject* thisObj = (!thisValue || thisValue->isUndefinedOrNull()) ? exec->dynamicGlobalObject() : thisValue->toObject(exec);
79
80 JSValue* exception = 0;
81 JSValue* result = machine().execute(programNode.get(), exec, scopeChain.node(), thisObj, &exec->dynamicGlobalObject()->registerFileStack(), &exception);
82
83 return exception ? Completion(Throw, exception) : Completion(Normal, result);
84}
85
86static bool printExceptions = false;
87
88bool Interpreter::shouldPrintExceptions()
89{
90 return printExceptions;
91}
92
93void Interpreter::setShouldPrintExceptions(bool print)
94{
95 printExceptions = print;
96}
97
98} // namespace KJS
Note: See TracBrowser for help on using the repository browser.