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

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

Rubber-stamped by Maciej.

Eliminate JSLock (it was already disabled, removing the stub implementaion and all
call sites now).

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