blob: b4a6cc1ed570ce99c070a66199f82eb3bdb9ef98 [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.
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
mjsb64c50a2005-10-03 21:13:12 +000023#include "config.h"
cwzwarich@webkit.org77647132008-11-05 23:48:18 +000024#include "Completion.h"
ggaren@apple.com4240a312008-11-17 17:55:40 +000025
mjse58111c2007-10-26 08:32:40 +000026#include "ExecState.h"
mjs07781952007-10-25 07:16:49 +000027#include "JSGlobalObject.h"
ap@webkit.org01aff702008-08-20 07:23:06 +000028#include "JSLock.h"
ggaren@apple.com901a8a22008-11-17 20:57:18 +000029#include "Interpreter.h"
ggaren@apple.com898e9cd2007-12-08 00:35:08 +000030#include "Parser.h"
cwzwarich@webkit.orga691b5a2008-10-31 05:56:58 +000031#include "Debugger.h"
ggaren7213ee02007-10-16 23:25:33 +000032#include <stdio.h>
mjs3bfb61b2006-03-02 09:12:06 +000033
darin@apple.com56b46672008-02-13 12:10:00 +000034#if !PLATFORM(WIN_OS)
35#include <unistd.h>
36#endif
37
cwzwarich@webkit.org3f782f62008-09-08 01:28:33 +000038namespace JSC {
mjs6f821c82002-03-22 00:31:57 +000039
ggaren@apple.comb7024cd2008-11-15 19:55:20 +000040Completion checkSyntax(ExecState* exec, const SourceCode& source)
mjs6f821c82002-03-22 00:31:57 +000041{
ap@webkit.org01aff702008-08-20 07:23:06 +000042 JSLock lock(exec);
43
ggaren2008a982006-07-05 16:52:54 +000044 int errLine;
45 UString errMsg;
mrowe@apple.com2f6dfdf2008-05-22 01:20:45 +000046
ggaren@apple.com9f980342008-10-15 23:33:07 +000047 RefPtr<ProgramNode> progNode = exec->globalData().parser->parse<ProgramNode>(exec, exec->dynamicGlobalObject()->debugger(), source, &errLine, &errMsg);
ggaren2008a982006-07-05 16:52:54 +000048 if (!progNode)
ggaren@apple.com69e9ccf2008-10-02 06:44:37 +000049 return Completion(Throw, Error::create(exec, SyntaxError, errMsg, errLine, source.provider()->asID(), source.provider()->url()));
ggaren2008a982006-07-05 16:52:54 +000050 return Completion(Normal);
mjs6f821c82002-03-22 00:31:57 +000051}
52
ggaren@apple.comb7024cd2008-11-15 19:55:20 +000053Completion evaluate(ExecState* exec, ScopeChain& scopeChain, const SourceCode& source, JSValue* thisValue)
mjs6f821c82002-03-22 00:31:57 +000054{
ap@webkit.org01aff702008-08-20 07:23:06 +000055 JSLock lock(exec);
56
ggaren01b2e772006-06-13 06:08:52 +000057 int errLine;
58 UString errMsg;
ggaren@apple.com9f980342008-10-15 23:33:07 +000059 RefPtr<ProgramNode> programNode = exec->globalData().parser->parse<ProgramNode>(exec, exec->dynamicGlobalObject()->debugger(), source, &errLine, &errMsg);
kmccullough@apple.comac769762008-04-16 19:08:03 +000060
mrowe@apple.com2f6dfdf2008-05-22 01:20:45 +000061 if (!programNode)
ggaren@apple.com69e9ccf2008-10-02 06:44:37 +000062 return Completion(Throw, Error::create(exec, SyntaxError, errMsg, errLine, source.provider()->asID(), source.provider()->url()));
mrowe@apple.com2f6dfdf2008-05-22 01:20:45 +000063
64 JSObject* thisObj = (!thisValue || thisValue->isUndefinedOrNull()) ? exec->dynamicGlobalObject() : thisValue->toObject(exec);
65
darin@apple.com44331f82008-10-24 16:22:51 +000066 JSValue* exception = noValue();
ggaren@apple.comb7024cd2008-11-15 19:55:20 +000067 JSValue* result = exec->interpreter()->execute(programNode.get(), exec, scopeChain.node(), thisObj, &exception);
kmccullough@apple.comac769762008-04-16 19:08:03 +000068
oliver@apple.comc8f3a752008-06-28 04:02:03 +000069 if (exception) {
darin@apple.com5a494422008-10-18 23:08:12 +000070 if (exception->isObject() && asObject(exception)->isWatchdogException())
oliver@apple.comc8f3a752008-06-28 04:02:03 +000071 return Completion(Interrupted, result);
72 return Completion(Throw, exception);
73 }
74 return Completion(Normal, result);
mjs6f821c82002-03-22 00:31:57 +000075}
76
cwzwarich@webkit.org3f782f62008-09-08 01:28:33 +000077} // namespace JSC