Title: [209022] trunk/Source/_javascript_Core
Revision
209022
Author
[email protected]
Date
2016-11-28 14:35:39 -0800 (Mon, 28 Nov 2016)

Log Message

Fix exception scope verification failures in runtime/String* files.
https://bugs.webkit.org/show_bug.cgi?id=165067

Reviewed by Saam Barati.

* runtime/StringConstructor.cpp:
(JSC::stringFromCodePoint):
(JSC::constructWithStringConstructor):
* runtime/StringObject.cpp:
(JSC::StringObject::put):
(JSC::StringObject::putByIndex):
(JSC::StringObject::defineOwnProperty):
* runtime/StringPrototype.cpp:
(JSC::jsSpliceSubstrings):
(JSC::jsSpliceSubstringsWithSeparators):
(JSC::replaceUsingRegExpSearch):
(JSC::replaceUsingStringSearch):
(JSC::repeatCharacter):
(JSC::replace):
(JSC::stringProtoFuncReplaceUsingStringSearch):
(JSC::stringProtoFuncCharAt):
(JSC::stringProtoFuncCodePointAt):
(JSC::stringProtoFuncConcat):
(JSC::stringProtoFuncIndexOf):
(JSC::stringProtoFuncLastIndexOf):
(JSC::splitStringByOneCharacterImpl):
(JSC::stringProtoFuncSplitFast):
(JSC::stringProtoFuncSubstring):
(JSC::stringProtoFuncToLowerCase):
(JSC::stringProtoFuncToUpperCase):
(JSC::toLocaleCase):
(JSC::trimString):
(JSC::stringProtoFuncIncludes):
(JSC::builtinStringIncludesInternal):
(JSC::stringProtoFuncIterator):
(JSC::normalize):
(JSC::stringProtoFuncNormalize):

Modified Paths

Diff

Modified: trunk/Source/_javascript_Core/ChangeLog (209021 => 209022)


--- trunk/Source/_javascript_Core/ChangeLog	2016-11-28 22:30:11 UTC (rev 209021)
+++ trunk/Source/_javascript_Core/ChangeLog	2016-11-28 22:35:39 UTC (rev 209022)
@@ -1,5 +1,45 @@
 2016-11-28  Mark Lam  <[email protected]>
 
+        Fix exception scope verification failures in runtime/String* files.
+        https://bugs.webkit.org/show_bug.cgi?id=165067
+
+        Reviewed by Saam Barati.
+
+        * runtime/StringConstructor.cpp:
+        (JSC::stringFromCodePoint):
+        (JSC::constructWithStringConstructor):
+        * runtime/StringObject.cpp:
+        (JSC::StringObject::put):
+        (JSC::StringObject::putByIndex):
+        (JSC::StringObject::defineOwnProperty):
+        * runtime/StringPrototype.cpp:
+        (JSC::jsSpliceSubstrings):
+        (JSC::jsSpliceSubstringsWithSeparators):
+        (JSC::replaceUsingRegExpSearch):
+        (JSC::replaceUsingStringSearch):
+        (JSC::repeatCharacter):
+        (JSC::replace):
+        (JSC::stringProtoFuncReplaceUsingStringSearch):
+        (JSC::stringProtoFuncCharAt):
+        (JSC::stringProtoFuncCodePointAt):
+        (JSC::stringProtoFuncConcat):
+        (JSC::stringProtoFuncIndexOf):
+        (JSC::stringProtoFuncLastIndexOf):
+        (JSC::splitStringByOneCharacterImpl):
+        (JSC::stringProtoFuncSplitFast):
+        (JSC::stringProtoFuncSubstring):
+        (JSC::stringProtoFuncToLowerCase):
+        (JSC::stringProtoFuncToUpperCase):
+        (JSC::toLocaleCase):
+        (JSC::trimString):
+        (JSC::stringProtoFuncIncludes):
+        (JSC::builtinStringIncludesInternal):
+        (JSC::stringProtoFuncIterator):
+        (JSC::normalize):
+        (JSC::stringProtoFuncNormalize):
+
+2016-11-28  Mark Lam  <[email protected]>
+
         Fix exception scope verification failures in ObjectConstructor.cpp and ObjectPrototype.cpp.
         https://bugs.webkit.org/show_bug.cgi?id=165051
 

Modified: trunk/Source/_javascript_Core/runtime/StringConstructor.cpp (209021 => 209022)


--- trunk/Source/_javascript_Core/runtime/StringConstructor.cpp	2016-11-28 22:30:11 UTC (rev 209021)
+++ trunk/Source/_javascript_Core/runtime/StringConstructor.cpp	2016-11-28 22:35:39 UTC (rev 209022)
@@ -114,6 +114,7 @@
         }
     }
 
+    scope.release();
     return JSValue::encode(jsString(exec, builder.toString()));
 }
 
@@ -128,7 +129,9 @@
 
     if (!exec->argumentCount())
         return JSValue::encode(StringObject::create(vm, structure));
-    return JSValue::encode(StringObject::create(vm, structure, exec->uncheckedArgument(0).toString(exec)));
+    JSString* str = exec->uncheckedArgument(0).toString(exec);
+    RETURN_IF_EXCEPTION(scope, encodedJSValue());
+    return JSValue::encode(StringObject::create(vm, structure, str));
 }
 
 ConstructType StringConstructor::getConstructData(JSCell*, ConstructData& constructData)

Modified: trunk/Source/_javascript_Core/runtime/StringObject.cpp (209021 => 209022)


--- trunk/Source/_javascript_Core/runtime/StringObject.cpp	2016-11-28 22:30:11 UTC (rev 209021)
+++ trunk/Source/_javascript_Core/runtime/StringObject.cpp	2016-11-28 22:35:39 UTC (rev 209022)
@@ -67,13 +67,18 @@
 
     StringObject* thisObject = jsCast<StringObject*>(cell);
 
-    if (UNLIKELY(isThisValueAltered(slot, thisObject)))
+    if (UNLIKELY(isThisValueAltered(slot, thisObject))) {
+        scope.release();
         return ordinarySetSlow(exec, thisObject, propertyName, value, slot.thisValue(), slot.isStrictMode());
+    }
 
     if (propertyName == vm.propertyNames->length)
         return typeError(exec, scope, slot.isStrictMode(), ASCIILiteral(ReadonlyPropertyWriteError));
-    if (std::optional<uint32_t> index = parseIndex(propertyName))
+    if (std::optional<uint32_t> index = parseIndex(propertyName)) {
+        scope.release();
         return putByIndex(cell, exec, index.value(), value, slot.isStrictMode());
+    }
+    scope.release();
     return JSObject::put(cell, exec, propertyName, value, slot);
 }
 
@@ -85,6 +90,7 @@
     StringObject* thisObject = jsCast<StringObject*>(cell);
     if (thisObject->internalValue()->canGetIndex(propertyName))
         return typeError(exec, scope, shouldThrow, ASCIILiteral(ReadonlyPropertyWriteError));
+    scope.release();
     return JSObject::putByIndex(cell, exec, propertyName, value, shouldThrow);
 }
 
@@ -116,9 +122,11 @@
         ASSERT(isCurrentDefined);
         bool isExtensible = thisObject->isExtensible(exec);
         RETURN_IF_EXCEPTION(scope, false);
+        scope.release();
         return validateAndApplyPropertyDescriptor(exec, nullptr, propertyName, isExtensible, descriptor, isCurrentDefined, current, throwException);
     }
 
+    scope.release();
     return Base::defineOwnProperty(object, exec, propertyName, descriptor, throwException);
 }
 

Modified: trunk/Source/_javascript_Core/runtime/StringPrototype.cpp (209021 => 209022)


--- trunk/Source/_javascript_Core/runtime/StringPrototype.cpp	2016-11-28 22:30:11 UTC (rev 209021)
+++ trunk/Source/_javascript_Core/runtime/StringPrototype.cpp	2016-11-28 22:35:39 UTC (rev 209022)
@@ -297,6 +297,7 @@
         if (position <= 0 && length >= sourceSize)
             return sourceVal;
         // We could call String::substringSharingImpl(), but this would result in redundant checks.
+        scope.release();
         return jsString(exec, StringImpl::createSubstringSharingImpl(*source.impl(), std::max(0, position), std::min(sourceSize, length)));
     }
 
@@ -322,6 +323,7 @@
             }
         }
 
+        scope.release();
         return jsString(exec, WTFMove(impl));
     }
 
@@ -340,6 +342,7 @@
         }
     }
 
+    scope.release();
     return jsString(exec, WTFMove(impl));
 }
 
@@ -355,6 +358,7 @@
         if (position <= 0 && length >= sourceSize)
             return sourceVal;
         // We could call String::substringSharingImpl(), but this would result in redundant checks.
+        scope.release();
         return jsString(exec, StringImpl::createSubstringSharingImpl(*source.impl(), std::max(0, position), std::min(sourceSize, length)));
     }
 
@@ -398,6 +402,7 @@
             }
         }        
 
+        scope.release();
         return jsString(exec, WTFMove(impl));
     }
 
@@ -429,6 +434,7 @@
         }
     }
 
+    scope.release();
     return jsString(exec, WTFMove(impl));
 }
 
@@ -627,10 +633,12 @@
                 args.append(jsNumber(result.start));
                 args.append(string);
 
-                JSValue value = call(exec, replaceValue, callType, callData, jsUndefined(), args);
+                JSValue replacement = call(exec, replaceValue, callType, callData, jsUndefined(), args);
                 RETURN_IF_EXCEPTION(scope, encodedJSValue());
-                replacements.append(value.toString(exec)->value(exec));
+                String replacementString = replacement.toString(exec)->value(exec);
                 RETURN_IF_EXCEPTION(scope, encodedJSValue());
+                replacements.append(replacementString);
+                RETURN_IF_EXCEPTION(scope, encodedJSValue());
             } else {
                 int replLen = replacementString.length();
                 if (lastIndex < result.start || replLen) {
@@ -663,6 +671,7 @@
         if (UNLIKELY(!sourceRanges.tryConstructAndAppend(lastIndex, sourceLen - lastIndex)))
             OUT_OF_MEMORY(exec, scope);
     }
+    scope.release();
     return JSValue::encode(jsSpliceSubstringsWithSeparators(exec, string, source, sourceRanges.data(), sourceRanges.size(), replacements.data(), replacements.size()));
 }
 
@@ -754,6 +763,7 @@
 
     size_t leftLength = stringImpl->length() - matchEnd;
     String rightPart(StringImpl::createSubstringSharingImpl(*stringImpl, matchEnd, leftLength));
+    scope.release();
     return JSValue::encode(JSC::jsString(exec, leftPart, middlePart, rightPart));
 }
 
@@ -786,6 +796,7 @@
 
     std::fill_n(buffer, repeatCount, character);
 
+    scope.release();
     return jsString(&exec, WTFMove(impl));
 }
 
@@ -839,6 +850,7 @@
         return throwVMTypeError(exec, scope);
     JSString* string = thisValue.toString(exec);
     RETURN_IF_EXCEPTION(scope, encodedJSValue());
+    scope.release();
     return replace(vm, exec, string, searchValue, replaceValue);
 }
 
@@ -866,6 +878,7 @@
     JSString* string = exec->thisValue().toString(exec);
     RETURN_IF_EXCEPTION(scope, encodedJSValue());
 
+    scope.release();
     return replaceUsingStringSearch(vm, exec, string, exec->argument(0), exec->argument(1));
 }
 
@@ -909,6 +922,7 @@
     auto viewWithString = thisValue.toString(exec)->viewWithUnderlyingString(*exec);
     RETURN_IF_EXCEPTION(scope, encodedJSValue());
     StringView view = viewWithString.view;
+    RETURN_IF_EXCEPTION(scope, encodedJSValue());
     JSValue a0 = exec->argument(0);
     if (a0.isUInt32()) {
         uint32_t i = a0.asUInt32();
@@ -966,6 +980,7 @@
         return throwVMTypeError(exec, scope);
 
     String string = thisValue.toWTFString(exec);
+    RETURN_IF_EXCEPTION(scope, encodedJSValue());
     unsigned length = string.length();
 
     JSValue argument0 = exec->argument(0);
@@ -979,6 +994,7 @@
     RETURN_IF_EXCEPTION(scope, encodedJSValue());
 
     double doublePosition = argument0.toInteger(exec);
+    RETURN_IF_EXCEPTION(scope, encodedJSValue());
     if (doublePosition >= 0 && doublePosition < length)
         return JSValue::encode(jsNumber(codePointAt(string, static_cast<unsigned>(doublePosition), length)));
     return JSValue::encode(jsUndefined());
@@ -990,11 +1006,16 @@
     auto scope = DECLARE_THROW_SCOPE(vm);
 
     JSValue thisValue = exec->thisValue();
-    if (thisValue.isString() && exec->argumentCount() == 1)
-        return JSValue::encode(jsString(exec, asString(thisValue), exec->uncheckedArgument(0).toString(exec)));
+    if (thisValue.isString() && exec->argumentCount() == 1) {
+        JSString* str = exec->uncheckedArgument(0).toString(exec);
+        RETURN_IF_EXCEPTION(scope, encodedJSValue());
+        scope.release();
+        return JSValue::encode(jsString(exec, asString(thisValue), str));
+    }
 
     if (!checkObjectCoercible(thisValue))
         return throwVMTypeError(exec, scope);
+    scope.release();
     return JSValue::encode(jsStringFromArguments(exec, thisValue));
 }
 
@@ -1011,7 +1032,9 @@
     JSValue a1 = exec->argument(1);
 
     JSString* thisJSString = thisValue.toString(exec);
+    RETURN_IF_EXCEPTION(scope, encodedJSValue());
     JSString* otherJSString = a0.toString(exec);
+    RETURN_IF_EXCEPTION(scope, encodedJSValue());
 
     unsigned pos = 0;
     if (!a1.isUndefined()) {
@@ -1055,8 +1078,10 @@
     JSValue a1 = exec->argument(1);
 
     JSString* thisJSString = thisValue.toString(exec);
+    RETURN_IF_EXCEPTION(scope, encodedJSValue());
     unsigned len = thisJSString->length();
     JSString* otherJSString = a0.toString(exec);
+    RETURN_IF_EXCEPTION(scope, encodedJSValue());
 
     double dpos = a1.toIntegerPreserveNaN(exec);
     unsigned startPosition;
@@ -1119,6 +1144,9 @@
 template<typename CharacterType>
 static ALWAYS_INLINE bool splitStringByOneCharacterImpl(ExecState* exec, JSArray* result, JSValue originalValue, const String& input, StringImpl* string, UChar separatorCharacter, size_t& position, unsigned& resultLength, unsigned limitLength)
 {
+    VM& vm = exec->vm();
+    auto scope = DECLARE_THROW_SCOPE(vm);
+
     // 12. Let q = p.
     size_t matchPosition;
     const CharacterType* characters = string->characters<CharacterType>();
@@ -1132,6 +1160,7 @@
         // 2. Call the [[DefineOwnProperty]] internal method of A with arguments ToString(lengthA),
         //    Property Descriptor {[[Value]]: T, [[Writable]]: true, [[Enumerable]]: true, [[Configurable]]: true}, and false.
         result->putDirectIndex(exec, resultLength, jsSubstring(exec, originalValue, input, position, matchPosition - position));
+        RETURN_IF_EXCEPTION(scope, false);
         // 3. Increment lengthA by 1.
         // 4. If lengthA == lim, return A.
         if (++resultLength == limitLength)
@@ -1186,6 +1215,7 @@
     // 11. If separator is undefined, then
     if (separatorValue.isUndefined()) {
         // a. Call the [[DefineOwnProperty]] internal method of A with arguments "0",
+        scope.release();
         result->putDirectIndex(exec, 0, jsStringWithReuse(exec, thisValue, input));
         // b. Return A.
         return JSValue::encode(result);
@@ -1197,8 +1227,10 @@
         // b. If z is not false, return A.
         // c. Call CreateDataProperty(A, "0", S).
         // d. Return A.
-        if (!separator.isEmpty())
+        if (!separator.isEmpty()) {
+            scope.release();
             result->putDirectIndex(exec, 0, jsStringWithReuse(exec, thisValue, input));
+        }
         return JSValue::encode(result);
     }
 
@@ -1210,6 +1242,7 @@
 
         do {
             result->putDirectIndex(exec, position, jsSingleCharacterString(exec, input[position]));
+            RETURN_IF_EXCEPTION(scope, encodedJSValue());
         } while (++position < limit);
 
         return JSValue::encode(result);
@@ -1231,12 +1264,17 @@
             separatorCharacter = separatorImpl->characters16()[0];
 
         if (stringImpl->is8Bit()) {
-            if (splitStringByOneCharacterImpl<LChar>(exec, result, thisValue, input, stringImpl, separatorCharacter, position, resultLength, limit))
+            if (splitStringByOneCharacterImpl<LChar>(exec, result, thisValue, input, stringImpl, separatorCharacter, position, resultLength, limit)) {
+                scope.release();
                 return JSValue::encode(result);
+            }
         } else {
-            if (splitStringByOneCharacterImpl<UChar>(exec, result, thisValue, input, stringImpl, separatorCharacter, position, resultLength, limit))
+            if (splitStringByOneCharacterImpl<UChar>(exec, result, thisValue, input, stringImpl, separatorCharacter, position, resultLength, limit)) {
+                scope.release();
                 return JSValue::encode(result);
+            }
         }
+        RETURN_IF_EXCEPTION(scope, encodedJSValue());
     } else {
         // 13. Let q = p.
         size_t matchPosition;
@@ -1249,6 +1287,7 @@
             //    through q (exclusive).
             // 2. Call CreateDataProperty(A, ToString(lengthA), T).
             result->putDirectIndex(exec, resultLength, jsSubstring(exec, thisValue, input, position, matchPosition - position));
+            RETURN_IF_EXCEPTION(scope, encodedJSValue());
             // 3. Increment lengthA by 1.
             // 4. If lengthA == lim, return A.
             if (++resultLength == limit)
@@ -1263,6 +1302,7 @@
     // 15. Let T be a String value equal to the substring of S consisting of the characters at positions p (inclusive)
     //     through s (exclusive).
     // 16. Call CreateDataProperty(A, ToString(lengthA), T).
+    scope.release();
     result->putDirectIndex(exec, resultLength++, jsSubstring(exec, thisValue, input, position, input.length() - position));
 
     // 17. Return A.
@@ -1345,6 +1385,7 @@
     RELEASE_ASSERT(len >= 0);
 
     double start = a0.toNumber(exec);
+    RETURN_IF_EXCEPTION(scope, encodedJSValue());
     double end;
     if (!(start >= 0)) // check for negative values or NaN
         start = 0;
@@ -1354,6 +1395,7 @@
         end = len;
     else { 
         end = a1.toNumber(exec);
+        RETURN_IF_EXCEPTION(scope, encodedJSValue());
         if (!(end >= 0)) // check for negative values or NaN
             end = 0;
         else if (end > len)
@@ -1378,10 +1420,12 @@
     if (!checkObjectCoercible(thisValue))
         return throwVMTypeError(exec, scope);
     JSString* sVal = thisValue.toString(exec);
+    RETURN_IF_EXCEPTION(scope, encodedJSValue());
     const String& s = sVal->value(exec);
     String lowercasedString = s.convertToLowercaseWithoutLocale();
     if (lowercasedString.impl() == s.impl())
         return JSValue::encode(sVal);
+    scope.release();
     return JSValue::encode(jsString(exec, lowercasedString));
 }
 
@@ -1394,10 +1438,12 @@
     if (!checkObjectCoercible(thisValue))
         return throwVMTypeError(exec, scope);
     JSString* sVal = thisValue.toString(exec);
+    RETURN_IF_EXCEPTION(scope, encodedJSValue());
     const String& s = sVal->value(exec);
     String uppercasedString = s.convertToUppercaseWithoutLocale();
     if (uppercasedString.impl() == s.impl())
         return JSValue::encode(sVal);
+    scope.release();
     return JSValue::encode(jsString(exec, uppercasedString));
 }
 
@@ -1431,6 +1477,7 @@
 
     // 2. Let S be ToString(O).
     JSString* sVal = thisValue.toString(state);
+    RETURN_IF_EXCEPTION(scope, encodedJSValue());
     const String& s = sVal->value(state);
 
     // 3. ReturnIfAbrupt(S).
@@ -1499,6 +1546,7 @@
         return throwVMTypeError(state, scope, u_errorName(error));
 
     // 18. Return L.
+    scope.release();
     return JSValue::encode(jsString(state, lower));
 }
 
@@ -1793,7 +1841,7 @@
     if (!checkObjectCoercible(thisValue))
         return throwTypeError(exec, scope);
     String str = thisValue.toString(exec)->value(exec);
-    RETURN_IF_EXCEPTION(scope, JSValue());
+    RETURN_IF_EXCEPTION(scope, { });
 
     unsigned left = 0;
     if (trimKind & TrimLeft) {
@@ -1810,6 +1858,7 @@
     if (left == 0 && right == str.length() && thisValue.isString())
         return thisValue;
 
+    scope.release();
     return jsString(exec, str.substringSharingImpl(left, right - left));
 }
 
@@ -1947,6 +1996,7 @@
 
     JSValue positionArg = exec->argument(1);
 
+    scope.release();
     return stringIncludesImpl(vm, exec, stringToSearchIn, searchString, positionArg);
 }
 
@@ -1967,6 +2017,7 @@
 
     JSValue positionArg = exec->argument(1);
 
+    scope.release();
     return stringIncludesImpl(vm, exec, stringToSearchIn, searchString, positionArg);
 }
 
@@ -1979,6 +2030,7 @@
     if (!checkObjectCoercible(thisValue))
         return throwVMTypeError(exec, scope);
     JSString* string = thisValue.toString(exec);
+    RETURN_IF_EXCEPTION(scope, encodedJSValue());
     return JSValue::encode(JSStringIterator::create(exec, exec->callee()->globalObject()->stringIteratorStructure(), string));
 }
 
@@ -2006,6 +2058,7 @@
     if (U_FAILURE(status))
         return throwTypeError(exec, scope);
 
+    scope.release();
     return jsString(exec, WTFMove(impl));
 }
 
@@ -2039,6 +2092,7 @@
             return throwVMError(exec, scope, createRangeError(exec, ASCIILiteral("argument does not match any normalization form")));
     }
 
+    scope.release();
     return JSValue::encode(normalize(exec, view.upconvertedCharacters(), view.length(), form));
 }
 
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to