<!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>[162918] 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/162918">162918</a></dd>
<dt>Author</dt> <dd>joepeck@webkit.org</dd>
<dt>Date</dt> <dd>2014-01-27 23:29:57 -0800 (Mon, 27 Jan 2014)</dd>
</dl>

<h3>Log Message</h3>
<pre>-[JSContext evaluteScript:] calls JSEvaluteScript with startingLineNumber 0, later interpreted as a oneBasedInt
https://bugs.webkit.org/show_bug.cgi?id=127648

Reviewed by Geoffrey Garen.

The actual bug being fixed here is that the line number for
scripts evaluated via the JSC APIs is now sane. However,
there is no good infrastructure in place right now to test that.

* API/tests/testapi.c:
(main):
* API/tests/testapi.mm:
(testObjectiveCAPI):
Add tests for exception line numbers and handling of bad
startingLineNumbers in public APIs. These tests were already
passing, I just add them to make sure they are not regressed
in the future.

* API/JSBase.cpp:
(JSEvaluateScript):
(JSCheckScriptSyntax):
* API/JSBase.h:
* API/JSObjectRef.cpp:
(JSObjectMakeFunction):
* API/JSObjectRef.h:
* API/JSScriptRef.cpp:
* API/JSScriptRefPrivate.h:
* API/JSStringRef.h:
- Clarify documentation that startingLineNumber is 1 based and clamped.
- Add clamping in the implementation to put sane values into JSC::SourceProvider.

* inspector/agents/InspectorDebuggerAgent.cpp:
(Inspector::InspectorDebuggerAgent::didParseSource):
Remove the FIXME now that the SourceProvider is giving us expected values.</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkSourceJavaScriptCoreAPIJSBasecpp">trunk/Source/JavaScriptCore/API/JSBase.cpp</a></li>
<li><a href="#trunkSourceJavaScriptCoreAPIJSBaseh">trunk/Source/JavaScriptCore/API/JSBase.h</a></li>
<li><a href="#trunkSourceJavaScriptCoreAPIJSObjectRefcpp">trunk/Source/JavaScriptCore/API/JSObjectRef.cpp</a></li>
<li><a href="#trunkSourceJavaScriptCoreAPIJSObjectRefh">trunk/Source/JavaScriptCore/API/JSObjectRef.h</a></li>
<li><a href="#trunkSourceJavaScriptCoreAPIJSScriptRefcpp">trunk/Source/JavaScriptCore/API/JSScriptRef.cpp</a></li>
<li><a href="#trunkSourceJavaScriptCoreAPIJSScriptRefPrivateh">trunk/Source/JavaScriptCore/API/JSScriptRefPrivate.h</a></li>
<li><a href="#trunkSourceJavaScriptCoreAPIJSStringRefh">trunk/Source/JavaScriptCore/API/JSStringRef.h</a></li>
<li><a href="#trunkSourceJavaScriptCoreAPIteststestapic">trunk/Source/JavaScriptCore/API/tests/testapi.c</a></li>
<li><a href="#trunkSourceJavaScriptCoreAPIteststestapimm">trunk/Source/JavaScriptCore/API/tests/testapi.mm</a></li>
<li><a href="#trunkSourceJavaScriptCoreChangeLog">trunk/Source/JavaScriptCore/ChangeLog</a></li>
<li><a href="#trunkSourceJavaScriptCoreinspectoragentsInspectorDebuggerAgentcpp">trunk/Source/JavaScriptCore/inspector/agents/InspectorDebuggerAgent.cpp</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkSourceJavaScriptCoreAPIJSBasecpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/API/JSBase.cpp (162917 => 162918)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/API/JSBase.cpp        2014-01-28 07:25:58 UTC (rev 162917)
+++ trunk/Source/JavaScriptCore/API/JSBase.cpp        2014-01-28 07:29:57 UTC (rev 162918)
</span><span class="lines">@@ -53,6 +53,8 @@
</span><span class="cx"> 
</span><span class="cx">     JSObject* jsThisObject = toJS(thisObject);
</span><span class="cx"> 
</span><ins>+    startingLineNumber = std::max(1, startingLineNumber);
+
</ins><span class="cx">     // evaluate sets &quot;this&quot; to the global object if it is NULL
</span><span class="cx">     JSGlobalObject* globalObject = exec-&gt;vmEntryGlobalObject();
</span><span class="cx">     SourceCode source = makeSource(script-&gt;string(), sourceURL-&gt;string(), TextPosition(OrdinalNumber::fromOneBasedInt(startingLineNumber), OrdinalNumber::first()));
</span><span class="lines">@@ -82,6 +84,8 @@
</span><span class="cx">     ExecState* exec = toJS(ctx);
</span><span class="cx">     APIEntryShim entryShim(exec);
</span><span class="cx"> 
</span><ins>+    startingLineNumber = std::max(1, startingLineNumber);
+
</ins><span class="cx">     SourceCode source = makeSource(script-&gt;string(), sourceURL-&gt;string(), TextPosition(OrdinalNumber::fromOneBasedInt(startingLineNumber), OrdinalNumber::first()));
</span><span class="cx">     
</span><span class="cx">     JSValue syntaxException;
</span></span></pre></div>
<a id="trunkSourceJavaScriptCoreAPIJSBaseh"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/API/JSBase.h (162917 => 162918)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/API/JSBase.h        2014-01-28 07:25:58 UTC (rev 162917)
+++ trunk/Source/JavaScriptCore/API/JSBase.h        2014-01-28 07:29:57 UTC (rev 162918)
</span><span class="lines">@@ -20,7 +20,7 @@
</span><span class="cx">  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
</span><span class="cx">  * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
</span><span class="cx">  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
</span><del>- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
</del><ins>+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
</ins><span class="cx">  */
</span><span class="cx"> 
</span><span class="cx"> #ifndef JSBase_h
</span><span class="lines">@@ -102,7 +102,7 @@
</span><span class="cx"> @param script A JSString containing the script to evaluate.
</span><span class="cx"> @param thisObject The object to use as &quot;this,&quot; or NULL to use the global object as &quot;this.&quot;
</span><span class="cx"> @param sourceURL A JSString containing a URL for the script's source file. This is only used when reporting exceptions. Pass NULL if you do not care to include source file information in exceptions.
</span><del>-@param startingLineNumber An integer value specifying the script's starting line number in the file located at sourceURL. This is only used when reporting exceptions.
</del><ins>+@param startingLineNumber An integer value specifying the script's starting line number in the file located at sourceURL. This is only used when reporting exceptions. The value is one-based, so the first line is line 1 and invalid values are clamped to 1.
</ins><span class="cx"> @param exception A pointer to a JSValueRef in which to store an exception, if any. Pass NULL if you do not care to store an exception.
</span><span class="cx"> @result The JSValue that results from evaluating script, or NULL if an exception is thrown.
</span><span class="cx"> */
</span><span class="lines">@@ -114,7 +114,7 @@
</span><span class="cx"> @param ctx The execution context to use.
</span><span class="cx"> @param script A JSString containing the script to check for syntax errors.
</span><span class="cx"> @param sourceURL A JSString containing a URL for the script's source file. This is only used when reporting exceptions. Pass NULL if you do not care to include source file information in exceptions.
</span><del>-@param startingLineNumber An integer value specifying the script's starting line number in the file located at sourceURL. This is only used when reporting exceptions.
</del><ins>+@param startingLineNumber An integer value specifying the script's starting line number in the file located at sourceURL. This is only used when reporting exceptions. The value is one-based, so the first line is line 1 and invalid values are clamped to 1.
</ins><span class="cx"> @param exception A pointer to a JSValueRef in which to store a syntax error exception, if any. Pass NULL if you do not care to store a syntax error exception.
</span><span class="cx"> @result true if the script is syntactically correct, otherwise false.
</span><span class="cx"> */
</span><span class="lines">@@ -122,13 +122,13 @@
</span><span class="cx"> 
</span><span class="cx"> /*!
</span><span class="cx"> @function JSGarbageCollect
</span><del>-@abstract Performs a JavaScript garbage collection. 
</del><ins>+@abstract Performs a JavaScript garbage collection.
</ins><span class="cx"> @param ctx The execution context to use.
</span><del>-@discussion JavaScript values that are on the machine stack, in a register, 
- protected by JSValueProtect, set as the global object of an execution context, 
</del><ins>+@discussion JavaScript values that are on the machine stack, in a register,
+ protected by JSValueProtect, set as the global object of an execution context,
</ins><span class="cx">  or reachable from any such value will not be collected.
</span><span class="cx"> 
</span><del>- During JavaScript execution, you are not required to call this function; the 
</del><ins>+ During JavaScript execution, you are not required to call this function; the
</ins><span class="cx">  JavaScript engine will garbage collect as needed. JavaScript values created
</span><span class="cx">  within a context group are automatically destroyed when the last reference
</span><span class="cx">  to the context group is released.
</span></span></pre></div>
<a id="trunkSourceJavaScriptCoreAPIJSObjectRefcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/API/JSObjectRef.cpp (162917 => 162918)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/API/JSObjectRef.cpp        2014-01-28 07:25:58 UTC (rev 162917)
+++ trunk/Source/JavaScriptCore/API/JSObjectRef.cpp        2014-01-28 07:29:57 UTC (rev 162918)
</span><span class="lines">@@ -21,7 +21,7 @@
</span><span class="cx">  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
</span><span class="cx">  * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
</span><span class="cx">  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
</span><del>- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
</del><ins>+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
</ins><span class="cx">  */
</span><span class="cx"> 
</span><span class="cx"> #include &quot;config.h&quot;
</span><span class="lines">@@ -135,6 +135,7 @@
</span><span class="cx">     ExecState* exec = toJS(ctx);
</span><span class="cx">     APIEntryShim entryShim(exec);
</span><span class="cx"> 
</span><ins>+    startingLineNumber = std::max(1, startingLineNumber);
</ins><span class="cx">     Identifier nameID = name ? name-&gt;identifier(&amp;exec-&gt;vm()) : Identifier(exec, &quot;anonymous&quot;);
</span><span class="cx">     
</span><span class="cx">     MarkedArgumentBuffer args;
</span></span></pre></div>
<a id="trunkSourceJavaScriptCoreAPIJSObjectRefh"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/API/JSObjectRef.h (162917 => 162918)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/API/JSObjectRef.h        2014-01-28 07:25:58 UTC (rev 162917)
+++ trunk/Source/JavaScriptCore/API/JSObjectRef.h        2014-01-28 07:29:57 UTC (rev 162918)
</span><span class="lines">@@ -21,7 +21,7 @@
</span><span class="cx">  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
</span><span class="cx">  * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
</span><span class="cx">  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
</span><del>- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
</del><ins>+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
</ins><span class="cx">  */
</span><span class="cx"> 
</span><span class="cx"> #ifndef JSObjectRef_h
</span><span class="lines">@@ -485,7 +485,7 @@
</span><span class="cx"> @param parameterNames A JSString array containing the names of the function's parameters. Pass NULL if parameterCount is 0.
</span><span class="cx"> @param body A JSString containing the script to use as the function's body.
</span><span class="cx"> @param sourceURL A JSString containing a URL for the script's source file. This is only used when reporting exceptions. Pass NULL if you do not care to include source file information in exceptions.
</span><del>-@param startingLineNumber An integer value specifying the script's starting line number in the file located at sourceURL. This is only used when reporting exceptions.
</del><ins>+@param startingLineNumber An integer value specifying the script's starting line number in the file located at sourceURL. This is only used when reporting exceptions. The value is one-based, so the first line is line 1 and invalid values are clamped to 1.
</ins><span class="cx"> @param exception A pointer to a JSValueRef in which to store a syntax error exception, if any. Pass NULL if you do not care to store a syntax error exception.
</span><span class="cx"> @result A JSObject that is a function, or NULL if either body or parameterNames contains a syntax error. The object's prototype will be the default function prototype.
</span><span class="cx"> @discussion Use this method when you want to execute a script repeatedly, to avoid the cost of re-parsing the script before each execution.
</span></span></pre></div>
<a id="trunkSourceJavaScriptCoreAPIJSScriptRefcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/API/JSScriptRef.cpp (162917 => 162918)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/API/JSScriptRef.cpp        2014-01-28 07:25:58 UTC (rev 162917)
+++ trunk/Source/JavaScriptCore/API/JSScriptRef.cpp        2014-01-28 07:29:57 UTC (rev 162918)
</span><span class="lines">@@ -83,6 +83,8 @@
</span><span class="cx">             return 0;
</span><span class="cx">     }
</span><span class="cx"> 
</span><ins>+    startingLineNumber = std::max(1, startingLineNumber);
+
</ins><span class="cx">     RefPtr&lt;OpaqueJSScript&gt; result = OpaqueJSScript::create(vm, url-&gt;string(), startingLineNumber, String(StringImpl::createFromLiteral(source, length)));
</span><span class="cx"> 
</span><span class="cx">     ParserError error;
</span><span class="lines">@@ -102,6 +104,8 @@
</span><span class="cx">     VM* vm = toJS(contextGroup);
</span><span class="cx">     APIEntryShim entryShim(vm);
</span><span class="cx"> 
</span><ins>+    startingLineNumber = std::max(1, startingLineNumber);
+
</ins><span class="cx">     RefPtr&lt;OpaqueJSScript&gt; result = OpaqueJSScript::create(vm, url-&gt;string(), startingLineNumber, source-&gt;string());
</span><span class="cx"> 
</span><span class="cx">     ParserError error;
</span></span></pre></div>
<a id="trunkSourceJavaScriptCoreAPIJSScriptRefPrivateh"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/API/JSScriptRefPrivate.h (162917 => 162918)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/API/JSScriptRefPrivate.h        2014-01-28 07:25:58 UTC (rev 162917)
+++ trunk/Source/JavaScriptCore/API/JSScriptRefPrivate.h        2014-01-28 07:29:57 UTC (rev 162918)
</span><span class="lines">@@ -42,7 +42,7 @@
</span><span class="cx">  @abstract Creates a script reference from an ascii string, without copying or taking ownership of the string
</span><span class="cx">  @param contextGroup The context group the script is to be used in.
</span><span class="cx">  @param url The source url to be reported in errors and exceptions.
</span><del>- @param startingLineNumber An integer value specifying the script's starting line number in the file located at sourceURL. This is only used when reporting exceptions.
</del><ins>+ @param startingLineNumber An integer value specifying the script's starting line number in the file located at sourceURL. This is only used when reporting exceptions. The value is one-based, so the first line is line 1 and invalid values are clamped to 1.
</ins><span class="cx">  @param source The source string.  This is required to be pure ASCII and to never be deallocated.
</span><span class="cx">  @param length The length of the source string.
</span><span class="cx">  @param errorMessage A pointer to a JSStringRef in which to store the parse error message if the source is not valid. Pass NULL if you do not care to store an error message.
</span><span class="lines">@@ -58,7 +58,7 @@
</span><span class="cx">  @abstract Creates a script reference from a string
</span><span class="cx">  @param contextGroup The context group the script is to be used in.
</span><span class="cx">  @param url The source url to be reported in errors and exceptions.
</span><del>- @param startingLineNumber An integer value specifying the script's starting line number in the file located at sourceURL. This is only used when reporting exceptions.
</del><ins>+ @param startingLineNumber An integer value specifying the script's starting line number in the file located at sourceURL. This is only used when reporting exceptions. The value is one-based, so the first line is line 1 and invalid values are clamped to 1.
</ins><span class="cx">  @param source The source string.
</span><span class="cx">  @param errorMessage A pointer to a JSStringRef in which to store the parse error message if the source is not valid. Pass NULL if you do not care to store an error message.
</span><span class="cx">  @param errorLine A pointer to an int in which to store the line number of a parser error. Pass NULL if you do not care to store an error line.
</span></span></pre></div>
<a id="trunkSourceJavaScriptCoreAPIJSStringRefh"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/API/JSStringRef.h (162917 => 162918)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/API/JSStringRef.h        2014-01-28 07:25:58 UTC (rev 162917)
+++ trunk/Source/JavaScriptCore/API/JSStringRef.h        2014-01-28 07:29:57 UTC (rev 162918)
</span><span class="lines">@@ -20,7 +20,7 @@
</span><span class="cx">  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
</span><span class="cx">  * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
</span><span class="cx">  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
</span><del>- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
</del><ins>+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
</ins><span class="cx">  */
</span><span class="cx"> 
</span><span class="cx"> #ifndef JSStringRef_h
</span></span></pre></div>
<a id="trunkSourceJavaScriptCoreAPIteststestapic"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/API/tests/testapi.c (162917 => 162918)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/API/tests/testapi.c        2014-01-28 07:25:58 UTC (rev 162917)
+++ trunk/Source/JavaScriptCore/API/tests/testapi.c        2014-01-28 07:29:57 UTC (rev 162918)
</span><span class="lines">@@ -1629,6 +1629,26 @@
</span><span class="cx">     JSStringRelease(line);
</span><span class="cx"> 
</span><span class="cx">     exception = NULL;
</span><ins>+    functionBody = JSStringCreateWithUTF8CString(&quot;rreturn Array;&quot;);
+    line = JSStringCreateWithUTF8CString(&quot;line&quot;);
+    ASSERT(!JSObjectMakeFunction(context, NULL, 0, NULL, functionBody, NULL, -42, &amp;exception));
+    ASSERT(JSValueIsObject(context, exception));
+    v = JSObjectGetProperty(context, JSValueToObject(context, exception, NULL), line, NULL);
+    assertEqualsAsNumber(v, 1);
+    JSStringRelease(functionBody);
+    JSStringRelease(line);
+
+    exception = NULL;
+    functionBody = JSStringCreateWithUTF8CString(&quot;// Line one.\nrreturn Array;&quot;);
+    line = JSStringCreateWithUTF8CString(&quot;line&quot;);
+    ASSERT(!JSObjectMakeFunction(context, NULL, 0, NULL, functionBody, NULL, 1, &amp;exception));
+    ASSERT(JSValueIsObject(context, exception));
+    v = JSObjectGetProperty(context, JSValueToObject(context, exception, NULL), line, NULL);
+    assertEqualsAsNumber(v, 2);
+    JSStringRelease(functionBody);
+    JSStringRelease(line);
+
+    exception = NULL;
</ins><span class="cx">     functionBody = JSStringCreateWithUTF8CString(&quot;return Array;&quot;);
</span><span class="cx">     function = JSObjectMakeFunction(context, NULL, 0, NULL, functionBody, NULL, 1, &amp;exception);
</span><span class="cx">     JSStringRelease(functionBody);
</span></span></pre></div>
<a id="trunkSourceJavaScriptCoreAPIteststestapimm"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/API/tests/testapi.mm (162917 => 162918)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/API/tests/testapi.mm        2014-01-28 07:25:58 UTC (rev 162917)
+++ trunk/Source/JavaScriptCore/API/tests/testapi.mm        2014-01-28 07:29:57 UTC (rev 162918)
</span><span class="lines">@@ -594,6 +594,22 @@
</span><span class="cx"> 
</span><span class="cx">     @autoreleasepool {
</span><span class="cx">         JSContext *context = [[JSContext alloc] init];
</span><ins>+        __block int expectedExceptionLineNumber = 1;
+        __block bool sawExpectedExceptionLineNumber = false;
+        context.exceptionHandler = ^(JSContext *, JSValue *exception) {
+            sawExpectedExceptionLineNumber = [exception[@&quot;line&quot;] toInt32] == expectedExceptionLineNumber;
+        };
+        [context evaluateScript:@&quot;!@#$%^&amp;*() THIS IS NOT VALID JAVASCRIPT SYNTAX !@#$%^&amp;*()&quot;];
+        checkResult(@&quot;evaluteScript exception on line 1&quot;, sawExpectedExceptionLineNumber);
+
+        expectedExceptionLineNumber = 2;
+        sawExpectedExceptionLineNumber = false;
+        [context evaluateScript:@&quot;// Line 1\n!@#$%^&amp;*() THIS IS NOT VALID JAVASCRIPT SYNTAX !@#$%^&amp;*()&quot;];
+        checkResult(@&quot;evaluteScript exception on line 2&quot;, sawExpectedExceptionLineNumber);
+    }
+
+    @autoreleasepool {
+        JSContext *context = [[JSContext alloc] init];
</ins><span class="cx">         context[@&quot;callback&quot;] = ^{
</span><span class="cx">             JSContext *context = [JSContext currentContext];
</span><span class="cx">             context.exception = [JSValue valueWithNewErrorFromMessage:@&quot;Something went wrong.&quot; inContext:context];
</span></span></pre></div>
<a id="trunkSourceJavaScriptCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/ChangeLog (162917 => 162918)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/ChangeLog        2014-01-28 07:25:58 UTC (rev 162917)
+++ trunk/Source/JavaScriptCore/ChangeLog        2014-01-28 07:29:57 UTC (rev 162918)
</span><span class="lines">@@ -1,5 +1,42 @@
</span><span class="cx"> 2014-01-27  Joseph Pecoraro  &lt;pecoraro@apple.com&gt;
</span><span class="cx"> 
</span><ins>+        -[JSContext evaluteScript:] calls JSEvaluteScript with startingLineNumber 0, later interpreted as a oneBasedInt
+        https://bugs.webkit.org/show_bug.cgi?id=127648
+
+        Reviewed by Geoffrey Garen.
+
+        The actual bug being fixed here is that the line number for
+        scripts evaluated via the JSC APIs is now sane. However,
+        there is no good infrastructure in place right now to test that.
+
+        * API/tests/testapi.c:
+        (main):
+        * API/tests/testapi.mm:
+        (testObjectiveCAPI):
+        Add tests for exception line numbers and handling of bad
+        startingLineNumbers in public APIs. These tests were already
+        passing, I just add them to make sure they are not regressed
+        in the future.
+
+        * API/JSBase.cpp:
+        (JSEvaluateScript):
+        (JSCheckScriptSyntax):
+        * API/JSBase.h:
+        * API/JSObjectRef.cpp:
+        (JSObjectMakeFunction):
+        * API/JSObjectRef.h:
+        * API/JSScriptRef.cpp:
+        * API/JSScriptRefPrivate.h:
+        * API/JSStringRef.h:
+        - Clarify documentation that startingLineNumber is 1 based and clamped.
+        - Add clamping in the implementation to put sane values into JSC::SourceProvider.
+
+        * inspector/agents/InspectorDebuggerAgent.cpp:
+        (Inspector::InspectorDebuggerAgent::didParseSource):
+        Remove the FIXME now that the SourceProvider is giving us expected values.
+
+2014-01-27  Joseph Pecoraro  &lt;pecoraro@apple.com&gt;
+
</ins><span class="cx">         Web Inspector: CRASH when debugger closes remote inspecting JSContext
</span><span class="cx">         https://bugs.webkit.org/show_bug.cgi?id=127738
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkSourceJavaScriptCoreinspectoragentsInspectorDebuggerAgentcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/inspector/agents/InspectorDebuggerAgent.cpp (162917 => 162918)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/inspector/agents/InspectorDebuggerAgent.cpp        2014-01-28 07:25:58 UTC (rev 162917)
+++ trunk/Source/JavaScriptCore/inspector/agents/InspectorDebuggerAgent.cpp        2014-01-28 07:29:57 UTC (rev 162918)
</span><span class="lines">@@ -575,7 +575,6 @@
</span><span class="cx"> void InspectorDebuggerAgent::didParseSource(JSC::SourceID sourceID, const Script&amp; inScript)
</span><span class="cx"> {
</span><span class="cx">     Script script = inScript;
</span><del>-    // FIXME: Why does -[JSContext evaluateScript] have a -1 startLine?
</del><span class="cx">     if (script.startLine &lt;= 0 &amp;&amp; !script.startColumn)
</span><span class="cx">         script.sourceURL = ContentSearchUtilities::findScriptSourceURL(script.source);
</span><span class="cx">     script.sourceMappingURL = sourceMapURLForScript(script);
</span></span></pre>
</div>
</div>

</body>
</html>