]>
git.saurik.com Git - apple/javascriptcore.git/blob - API/JSBase.cpp
2 * Copyright (C) 2006, 2007, 2013 Apple Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 #include "JSBasePrivate.h"
31 #include "CallFrame.h"
32 #include "Completion.h"
33 #include "Exception.h"
34 #include "GCActivityCallback.h"
35 #include "InitializeThreading.h"
36 #include "JSGlobalObject.h"
39 #include "OpaqueJSString.h"
40 #include "JSCInlines.h"
41 #include "SourceCode.h"
42 #include <wtf/text/StringHash.h>
44 #if ENABLE(REMOTE_INSPECTOR)
45 #include "JSGlobalObjectInspectorController.h"
50 JSValueRef
JSEvaluateScript(JSContextRef ctx
, JSStringRef script
, JSObjectRef thisObject
, JSStringRef sourceURL
, int startingLineNumber
, JSValueRef
* exception
)
56 ExecState
* exec
= toJS(ctx
);
57 JSLockHolder
locker(exec
);
59 JSObject
* jsThisObject
= toJS(thisObject
);
61 startingLineNumber
= std::max(1, startingLineNumber
);
63 // evaluate sets "this" to the global object if it is NULL
64 JSGlobalObject
* globalObject
= exec
->vmEntryGlobalObject();
65 SourceCode source
= makeSource(script
->string(), sourceURL
? sourceURL
->string() : String(), TextPosition(OrdinalNumber::fromOneBasedInt(startingLineNumber
), OrdinalNumber::first()));
67 NakedPtr
<Exception
> evaluationException
;
68 JSValue returnValue
= evaluate(globalObject
->globalExec(), source
, jsThisObject
, evaluationException
);
70 if (evaluationException
) {
72 *exception
= toRef(exec
, evaluationException
->value());
73 #if ENABLE(REMOTE_INSPECTOR)
74 // FIXME: If we have a debugger attached we could learn about ParseError exceptions through
75 // ScriptDebugServer::sourceParsed and this path could produce a duplicate warning. The
76 // Debugger path is currently ignored by inspector.
77 // NOTE: If we don't have a debugger, this SourceCode will be forever lost to the inspector.
78 // We could stash it in the inspector in case an inspector is ever opened.
79 globalObject
->inspectorController().reportAPIException(exec
, evaluationException
);
85 return toRef(exec
, returnValue
);
87 // happens, for example, when the only statement is an empty (';') statement
88 return toRef(exec
, jsUndefined());
91 bool JSCheckScriptSyntax(JSContextRef ctx
, JSStringRef script
, JSStringRef sourceURL
, int startingLineNumber
, JSValueRef
* exception
)
97 ExecState
* exec
= toJS(ctx
);
98 JSLockHolder
locker(exec
);
100 startingLineNumber
= std::max(1, startingLineNumber
);
102 SourceCode source
= makeSource(script
->string(), sourceURL
? sourceURL
->string() : String(), TextPosition(OrdinalNumber::fromOneBasedInt(startingLineNumber
), OrdinalNumber::first()));
104 JSValue syntaxException
;
105 bool isValidSyntax
= checkSyntax(exec
->vmEntryGlobalObject()->globalExec(), source
, &syntaxException
);
107 if (!isValidSyntax
) {
109 *exception
= toRef(exec
, syntaxException
);
110 #if ENABLE(REMOTE_INSPECTOR)
111 Exception
* exception
= Exception::create(exec
->vm(), syntaxException
);
112 exec
->vmEntryGlobalObject()->inspectorController().reportAPIException(exec
, exception
);
120 void JSGarbageCollect(JSContextRef ctx
)
122 // We used to recommend passing NULL as an argument here, which caused the only heap to be collected.
123 // As there is no longer a shared heap, the previously recommended usage became a no-op (but the GC
124 // will happen when the context group is destroyed).
125 // Because the function argument was originally ignored, some clients may pass their released context here,
126 // in which case there is a risk of crashing if another thread performs GC on the same heap in between.
130 ExecState
* exec
= toJS(ctx
);
131 JSLockHolder
locker(exec
);
133 exec
->vm().heap
.reportAbandonedObjectGraph();
136 void JSReportExtraMemoryCost(JSContextRef ctx
, size_t size
)
139 ASSERT_NOT_REACHED();
142 ExecState
* exec
= toJS(ctx
);
143 JSLockHolder
locker(exec
);
145 exec
->vm().heap
.deprecatedReportExtraMemory(size
);
148 extern "C" JS_EXPORT
void JSSynchronousGarbageCollectForDebugging(JSContextRef
);
149 extern "C" JS_EXPORT
void JSSynchronousEdenCollectForDebugging(JSContextRef
);
151 void JSSynchronousGarbageCollectForDebugging(JSContextRef ctx
)
156 ExecState
* exec
= toJS(ctx
);
157 JSLockHolder
locker(exec
);
158 exec
->vm().heap
.collectAllGarbage();
161 void JSSynchronousEdenCollectForDebugging(JSContextRef ctx
)
166 ExecState
* exec
= toJS(ctx
);
167 JSLockHolder
locker(exec
);
168 exec
->vm().heap
.collect(EdenCollection
);
171 void JSDisableGCTimer(void)
173 GCActivityCallback::s_shouldCreateGCTimer
= false;
177 // FIXME: Expose symbols to tell dyld where to find JavaScriptCore on older versions of
178 // iOS (< 7.0). We should remove these symbols once we no longer need to support such
179 // versions of iOS. See <rdar://problem/13696872> for more details.
180 JS_EXPORT
extern const char iosInstallName43
__asm("$ld$install_name$os4.3$/System/Library/PrivateFrameworks/JavaScriptCore.framework/JavaScriptCore");
181 JS_EXPORT
extern const char iosInstallName50
__asm("$ld$install_name$os5.0$/System/Library/PrivateFrameworks/JavaScriptCore.framework/JavaScriptCore");
182 JS_EXPORT
extern const char iosInstallName51
__asm("$ld$install_name$os5.1$/System/Library/PrivateFrameworks/JavaScriptCore.framework/JavaScriptCore");
183 JS_EXPORT
extern const char iosInstallName60
__asm("$ld$install_name$os6.0$/System/Library/PrivateFrameworks/JavaScriptCore.framework/JavaScriptCore");
184 JS_EXPORT
extern const char iosInstallName61
__asm("$ld$install_name$os6.1$/System/Library/PrivateFrameworks/JavaScriptCore.framework/JavaScriptCore");
186 const char iosInstallName43
= 0;
187 const char iosInstallName50
= 0;
188 const char iosInstallName51
= 0;
189 const char iosInstallName60
= 0;
190 const char iosInstallName61
= 0;