]> git.saurik.com Git - apple/javascriptcore.git/blame - runtime/Completion.cpp
JavaScriptCore-1218.0.1.tar.gz
[apple/javascriptcore.git] / runtime / Completion.cpp
CommitLineData
9dae56ea
A
1/*
2 * Copyright (C) 1999-2001 Harri Porten (porten@kde.org)
3 * Copyright (C) 2001 Peter Kelly (pmk@post.com)
4 * Copyright (C) 2003, 2007 Apple Inc.
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
18 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19 * Boston, MA 02110-1301, USA.
20 *
21 */
22
23#include "config.h"
24#include "Completion.h"
25
26#include "CallFrame.h"
6fe7ccc8 27#include "CodeProfiling.h"
93a37866
A
28#include "Debugger.h"
29#include "Interpreter.h"
9dae56ea
A
30#include "JSGlobalObject.h"
31#include "JSLock.h"
93a37866 32#include "Operations.h"
9dae56ea 33#include "Parser.h"
6fe7ccc8 34#include <wtf/WTFThreadData.h>
9dae56ea
A
35#include <stdio.h>
36
9dae56ea
A
37namespace JSC {
38
6fe7ccc8 39bool checkSyntax(ExecState* exec, const SourceCode& source, JSValue* returnedException)
9dae56ea 40{
6fe7ccc8 41 JSLockHolder lock(exec);
93a37866 42 RELEASE_ASSERT(exec->vm().identifierTable == wtfThreadData().currentIdentifierTable());
9dae56ea 43
14957cd0 44 ProgramExecutable* program = ProgramExecutable::create(exec, source);
f9bf01c6 45 JSObject* error = program->checkSyntax(exec);
6fe7ccc8
A
46 if (error) {
47 if (returnedException)
48 *returnedException = error;
49 return false;
50 }
9dae56ea 51
6fe7ccc8 52 return true;
9dae56ea 53}
93a37866
A
54
55bool checkSyntax(VM& vm, const SourceCode& source, ParserError& error)
56{
57 JSLockHolder lock(vm);
58 RELEASE_ASSERT(vm.identifierTable == wtfThreadData().currentIdentifierTable());
59 RefPtr<ProgramNode> programNode = parse<ProgramNode>(&vm, source, 0, Identifier(), JSParseNormal, JSParseProgramCode, error);
60 return programNode;
61}
9dae56ea 62
93a37866 63JSValue evaluate(ExecState* exec, const SourceCode& source, JSValue thisValue, JSValue* returnedException)
9dae56ea 64{
6fe7ccc8 65 JSLockHolder lock(exec);
93a37866
A
66 RELEASE_ASSERT(exec->vm().identifierTable == wtfThreadData().currentIdentifierTable());
67 RELEASE_ASSERT(!exec->vm().isCollectorBusy());
6fe7ccc8
A
68
69 CodeProfiling profile(source);
9dae56ea 70
14957cd0
A
71 ProgramExecutable* program = ProgramExecutable::create(exec, source);
72 if (!program) {
6fe7ccc8 73 if (returnedException)
93a37866 74 *returnedException = exec->vm().exception;
6fe7ccc8 75
93a37866 76 exec->vm().exception = JSValue();
6fe7ccc8 77 return jsUndefined();
14957cd0 78 }
9dae56ea 79
6fe7ccc8
A
80 if (!thisValue || thisValue.isUndefinedOrNull())
81 thisValue = exec->dynamicGlobalObject();
82 JSObject* thisObj = thisValue.toThisObject(exec);
93a37866 83 JSValue result = exec->interpreter()->execute(program, exec, thisObj);
14957cd0
A
84
85 if (exec->hadException()) {
6fe7ccc8
A
86 if (returnedException)
87 *returnedException = exec->exception();
9dae56ea 88
6fe7ccc8
A
89 exec->clearException();
90 return jsUndefined();
9dae56ea 91 }
6fe7ccc8 92
93a37866 93 RELEASE_ASSERT(result);
6fe7ccc8 94 return result;
9dae56ea
A
95}
96
97} // namespace JSC