]>
Commit | Line | Data |
---|---|---|
b37bf2e1 | 1 | /* |
81345200 | 2 | * Copyright (C) 2006, 2007, 2013 Apple Inc. All rights reserved. |
b37bf2e1 A |
3 | * |
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 | * 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. | |
12 | * | |
81345200 | 13 | * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY |
b37bf2e1 A |
14 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
15 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | |
81345200 | 16 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR |
b37bf2e1 A |
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 | |
9dae56ea | 23 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
b37bf2e1 A |
24 | */ |
25 | ||
26 | #include "config.h" | |
27 | #include "JSBase.h" | |
9dae56ea | 28 | #include "JSBasePrivate.h" |
b37bf2e1 A |
29 | |
30 | #include "APICast.h" | |
93a37866 A |
31 | #include "CallFrame.h" |
32 | #include "Completion.h" | |
ed1e77d3 A |
33 | #include "Exception.h" |
34 | #include "GCActivityCallback.h" | |
93a37866 A |
35 | #include "InitializeThreading.h" |
36 | #include "JSGlobalObject.h" | |
37 | #include "JSLock.h" | |
38 | #include "JSObject.h" | |
9dae56ea | 39 | #include "OpaqueJSString.h" |
81345200 | 40 | #include "JSCInlines.h" |
b5422865 | 41 | #include "SourceCode.h" |
4e4e5a6f | 42 | #include <wtf/text/StringHash.h> |
b37bf2e1 | 43 | |
81345200 A |
44 | #if ENABLE(REMOTE_INSPECTOR) |
45 | #include "JSGlobalObjectInspectorController.h" | |
46 | #endif | |
47 | ||
9dae56ea | 48 | using namespace JSC; |
b37bf2e1 A |
49 | |
50 | JSValueRef JSEvaluateScript(JSContextRef ctx, JSStringRef script, JSObjectRef thisObject, JSStringRef sourceURL, int startingLineNumber, JSValueRef* exception) | |
51 | { | |
93a37866 A |
52 | if (!ctx) { |
53 | ASSERT_NOT_REACHED(); | |
54 | return 0; | |
55 | } | |
b37bf2e1 | 56 | ExecState* exec = toJS(ctx); |
81345200 | 57 | JSLockHolder locker(exec); |
9dae56ea | 58 | |
b37bf2e1 | 59 | JSObject* jsThisObject = toJS(thisObject); |
9dae56ea | 60 | |
81345200 A |
61 | startingLineNumber = std::max(1, startingLineNumber); |
62 | ||
9dae56ea | 63 | // evaluate sets "this" to the global object if it is NULL |
81345200 | 64 | JSGlobalObject* globalObject = exec->vmEntryGlobalObject(); |
ed1e77d3 | 65 | SourceCode source = makeSource(script->string(), sourceURL ? sourceURL->string() : String(), TextPosition(OrdinalNumber::fromOneBasedInt(startingLineNumber), OrdinalNumber::first())); |
b37bf2e1 | 66 | |
ed1e77d3 A |
67 | NakedPtr<Exception> evaluationException; |
68 | JSValue returnValue = evaluate(globalObject->globalExec(), source, jsThisObject, evaluationException); | |
6fe7ccc8 A |
69 | |
70 | if (evaluationException) { | |
b37bf2e1 | 71 | if (exception) |
ed1e77d3 | 72 | *exception = toRef(exec, evaluationException->value()); |
81345200 A |
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); | |
80 | #endif | |
b37bf2e1 A |
81 | return 0; |
82 | } | |
ba379fdc | 83 | |
6fe7ccc8 A |
84 | if (returnValue) |
85 | return toRef(exec, returnValue); | |
86 | ||
b37bf2e1 | 87 | // happens, for example, when the only statement is an empty (';') statement |
ba379fdc | 88 | return toRef(exec, jsUndefined()); |
b37bf2e1 A |
89 | } |
90 | ||
91 | bool JSCheckScriptSyntax(JSContextRef ctx, JSStringRef script, JSStringRef sourceURL, int startingLineNumber, JSValueRef* exception) | |
92 | { | |
93a37866 A |
93 | if (!ctx) { |
94 | ASSERT_NOT_REACHED(); | |
95 | return false; | |
96 | } | |
b37bf2e1 | 97 | ExecState* exec = toJS(ctx); |
81345200 A |
98 | JSLockHolder locker(exec); |
99 | ||
100 | startingLineNumber = std::max(1, startingLineNumber); | |
9dae56ea | 101 | |
ed1e77d3 | 102 | SourceCode source = makeSource(script->string(), sourceURL ? sourceURL->string() : String(), TextPosition(OrdinalNumber::fromOneBasedInt(startingLineNumber), OrdinalNumber::first())); |
6fe7ccc8 A |
103 | |
104 | JSValue syntaxException; | |
81345200 | 105 | bool isValidSyntax = checkSyntax(exec->vmEntryGlobalObject()->globalExec(), source, &syntaxException); |
6fe7ccc8 A |
106 | |
107 | if (!isValidSyntax) { | |
b37bf2e1 | 108 | if (exception) |
6fe7ccc8 | 109 | *exception = toRef(exec, syntaxException); |
81345200 | 110 | #if ENABLE(REMOTE_INSPECTOR) |
ed1e77d3 A |
111 | Exception* exception = Exception::create(exec->vm(), syntaxException); |
112 | exec->vmEntryGlobalObject()->inspectorController().reportAPIException(exec, exception); | |
81345200 | 113 | #endif |
b37bf2e1 A |
114 | return false; |
115 | } | |
6fe7ccc8 | 116 | |
b37bf2e1 A |
117 | return true; |
118 | } | |
119 | ||
9dae56ea | 120 | void JSGarbageCollect(JSContextRef ctx) |
b37bf2e1 | 121 | { |
9dae56ea A |
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. | |
127 | if (!ctx) | |
128 | return; | |
129 | ||
130 | ExecState* exec = toJS(ctx); | |
81345200 | 131 | JSLockHolder locker(exec); |
9dae56ea | 132 | |
93a37866 | 133 | exec->vm().heap.reportAbandonedObjectGraph(); |
b37bf2e1 | 134 | } |
9dae56ea A |
135 | |
136 | void JSReportExtraMemoryCost(JSContextRef ctx, size_t size) | |
137 | { | |
93a37866 A |
138 | if (!ctx) { |
139 | ASSERT_NOT_REACHED(); | |
140 | return; | |
141 | } | |
142 | ExecState* exec = toJS(ctx); | |
81345200 | 143 | JSLockHolder locker(exec); |
ed1e77d3 A |
144 | |
145 | exec->vm().heap.deprecatedReportExtraMemory(size); | |
93a37866 A |
146 | } |
147 | ||
148 | extern "C" JS_EXPORT void JSSynchronousGarbageCollectForDebugging(JSContextRef); | |
81345200 | 149 | extern "C" JS_EXPORT void JSSynchronousEdenCollectForDebugging(JSContextRef); |
93a37866 A |
150 | |
151 | void JSSynchronousGarbageCollectForDebugging(JSContextRef ctx) | |
152 | { | |
153 | if (!ctx) | |
154 | return; | |
155 | ||
9dae56ea | 156 | ExecState* exec = toJS(ctx); |
81345200 | 157 | JSLockHolder locker(exec); |
93a37866 | 158 | exec->vm().heap.collectAllGarbage(); |
9dae56ea | 159 | } |
6fe7ccc8 | 160 | |
81345200 A |
161 | void JSSynchronousEdenCollectForDebugging(JSContextRef ctx) |
162 | { | |
163 | if (!ctx) | |
164 | return; | |
165 | ||
166 | ExecState* exec = toJS(ctx); | |
167 | JSLockHolder locker(exec); | |
168 | exec->vm().heap.collect(EdenCollection); | |
169 | } | |
170 | ||
6fe7ccc8 A |
171 | void JSDisableGCTimer(void) |
172 | { | |
173 | GCActivityCallback::s_shouldCreateGCTimer = false; | |
174 | } | |
93a37866 | 175 | |
81345200 A |
176 | #if PLATFORM(IOS) |
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"); | |
185 | ||
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; | |
191 | #endif |