]> git.saurik.com Git - apple/javascriptcore.git/blob - runtime/Completion.cpp
JavaScriptCore-1218.33.tar.gz
[apple/javascriptcore.git] / runtime / Completion.cpp
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"
27 #include "CodeProfiling.h"
28 #include "Debugger.h"
29 #include "Interpreter.h"
30 #include "JSGlobalObject.h"
31 #include "JSLock.h"
32 #include "Operations.h"
33 #include "Parser.h"
34 #include <wtf/WTFThreadData.h>
35 #include <stdio.h>
36
37 namespace JSC {
38
39 bool checkSyntax(ExecState* exec, const SourceCode& source, JSValue* returnedException)
40 {
41 JSLockHolder lock(exec);
42 RELEASE_ASSERT(exec->vm().identifierTable == wtfThreadData().currentIdentifierTable());
43
44 ProgramExecutable* program = ProgramExecutable::create(exec, source);
45 JSObject* error = program->checkSyntax(exec);
46 if (error) {
47 if (returnedException)
48 *returnedException = error;
49 return false;
50 }
51
52 return true;
53 }
54
55 bool 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 }
62
63 JSValue evaluate(ExecState* exec, const SourceCode& source, JSValue thisValue, JSValue* returnedException)
64 {
65 JSLockHolder lock(exec);
66 RELEASE_ASSERT(exec->vm().identifierTable == wtfThreadData().currentIdentifierTable());
67 RELEASE_ASSERT(!exec->vm().isCollectorBusy());
68
69 CodeProfiling profile(source);
70
71 ProgramExecutable* program = ProgramExecutable::create(exec, source);
72 if (!program) {
73 if (returnedException)
74 *returnedException = exec->vm().exception;
75
76 exec->vm().exception = JSValue();
77 return jsUndefined();
78 }
79
80 if (!thisValue || thisValue.isUndefinedOrNull())
81 thisValue = exec->dynamicGlobalObject();
82 JSObject* thisObj = thisValue.toThisObject(exec);
83 JSValue result = exec->interpreter()->execute(program, exec, thisObj);
84
85 if (exec->hadException()) {
86 if (returnedException)
87 *returnedException = exec->exception();
88
89 exec->clearException();
90 return jsUndefined();
91 }
92
93 RELEASE_ASSERT(result);
94 return result;
95 }
96
97 } // namespace JSC