blob: a8dbd6e47bd5c34619c7b45570c9ffc4bdab9af7 [file] [log] [blame]
mjs6f821c82002-03-22 00:31:57 +00001/*
mjs6f821c82002-03-22 00:31:57 +00002 * Copyright (C) 1999-2001 Harri Porten (porten@kde.org)
3 * Copyright (C) 2001 Peter Kelly (pmk@post.com)
ggaren@apple.com1b4d90b2007-12-06 02:31:41 +00004 * Copyright (C) 2003, 2007 Apple Inc. All rights reserved.
mjs6f821c82002-03-22 00:31:57 +00005 *
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
mjscdff33b2006-01-23 21:41:36 +000018 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
ggaren07d4ce62005-07-14 18:27:04 +000019 * Boston, MA 02110-1301, USA.
mjs6f821c82002-03-22 00:31:57 +000020 *
mjs6f821c82002-03-22 00:31:57 +000021 */
22
ggaren@apple.com1b4d90b2007-12-06 02:31:41 +000023#ifndef KJS_Interpreter_h
24#define KJS_Interpreter_h
rjwdcdc36b2005-02-12 00:58:13 +000025
mrowe@apple.com2f6dfdf2008-05-22 01:20:45 +000026#include <wtf/PassRefPtr.h>
eric@webkit.org87d855b2008-03-10 22:06:44 +000027#include <wtf/unicode/Unicode.h>
28
mjs6f821c82002-03-22 00:31:57 +000029namespace KJS {
30
ggaren@apple.com1b4d90b2007-12-06 02:31:41 +000031 class Completion;
32 class ExecState;
33 class JSValue;
mrowe@apple.com2f6dfdf2008-05-22 01:20:45 +000034 class ScopeChain;
35 class SourceProvider;
ggaren@apple.com1b4d90b2007-12-06 02:31:41 +000036 class UString;
anderscabfa44ad2006-06-16 23:47:20 +000037
ggaren@apple.com41893212007-12-01 23:56:56 +000038 class Interpreter {
mjs6f821c82002-03-22 00:31:57 +000039 public:
40 /**
mjs6f821c82002-03-22 00:31:57 +000041 * Parses the supplied ECMAScript code and checks for syntax errors.
42 *
43 * @param code The code to check
ggaren2008a982006-07-05 16:52:54 +000044 * @return A normal completion if there were no syntax errors in the code,
45 * otherwise a throw completion with the syntax error as its value.
mjs6f821c82002-03-22 00:31:57 +000046 */
ggaren@apple.com1b4d90b2007-12-06 02:31:41 +000047 static Completion checkSyntax(ExecState*, const UString& sourceURL, int startingLineNumber, const UString& code);
mrowe@apple.com2f6dfdf2008-05-22 01:20:45 +000048 static Completion checkSyntax(ExecState*, const UString& sourceURL, int startingLineNumber, PassRefPtr<SourceProvider> source);
mjs6f821c82002-03-22 00:31:57 +000049
50 /**
51 * Evaluates the supplied ECMAScript code.
52 *
53 * Since this method returns a Completion, you should check the type of
54 * completion to detect an error or before attempting to access the returned
55 * value. For example, if an error occurs during script execution and is not
56 * caught by the script, the completion type will be Throw.
57 *
58 * If the supplied code is invalid, a SyntaxError will be thrown.
59 *
60 * @param code The code to evaluate
61 * @param thisV The value to pass in as the "this" value for the script
darin7fcaf3a2005-12-11 00:38:07 +000062 * execution. This should either be jsNull() or an Object.
mjs6f821c82002-03-22 00:31:57 +000063 * @return A completion object representing the result of the execution.
64 */
mrowe@apple.com2f6dfdf2008-05-22 01:20:45 +000065 static Completion evaluate(ExecState*, ScopeChain&, const UString& sourceURL, int startingLineNumber, const UString& code, JSValue* thisV = 0);
66 static Completion evaluate(ExecState*, ScopeChain&, const UString& sourceURL, int startingLineNumber, PassRefPtr<SourceProvider>, JSValue* thisV = 0);
ggaren01b2e772006-06-13 06:08:52 +000067
mjsc9953bf2003-05-13 21:19:57 +000068 static bool shouldPrintExceptions();
69 static void setShouldPrintExceptions(bool);
mjs6f821c82002-03-22 00:31:57 +000070 };
71
ggaren@apple.com1b4d90b2007-12-06 02:31:41 +000072} // namespace KJS
mjs6f821c82002-03-22 00:31:57 +000073
ggaren@apple.com1b4d90b2007-12-06 02:31:41 +000074#endif // KJS_Interpreter_h