diff options
author | The Android Open Source Project <initial-contribution@android.com> | 2008-12-17 18:05:15 -0800 |
---|---|---|
committer | The Android Open Source Project <initial-contribution@android.com> | 2008-12-17 18:05:15 -0800 |
commit | 1cbdecfa9fc428ac2d8aca0fa91c9580b3d57353 (patch) | |
tree | 4457a7306ea5acb43fe05bfe0973b1f7faf97ba2 /JavaScriptCore/API/JSBase.cpp | |
parent | 9364f22aed35e1a1e9d07c121510f80be3ab0502 (diff) | |
download | external_webkit-1cbdecfa9fc428ac2d8aca0fa91c9580b3d57353.zip external_webkit-1cbdecfa9fc428ac2d8aca0fa91c9580b3d57353.tar.gz external_webkit-1cbdecfa9fc428ac2d8aca0fa91c9580b3d57353.tar.bz2 |
Code drop from //branches/cupcake/...@124589
Diffstat (limited to 'JavaScriptCore/API/JSBase.cpp')
-rw-r--r-- | JavaScriptCore/API/JSBase.cpp | 69 |
1 files changed, 49 insertions, 20 deletions
diff --git a/JavaScriptCore/API/JSBase.cpp b/JavaScriptCore/API/JSBase.cpp index d8acc42..bd2935c 100644 --- a/JavaScriptCore/API/JSBase.cpp +++ b/JavaScriptCore/API/JSBase.cpp @@ -1,4 +1,3 @@ -// -*- mode: c++; c-basic-offset: 4 -*- /* * Copyright (C) 2006, 2007 Apple Inc. All rights reserved. * @@ -21,30 +20,38 @@ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include "config.h" #include "JSBase.h" +#include "JSBasePrivate.h" #include "APICast.h" -#include <kjs/ExecState.h> -#include <kjs/JSGlobalObject.h> -#include <kjs/JSLock.h> +#include "completion.h" +#include "OpaqueJSString.h" +#include "SourceCode.h" +#include <runtime/ExecState.h> +#include <runtime/InitializeThreading.h> #include <kjs/interpreter.h> -#include <kjs/object.h> +#include <runtime/JSGlobalObject.h> +#include <runtime/JSLock.h> +#include <runtime/JSObject.h> -using namespace KJS; +using namespace JSC; JSValueRef JSEvaluateScript(JSContextRef ctx, JSStringRef script, JSObjectRef thisObject, JSStringRef sourceURL, int startingLineNumber, JSValueRef* exception) { - JSLock lock; ExecState* exec = toJS(ctx); + exec->globalData().heap.registerThread(); + JSLock lock(exec); + JSObject* jsThisObject = toJS(thisObject); - UString::Rep* scriptRep = toJS(script); - UString::Rep* sourceURLRep = sourceURL ? toJS(sourceURL) : &UString::Rep::null; + // Interpreter::evaluate sets "this" to the global object if it is NULL - Completion completion = Interpreter::evaluate(exec->dynamicGlobalObject()->globalExec(), UString(sourceURLRep), startingLineNumber, UString(scriptRep), jsThisObject); + JSGlobalObject* globalObject = exec->dynamicGlobalObject(); + SourceCode source = makeSource(script->ustring(), sourceURL->ustring(), startingLineNumber); + Completion completion = Interpreter::evaluate(globalObject->globalExec(), globalObject->globalScopeChain(), source, jsThisObject); if (completion.complType() == Throw) { if (exception) @@ -61,12 +68,12 @@ JSValueRef JSEvaluateScript(JSContextRef ctx, JSStringRef script, JSObjectRef th bool JSCheckScriptSyntax(JSContextRef ctx, JSStringRef script, JSStringRef sourceURL, int startingLineNumber, JSValueRef* exception) { - JSLock lock; - ExecState* exec = toJS(ctx); - UString::Rep* scriptRep = toJS(script); - UString::Rep* sourceURLRep = sourceURL ? toJS(sourceURL) : &UString::Rep::null; - Completion completion = Interpreter::checkSyntax(exec->dynamicGlobalObject()->globalExec(), UString(sourceURLRep), startingLineNumber, UString(scriptRep)); + exec->globalData().heap.registerThread(); + JSLock lock(exec); + + SourceCode source = makeSource(script->ustring(), sourceURL->ustring(), startingLineNumber); + Completion completion = Interpreter::checkSyntax(exec->dynamicGlobalObject()->globalExec(), source); if (completion.complType() == Throw) { if (exception) *exception = toRef(completion.value()); @@ -76,12 +83,34 @@ bool JSCheckScriptSyntax(JSContextRef ctx, JSStringRef script, JSStringRef sourc return true; } -void JSGarbageCollect(JSContextRef) +void JSGarbageCollect(JSContextRef ctx) { - JSLock lock; - if (!Collector::isBusy()) - Collector::collect(); + // We used to recommend passing NULL as an argument here, which caused the only heap to be collected. + // As there is no longer a shared heap, the previously recommended usage became a no-op (but the GC + // will happen when the context group is destroyed). + // Because the function argument was originally ignored, some clients may pass their released context here, + // in which case there is a risk of crashing if another thread performs GC on the same heap in between. + if (!ctx) + return; + + ExecState* exec = toJS(ctx); + JSGlobalData& globalData = exec->globalData(); + + JSLock lock(globalData.isSharedInstance); + + if (!globalData.heap.isBusy()) + globalData.heap.collect(); + // FIXME: Perhaps we should trigger a second mark and sweep // once the garbage collector is done if this is called when // the collector is busy. } + +void JSReportExtraMemoryCost(JSContextRef ctx, size_t size) +{ + ExecState* exec = toJS(ctx); + exec->globalData().heap.registerThread(); + JSLock lock(exec); + + exec->globalData().heap.reportExtraMemoryCost(size); +} |