blob: 23d9c9cecc4ac7b60f3a7a386031bd63e4f9ca06 [file] [log] [blame]
thatcher43a8c5172006-01-19 02:40:56 +00001/*
darin@apple.com74e6ed62008-10-23 00:11:11 +00002 * Copyright (C) 2005, 2008 Apple Inc. All rights reserved.
thatcher43a8c5172006-01-19 02:40:56 +00003 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 *
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of
14 * its contributors may be used to endorse or promote products derived
15 * from this software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
18 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20 * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
21 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
22 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
23 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
24 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
mjs7f5285a2005-09-06 08:10:03 +000028
mjs3bfb61b2006-03-02 09:12:06 +000029#include "config.h"
mjs7f5285a2005-09-06 08:10:03 +000030#include "JSRun.h"
31
darin@apple.com74e6ed62008-10-23 00:11:11 +000032#include "UserObjectImp.h"
cwzwarich@webkit.org06b26742008-11-06 07:24:10 +000033#include <JavaScriptCore/Completion.h>
slewis@apple.com487c4522008-11-01 04:28:56 +000034#include <JavaScriptCore/SourceCode.h>
darin@apple.com74e6ed62008-10-23 00:11:11 +000035
darin@apple.coma9778f92008-11-16 04:40:06 +000036JSGlueGlobalObject::JSGlueGlobalObject(PassRefPtr<Structure> structure, JSFlags flags)
darin@apple.com74e6ed62008-10-23 00:11:11 +000037 : JSGlobalObject(structure, new Data, this)
38{
39 d()->flags = flags;
darin@apple.coma9778f92008-11-16 04:40:06 +000040 d()->userObjectStructure = UserObjectImp::createStructure(jsNull());
darin@apple.com74e6ed62008-10-23 00:11:11 +000041}
ap@webkit.org960c28e2008-06-19 17:29:29 +000042
darin09654692005-10-10 23:32:34 +000043JSRun::JSRun(CFStringRef source, JSFlags inFlags)
44 : JSBase(kJSRunTypeID),
45 fSource(CFStringToUString(source)),
darin@apple.coma9778f92008-11-16 04:40:06 +000046 fGlobalObject(new (&getThreadGlobalExecState()->globalData()) JSGlueGlobalObject(JSGlueGlobalObject::createStructure(jsNull()), inFlags)),
darin09654692005-10-10 23:32:34 +000047 fFlags(inFlags)
mjs7f5285a2005-09-06 08:10:03 +000048{
49}
darin09654692005-10-10 23:32:34 +000050
51JSRun::~JSRun()
52{
mjs7f5285a2005-09-06 08:10:03 +000053}
54
55JSFlags JSRun::Flags() const
56{
darin09654692005-10-10 23:32:34 +000057 return fFlags;
mjs7f5285a2005-09-06 08:10:03 +000058}
59
60UString JSRun::GetSource() const
61{
darin09654692005-10-10 23:32:34 +000062 return fSource;
mjs7f5285a2005-09-06 08:10:03 +000063}
64
eseidelefabcc02007-10-25 07:07:06 +000065JSGlobalObject* JSRun::GlobalObject() const
mjs7f5285a2005-09-06 08:10:03 +000066{
darin09654692005-10-10 23:32:34 +000067 return fGlobalObject;
mjs7f5285a2005-09-06 08:10:03 +000068}
69
darin09654692005-10-10 23:32:34 +000070Completion JSRun::Evaluate()
71{
ggaren@apple.comb7024cd2008-11-15 19:55:20 +000072 return JSC::evaluate(fGlobalObject->globalExec(), fGlobalObject->globalScopeChain(), makeSource(fSource));
mjs7f5285a2005-09-06 08:10:03 +000073}
74
darin09654692005-10-10 23:32:34 +000075bool JSRun::CheckSyntax()
76{
ggaren@apple.comb7024cd2008-11-15 19:55:20 +000077 return JSC::checkSyntax(fGlobalObject->globalExec(), makeSource(fSource)).complType() != Throw;
mjs7f5285a2005-09-06 08:10:03 +000078}