]> git.saurik.com Git - apple/javascriptcore.git/blobdiff - API/JSBase.cpp
JavaScriptCore-1218.33.tar.gz
[apple/javascriptcore.git] / API / JSBase.cpp
index fc3d0fe1bcbe8707232390a9f23cc1cfc67a2b7a..c51231c3c43e88e57d818dde1eb5b546455006ec 100644 (file)
 #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 <interpreter/CallFrame.h>
-#include <runtime/InitializeThreading.h>
-#include <runtime/Completion.h>
-#include <runtime/JSGlobalObject.h>
-#include <runtime/JSLock.h>
-#include <runtime/JSObject.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);
-    exec->globalData().heap.registerThread();
-    JSLock lock(exec);
+    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->ustring(), sourceURL->ustring(), startingLineNumber);
-    Completion completion = evaluate(globalObject->globalExec(), globalObject->globalScopeChain(), source, jsThisObject);
+    SourceCode source = makeSource(script->string(), sourceURL->string(), TextPosition(OrdinalNumber::fromOneBasedInt(startingLineNumber), OrdinalNumber::first()));
 
-    if (completion.complType() == Throw) {
+    JSValue evaluationException;
+    JSValue returnValue = evaluate(globalObject->globalExec(), source, jsThisObject, &evaluationException);
+
+    if (evaluationException) {
         if (exception)
-            *exception = toRef(exec, completion.value());
+            *exception = toRef(exec, evaluationException);
         return 0;
     }
 
-    if (completion.value())
-        return toRef(exec, completion.value());
-    
+    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);
-    exec->globalData().heap.registerThread();
-    JSLock lock(exec);
+    APIEntryShim entryShim(exec);
 
-    SourceCode source = makeSource(script->ustring(), sourceURL->ustring(), startingLineNumber);
-    Completion completion = checkSyntax(exec->dynamicGlobalObject()->globalExec(), source);
-    if (completion.complType() == Throw) {
+    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, completion.value());
+            *exception = toRef(exec, syntaxException);
         return false;
     }
-    
+
     return true;
 }
 
@@ -94,23 +107,49 @@ void JSGarbageCollect(JSContextRef ctx)
         return;
 
     ExecState* exec = toJS(ctx);
-    JSGlobalData& globalData = exec->globalData();
-
-    JSLock lock(globalData.isSharedInstance);
-
-    if (!globalData.heap.isBusy())
-        globalData.heap.collect();
+    APIEntryShim entryShim(exec, false);
 
-    // 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.
+    exec->vm().heap.reportAbandonedObjectGraph();
 }
 
 void JSReportExtraMemoryCost(JSContextRef ctx, size_t size)
 {
+    if (!ctx) {
+        ASSERT_NOT_REACHED();
+        return;
+    }
     ExecState* exec = toJS(ctx);
-    exec->globalData().heap.registerThread();
-    JSLock lock(exec);
+    APIEntryShim entryShim(exec);
+    exec->vm().heap.reportExtraMemoryCost(size);
+}
+
+extern "C" JS_EXPORT void JSSynchronousGarbageCollectForDebugging(JSContextRef);
 
-    exec->globalData().heap.reportExtraMemoryCost(size);
+void JSSynchronousGarbageCollectForDebugging(JSContextRef ctx)
+{
+    if (!ctx)
+        return;
+
+    ExecState* exec = toJS(ctx);
+    APIEntryShim entryShim(exec);
+    exec->vm().heap.collectAllGarbage();
+}
+
+#if PLATFORM(IOS)
+void JSDisableGCTimer(void)
+{
+    GCActivityCallback::s_shouldCreateGCTimer = false;
 }
+
+JS_EXPORT extern const char install_name_4_3 __asm("$ld$install_name$os4.3$/System/Library/PrivateFrameworks/JavaScriptCore.framework/JavaScriptCore");
+JS_EXPORT extern const char install_name_5_0 __asm("$ld$install_name$os5.0$/System/Library/PrivateFrameworks/JavaScriptCore.framework/JavaScriptCore");
+JS_EXPORT extern const char install_name_5_1 __asm("$ld$install_name$os5.1$/System/Library/PrivateFrameworks/JavaScriptCore.framework/JavaScriptCore");
+JS_EXPORT extern const char install_name_6_0 __asm("$ld$install_name$os6.0$/System/Library/PrivateFrameworks/JavaScriptCore.framework/JavaScriptCore");
+JS_EXPORT extern const char install_name_6_1 __asm("$ld$install_name$os6.1$/System/Library/PrivateFrameworks/JavaScriptCore.framework/JavaScriptCore");
+
+const char install_name_4_3 = 0;
+const char install_name_5_0 = 0;
+const char install_name_5_1 = 0;
+const char install_name_6_0 = 0;
+const char install_name_6_1 = 0;
+#endif // PLATFORM(IOS)