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. |
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 | |
mjs | b64c50a | 2005-10-03 21:13:12 +0000 | [diff] [blame] | 23 | #include "config.h" |
cwzwarich@webkit.org | 7764713 | 2008-11-05 23:48:18 +0000 | [diff] [blame] | 24 | #include "Completion.h" |
ggaren@apple.com | 4240a31 | 2008-11-17 17:55:40 +0000 | [diff] [blame] | 25 | |
mjs | e58111c | 2007-10-26 08:32:40 +0000 | [diff] [blame] | 26 | #include "ExecState.h" |
mjs | 0778195 | 2007-10-25 07:16:49 +0000 | [diff] [blame] | 27 | #include "JSGlobalObject.h" |
ap@webkit.org | 01aff70 | 2008-08-20 07:23:06 +0000 | [diff] [blame] | 28 | #include "JSLock.h" |
ggaren@apple.com | 901a8a2 | 2008-11-17 20:57:18 +0000 | [diff] [blame^] | 29 | #include "Interpreter.h" |
ggaren@apple.com | 898e9cd | 2007-12-08 00:35:08 +0000 | [diff] [blame] | 30 | #include "Parser.h" |
cwzwarich@webkit.org | a691b5a | 2008-10-31 05:56:58 +0000 | [diff] [blame] | 31 | #include "Debugger.h" |
ggaren | 7213ee0 | 2007-10-16 23:25:33 +0000 | [diff] [blame] | 32 | #include <stdio.h> |
mjs | 3bfb61b | 2006-03-02 09:12:06 +0000 | [diff] [blame] | 33 | |
darin@apple.com | 56b4667 | 2008-02-13 12:10:00 +0000 | [diff] [blame] | 34 | #if !PLATFORM(WIN_OS) |
| 35 | #include <unistd.h> |
| 36 | #endif |
| 37 | |
cwzwarich@webkit.org | 3f782f6 | 2008-09-08 01:28:33 +0000 | [diff] [blame] | 38 | namespace JSC { |
mjs | 6f821c8 | 2002-03-22 00:31:57 +0000 | [diff] [blame] | 39 | |
ggaren@apple.com | b7024cd | 2008-11-15 19:55:20 +0000 | [diff] [blame] | 40 | Completion checkSyntax(ExecState* exec, const SourceCode& source) |
mjs | 6f821c8 | 2002-03-22 00:31:57 +0000 | [diff] [blame] | 41 | { |
ap@webkit.org | 01aff70 | 2008-08-20 07:23:06 +0000 | [diff] [blame] | 42 | JSLock lock(exec); |
| 43 | |
ggaren | 2008a98 | 2006-07-05 16:52:54 +0000 | [diff] [blame] | 44 | int errLine; |
| 45 | UString errMsg; |
mrowe@apple.com | 2f6dfdf | 2008-05-22 01:20:45 +0000 | [diff] [blame] | 46 | |
ggaren@apple.com | 9f98034 | 2008-10-15 23:33:07 +0000 | [diff] [blame] | 47 | RefPtr<ProgramNode> progNode = exec->globalData().parser->parse<ProgramNode>(exec, exec->dynamicGlobalObject()->debugger(), source, &errLine, &errMsg); |
ggaren | 2008a98 | 2006-07-05 16:52:54 +0000 | [diff] [blame] | 48 | if (!progNode) |
ggaren@apple.com | 69e9ccf | 2008-10-02 06:44:37 +0000 | [diff] [blame] | 49 | return Completion(Throw, Error::create(exec, SyntaxError, errMsg, errLine, source.provider()->asID(), source.provider()->url())); |
ggaren | 2008a98 | 2006-07-05 16:52:54 +0000 | [diff] [blame] | 50 | return Completion(Normal); |
mjs | 6f821c8 | 2002-03-22 00:31:57 +0000 | [diff] [blame] | 51 | } |
| 52 | |
ggaren@apple.com | b7024cd | 2008-11-15 19:55:20 +0000 | [diff] [blame] | 53 | Completion evaluate(ExecState* exec, ScopeChain& scopeChain, const SourceCode& source, JSValue* thisValue) |
mjs | 6f821c8 | 2002-03-22 00:31:57 +0000 | [diff] [blame] | 54 | { |
ap@webkit.org | 01aff70 | 2008-08-20 07:23:06 +0000 | [diff] [blame] | 55 | JSLock lock(exec); |
| 56 | |
ggaren | 01b2e77 | 2006-06-13 06:08:52 +0000 | [diff] [blame] | 57 | int errLine; |
| 58 | UString errMsg; |
ggaren@apple.com | 9f98034 | 2008-10-15 23:33:07 +0000 | [diff] [blame] | 59 | RefPtr<ProgramNode> programNode = exec->globalData().parser->parse<ProgramNode>(exec, exec->dynamicGlobalObject()->debugger(), source, &errLine, &errMsg); |
kmccullough@apple.com | ac76976 | 2008-04-16 19:08:03 +0000 | [diff] [blame] | 60 | |
mrowe@apple.com | 2f6dfdf | 2008-05-22 01:20:45 +0000 | [diff] [blame] | 61 | if (!programNode) |
ggaren@apple.com | 69e9ccf | 2008-10-02 06:44:37 +0000 | [diff] [blame] | 62 | return Completion(Throw, Error::create(exec, SyntaxError, errMsg, errLine, source.provider()->asID(), source.provider()->url())); |
mrowe@apple.com | 2f6dfdf | 2008-05-22 01:20:45 +0000 | [diff] [blame] | 63 | |
| 64 | JSObject* thisObj = (!thisValue || thisValue->isUndefinedOrNull()) ? exec->dynamicGlobalObject() : thisValue->toObject(exec); |
| 65 | |
darin@apple.com | 44331f8 | 2008-10-24 16:22:51 +0000 | [diff] [blame] | 66 | JSValue* exception = noValue(); |
ggaren@apple.com | b7024cd | 2008-11-15 19:55:20 +0000 | [diff] [blame] | 67 | JSValue* result = exec->interpreter()->execute(programNode.get(), exec, scopeChain.node(), thisObj, &exception); |
kmccullough@apple.com | ac76976 | 2008-04-16 19:08:03 +0000 | [diff] [blame] | 68 | |
oliver@apple.com | c8f3a75 | 2008-06-28 04:02:03 +0000 | [diff] [blame] | 69 | if (exception) { |
darin@apple.com | 5a49442 | 2008-10-18 23:08:12 +0000 | [diff] [blame] | 70 | if (exception->isObject() && asObject(exception)->isWatchdogException()) |
oliver@apple.com | c8f3a75 | 2008-06-28 04:02:03 +0000 | [diff] [blame] | 71 | return Completion(Interrupted, result); |
| 72 | return Completion(Throw, exception); |
| 73 | } |
| 74 | return Completion(Normal, result); |
mjs | 6f821c8 | 2002-03-22 00:31:57 +0000 | [diff] [blame] | 75 | } |
| 76 | |
cwzwarich@webkit.org | 3f782f6 | 2008-09-08 01:28:33 +0000 | [diff] [blame] | 77 | } // namespace JSC |