blob: 2dd18a2ebc95803b77351c8cea0ebd238a469417 [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
ggaren@apple.com5169fc92008-11-17 22:11:26 +000026#include "CallFrame.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"
barraclough@apple.com43e9a932010-04-20 08:30:12 +000032#include "WTFThreadData.h"
ggaren7213ee02007-10-16 23:25:33 +000033#include <stdio.h>
mjs3bfb61b2006-03-02 09:12:06 +000034
cwzwarich@webkit.org3f782f62008-09-08 01:28:33 +000035namespace JSC {
mjs6f821c82002-03-22 00:31:57 +000036
ggaren@apple.comb7024cd2008-11-15 19:55:20 +000037Completion checkSyntax(ExecState* exec, const SourceCode& source)
mjs6f821c82002-03-22 00:31:57 +000038{
ap@webkit.org01aff702008-08-20 07:23:06 +000039 JSLock lock(exec);
barraclough@apple.com43e9a932010-04-20 08:30:12 +000040 ASSERT(exec->globalData().identifierTable == wtfThreadData().currentIdentifierTable());
ap@webkit.org01aff702008-08-20 07:23:06 +000041
oliver@apple.comba10bec2011-03-08 23:17:32 +000042 ProgramExecutable* program = ProgramExecutable::create(exec, source);
oliver@apple.comebd0b4c2009-09-29 21:48:52 +000043 JSObject* error = program->checkSyntax(exec);
barraclough@apple.com836511562009-08-15 01:14:00 +000044 if (error)
45 return Completion(Throw, error);
mrowe@apple.com2f6dfdf2008-05-22 01:20:45 +000046
ggaren2008a982006-07-05 16:52:54 +000047 return Completion(Normal);
mjs6f821c82002-03-22 00:31:57 +000048}
49
oliver@apple.com97cdbd42011-02-28 21:05:22 +000050Completion evaluate(ExecState* exec, ScopeChainNode* scopeChain, const SourceCode& source, JSValue thisValue)
mjs6f821c82002-03-22 00:31:57 +000051{
ap@webkit.org01aff702008-08-20 07:23:06 +000052 JSLock lock(exec);
barraclough@apple.com43e9a932010-04-20 08:30:12 +000053 ASSERT(exec->globalData().identifierTable == wtfThreadData().currentIdentifierTable());
kmccullough@apple.comac769762008-04-16 19:08:03 +000054
oliver@apple.comba10bec2011-03-08 23:17:32 +000055 ProgramExecutable* program = ProgramExecutable::create(exec, source);
56 if (!program) {
ggaren@apple.com1c5376a2011-03-15 23:29:56 +000057 JSValue exception = exec->globalData().exception;
oliver@apple.comba10bec2011-03-08 23:17:32 +000058 exec->globalData().exception = JSValue();
59 return Completion(Throw, exception);
60 }
mrowe@apple.com2f6dfdf2008-05-22 01:20:45 +000061
barraclough@apple.com19afece2011-07-15 19:51:49 +000062 if (!thisValue || thisValue.isUndefinedOrNull())
63 thisValue = exec->dynamicGlobalObject();
64 JSObject* thisObj = thisValue.toThisObject(exec);
mrowe@apple.com2f6dfdf2008-05-22 01:20:45 +000065
oliver@apple.comba10bec2011-03-08 23:17:32 +000066 JSValue result = exec->interpreter()->execute(program, exec, scopeChain, thisObj);
kmccullough@apple.comac769762008-04-16 19:08:03 +000067
barraclough@apple.com2607dd02010-10-27 20:46:09 +000068 if (exec->hadException()) {
69 JSValue exception = exec->exception();
70 exec->clearException();
71
eric@webkit.org5d91a8d2010-04-07 04:38:23 +000072 ComplType exceptionType = Throw;
73 if (exception.isObject())
74 exceptionType = asObject(exception)->exceptionType();
75 return Completion(exceptionType, exception);
oliver@apple.comc8f3a752008-06-28 04:02:03 +000076 }
77 return Completion(Normal, result);
mjs6f821c82002-03-22 00:31:57 +000078}
79
cwzwarich@webkit.org3f782f62008-09-08 01:28:33 +000080} // namespace JSC