<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[181670] trunk/Source/JavaScriptCore</title>
</head>
<body>
<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; }
#msg dl a { font-weight: bold}
#msg dl a:link { color:#fc3; }
#msg dl a:active { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://trac.webkit.org/projects/webkit/changeset/181670">181670</a></dd>
<dt>Author</dt> <dd>mark.lam@apple.com</dd>
<dt>Date</dt> <dd>2015-03-17 16:06:37 -0700 (Tue, 17 Mar 2015)</dd>
</dl>
<h3>Log Message</h3>
<pre>Refactor execution time limit tests out of testapi.c.
<https://webkit.org/b/142798>
Rubber stamped by Michael Saboff.
These tests were sometimes failing to time out on C loop builds. Let's
refactor them out of the big monolith that is testapi.c so that we can
reason more easily about them and make adjustments if needed.
* API/tests/ExecutionTimeLimitTest.cpp: Added.
(currentCPUTime):
(currentCPUTimeAsJSFunctionCallback):
(shouldTerminateCallback):
(cancelTerminateCallback):
(extendTerminateCallback):
(testExecutionTimeLimit):
* API/tests/ExecutionTimeLimitTest.h: Added.
* API/tests/testapi.c:
(main):
(currentCPUTime): Deleted.
(currentCPUTime_callAsFunction): Deleted.
(shouldTerminateCallback): Deleted.
(cancelTerminateCallback): Deleted.
(extendTerminateCallback): Deleted.
* JavaScriptCore.xcodeproj/project.pbxproj:</pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkSourceJavaScriptCoreAPIteststestapic">trunk/Source/JavaScriptCore/API/tests/testapi.c</a></li>
<li><a href="#trunkSourceJavaScriptCoreChangeLog">trunk/Source/JavaScriptCore/ChangeLog</a></li>
<li><a href="#trunkSourceJavaScriptCoreJavaScriptCorexcodeprojprojectpbxproj">trunk/Source/JavaScriptCore/JavaScriptCore.xcodeproj/project.pbxproj</a></li>
</ul>
<h3>Added Paths</h3>
<ul>
<li><a href="#trunkSourceJavaScriptCoreAPItestsExecutionTimeLimitTestcpp">trunk/Source/JavaScriptCore/API/tests/ExecutionTimeLimitTest.cpp</a></li>
<li><a href="#trunkSourceJavaScriptCoreAPItestsExecutionTimeLimitTesth">trunk/Source/JavaScriptCore/API/tests/ExecutionTimeLimitTest.h</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkSourceJavaScriptCoreAPItestsExecutionTimeLimitTestcpp"></a>
<div class="addfile"><h4>Added: trunk/Source/JavaScriptCore/API/tests/ExecutionTimeLimitTest.cpp (0 => 181670)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/API/tests/ExecutionTimeLimitTest.cpp         (rev 0)
+++ trunk/Source/JavaScriptCore/API/tests/ExecutionTimeLimitTest.cpp        2015-03-17 23:06:37 UTC (rev 181670)
</span><span class="lines">@@ -0,0 +1,267 @@
</span><ins>+/*
+ * Copyright (C) 2015 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 INC. AND ITS CONTRIBUTORS ``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 INC. OR ITS 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 "ExecutionTimeLimitTest.h"
+
+#if OS(DARWIN)
+
+#include "JavaScriptCore.h"
+
+#include <mach/mach.h>
+#include <mach/mach_time.h>
+#include <stdio.h>
+#include <sys/time.h>
+
+static JSGlobalContextRef* currentContextForAssertion = nullptr;
+
+static double currentCPUTime()
+{
+ mach_msg_type_number_t infoCount = THREAD_BASIC_INFO_COUNT;
+ thread_basic_info_data_t info;
+
+ /* Get thread information */
+ mach_port_t threadPort = mach_thread_self();
+ thread_info(threadPort, THREAD_BASIC_INFO, (thread_info_t)(&info), &infoCount);
+ mach_port_deallocate(mach_task_self(), threadPort);
+
+ double time = info.user_time.seconds + info.user_time.microseconds / 1000000.;
+ time += info.system_time.seconds + info.system_time.microseconds / 1000000.;
+
+ return time;
+}
+
+static JSValueRef currentCPUTimeAsJSFunctionCallback(JSContextRef ctx, JSObjectRef functionObject, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
+{
+ UNUSED_PARAM(functionObject);
+ UNUSED_PARAM(thisObject);
+ UNUSED_PARAM(argumentCount);
+ UNUSED_PARAM(arguments);
+ UNUSED_PARAM(exception);
+
+ ASSERT(JSContextGetGlobalContext(ctx) == *currentContextForAssertion);
+ return JSValueMakeNumber(ctx, currentCPUTime());
+}
+
+bool shouldTerminateCallbackWasCalled = false;
+static bool shouldTerminateCallback(JSContextRef ctx, void* context)
+{
+ UNUSED_PARAM(ctx);
+ UNUSED_PARAM(context);
+ shouldTerminateCallbackWasCalled = true;
+ return true;
+}
+
+bool cancelTerminateCallbackWasCalled = false;
+static bool cancelTerminateCallback(JSContextRef ctx, void* context)
+{
+ UNUSED_PARAM(ctx);
+ UNUSED_PARAM(context);
+ cancelTerminateCallbackWasCalled = true;
+ return false;
+}
+
+int extendTerminateCallbackCalled = 0;
+static bool extendTerminateCallback(JSContextRef ctx, void* context)
+{
+ UNUSED_PARAM(context);
+ extendTerminateCallbackCalled++;
+ if (extendTerminateCallbackCalled == 1) {
+ JSContextGroupRef contextGroup = JSContextGetGroup(ctx);
+ JSContextGroupSetExecutionTimeLimit(contextGroup, .200f, extendTerminateCallback, 0);
+ return false;
+ }
+ return true;
+}
+
+
+int testExecutionTimeLimit(JSGlobalContextRef* globalContext)
+{
+ JSGlobalContextRef& context = *globalContext;
+ currentContextForAssertion = globalContext;
+
+ JSContextGroupRef contextGroup = JSContextGetGroup(context);
+ JSObjectRef globalObject = JSContextGetGlobalObject(context);
+ ASSERT(JSValueIsObject(context, globalObject));
+
+ JSValueRef v = nullptr;
+ JSValueRef exception = nullptr;
+ bool failed = false;
+
+ JSStringRef currentCPUTimeStr = JSStringCreateWithUTF8CString("currentCPUTime");
+ JSObjectRef currentCPUTimeFunction = JSObjectMakeFunctionWithCallback(context, currentCPUTimeStr, currentCPUTimeAsJSFunctionCallback);
+ JSObjectSetProperty(context, globalObject, currentCPUTimeStr, currentCPUTimeFunction, kJSPropertyAttributeNone, nullptr);
+ JSStringRelease(currentCPUTimeStr);
+
+ /* Test script timeout: */
+ JSContextGroupSetExecutionTimeLimit(contextGroup, .10f, shouldTerminateCallback, 0);
+ {
+ const char* loopForeverScript = "var startTime = currentCPUTime(); while (true) { if (currentCPUTime() - startTime > .150) break; } ";
+ JSStringRef script = JSStringCreateWithUTF8CString(loopForeverScript);
+ double startTime;
+ double endTime;
+ exception = nullptr;
+ shouldTerminateCallbackWasCalled = false;
+ startTime = currentCPUTime();
+ v = JSEvaluateScript(context, script, nullptr, nullptr, 1, &exception);
+ endTime = currentCPUTime();
+
+ if (((endTime - startTime) < .150f) && shouldTerminateCallbackWasCalled)
+ printf("PASS: script timed out as expected.\n");
+ else {
+ if (!((endTime - startTime) < .150f))
+ printf("FAIL: script did not time out as expected.\n");
+ if (!shouldTerminateCallbackWasCalled)
+ printf("FAIL: script timeout callback was not called.\n");
+ failed = true;
+ }
+
+ if (!exception) {
+ printf("FAIL: TerminatedExecutionException was not thrown.\n");
+ failed = true;
+ }
+ }
+
+ /* Test the script timeout's TerminatedExecutionException should NOT be catchable: */
+ JSContextGroupSetExecutionTimeLimit(contextGroup, 0.10f, shouldTerminateCallback, 0);
+ {
+ const char* loopForeverScript = "var startTime = currentCPUTime(); try { while (true) { if (currentCPUTime() - startTime > .150) break; } } catch(e) { }";
+ JSStringRef script = JSStringCreateWithUTF8CString(loopForeverScript);
+ double startTime;
+ double endTime;
+ exception = nullptr;
+ shouldTerminateCallbackWasCalled = false;
+ startTime = currentCPUTime();
+ v = JSEvaluateScript(context, script, nullptr, nullptr, 1, &exception);
+ endTime = currentCPUTime();
+
+ if (((endTime - startTime) >= .150f) || !shouldTerminateCallbackWasCalled) {
+ if (!((endTime - startTime) < .150f))
+ printf("FAIL: script did not time out as expected.\n");
+ if (!shouldTerminateCallbackWasCalled)
+ printf("FAIL: script timeout callback was not called.\n");
+ failed = true;
+ }
+
+ if (exception)
+ printf("PASS: TerminatedExecutionException was not catchable as expected.\n");
+ else {
+ printf("FAIL: TerminatedExecutionException was caught.\n");
+ failed = true;
+ }
+ }
+
+ /* Test script timeout with no callback: */
+ JSContextGroupSetExecutionTimeLimit(contextGroup, .10f, 0, 0);
+ {
+ const char* loopForeverScript = "var startTime = currentCPUTime(); while (true) { if (currentCPUTime() - startTime > .150) break; } ";
+ JSStringRef script = JSStringCreateWithUTF8CString(loopForeverScript);
+ double startTime;
+ double endTime;
+ exception = nullptr;
+ startTime = currentCPUTime();
+ v = JSEvaluateScript(context, script, nullptr, nullptr, 1, &exception);
+ endTime = currentCPUTime();
+
+ if (((endTime - startTime) < .150f) && shouldTerminateCallbackWasCalled)
+ printf("PASS: script timed out as expected when no callback is specified.\n");
+ else {
+ if (!((endTime - startTime) < .150f))
+ printf("FAIL: script did not time out as expected when no callback is specified.\n");
+ failed = true;
+ }
+
+ if (!exception) {
+ printf("FAIL: TerminatedExecutionException was not thrown.\n");
+ failed = true;
+ }
+ }
+
+ /* Test script timeout cancellation: */
+ JSContextGroupSetExecutionTimeLimit(contextGroup, 0.10f, cancelTerminateCallback, 0);
+ {
+ const char* loopForeverScript = "var startTime = currentCPUTime(); while (true) { if (currentCPUTime() - startTime > .150) break; } ";
+ JSStringRef script = JSStringCreateWithUTF8CString(loopForeverScript);
+ double startTime;
+ double endTime;
+ exception = nullptr;
+ startTime = currentCPUTime();
+ v = JSEvaluateScript(context, script, nullptr, nullptr, 1, &exception);
+ endTime = currentCPUTime();
+
+ if (((endTime - startTime) >= .150f) && cancelTerminateCallbackWasCalled && !exception)
+ printf("PASS: script timeout was cancelled as expected.\n");
+ else {
+ if (((endTime - startTime) < .150) || exception)
+ printf("FAIL: script timeout was not cancelled.\n");
+ if (!cancelTerminateCallbackWasCalled)
+ printf("FAIL: script timeout callback was not called.\n");
+ failed = true;
+ }
+
+ if (exception) {
+ printf("FAIL: Unexpected TerminatedExecutionException thrown.\n");
+ failed = true;
+ }
+ }
+
+ /* Test script timeout extension: */
+ JSContextGroupSetExecutionTimeLimit(contextGroup, 0.100f, extendTerminateCallback, 0);
+ {
+ const char* loopForeverScript = "var startTime = currentCPUTime(); while (true) { if (currentCPUTime() - startTime > .500) break; } ";
+ JSStringRef script = JSStringCreateWithUTF8CString(loopForeverScript);
+ double startTime;
+ double endTime;
+ double deltaTime;
+ exception = nullptr;
+ startTime = currentCPUTime();
+ v = JSEvaluateScript(context, script, nullptr, nullptr, 1, &exception);
+ endTime = currentCPUTime();
+ deltaTime = endTime - startTime;
+
+ if ((deltaTime >= .300f) && (deltaTime < .500f) && (extendTerminateCallbackCalled == 2) && exception)
+ printf("PASS: script timeout was extended as expected.\n");
+ else {
+ if (deltaTime < .200f)
+ printf("FAIL: script timeout was not extended as expected.\n");
+ else if (deltaTime >= .500f)
+ printf("FAIL: script did not timeout.\n");
+
+ if (extendTerminateCallbackCalled < 1)
+ printf("FAIL: script timeout callback was not called.\n");
+ if (extendTerminateCallbackCalled < 2)
+ printf("FAIL: script timeout callback was not called after timeout extension.\n");
+
+ if (!exception)
+ printf("FAIL: TerminatedExecutionException was not thrown during timeout extension test.\n");
+
+ failed = true;
+ }
+ }
+
+ return failed;
+}
+
+#endif // OS(DARWIN)
</ins></span></pre></div>
<a id="trunkSourceJavaScriptCoreAPItestsExecutionTimeLimitTesth"></a>
<div class="addfile"><h4>Added: trunk/Source/JavaScriptCore/API/tests/ExecutionTimeLimitTest.h (0 => 181670)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/API/tests/ExecutionTimeLimitTest.h         (rev 0)
+++ trunk/Source/JavaScriptCore/API/tests/ExecutionTimeLimitTest.h        2015-03-17 23:06:37 UTC (rev 181670)
</span><span class="lines">@@ -0,0 +1,42 @@
</span><ins>+/*
+ * Copyright (C) 2015 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 INC. AND ITS CONTRIBUTORS ``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 INC. OR ITS 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.
+ */
+
+#ifndef ExecutionTimeLimitTest_h
+#define ExecutionTimeLimitTest_h
+
+#include "JSContextRefPrivate.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/* Returns 1 if failures were encountered. Else, returns 0. */
+int testExecutionTimeLimit(JSGlobalContextRef*);
+
+#ifdef __cplusplus
+} /* extern "C" */
+#endif
+
+#endif /* ExecutionTimeLimitTest_h */
</ins></span></pre></div>
<a id="trunkSourceJavaScriptCoreAPIteststestapic"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/API/tests/testapi.c (181669 => 181670)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/API/tests/testapi.c        2015-03-17 22:57:40 UTC (rev 181669)
+++ trunk/Source/JavaScriptCore/API/tests/testapi.c        2015-03-17 23:06:37 UTC (rev 181670)
</span><span class="lines">@@ -35,12 +35,6 @@
</span><span class="cx"> #define ASSERT_DISABLED 0
</span><span class="cx"> #include <wtf/Assertions.h>
</span><span class="cx">
</span><del>-#if OS(DARWIN)
-#include <mach/mach.h>
-#include <mach/mach_time.h>
-#include <sys/time.h>
-#endif
-
</del><span class="cx"> #if OS(WINDOWS)
</span><span class="cx"> #include <windows.h>
</span><span class="cx"> #endif
</span><span class="lines">@@ -48,6 +42,10 @@
</span><span class="cx"> #include "CompareAndSwapTest.h"
</span><span class="cx"> #include "CustomGlobalObjectClassTest.h"
</span><span class="cx">
</span><ins>+#if OS(DARWIN)
+#include "ExecutionTimeLimitTest.h"
+#endif
+
</ins><span class="cx"> #if JSC_OBJC_API_ENABLED
</span><span class="cx"> void testObjectiveCAPI(void);
</span><span class="cx"> #endif
</span><span class="lines">@@ -1113,68 +1111,7 @@
</span><span class="cx"> val.name = "something";
</span><span class="cx"> }
</span><span class="cx">
</span><del>-#if OS(DARWIN)
-static double currentCPUTime()
-{
- mach_msg_type_number_t infoCount = THREAD_BASIC_INFO_COUNT;
- thread_basic_info_data_t info;
</del><span class="cx">
</span><del>- /* Get thread information */
- mach_port_t threadPort = mach_thread_self();
- thread_info(threadPort, THREAD_BASIC_INFO, (thread_info_t)(&info), &infoCount);
- mach_port_deallocate(mach_task_self(), threadPort);
-
- double time = info.user_time.seconds + info.user_time.microseconds / 1000000.;
- time += info.system_time.seconds + info.system_time.microseconds / 1000000.;
-
- return time;
-}
-
-static JSValueRef currentCPUTime_callAsFunction(JSContextRef ctx, JSObjectRef functionObject, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
-{
- UNUSED_PARAM(functionObject);
- UNUSED_PARAM(thisObject);
- UNUSED_PARAM(argumentCount);
- UNUSED_PARAM(arguments);
- UNUSED_PARAM(exception);
-
- ASSERT(JSContextGetGlobalContext(ctx) == context);
- return JSValueMakeNumber(ctx, currentCPUTime());
-}
-
-bool shouldTerminateCallbackWasCalled = false;
-static bool shouldTerminateCallback(JSContextRef ctx, void* context)
-{
- UNUSED_PARAM(ctx);
- UNUSED_PARAM(context);
- shouldTerminateCallbackWasCalled = true;
- return true;
-}
-
-bool cancelTerminateCallbackWasCalled = false;
-static bool cancelTerminateCallback(JSContextRef ctx, void* context)
-{
- UNUSED_PARAM(ctx);
- UNUSED_PARAM(context);
- cancelTerminateCallbackWasCalled = true;
- return false;
-}
-
-int extendTerminateCallbackCalled = 0;
-static bool extendTerminateCallback(JSContextRef ctx, void* context)
-{
- UNUSED_PARAM(context);
- extendTerminateCallbackCalled++;
- if (extendTerminateCallbackCalled == 1) {
- JSContextGroupRef contextGroup = JSContextGetGroup(ctx);
- JSContextGroupSetExecutionTimeLimit(contextGroup, .200f, extendTerminateCallback, 0);
- return false;
- }
- return true;
-}
-#endif /* OS(DARWIN) */
-
-
</del><span class="cx"> int main(int argc, char* argv[])
</span><span class="cx"> {
</span><span class="cx"> #if OS(WINDOWS)
</span><span class="lines">@@ -1917,156 +1854,7 @@
</span><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> #if OS(DARWIN)
</span><del>- JSStringRef currentCPUTimeStr = JSStringCreateWithUTF8CString("currentCPUTime");
- JSObjectRef currentCPUTimeFunction = JSObjectMakeFunctionWithCallback(context, currentCPUTimeStr, currentCPUTime_callAsFunction);
- JSObjectSetProperty(context, globalObject, currentCPUTimeStr, currentCPUTimeFunction, kJSPropertyAttributeNone, NULL);
- JSStringRelease(currentCPUTimeStr);
-
- /* Test script timeout: */
- JSContextGroupSetExecutionTimeLimit(contextGroup, .10f, shouldTerminateCallback, 0);
- {
- const char* loopForeverScript = "var startTime = currentCPUTime(); while (true) { if (currentCPUTime() - startTime > .150) break; } ";
- JSStringRef script = JSStringCreateWithUTF8CString(loopForeverScript);
- double startTime;
- double endTime;
- exception = NULL;
- shouldTerminateCallbackWasCalled = false;
- startTime = currentCPUTime();
- v = JSEvaluateScript(context, script, NULL, NULL, 1, &exception);
- endTime = currentCPUTime();
-
- if (((endTime - startTime) < .150f) && shouldTerminateCallbackWasCalled)
- printf("PASS: script timed out as expected.\n");
- else {
- if (!((endTime - startTime) < .150f))
- printf("FAIL: script did not time out as expected.\n");
- if (!shouldTerminateCallbackWasCalled)
- printf("FAIL: script timeout callback was not called.\n");
- failed = true;
- }
-
- if (!exception) {
- printf("FAIL: TerminatedExecutionException was not thrown.\n");
- failed = true;
- }
- }
-
- /* Test the script timeout's TerminatedExecutionException should NOT be catchable: */
- JSContextGroupSetExecutionTimeLimit(contextGroup, 0.10f, shouldTerminateCallback, 0);
- {
- const char* loopForeverScript = "var startTime = currentCPUTime(); try { while (true) { if (currentCPUTime() - startTime > .150) break; } } catch(e) { }";
- JSStringRef script = JSStringCreateWithUTF8CString(loopForeverScript);
- double startTime;
- double endTime;
- exception = NULL;
- shouldTerminateCallbackWasCalled = false;
- startTime = currentCPUTime();
- v = JSEvaluateScript(context, script, NULL, NULL, 1, &exception);
- endTime = currentCPUTime();
-
- if (((endTime - startTime) >= .150f) || !shouldTerminateCallbackWasCalled) {
- if (!((endTime - startTime) < .150f))
- printf("FAIL: script did not time out as expected.\n");
- if (!shouldTerminateCallbackWasCalled)
- printf("FAIL: script timeout callback was not called.\n");
- failed = true;
- }
-
- if (exception)
- printf("PASS: TerminatedExecutionException was not catchable as expected.\n");
- else {
- printf("FAIL: TerminatedExecutionException was caught.\n");
- failed = true;
- }
- }
-
- /* Test script timeout with no callback: */
- JSContextGroupSetExecutionTimeLimit(contextGroup, .10f, 0, 0);
- {
- const char* loopForeverScript = "var startTime = currentCPUTime(); while (true) { if (currentCPUTime() - startTime > .150) break; } ";
- JSStringRef script = JSStringCreateWithUTF8CString(loopForeverScript);
- double startTime;
- double endTime;
- exception = NULL;
- startTime = currentCPUTime();
- v = JSEvaluateScript(context, script, NULL, NULL, 1, &exception);
- endTime = currentCPUTime();
-
- if (((endTime - startTime) < .150f) && shouldTerminateCallbackWasCalled)
- printf("PASS: script timed out as expected when no callback is specified.\n");
- else {
- if (!((endTime - startTime) < .150f))
- printf("FAIL: script did not time out as expected when no callback is specified.\n");
- failed = true;
- }
-
- if (!exception) {
- printf("FAIL: TerminatedExecutionException was not thrown.\n");
- failed = true;
- }
- }
-
- /* Test script timeout cancellation: */
- JSContextGroupSetExecutionTimeLimit(contextGroup, 0.10f, cancelTerminateCallback, 0);
- {
- const char* loopForeverScript = "var startTime = currentCPUTime(); while (true) { if (currentCPUTime() - startTime > .150) break; } ";
- JSStringRef script = JSStringCreateWithUTF8CString(loopForeverScript);
- double startTime;
- double endTime;
- exception = NULL;
- startTime = currentCPUTime();
- v = JSEvaluateScript(context, script, NULL, NULL, 1, &exception);
- endTime = currentCPUTime();
-
- if (((endTime - startTime) >= .150f) && cancelTerminateCallbackWasCalled && !exception)
- printf("PASS: script timeout was cancelled as expected.\n");
- else {
- if (((endTime - startTime) < .150) || exception)
- printf("FAIL: script timeout was not cancelled.\n");
- if (!cancelTerminateCallbackWasCalled)
- printf("FAIL: script timeout callback was not called.\n");
- failed = true;
- }
-
- if (exception) {
- printf("FAIL: Unexpected TerminatedExecutionException thrown.\n");
- failed = true;
- }
- }
-
- /* Test script timeout extension: */
- JSContextGroupSetExecutionTimeLimit(contextGroup, 0.100f, extendTerminateCallback, 0);
- {
- const char* loopForeverScript = "var startTime = currentCPUTime(); while (true) { if (currentCPUTime() - startTime > .500) break; } ";
- JSStringRef script = JSStringCreateWithUTF8CString(loopForeverScript);
- double startTime;
- double endTime;
- double deltaTime;
- exception = NULL;
- startTime = currentCPUTime();
- v = JSEvaluateScript(context, script, NULL, NULL, 1, &exception);
- endTime = currentCPUTime();
- deltaTime = endTime - startTime;
-
- if ((deltaTime >= .300f) && (deltaTime < .500f) && (extendTerminateCallbackCalled == 2) && exception)
- printf("PASS: script timeout was extended as expected.\n");
- else {
- if (deltaTime < .200f)
- printf("FAIL: script timeout was not extended as expected.\n");
- else if (deltaTime >= .500f)
- printf("FAIL: script did not timeout.\n");
-
- if (extendTerminateCallbackCalled < 1)
- printf("FAIL: script timeout callback was not called.\n");
- if (extendTerminateCallbackCalled < 2)
- printf("FAIL: script timeout callback was not called after timeout extension.\n");
-
- if (!exception)
- printf("FAIL: TerminatedExecutionException was not thrown during timeout extension test.\n");
-
- failed = true;
- }
- }
</del><ins>+ failed = testExecutionTimeLimit(&context) || failed;
</ins><span class="cx"> #endif /* OS(DARWIN) */
</span><span class="cx">
</span><span class="cx"> // Clear out local variables pointing at JSObjectRefs to allow their values to be collected
</span></span></pre></div>
<a id="trunkSourceJavaScriptCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/ChangeLog (181669 => 181670)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/ChangeLog        2015-03-17 22:57:40 UTC (rev 181669)
+++ trunk/Source/JavaScriptCore/ChangeLog        2015-03-17 23:06:37 UTC (rev 181670)
</span><span class="lines">@@ -1,3 +1,31 @@
</span><ins>+2015-03-17 Mark Lam <mark.lam@apple.com>
+
+ Refactor execution time limit tests out of testapi.c.
+ <https://webkit.org/b/142798>
+
+ Rubber stamped by Michael Saboff.
+
+ These tests were sometimes failing to time out on C loop builds. Let's
+ refactor them out of the big monolith that is testapi.c so that we can
+ reason more easily about them and make adjustments if needed.
+
+ * API/tests/ExecutionTimeLimitTest.cpp: Added.
+ (currentCPUTime):
+ (currentCPUTimeAsJSFunctionCallback):
+ (shouldTerminateCallback):
+ (cancelTerminateCallback):
+ (extendTerminateCallback):
+ (testExecutionTimeLimit):
+ * API/tests/ExecutionTimeLimitTest.h: Added.
+ * API/tests/testapi.c:
+ (main):
+ (currentCPUTime): Deleted.
+ (currentCPUTime_callAsFunction): Deleted.
+ (shouldTerminateCallback): Deleted.
+ (cancelTerminateCallback): Deleted.
+ (extendTerminateCallback): Deleted.
+ * JavaScriptCore.xcodeproj/project.pbxproj:
+
</ins><span class="cx"> 2015-03-17 Geoffrey Garen <ggaren@apple.com>
</span><span class="cx">
</span><span class="cx"> Built-in functions should know that they use strict mode
</span></span></pre></div>
<a id="trunkSourceJavaScriptCoreJavaScriptCorexcodeprojprojectpbxproj"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/JavaScriptCore.xcodeproj/project.pbxproj (181669 => 181670)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/JavaScriptCore.xcodeproj/project.pbxproj        2015-03-17 22:57:40 UTC (rev 181669)
+++ trunk/Source/JavaScriptCore/JavaScriptCore.xcodeproj/project.pbxproj        2015-03-17 23:06:37 UTC (rev 181670)
</span><span class="lines">@@ -74,6 +74,7 @@
</span><span class="cx"> /* End PBXAggregateTarget section */
</span><span class="cx">
</span><span class="cx"> /* Begin PBXBuildFile section */
</span><ins>+                0A6441519420A6C61AD1882E /* MapDataInlines.h in Headers */ = {isa = PBXBuildFile; fileRef = 593D43CCA0BBE06D89C59707 /* MapDataInlines.h */; settings = {ATTRIBUTES = (Private, ); }; };
</ins><span class="cx">                 0F0123321944EA1B00843A0C /* DFGValueStrength.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 0F0123301944EA1B00843A0C /* DFGValueStrength.cpp */; };
</span><span class="cx">                 0F0123331944EA1B00843A0C /* DFGValueStrength.h in Headers */ = {isa = PBXBuildFile; fileRef = 0F0123311944EA1B00843A0C /* DFGValueStrength.h */; settings = {ATTRIBUTES = (Private, ); }; };
</span><span class="cx">                 0F0332C018ADFAE1005F979A /* ExitingJITType.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 0F0332BF18ADFAE1005F979A /* ExitingJITType.cpp */; };
</span><span class="lines">@@ -1331,7 +1332,6 @@
</span><span class="cx">                 A784A26111D16622005776AC /* ASTBuilder.h in Headers */ = {isa = PBXBuildFile; fileRef = A7A7EE7411B98B8D0065A14F /* ASTBuilder.h */; settings = {ATTRIBUTES = (Private, ); }; };
</span><span class="cx">                 A784A26411D16622005776AC /* SyntaxChecker.h in Headers */ = {isa = PBXBuildFile; fileRef = A7A7EE7711B98B8D0065A14F /* SyntaxChecker.h */; settings = {ATTRIBUTES = (Private, ); }; };
</span><span class="cx">                 A78507D717CBC6FD0011F6E7 /* MapData.h in Headers */ = {isa = PBXBuildFile; fileRef = A78507D517CBC6FD0011F6E7 /* MapData.h */; settings = {ATTRIBUTES = (Private, ); }; };
</span><del>-                0A6441519420A6C61AD1882E /* MapDataInlines.h in Headers */ = {isa = PBXBuildFile; fileRef = 593D43CCA0BBE06D89C59707 /* MapDataInlines.h */; settings = {ATTRIBUTES = (Private, ); }; };
</del><span class="cx">                 A785F6BC18C553FE00F10626 /* SpillRegistersMode.h in Headers */ = {isa = PBXBuildFile; fileRef = A7FF647A18C52E8500B55307 /* SpillRegistersMode.h */; settings = {ATTRIBUTES = (Private, ); }; };
</span><span class="cx">                 A78853F917972629001440E4 /* IntendedStructureChain.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A78853F717972629001440E4 /* IntendedStructureChain.cpp */; };
</span><span class="cx">                 A78853FA17972629001440E4 /* IntendedStructureChain.h in Headers */ = {isa = PBXBuildFile; fileRef = A78853F817972629001440E4 /* IntendedStructureChain.h */; settings = {ATTRIBUTES = (Private, ); }; };
</span><span class="lines">@@ -1611,6 +1611,7 @@
</span><span class="cx">                 E49DC16B12EF293E00184A1F /* SourceProviderCache.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E49DC15512EF277200184A1F /* SourceProviderCache.cpp */; };
</span><span class="cx">                 E49DC16C12EF294E00184A1F /* SourceProviderCache.h in Headers */ = {isa = PBXBuildFile; fileRef = E49DC15112EF272200184A1F /* SourceProviderCache.h */; settings = {ATTRIBUTES = (Private, ); }; };
</span><span class="cx">                 E49DC16D12EF295300184A1F /* SourceProviderCacheItem.h in Headers */ = {isa = PBXBuildFile; fileRef = E49DC14912EF261A00184A1F /* SourceProviderCacheItem.h */; settings = {ATTRIBUTES = (Private, ); }; };
</span><ins>+                FE0D4A061AB8DD0A002F54BF /* ExecutionTimeLimitTest.cpp in Sources */ = {isa = PBXBuildFile; fileRef = FE0D4A041AB8DD0A002F54BF /* ExecutionTimeLimitTest.cpp */; };
</ins><span class="cx">                 FE20CE9D15F04A9500DF3430 /* LLIntCLoop.cpp in Sources */ = {isa = PBXBuildFile; fileRef = FE20CE9B15F04A9500DF3430 /* LLIntCLoop.cpp */; };
</span><span class="cx">                 FE20CE9E15F04A9500DF3430 /* LLIntCLoop.h in Headers */ = {isa = PBXBuildFile; fileRef = FE20CE9C15F04A9500DF3430 /* LLIntCLoop.h */; settings = {ATTRIBUTES = (Private, ); }; };
</span><span class="cx">                 FE4A331F15BD2E07006F54F3 /* VMInspector.cpp in Sources */ = {isa = PBXBuildFile; fileRef = FE4A331D15BD2E07006F54F3 /* VMInspector.cpp */; };
</span><span class="lines">@@ -2575,6 +2576,7 @@
</span><span class="cx">                 52C952B619A289850069B386 /* TypeProfiler.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = TypeProfiler.h; sourceTree = "<group>"; };
</span><span class="cx">                 52C952B819A28A1C0069B386 /* TypeProfiler.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = TypeProfiler.cpp; sourceTree = "<group>"; };
</span><span class="cx">                 5540758418F4A37500602A5D /* CompileRuntimeToLLVMIR.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; path = CompileRuntimeToLLVMIR.xcconfig; sourceTree = "<group>"; };
</span><ins>+                593D43CCA0BBE06D89C59707 /* MapDataInlines.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MapDataInlines.h; sourceTree = "<group>"; };
</ins><span class="cx">                 5D53726D0E1C546B0021E549 /* Tracing.d */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = Tracing.d; sourceTree = "<group>"; };
</span><span class="cx">                 5D53726E0E1C54880021E549 /* Tracing.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Tracing.h; sourceTree = "<group>"; };
</span><span class="cx">                 5D53727D0E1C55EC0021E549 /* TracingDtrace.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TracingDtrace.h; sourceTree = "<group>"; };
</span><span class="lines">@@ -3039,7 +3041,6 @@
</span><span class="cx">                 A77F1820164088B200640A47 /* CodeCache.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CodeCache.h; sourceTree = "<group>"; };
</span><span class="cx">                 A77F18241641925400640A47 /* ParserModes.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ParserModes.h; sourceTree = "<group>"; };
</span><span class="cx">                 A78507D517CBC6FD0011F6E7 /* MapData.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MapData.h; sourceTree = "<group>"; };
</span><del>-                593D43CCA0BBE06D89C59707 /* MapDataInlines.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MapDataInlines.h; sourceTree = "<group>"; };
</del><span class="cx">                 A78853F717972629001440E4 /* IntendedStructureChain.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = IntendedStructureChain.cpp; sourceTree = "<group>"; };
</span><span class="cx">                 A78853F817972629001440E4 /* IntendedStructureChain.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = IntendedStructureChain.h; sourceTree = "<group>"; };
</span><span class="cx">                 A78A976C179738B8009DF744 /* DFGFailedFinalizer.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = DFGFailedFinalizer.cpp; path = dfg/DFGFailedFinalizer.cpp; sourceTree = "<group>"; };
</span><span class="lines">@@ -3357,6 +3358,8 @@
</span><span class="cx">                 F692A87D0255597D01FF60F7 /* RegExp.cpp */ = {isa = PBXFileReference; fileEncoding = 30; indentWidth = 4; lastKnownFileType = sourcecode.cpp.cpp; path = RegExp.cpp; sourceTree = "<group>"; tabWidth = 8; };
</span><span class="cx">                 F692A87E0255597D01FF60F7 /* RegExp.h */ = {isa = PBXFileReference; fileEncoding = 30; indentWidth = 4; lastKnownFileType = sourcecode.c.h; path = RegExp.h; sourceTree = "<group>"; tabWidth = 8; };
</span><span class="cx">                 F692A8870255597D01FF60F7 /* JSCJSValue.cpp */ = {isa = PBXFileReference; fileEncoding = 30; indentWidth = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSCJSValue.cpp; sourceTree = "<group>"; tabWidth = 8; };
</span><ins>+                FE0D4A041AB8DD0A002F54BF /* ExecutionTimeLimitTest.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = ExecutionTimeLimitTest.cpp; path = API/tests/ExecutionTimeLimitTest.cpp; sourceTree = "<group>"; };
+                FE0D4A051AB8DD0A002F54BF /* ExecutionTimeLimitTest.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = ExecutionTimeLimitTest.h; path = API/tests/ExecutionTimeLimitTest.h; sourceTree = "<group>"; };
</ins><span class="cx">                 FE20CE9B15F04A9500DF3430 /* LLIntCLoop.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = LLIntCLoop.cpp; path = llint/LLIntCLoop.cpp; sourceTree = "<group>"; };
</span><span class="cx">                 FE20CE9C15F04A9500DF3430 /* LLIntCLoop.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = LLIntCLoop.h; path = llint/LLIntCLoop.h; sourceTree = "<group>"; };
</span><span class="cx">                 FE4A331D15BD2E07006F54F3 /* VMInspector.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = VMInspector.cpp; sourceTree = "<group>"; };
</span><span class="lines">@@ -3742,6 +3745,8 @@
</span><span class="cx">                                 C29ECB011804D0ED00D2CBB4 /* CurrentThisInsideBlockGetterTest.mm */,
</span><span class="cx">                                 C288B2DC18A54D3E007BE40B /* DateTests.h */,
</span><span class="cx">                                 C288B2DD18A54D3E007BE40B /* DateTests.mm */,
</span><ins>+                                FE0D4A041AB8DD0A002F54BF /* ExecutionTimeLimitTest.cpp */,
+                                FE0D4A051AB8DD0A002F54BF /* ExecutionTimeLimitTest.h */,
</ins><span class="cx">                                 C2181FC018A948FB0025A235 /* JSExportTests.h */,
</span><span class="cx">                                 C2181FC118A948FB0025A235 /* JSExportTests.mm */,
</span><span class="cx">                                 65570F581AA4C00A009B3C23 /* Regress141275.h */,
</span><span class="lines">@@ -6791,6 +6796,7 @@
</span><span class="cx">                                 FEF040511AAE662D00BD28B0 /* CompareAndSwapTest.cpp in Sources */,
</span><span class="cx">                                 1440F6100A4F85670005F061 /* testapi.c in Sources */,
</span><span class="cx">                                 86D2221A167EF9440024C804 /* testapi.mm in Sources */,
</span><ins>+                                FE0D4A061AB8DD0A002F54BF /* ExecutionTimeLimitTest.cpp in Sources */,
</ins><span class="cx">                         );
</span><span class="cx">                         runOnlyForDeploymentPostprocessing = 0;
</span><span class="cx">                 };
</span></span></pre>
</div>
</div>
</body>
</html>