+#if OS(DARWIN)
+#include <mach-o/dyld.h>
+
+static const int32_t webkitFirstVersionWithConcurrentGlobalContexts = 0x2100500; // 528.5.0
+#endif
+
+using namespace JSC;
+
+// From the API's perspective, a context group remains alive iff
+// (a) it has been JSContextGroupRetained
+// OR
+// (b) one of its contexts has been JSContextRetained
+
+JSContextGroupRef JSContextGroupCreate()
+{
+ initializeThreading();
+ return toRef(VM::createContextGroup().leakRef());
+}
+
+JSContextGroupRef JSContextGroupRetain(JSContextGroupRef group)
+{
+ toJS(group)->ref();
+ return group;
+}
+
+void JSContextGroupRelease(JSContextGroupRef group)
+{
+ IdentifierTable* savedIdentifierTable;
+ VM& vm = *toJS(group);
+
+ {
+ JSLockHolder lock(vm);
+ savedIdentifierTable = wtfThreadData().setCurrentIdentifierTable(vm.identifierTable);
+ vm.deref();
+ }
+
+ wtfThreadData().setCurrentIdentifierTable(savedIdentifierTable);
+}
+
+static bool internalScriptTimeoutCallback(ExecState* exec, void* callbackPtr, void* callbackData)
+{
+ JSShouldTerminateCallback callback = reinterpret_cast<JSShouldTerminateCallback>(callbackPtr);
+ JSContextRef contextRef = toRef(exec);
+ ASSERT(callback);
+ return callback(contextRef, callbackData);
+}
+
+void JSContextGroupSetExecutionTimeLimit(JSContextGroupRef group, double limit, JSShouldTerminateCallback callback, void* callbackData)
+{
+ VM& vm = *toJS(group);
+ APIEntryShim entryShim(&vm);
+ Watchdog& watchdog = vm.watchdog;
+ if (callback) {
+ void* callbackPtr = reinterpret_cast<void*>(callback);
+ watchdog.setTimeLimit(vm, limit, internalScriptTimeoutCallback, callbackPtr, callbackData);
+ } else
+ watchdog.setTimeLimit(vm, limit);
+}
+
+void JSContextGroupClearExecutionTimeLimit(JSContextGroupRef group)
+{
+ VM& vm = *toJS(group);
+ APIEntryShim entryShim(&vm);
+ Watchdog& watchdog = vm.watchdog;
+ watchdog.setTimeLimit(vm, std::numeric_limits<double>::infinity());
+}
+
+// From the API's perspective, a global context remains alive iff it has been JSGlobalContextRetained.