Changeset 266983 in webkit
- Timestamp:
- Sep 12, 2020 4:11:38 PM (4 years ago)
- Location:
- trunk/Source/WebCore
- Files:
-
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r266982 r266983 1 2020-09-12 Sam Weinig <weinig@apple.com> 2 3 [WebIDL] Remove need for [MayThrowException] on named deleters 4 https://bugs.webkit.org/show_bug.cgi?id=216429 5 6 Reviewed by Darin Adler. 7 8 Deduce implementation potentially thowing by introspecting the return 9 type of the deleters implementation. This allows us to remove another 10 use of [MayThrowException]. 11 12 * bindings/js/JSDOMAbstractOperations.h: 13 (WebCore::performLegacyPlatformObjectDeleteOperation): 14 Add helper function to house shared implementation of the various 15 combinations of return types allowed. 16 17 * bindings/scripts/CodeGeneratorJS.pm: 18 (GenerateDeletePropertyCommon): 19 Convert the commented expectation that unnamed deleters return bool 20 or ExceptionOr<bool> into a static assertion and use the new helper 21 function to simplify code generation. 22 23 * storage/Storage.idl: 24 Remove now unneeded [MayThrowException]. 25 26 * bindings/scripts/test/JS/JSTestNamedDeleterNoIdentifier.cpp: 27 * bindings/scripts/test/JS/JSTestNamedDeleterThrowingException.cpp: 28 * bindings/scripts/test/JS/JSTestNamedDeleterWithIdentifier.cpp: 29 * bindings/scripts/test/JS/JSTestNamedDeleterWithIndexedGetter.cpp: 30 * bindings/scripts/test/TestNamedDeleterThrowingException.idl: 31 Update tests/expectations. 32 1 33 2020-09-12 Myles C. Maxfield <mmaxfield@apple.com> 2 34 -
trunk/Source/WebCore/bindings/js/JSDOMAbstractOperations.h
r266676 r266983 27 27 28 28 #include "JSDOMConvertStrings.h" 29 #include "JSDOMExceptionHandling.h" 29 30 30 31 namespace WebCore { … … 118 119 } 119 120 121 // This implements steps 2.2 through 2.5 of https://heycam.github.io/webidl/#legacy-platform-object-delete. 122 template<typename Functor> bool performLegacyPlatformObjectDeleteOperation(JSC::JSGlobalObject& lexicalGlobalObject, Functor&& functor) 123 { 124 using ReturnType = std::invoke_result_t<Functor>; 125 126 if constexpr (IsExceptionOr<ReturnType>::value) { 127 auto result = functor(); 128 if (result.hasException()) { 129 auto throwScope = DECLARE_THROW_SCOPE(JSC::getVM(&lexicalGlobalObject)); 130 propagateException(lexicalGlobalObject, throwScope, result.releaseException()); 131 return true; 132 } 133 134 if constexpr (std::is_same_v<ReturnType, ExceptionOr<bool>>) 135 return result.releaseReturnValue(); 136 return true; 137 } 138 139 if constexpr (std::is_same_v<ReturnType, bool>) 140 return functor(); 141 142 functor(); 143 return true; 120 144 } 145 146 } -
trunk/Source/WebCore/bindings/scripts/CodeGeneratorJS.pm
r266954 r266983 1275 1275 my $functionCall = "impl." . $functionImplementationName . "(propertyNameToString(propertyName))"; 1276 1276 1277 # NOTE: We expect the implementation function of named deleters without an identifier to 1278 # return either bool or ExceptionOr<bool>. the implementation function of named deleters 1279 # with an identifier have no restriction, but if the return value of the operation is 1280 # boolean, we return that value, otherwise it is ignored (as per section 4.2). 1281 1282 if ($operation->extendedAttributes->{MayThrowException}) { 1283 push(@$outputArray, " auto result = ${functionCall};\n"); 1284 push(@$outputArray, " if (result.hasException()) {\n"); 1285 push(@$outputArray, " auto throwScope = DECLARE_THROW_SCOPE(JSC::getVM(lexicalGlobalObject));\n"); 1286 push(@$outputArray, " propagateException(*lexicalGlobalObject, throwScope, result.releaseException());\n"); 1287 push(@$outputArray, " return true;\n"); 1288 push(@$outputArray, " }\n\n"); 1289 1290 if (!$operation->name || $operation->name && $operation->type->name eq "boolean") { 1291 push(@$outputArray, " return result.releaseReturnValue();\n"); 1292 } else { 1293 push(@$outputArray, " return true;\n"); 1294 } 1295 } else { 1296 if (!$operation->name || $operation->name && $operation->type->name eq "boolean") { 1297 push(@$outputArray, " return ${functionCall};\n"); 1298 } else { 1299 push(@$outputArray, " ${functionCall};\n"); 1300 push(@$outputArray, " return true;\n"); 1301 } 1302 } 1303 1277 # NOTE: We require the implementation function of named deleters without an identifier to 1278 # return either bool or ExceptionOr<bool>. 1279 if (!$operation->name) { 1280 push(@$outputArray, " using ReturnType = decltype($functionCall);\n"); 1281 push(@$outputArray, " static_assert(std::is_same_v<ReturnType, ExceptionOr<bool>> || std::is_same_v<ReturnType, bool>, \"The implementation of named deleters without an identifer must return either bool or ExceptionOr<bool>.\");\n"); 1282 } 1283 1284 push(@$outputArray, " return performLegacyPlatformObjectDeleteOperation(*lexicalGlobalObject, [&] { return $functionCall; });\n"); 1304 1285 push(@$outputArray, " }\n"); 1305 1286 } -
trunk/Source/WebCore/bindings/scripts/test/JS/JSTestNamedDeleterNoIdentifier.cpp
r266662 r266983 207 207 auto& impl = thisObject.wrapped(); 208 208 if (isVisibleNamedProperty<LegacyOverrideBuiltIns::No>(*lexicalGlobalObject, thisObject, propertyName)) { 209 return impl.deleteNamedProperty(propertyNameToString(propertyName)); 209 using ReturnType = decltype(impl.deleteNamedProperty(propertyNameToString(propertyName))); 210 static_assert(std::is_same_v<ReturnType, ExceptionOr<bool>> || std::is_same_v<ReturnType, bool>, "The implementation of named deleters without an identifer must return either bool or ExceptionOr<bool>."); 211 return performLegacyPlatformObjectDeleteOperation(*lexicalGlobalObject, [&] { return impl.deleteNamedProperty(propertyNameToString(propertyName)); }); 210 212 } 211 213 return JSObject::deleteProperty(cell, lexicalGlobalObject, propertyName, slot); … … 219 221 auto propertyName = Identifier::from(vm, index); 220 222 if (isVisibleNamedProperty<LegacyOverrideBuiltIns::No>(*lexicalGlobalObject, thisObject, propertyName)) { 221 return impl.deleteNamedProperty(propertyNameToString(propertyName)); 223 using ReturnType = decltype(impl.deleteNamedProperty(propertyNameToString(propertyName))); 224 static_assert(std::is_same_v<ReturnType, ExceptionOr<bool>> || std::is_same_v<ReturnType, bool>, "The implementation of named deleters without an identifer must return either bool or ExceptionOr<bool>."); 225 return performLegacyPlatformObjectDeleteOperation(*lexicalGlobalObject, [&] { return impl.deleteNamedProperty(propertyNameToString(propertyName)); }); 222 226 } 223 227 return JSObject::deletePropertyByIndex(cell, lexicalGlobalObject, index); -
trunk/Source/WebCore/bindings/scripts/test/JS/JSTestNamedDeleterThrowingException.cpp
r266662 r266983 207 207 auto& impl = thisObject.wrapped(); 208 208 if (isVisibleNamedProperty<LegacyOverrideBuiltIns::No>(*lexicalGlobalObject, thisObject, propertyName)) { 209 auto result = impl.deleteNamedProperty(propertyNameToString(propertyName)); 210 if (result.hasException()) { 211 auto throwScope = DECLARE_THROW_SCOPE(JSC::getVM(lexicalGlobalObject)); 212 propagateException(*lexicalGlobalObject, throwScope, result.releaseException()); 213 return true; 214 } 215 216 return result.releaseReturnValue(); 209 using ReturnType = decltype(impl.deleteNamedProperty(propertyNameToString(propertyName))); 210 static_assert(std::is_same_v<ReturnType, ExceptionOr<bool>> || std::is_same_v<ReturnType, bool>, "The implementation of named deleters without an identifer must return either bool or ExceptionOr<bool>."); 211 return performLegacyPlatformObjectDeleteOperation(*lexicalGlobalObject, [&] { return impl.deleteNamedProperty(propertyNameToString(propertyName)); }); 217 212 } 218 213 return JSObject::deleteProperty(cell, lexicalGlobalObject, propertyName, slot); … … 226 221 auto propertyName = Identifier::from(vm, index); 227 222 if (isVisibleNamedProperty<LegacyOverrideBuiltIns::No>(*lexicalGlobalObject, thisObject, propertyName)) { 228 auto result = impl.deleteNamedProperty(propertyNameToString(propertyName)); 229 if (result.hasException()) { 230 auto throwScope = DECLARE_THROW_SCOPE(JSC::getVM(lexicalGlobalObject)); 231 propagateException(*lexicalGlobalObject, throwScope, result.releaseException()); 232 return true; 233 } 234 235 return result.releaseReturnValue(); 223 using ReturnType = decltype(impl.deleteNamedProperty(propertyNameToString(propertyName))); 224 static_assert(std::is_same_v<ReturnType, ExceptionOr<bool>> || std::is_same_v<ReturnType, bool>, "The implementation of named deleters without an identifer must return either bool or ExceptionOr<bool>."); 225 return performLegacyPlatformObjectDeleteOperation(*lexicalGlobalObject, [&] { return impl.deleteNamedProperty(propertyNameToString(propertyName)); }); 236 226 } 237 227 return JSObject::deletePropertyByIndex(cell, lexicalGlobalObject, index); -
trunk/Source/WebCore/bindings/scripts/test/JS/JSTestNamedDeleterWithIdentifier.cpp
r266662 r266983 213 213 auto& impl = thisObject.wrapped(); 214 214 if (isVisibleNamedProperty<LegacyOverrideBuiltIns::No>(*lexicalGlobalObject, thisObject, propertyName)) { 215 impl.namedDeleter(propertyNameToString(propertyName)); 216 return true; 215 return performLegacyPlatformObjectDeleteOperation(*lexicalGlobalObject, [&] { return impl.namedDeleter(propertyNameToString(propertyName)); }); 217 216 } 218 217 return JSObject::deleteProperty(cell, lexicalGlobalObject, propertyName, slot); … … 226 225 auto propertyName = Identifier::from(vm, index); 227 226 if (isVisibleNamedProperty<LegacyOverrideBuiltIns::No>(*lexicalGlobalObject, thisObject, propertyName)) { 228 impl.namedDeleter(propertyNameToString(propertyName)); 229 return true; 227 return performLegacyPlatformObjectDeleteOperation(*lexicalGlobalObject, [&] { return impl.namedDeleter(propertyNameToString(propertyName)); }); 230 228 } 231 229 return JSObject::deletePropertyByIndex(cell, lexicalGlobalObject, index); -
trunk/Source/WebCore/bindings/scripts/test/JS/JSTestNamedDeleterWithIndexedGetter.cpp
r266662 r266983 228 228 return !impl.isSupportedPropertyIndex(index.value()); 229 229 if (isVisibleNamedProperty<LegacyOverrideBuiltIns::No>(*lexicalGlobalObject, thisObject, propertyName)) { 230 return impl.deleteNamedProperty(propertyNameToString(propertyName)); 230 using ReturnType = decltype(impl.deleteNamedProperty(propertyNameToString(propertyName))); 231 static_assert(std::is_same_v<ReturnType, ExceptionOr<bool>> || std::is_same_v<ReturnType, bool>, "The implementation of named deleters without an identifer must return either bool or ExceptionOr<bool>."); 232 return performLegacyPlatformObjectDeleteOperation(*lexicalGlobalObject, [&] { return impl.deleteNamedProperty(propertyNameToString(propertyName)); }); 231 233 } 232 234 return JSObject::deleteProperty(cell, lexicalGlobalObject, propertyName, slot); -
trunk/Source/WebCore/bindings/scripts/test/TestNamedDeleterThrowingException.idl
r266311 r266983 25 25 26 26 interface TestNamedDeleterThrowingException { 27 [MayThrowException]deleter undefined (DOMString name);27 deleter undefined (DOMString name); 28 28 29 29 // NOTE: Named deleters require the presence of a named getter as well. -
trunk/Source/WebCore/storage/Storage.idl
r266311 r266983 32 32 getter DOMString? getItem(DOMString key); 33 33 [MayThrowException] setter undefined setItem(DOMString key, DOMString data); 34 [MayThrowException]deleter undefined removeItem(DOMString key);34 deleter undefined removeItem(DOMString key); 35 35 [MayThrowException] undefined clear(); 36 36 };
Note: See TracChangeset
for help on using the changeset viewer.