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 | |
ggaren@apple.com | 5169fc9 | 2008-11-17 22:11:26 +0000 | [diff] [blame] | 26 | #include "CallFrame.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" |
barraclough@apple.com | 43e9a93 | 2010-04-20 08:30:12 +0000 | [diff] [blame] | 32 | #include "WTFThreadData.h" |
ggaren | 7213ee0 | 2007-10-16 23:25:33 +0000 | [diff] [blame] | 33 | #include <stdio.h> |
mjs | 3bfb61b | 2006-03-02 09:12:06 +0000 | [diff] [blame] | 34 | |
cwzwarich@webkit.org | 3f782f6 | 2008-09-08 01:28:33 +0000 | [diff] [blame] | 35 | namespace JSC { |
mjs | 6f821c8 | 2002-03-22 00:31:57 +0000 | [diff] [blame] | 36 | |
ggaren@apple.com | b7024cd | 2008-11-15 19:55:20 +0000 | [diff] [blame] | 37 | Completion checkSyntax(ExecState* exec, const SourceCode& source) |
mjs | 6f821c8 | 2002-03-22 00:31:57 +0000 | [diff] [blame] | 38 | { |
ap@webkit.org | 01aff70 | 2008-08-20 07:23:06 +0000 | [diff] [blame] | 39 | JSLock lock(exec); |
barraclough@apple.com | 43e9a93 | 2010-04-20 08:30:12 +0000 | [diff] [blame] | 40 | ASSERT(exec->globalData().identifierTable == wtfThreadData().currentIdentifierTable()); |
ap@webkit.org | 01aff70 | 2008-08-20 07:23:06 +0000 | [diff] [blame] | 41 | |
oliver@apple.com | ba10bec | 2011-03-08 23:17:32 +0000 | [diff] [blame] | 42 | ProgramExecutable* program = ProgramExecutable::create(exec, source); |
oliver@apple.com | ebd0b4c | 2009-09-29 21:48:52 +0000 | [diff] [blame] | 43 | JSObject* error = program->checkSyntax(exec); |
barraclough@apple.com | 83651156 | 2009-08-15 01:14:00 +0000 | [diff] [blame] | 44 | if (error) |
| 45 | return Completion(Throw, error); |
mrowe@apple.com | 2f6dfdf | 2008-05-22 01:20:45 +0000 | [diff] [blame] | 46 | |
ggaren | 2008a98 | 2006-07-05 16:52:54 +0000 | [diff] [blame] | 47 | return Completion(Normal); |
mjs | 6f821c8 | 2002-03-22 00:31:57 +0000 | [diff] [blame] | 48 | } |
| 49 | |
oliver@apple.com | 97cdbd4 | 2011-02-28 21:05:22 +0000 | [diff] [blame] | 50 | Completion evaluate(ExecState* exec, ScopeChainNode* scopeChain, const SourceCode& source, JSValue thisValue) |
mjs | 6f821c8 | 2002-03-22 00:31:57 +0000 | [diff] [blame] | 51 | { |
ap@webkit.org | 01aff70 | 2008-08-20 07:23:06 +0000 | [diff] [blame] | 52 | JSLock lock(exec); |
barraclough@apple.com | 43e9a93 | 2010-04-20 08:30:12 +0000 | [diff] [blame] | 53 | ASSERT(exec->globalData().identifierTable == wtfThreadData().currentIdentifierTable()); |
kmccullough@apple.com | ac76976 | 2008-04-16 19:08:03 +0000 | [diff] [blame] | 54 | |
oliver@apple.com | ba10bec | 2011-03-08 23:17:32 +0000 | [diff] [blame] | 55 | ProgramExecutable* program = ProgramExecutable::create(exec, source); |
| 56 | if (!program) { |
ggaren@apple.com | 1c5376a | 2011-03-15 23:29:56 +0000 | [diff] [blame] | 57 | JSValue exception = exec->globalData().exception; |
oliver@apple.com | ba10bec | 2011-03-08 23:17:32 +0000 | [diff] [blame] | 58 | exec->globalData().exception = JSValue(); |
| 59 | return Completion(Throw, exception); |
| 60 | } |
mrowe@apple.com | 2f6dfdf | 2008-05-22 01:20:45 +0000 | [diff] [blame] | 61 | |
barraclough@apple.com | 19afece | 2011-07-15 19:51:49 +0000 | [diff] [blame] | 62 | if (!thisValue || thisValue.isUndefinedOrNull()) |
| 63 | thisValue = exec->dynamicGlobalObject(); |
| 64 | JSObject* thisObj = thisValue.toThisObject(exec); |
mrowe@apple.com | 2f6dfdf | 2008-05-22 01:20:45 +0000 | [diff] [blame] | 65 | |
oliver@apple.com | ba10bec | 2011-03-08 23:17:32 +0000 | [diff] [blame] | 66 | JSValue result = exec->interpreter()->execute(program, exec, scopeChain, thisObj); |
kmccullough@apple.com | ac76976 | 2008-04-16 19:08:03 +0000 | [diff] [blame] | 67 | |
barraclough@apple.com | 2607dd0 | 2010-10-27 20:46:09 +0000 | [diff] [blame] | 68 | if (exec->hadException()) { |
| 69 | JSValue exception = exec->exception(); |
| 70 | exec->clearException(); |
| 71 | |
eric@webkit.org | 5d91a8d | 2010-04-07 04:38:23 +0000 | [diff] [blame] | 72 | ComplType exceptionType = Throw; |
| 73 | if (exception.isObject()) |
| 74 | exceptionType = asObject(exception)->exceptionType(); |
| 75 | return Completion(exceptionType, exception); |
oliver@apple.com | c8f3a75 | 2008-06-28 04:02:03 +0000 | [diff] [blame] | 76 | } |
| 77 | return Completion(Normal, result); |
mjs | 6f821c8 | 2002-03-22 00:31:57 +0000 | [diff] [blame] | 78 | } |
| 79 | |
cwzwarich@webkit.org | 3f782f6 | 2008-09-08 01:28:33 +0000 | [diff] [blame] | 80 | } // namespace JSC |