<!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>[208966] 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/208966">208966</a></dd>
<dt>Author</dt> <dd>mark.lam@apple.com</dd>
<dt>Date</dt> <dd>2016-11-22 11:16:55 -0800 (Tue, 22 Nov 2016)</dd>
</dl>
<h3>Log Message</h3>
<pre>Fix exception scope verification failures in JSONObject.cpp.
https://bugs.webkit.org/show_bug.cgi?id=165025
Reviewed by Saam Barati.
* runtime/JSONObject.cpp:
(JSC::gap):
(JSC::Stringifier::Stringifier):
(JSC::Stringifier::stringify):
(JSC::Stringifier::toJSON):
(JSC::Stringifier::appendStringifiedValue):
(JSC::Stringifier::Holder::appendNextProperty):
(JSC::Walker::walk):
(JSC::JSONProtoFuncParse):
(JSC::JSONProtoFuncStringify):
(JSC::JSONStringify):</pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkSourceJavaScriptCoreChangeLog">trunk/Source/JavaScriptCore/ChangeLog</a></li>
<li><a href="#trunkSourceJavaScriptCoreruntimeJSONObjectcpp">trunk/Source/JavaScriptCore/runtime/JSONObject.cpp</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkSourceJavaScriptCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/ChangeLog (208965 => 208966)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/ChangeLog        2016-11-22 18:43:53 UTC (rev 208965)
+++ trunk/Source/JavaScriptCore/ChangeLog        2016-11-22 19:16:55 UTC (rev 208966)
</span><span class="lines">@@ -1,3 +1,22 @@
</span><ins>+2016-11-22 Mark Lam <mark.lam@apple.com>
+
+ Fix exception scope verification failures in JSONObject.cpp.
+ https://bugs.webkit.org/show_bug.cgi?id=165025
+
+ Reviewed by Saam Barati.
+
+ * runtime/JSONObject.cpp:
+ (JSC::gap):
+ (JSC::Stringifier::Stringifier):
+ (JSC::Stringifier::stringify):
+ (JSC::Stringifier::toJSON):
+ (JSC::Stringifier::appendStringifiedValue):
+ (JSC::Stringifier::Holder::appendNextProperty):
+ (JSC::Walker::walk):
+ (JSC::JSONProtoFuncParse):
+ (JSC::JSONProtoFuncStringify):
+ (JSC::JSONStringify):
+
</ins><span class="cx"> 2016-11-21 Mark Lam <mark.lam@apple.com>
</span><span class="cx">
</span><span class="cx"> Removed an extra space character at the end of line.
</span></span></pre></div>
<a id="trunkSourceJavaScriptCoreruntimeJSONObjectcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/runtime/JSONObject.cpp (208965 => 208966)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/runtime/JSONObject.cpp        2016-11-22 18:43:53 UTC (rev 208965)
+++ trunk/Source/JavaScriptCore/runtime/JSONObject.cpp        2016-11-22 19:16:55 UTC (rev 208966)
</span><span class="lines">@@ -130,7 +130,7 @@
</span><span class="cx"> PropertyNameArray m_arrayReplacerPropertyNames;
</span><span class="cx"> CallType m_replacerCallType;
</span><span class="cx"> CallData m_replacerCallData;
</span><del>- const String m_gap;
</del><ins>+ String m_gap;
</ins><span class="cx">
</span><span class="cx"> Vector<Holder, 16, UnsafeVectorOverflow> m_holderStack;
</span><span class="cx"> String m_repeatedGap;
</span><span class="lines">@@ -158,8 +158,12 @@
</span><span class="cx">
</span><span class="cx"> static inline String gap(ExecState* exec, JSValue space)
</span><span class="cx"> {
</span><ins>+ VM& vm = exec->vm();
+ auto scope = DECLARE_THROW_SCOPE(vm);
+
</ins><span class="cx"> const unsigned maxGapLength = 10;
</span><span class="cx"> space = unwrapBoxedPrimitive(exec, space);
</span><ins>+ RETURN_IF_EXCEPTION(scope, { });
</ins><span class="cx">
</span><span class="cx"> // If the space value is a number, create a gap string with that number of spaces.
</span><span class="cx"> if (space.isNumber()) {
</span><span class="lines">@@ -221,10 +225,14 @@
</span><span class="cx"> , m_usingArrayReplacer(false)
</span><span class="cx"> , m_arrayReplacerPropertyNames(exec, PropertyNameMode::Strings)
</span><span class="cx"> , m_replacerCallType(CallType::None)
</span><del>- , m_gap(gap(exec, space.get()))
</del><span class="cx"> {
</span><span class="cx"> VM& vm = exec->vm();
</span><span class="cx"> auto scope = DECLARE_THROW_SCOPE(vm);
</span><ins>+
+ m_gap = gap(exec, space.get());
+ if (UNLIKELY(scope.exception()))
+ return;
+
</ins><span class="cx"> if (!m_replacer.isObject())
</span><span class="cx"> return;
</span><span class="cx">
</span><span class="lines">@@ -232,6 +240,8 @@
</span><span class="cx"> m_usingArrayReplacer = true;
</span><span class="cx"> Handle<JSObject> array = m_replacer.asObject();
</span><span class="cx"> unsigned length = array->get(exec, vm.propertyNames->length).toUInt32(exec);
</span><ins>+ if (UNLIKELY(scope.exception()))
+ return;
</ins><span class="cx"> for (unsigned i = 0; i < length; ++i) {
</span><span class="cx"> JSValue name = array->get(exec, i);
</span><span class="cx"> if (UNLIKELY(scope.exception()))
</span><span class="lines">@@ -263,10 +273,12 @@
</span><span class="cx">
</span><span class="cx"> StringBuilder result;
</span><span class="cx"> Holder root(Holder::RootHolder, vm, object);
</span><del>- if (appendStringifiedValue(result, value.get(), root, emptyPropertyName) != StringifySucceeded)
</del><ins>+ auto stringifyResult = appendStringifiedValue(result, value.get(), root, emptyPropertyName);
+ ASSERT(!scope.exception() || (stringifyResult != StringifySucceeded));
+ if (UNLIKELY(stringifyResult != StringifySucceeded))
</ins><span class="cx"> return Local<Unknown>(vm, jsUndefined());
</span><del>- RETURN_IF_EXCEPTION(scope, Local<Unknown>(vm, jsNull()));
</del><span class="cx">
</span><ins>+ scope.release();
</ins><span class="cx"> return Local<Unknown>(vm, jsString(m_exec, result.toString()));
</span><span class="cx"> }
</span><span class="cx">
</span><span class="lines">@@ -280,11 +292,14 @@
</span><span class="cx">
</span><span class="cx"> JSObject* object = asObject(value);
</span><span class="cx"> PropertySlot slot(object, PropertySlot::InternalMethodType::Get);
</span><del>- if (!object->getPropertySlot(m_exec, vm.propertyNames->toJSON, slot))
</del><ins>+ bool hasProperty = object->getPropertySlot(m_exec, vm.propertyNames->toJSON, slot);
+ ASSERT(!scope.exception() || !hasProperty);
+ if (!hasProperty)
</ins><span class="cx"> return value;
</span><span class="cx">
</span><span class="cx"> JSValue toJSONFunction = slot.getValue(m_exec, vm.propertyNames->toJSON);
</span><del>- RETURN_IF_EXCEPTION(scope, JSValue());
</del><ins>+ RETURN_IF_EXCEPTION(scope, { });
+ scope.release();
</ins><span class="cx"> return toJSONImpl(value, toJSONFunction, propertyName);
</span><span class="cx"> }
</span><span class="cx">
</span><span class="lines">@@ -387,6 +402,7 @@
</span><span class="cx"> do {
</span><span class="cx"> while (m_holderStack.last().appendNextProperty(*this, builder))
</span><span class="cx"> RETURN_IF_EXCEPTION(scope, StringifyFailed);
</span><ins>+ RETURN_IF_EXCEPTION(scope, StringifyFailed);
</ins><span class="cx"> m_holderStack.removeLast();
</span><span class="cx"> } while (!m_holderStack.isEmpty());
</span><span class="cx"> return StringifySucceeded;
</span><span class="lines">@@ -457,8 +473,10 @@
</span><span class="cx"> if (m_isJSArray)
</span><span class="cx"> m_size = asArray(m_object.get())->length();
</span><span class="cx"> else {
</span><del>- m_size = m_object->get(exec, vm.propertyNames->length).toUInt32(exec);
</del><ins>+ JSValue value = m_object->get(exec, vm.propertyNames->length);
</ins><span class="cx"> RETURN_IF_EXCEPTION(scope, false);
</span><ins>+ m_size = value.toUInt32(exec);
+ RETURN_IF_EXCEPTION(scope, false);
</ins><span class="cx"> }
</span><span class="cx"> builder.append('[');
</span><span class="cx"> } else {
</span><span class="lines">@@ -536,6 +554,7 @@
</span><span class="cx"> // Append the stringified value.
</span><span class="cx"> stringifyResult = stringifier.appendStringifiedValue(builder, value, *this, propertyName);
</span><span class="cx"> }
</span><ins>+ RETURN_IF_EXCEPTION(scope, false);
</ins><span class="cx">
</span><span class="cx"> // From this point on, no access to the this pointer or to any members, because the
</span><span class="cx"> // Holder object may have moved if the call to stringify pushed a new Holder onto
</span><span class="lines">@@ -653,7 +672,7 @@
</span><span class="cx"> inValue = slot.getValue(m_exec, index);
</span><span class="cx"> else
</span><span class="cx"> inValue = jsUndefined();
</span><del>- RETURN_IF_EXCEPTION(scope, JSValue());
</del><ins>+ RETURN_IF_EXCEPTION(scope, { });
</ins><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> if (inValue.isObject()) {
</span><span class="lines">@@ -666,11 +685,12 @@
</span><span class="cx"> case ArrayEndVisitMember: {
</span><span class="cx"> JSArray* array = arrayStack.peek();
</span><span class="cx"> JSValue filteredValue = callReviver(array, jsString(m_exec, String::number(indexStack.last())), outValue);
</span><ins>+ RETURN_IF_EXCEPTION(scope, { });
</ins><span class="cx"> if (filteredValue.isUndefined())
</span><span class="cx"> array->methodTable(vm)->deletePropertyByIndex(array, m_exec, indexStack.last());
</span><span class="cx"> else
</span><span class="cx"> array->putDirectIndex(m_exec, indexStack.last(), filteredValue, 0, PutDirectIndexShouldNotThrow);
</span><del>- RETURN_IF_EXCEPTION(scope, JSValue());
</del><ins>+ RETURN_IF_EXCEPTION(scope, { });
</ins><span class="cx"> indexStack.last()++;
</span><span class="cx"> goto arrayStartVisitMember;
</span><span class="cx"> }
</span><span class="lines">@@ -686,7 +706,7 @@
</span><span class="cx"> indexStack.append(0);
</span><span class="cx"> propertyStack.append(PropertyNameArray(m_exec, PropertyNameMode::Strings));
</span><span class="cx"> object->methodTable(vm)->getOwnPropertyNames(object, m_exec, propertyStack.last(), EnumerationMode());
</span><del>- RETURN_IF_EXCEPTION(scope, JSValue());
</del><ins>+ RETURN_IF_EXCEPTION(scope, { });
</ins><span class="cx"> }
</span><span class="cx"> objectStartVisitMember:
</span><span class="cx"> FALLTHROUGH;
</span><span class="lines">@@ -708,7 +728,7 @@
</span><span class="cx"> inValue = jsUndefined();
</span><span class="cx">
</span><span class="cx"> // The holder may be modified by the reviver function so any lookup may throw
</span><del>- RETURN_IF_EXCEPTION(scope, JSValue());
</del><ins>+ RETURN_IF_EXCEPTION(scope, { });
</ins><span class="cx">
</span><span class="cx"> if (inValue.isObject()) {
</span><span class="cx"> stateStack.append(ObjectEndVisitMember);
</span><span class="lines">@@ -722,11 +742,12 @@
</span><span class="cx"> Identifier prop = propertyStack.last()[indexStack.last()];
</span><span class="cx"> PutPropertySlot slot(object);
</span><span class="cx"> JSValue filteredValue = callReviver(object, jsString(m_exec, prop.string()), outValue);
</span><ins>+ RETURN_IF_EXCEPTION(scope, { });
</ins><span class="cx"> if (filteredValue.isUndefined())
</span><span class="cx"> object->methodTable(vm)->deleteProperty(object, m_exec, prop);
</span><span class="cx"> else
</span><span class="cx"> object->methodTable(vm)->put(object, m_exec, prop, filteredValue, slot);
</span><del>- RETURN_IF_EXCEPTION(scope, JSValue());
</del><ins>+ RETURN_IF_EXCEPTION(scope, { });
</ins><span class="cx"> indexStack.last()++;
</span><span class="cx"> goto objectStartVisitMember;
</span><span class="cx"> }
</span><span class="lines">@@ -750,6 +771,8 @@
</span><span class="cx"> JSObject* finalHolder = constructEmptyObject(m_exec);
</span><span class="cx"> PutPropertySlot slot(finalHolder);
</span><span class="cx"> finalHolder->methodTable(vm)->put(finalHolder, m_exec, vm.propertyNames->emptyIdentifier, outValue, slot);
</span><ins>+ RETURN_IF_EXCEPTION(scope, { });
+ scope.release();
</ins><span class="cx"> return callReviver(finalHolder, jsEmptyString(m_exec), outValue);
</span><span class="cx"> }
</span><span class="cx">
</span><span class="lines">@@ -762,7 +785,7 @@
</span><span class="cx"> if (!exec->argumentCount())
</span><span class="cx"> return throwVMError(exec, scope, createError(exec, ASCIILiteral("JSON.parse requires at least one parameter")));
</span><span class="cx"> auto viewWithString = exec->uncheckedArgument(0).toString(exec)->viewWithUnderlyingString(*exec);
</span><del>- RETURN_IF_EXCEPTION(scope, encodedJSValue());
</del><ins>+ RETURN_IF_EXCEPTION(scope, { });
</ins><span class="cx"> StringView view = viewWithString.view;
</span><span class="cx">
</span><span class="cx"> JSValue unfiltered;
</span><span class="lines">@@ -770,13 +793,19 @@
</span><span class="cx"> if (view.is8Bit()) {
</span><span class="cx"> LiteralParser<LChar> jsonParser(exec, view.characters8(), view.length(), StrictJSON);
</span><span class="cx"> unfiltered = jsonParser.tryLiteralParse();
</span><del>- if (!unfiltered)
</del><ins>+ ASSERT(!scope.exception() || !unfiltered);
+ if (!unfiltered) {
+ RETURN_IF_EXCEPTION(scope, { });
</ins><span class="cx"> return throwVMError(exec, scope, createSyntaxError(exec, jsonParser.getErrorMessage()));
</span><ins>+ }
</ins><span class="cx"> } else {
</span><span class="cx"> LiteralParser<UChar> jsonParser(exec, view.characters16(), view.length(), StrictJSON);
</span><span class="cx"> unfiltered = jsonParser.tryLiteralParse();
</span><del>- if (!unfiltered)
</del><ins>+ ASSERT(!scope.exception() || !unfiltered);
+ if (!unfiltered) {
+ RETURN_IF_EXCEPTION(scope, { });
</ins><span class="cx"> return throwVMError(exec, scope, createSyntaxError(exec, jsonParser.getErrorMessage()));
</span><ins>+ }
</ins><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> if (exec->argumentCount() < 2)
</span><span class="lines">@@ -787,6 +816,7 @@
</span><span class="cx"> CallType callType = getCallData(function, callData);
</span><span class="cx"> if (callType == CallType::None)
</span><span class="cx"> return JSValue::encode(unfiltered);
</span><ins>+ scope.release();
</ins><span class="cx"> return JSValue::encode(Walker(exec, Local<JSObject>(vm, asObject(function)), callType, callData).walk(unfiltered));
</span><span class="cx"> }
</span><span class="cx">
</span><span class="lines">@@ -802,7 +832,10 @@
</span><span class="cx"> Local<Unknown> value(vm, exec->uncheckedArgument(0));
</span><span class="cx"> Local<Unknown> replacer(vm, exec->argument(1));
</span><span class="cx"> Local<Unknown> space(vm, exec->argument(2));
</span><del>- JSValue result = Stringifier(exec, replacer, space).stringify(value).get();
</del><ins>+ Stringifier stringifier(exec, replacer, space);
+ RETURN_IF_EXCEPTION(scope, { });
+ scope.release();
+ JSValue result = stringifier.stringify(value).get();
</ins><span class="cx"> return JSValue::encode(result);
</span><span class="cx"> }
</span><span class="cx">
</span><span class="lines">@@ -824,9 +857,13 @@
</span><span class="cx">
</span><span class="cx"> String JSONStringify(ExecState* exec, JSValue value, unsigned indent)
</span><span class="cx"> {
</span><del>- LocalScope scope(exec->vm());
- Local<Unknown> result = Stringifier(exec, Local<Unknown>(exec->vm(), jsNull()), Local<Unknown>(exec->vm(), jsNumber(indent))).stringify(Local<Unknown>(exec->vm(), value));
- if (result.isUndefinedOrNull())
</del><ins>+ VM& vm = exec->vm();
+ auto throwScope = DECLARE_THROW_SCOPE(vm);
+ LocalScope scope(vm);
+ Stringifier stringifier(exec, Local<Unknown>(vm, jsNull()), Local<Unknown>(vm, jsNumber(indent)));
+ RETURN_IF_EXCEPTION(throwScope, { });
+ Local<Unknown> result = stringifier.stringify(Local<Unknown>(vm, value));
+ if (UNLIKELY(throwScope.exception()) || result.isUndefinedOrNull())
</ins><span class="cx"> return String();
</span><span class="cx"> return result.getString(exec);
</span><span class="cx"> }
</span></span></pre>
</div>
</div>
</body>
</html>