mjs | 6f821c8 | 2002-03-22 00:31:57 +0000 | [diff] [blame] | 1 | /* |
mjs | 6f821c8 | 2002-03-22 00:31:57 +0000 | [diff] [blame] | 2 | * Copyright (C) 1999-2001 Harri Porten (porten@kde.org) |
| 3 | * Copyright (C) 2001 Peter Kelly (pmk@post.com) |
ggaren@apple.com | 1b4d90b | 2007-12-06 02:31:41 +0000 | [diff] [blame] | 4 | * Copyright (C) 2003, 2007 Apple Inc. All rights reserved. |
mjs | 6f821c8 | 2002-03-22 00:31:57 +0000 | [diff] [blame] | 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 |
mjs | cdff33b | 2006-01-23 21:41:36 +0000 | [diff] [blame] | 18 | * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
ggaren | 07d4ce6 | 2005-07-14 18:27:04 +0000 | [diff] [blame] | 19 | * Boston, MA 02110-1301, USA. |
mjs | 6f821c8 | 2002-03-22 00:31:57 +0000 | [diff] [blame] | 20 | * |
mjs | 6f821c8 | 2002-03-22 00:31:57 +0000 | [diff] [blame] | 21 | */ |
| 22 | |
ggaren@apple.com | 1b4d90b | 2007-12-06 02:31:41 +0000 | [diff] [blame] | 23 | #ifndef KJS_Interpreter_h |
| 24 | #define KJS_Interpreter_h |
rjw | dcdc36b | 2005-02-12 00:58:13 +0000 | [diff] [blame] | 25 | |
mrowe@apple.com | 2f6dfdf | 2008-05-22 01:20:45 +0000 | [diff] [blame] | 26 | #include <wtf/PassRefPtr.h> |
eric@webkit.org | 87d855b | 2008-03-10 22:06:44 +0000 | [diff] [blame] | 27 | #include <wtf/unicode/Unicode.h> |
| 28 | |
mjs | 6f821c8 | 2002-03-22 00:31:57 +0000 | [diff] [blame] | 29 | namespace KJS { |
| 30 | |
ggaren@apple.com | 1b4d90b | 2007-12-06 02:31:41 +0000 | [diff] [blame] | 31 | class Completion; |
| 32 | class ExecState; |
| 33 | class JSValue; |
mrowe@apple.com | 2f6dfdf | 2008-05-22 01:20:45 +0000 | [diff] [blame] | 34 | class ScopeChain; |
| 35 | class SourceProvider; |
ggaren@apple.com | 1b4d90b | 2007-12-06 02:31:41 +0000 | [diff] [blame] | 36 | class UString; |
andersca | bfa44ad | 2006-06-16 23:47:20 +0000 | [diff] [blame] | 37 | |
ggaren@apple.com | 4189321 | 2007-12-01 23:56:56 +0000 | [diff] [blame] | 38 | class Interpreter { |
mjs | 6f821c8 | 2002-03-22 00:31:57 +0000 | [diff] [blame] | 39 | public: |
| 40 | /** |
mjs | 6f821c8 | 2002-03-22 00:31:57 +0000 | [diff] [blame] | 41 | * Parses the supplied ECMAScript code and checks for syntax errors. |
| 42 | * |
| 43 | * @param code The code to check |
ggaren | 2008a98 | 2006-07-05 16:52:54 +0000 | [diff] [blame] | 44 | * @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. |
mjs | 6f821c8 | 2002-03-22 00:31:57 +0000 | [diff] [blame] | 46 | */ |
ggaren@apple.com | 1b4d90b | 2007-12-06 02:31:41 +0000 | [diff] [blame] | 47 | static Completion checkSyntax(ExecState*, const UString& sourceURL, int startingLineNumber, const UString& code); |
mrowe@apple.com | 2f6dfdf | 2008-05-22 01:20:45 +0000 | [diff] [blame] | 48 | static Completion checkSyntax(ExecState*, const UString& sourceURL, int startingLineNumber, PassRefPtr<SourceProvider> source); |
mjs | 6f821c8 | 2002-03-22 00:31:57 +0000 | [diff] [blame] | 49 | |
| 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 |
darin | 7fcaf3a | 2005-12-11 00:38:07 +0000 | [diff] [blame] | 62 | * execution. This should either be jsNull() or an Object. |
mjs | 6f821c8 | 2002-03-22 00:31:57 +0000 | [diff] [blame] | 63 | * @return A completion object representing the result of the execution. |
| 64 | */ |
mrowe@apple.com | 2f6dfdf | 2008-05-22 01:20:45 +0000 | [diff] [blame] | 65 | 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); |
ggaren | 01b2e77 | 2006-06-13 06:08:52 +0000 | [diff] [blame] | 67 | |
mjs | c9953bf | 2003-05-13 21:19:57 +0000 | [diff] [blame] | 68 | static bool shouldPrintExceptions(); |
| 69 | static void setShouldPrintExceptions(bool); |
mjs | 6f821c8 | 2002-03-22 00:31:57 +0000 | [diff] [blame] | 70 | }; |
| 71 | |
ggaren@apple.com | 1b4d90b | 2007-12-06 02:31:41 +0000 | [diff] [blame] | 72 | } // namespace KJS |
mjs | 6f821c8 | 2002-03-22 00:31:57 +0000 | [diff] [blame] | 73 | |
ggaren@apple.com | 1b4d90b | 2007-12-06 02:31:41 +0000 | [diff] [blame] | 74 | #endif // KJS_Interpreter_h |