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 "InitializeThreading.h"
34 #include "JSGlobalObject.h"
37 #include "OpaqueJSString.h"
38 #include "JSCInlines.h"
39 #include "SourceCode.h"
40 #include <wtf/text/StringHash.h>
42 #if ENABLE(REMOTE_INSPECTOR)
43 #include "JSGlobalObjectInspectorController.h"
48 JSValueRef
JSEvaluateScript(JSContextRef ctx
, JSStringRef script
, JSObjectRef thisObject
, JSStringRef sourceURL
, int startingLineNumber
, JSValueRef
* exception
)
54 ExecState
* exec
= toJS(ctx
);
55 JSLockHolder
locker(exec
);
57 JSObject
* jsThisObject
= toJS(thisObject
);
59 startingLineNumber
= std::max(1, startingLineNumber
);
61 // evaluate sets "this" to the global object if it is NULL
62 JSGlobalObject
* globalObject
= exec
->vmEntryGlobalObject();
63 SourceCode source
= makeSource(script
->string(), sourceURL
->string(), TextPosition(OrdinalNumber::fromOneBasedInt(startingLineNumber
), OrdinalNumber::first()));
65 JSValue evaluationException
;
66 JSValue returnValue
= evaluate(globalObject
->globalExec(), source
, jsThisObject
, &evaluationException
);
68 if (evaluationException
) {
70 *exception
= toRef(exec
, evaluationException
);
71 #if ENABLE(REMOTE_INSPECTOR)
72 // FIXME: If we have a debugger attached we could learn about ParseError exceptions through
73 // ScriptDebugServer::sourceParsed and this path could produce a duplicate warning. The
74 // Debugger path is currently ignored by inspector.
75 // NOTE: If we don't have a debugger, this SourceCode will be forever lost to the inspector.
76 // We could stash it in the inspector in case an inspector is ever opened.
77 globalObject
->inspectorController().reportAPIException(exec
, evaluationException
);
83 return toRef(exec
, returnValue
);
85 // happens, for example, when the only statement is an empty (';') statement
86 return toRef(exec
, jsUndefined());
89 bool JSCheckScriptSyntax(JSContextRef ctx
, JSStringRef script
, JSStringRef sourceURL
, int startingLineNumber
, JSValueRef
* exception
)
95 ExecState
* exec
= toJS(ctx
);
96 JSLockHolder
locker(exec
);
98 startingLineNumber
= std::max(1, startingLineNumber
);
100 SourceCode source
= makeSource(script
->string(), sourceURL
->string(), TextPosition(OrdinalNumber::fromOneBasedInt(startingLineNumber
), OrdinalNumber::first()));
102 JSValue syntaxException
;
103 bool isValidSyntax
= checkSyntax(exec
->vmEntryGlobalObject()->globalExec(), source
, &syntaxException
);
105 if (!isValidSyntax
) {
107 *exception
= toRef(exec
, syntaxException
);
108 #if ENABLE(REMOTE_INSPECTOR)
109 exec
->vmEntryGlobalObject()->inspectorController().reportAPIException(exec
, syntaxException
);
117 void JSGarbageCollect(JSContextRef ctx
)
119 // We used to recommend passing NULL as an argument here, which caused the only heap to be collected.
120 // As there is no longer a shared heap, the previously recommended usage became a no-op (but the GC
121 // will happen when the context group is destroyed).
122 // Because the function argument was originally ignored, some clients may pass their released context here,
123 // in which case there is a risk of crashing if another thread performs GC on the same heap in between.
127 ExecState
* exec
= toJS(ctx
);
128 JSLockHolder
locker(exec
);
130 exec
->vm().heap
.reportAbandonedObjectGraph();
133 void JSReportExtraMemoryCost(JSContextRef ctx
, size_t size
)
136 ASSERT_NOT_REACHED();
139 ExecState
* exec
= toJS(ctx
);
140 JSLockHolder
locker(exec
);
141 exec
->vm().heap
.reportExtraMemoryCost(size
);
144 extern "C" JS_EXPORT
void JSSynchronousGarbageCollectForDebugging(JSContextRef
);
145 extern "C" JS_EXPORT
void JSSynchronousEdenCollectForDebugging(JSContextRef
);
147 void JSSynchronousGarbageCollectForDebugging(JSContextRef ctx
)
152 ExecState
* exec
= toJS(ctx
);
153 JSLockHolder
locker(exec
);
154 exec
->vm().heap
.collectAllGarbage();
157 void JSSynchronousEdenCollectForDebugging(JSContextRef ctx
)
162 ExecState
* exec
= toJS(ctx
);
163 JSLockHolder
locker(exec
);
164 exec
->vm().heap
.collect(EdenCollection
);
167 void JSDisableGCTimer(void)
169 GCActivityCallback::s_shouldCreateGCTimer
= false;
173 // FIXME: Expose symbols to tell dyld where to find JavaScriptCore on older versions of
174 // iOS (< 7.0). We should remove these symbols once we no longer need to support such
175 // versions of iOS. See <rdar://problem/13696872> for more details.
176 JS_EXPORT
extern const char iosInstallName43
__asm("$ld$install_name$os4.3$/System/Library/PrivateFrameworks/JavaScriptCore.framework/JavaScriptCore");
177 JS_EXPORT
extern const char iosInstallName50
__asm("$ld$install_name$os5.0$/System/Library/PrivateFrameworks/JavaScriptCore.framework/JavaScriptCore");
178 JS_EXPORT
extern const char iosInstallName51
__asm("$ld$install_name$os5.1$/System/Library/PrivateFrameworks/JavaScriptCore.framework/JavaScriptCore");
179 JS_EXPORT
extern const char iosInstallName60
__asm("$ld$install_name$os6.0$/System/Library/PrivateFrameworks/JavaScriptCore.framework/JavaScriptCore");
180 JS_EXPORT
extern const char iosInstallName61
__asm("$ld$install_name$os6.1$/System/Library/PrivateFrameworks/JavaScriptCore.framework/JavaScriptCore");
182 const char iosInstallName43
= 0;
183 const char iosInstallName50
= 0;
184 const char iosInstallName51
= 0;
185 const char iosInstallName60
= 0;
186 const char iosInstallName61
= 0;