123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137 |
- /*
- * Copyright (C) 2006, 2007 Apple Inc. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
- * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
- * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
- * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
- * 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.
- */
- #include "config.h"
- #include "JSBase.h"
- #include "JSBasePrivate.h"
- #include "APICast.h"
- #include "APIShims.h"
- #include "CallFrame.h"
- #include "Completion.h"
- #include "InitializeThreading.h"
- #include "JSGlobalObject.h"
- #include "JSLock.h"
- #include "JSObject.h"
- #include "OpaqueJSString.h"
- #include "Operations.h"
- #include "SourceCode.h"
- #include <wtf/text/StringHash.h>
- using namespace JSC;
- JSValueRef JSEvaluateScript(JSContextRef ctx, JSStringRef script, JSObjectRef thisObject, JSStringRef sourceURL, int startingLineNumber, JSValueRef* exception)
- {
- if (!ctx) {
- ASSERT_NOT_REACHED();
- return 0;
- }
- ExecState* exec = toJS(ctx);
- APIEntryShim entryShim(exec);
- JSObject* jsThisObject = toJS(thisObject);
- // evaluate sets "this" to the global object if it is NULL
- JSGlobalObject* globalObject = exec->dynamicGlobalObject();
- SourceCode source = makeSource(script->string(), sourceURL->string(), TextPosition(OrdinalNumber::fromOneBasedInt(startingLineNumber), OrdinalNumber::first()));
- JSValue evaluationException;
- JSValue returnValue = evaluate(globalObject->globalExec(), source, jsThisObject, &evaluationException);
- if (evaluationException) {
- if (exception)
- *exception = toRef(exec, evaluationException);
- return 0;
- }
- if (returnValue)
- return toRef(exec, returnValue);
- // happens, for example, when the only statement is an empty (';') statement
- return toRef(exec, jsUndefined());
- }
- bool JSCheckScriptSyntax(JSContextRef ctx, JSStringRef script, JSStringRef sourceURL, int startingLineNumber, JSValueRef* exception)
- {
- if (!ctx) {
- ASSERT_NOT_REACHED();
- return false;
- }
- ExecState* exec = toJS(ctx);
- APIEntryShim entryShim(exec);
- SourceCode source = makeSource(script->string(), sourceURL->string(), TextPosition(OrdinalNumber::fromOneBasedInt(startingLineNumber), OrdinalNumber::first()));
-
- JSValue syntaxException;
- bool isValidSyntax = checkSyntax(exec->dynamicGlobalObject()->globalExec(), source, &syntaxException);
- if (!isValidSyntax) {
- if (exception)
- *exception = toRef(exec, syntaxException);
- return false;
- }
- return true;
- }
- void JSGarbageCollect(JSContextRef ctx)
- {
- // 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);
- APIEntryShim entryShim(exec, false);
- exec->vm().heap.reportAbandonedObjectGraph();
- }
- void JSReportExtraMemoryCost(JSContextRef ctx, size_t size)
- {
- if (!ctx) {
- ASSERT_NOT_REACHED();
- return;
- }
- ExecState* exec = toJS(ctx);
- APIEntryShim entryShim(exec);
- exec->vm().heap.reportExtraMemoryCost(size);
- }
- extern "C" JS_EXPORT void JSSynchronousGarbageCollectForDebugging(JSContextRef);
- void JSSynchronousGarbageCollectForDebugging(JSContextRef ctx)
- {
- if (!ctx)
- return;
- ExecState* exec = toJS(ctx);
- APIEntryShim entryShim(exec);
- exec->vm().heap.collectAllGarbage();
- }
|