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

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

Non-AllInOne build fix.

  • kjs/interpreter.cpp: Include JSLock.h.
  • Property svn:eol-style set to native
File size: 3.6 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 "JSLock.h"
29#include "Machine.h"
30#include "Parser.h"
31#include "completion.h"
32#include "debugger.h"
33#include <profiler/Profiler.h>
34#include <stdio.h>
35
36#if !PLATFORM(WIN_OS)
37#include <unistd.h>
38#endif
39
40namespace KJS {
41
42Completion Interpreter::checkSyntax(ExecState* exec, const UString& sourceURL, int startingLineNumber, const UString& code)
43{
44 return checkSyntax(exec, sourceURL, startingLineNumber, UStringSourceProvider::create(code));
45}
46
47Completion Interpreter::checkSyntax(ExecState* exec, const UString& sourceURL, int startingLineNumber, PassRefPtr<SourceProvider> source)
48{
49 JSLock lock(exec);
50
51 int errLine;
52 UString errMsg;
53
54 RefPtr<ProgramNode> progNode = exec->parser()->parse<ProgramNode>(exec, sourceURL, startingLineNumber, source, 0, &errLine, &errMsg);
55 if (!progNode)
56 return Completion(Throw, Error::create(exec, SyntaxError, errMsg, errLine, 0, sourceURL));
57 return Completion(Normal);
58}
59
60Completion Interpreter::evaluate(ExecState* exec, ScopeChain& scopeChain, const UString& sourceURL, int startingLineNumber, const UString& code, JSValue* thisV)
61{
62 return evaluate(exec, scopeChain, sourceURL, startingLineNumber, UStringSourceProvider::create(code), thisV);
63}
64
65Completion Interpreter::evaluate(ExecState* exec, ScopeChain& scopeChain, const UString& sourceURL, int startingLineNumber, PassRefPtr<SourceProvider> source, JSValue* thisValue)
66{
67 JSLock lock(exec);
68
69 // parse the source code
70 int sourceId;
71 int errLine;
72 UString errMsg;
73
74 RefPtr<ProgramNode> programNode = exec->parser()->parse<ProgramNode>(exec, sourceURL, startingLineNumber, source, &sourceId, &errLine, &errMsg);
75
76 // no program node means a syntax error occurred
77 if (!programNode)
78 return Completion(Throw, Error::create(exec, SyntaxError, errMsg, errLine, sourceId, sourceURL));
79
80 JSObject* thisObj = (!thisValue || thisValue->isUndefinedOrNull()) ? exec->dynamicGlobalObject() : thisValue->toObject(exec);
81
82 JSValue* exception = 0;
83 JSValue* result = exec->machine()->execute(programNode.get(), exec, scopeChain.node(), thisObj, &exception);
84
85 if (exception) {
86 if (exception->isObject() && static_cast<JSObject*>(exception)->isWatchdogException())
87 return Completion(Interrupted, result);
88 return Completion(Throw, exception);
89 }
90 return Completion(Normal, result);
91}
92
93static bool printExceptions = false;
94
95bool Interpreter::shouldPrintExceptions()
96{
97 return printExceptions;
98}
99
100void Interpreter::setShouldPrintExceptions(bool print)
101{
102 printExceptions = print;
103}
104
105} // namespace KJS
Note: See TracBrowser for help on using the repository browser.