Remove setDOMException and a few custom bindings
authordarin@apple.com <darin@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 31 Dec 2016 09:57:11 +0000 (09:57 +0000)
committerdarin@apple.com <darin@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 31 Dec 2016 09:57:11 +0000 (09:57 +0000)
https://bugs.webkit.org/show_bug.cgi?id=166002

Reviewed by Sam Weinig.

* CMakeLists.txt: Removed JSFileReaderCustom.cpp.

* WebCore.xcodeproj/project.pbxproj: Removed JSFileReaderCustom.cpp.

* bindings/js/CallbackFunction.cpp:
(WebCore::checkFunctionOnlyCallback): Use throwTypeMismatchError instead
of calling setDOMException with TYPE_MISMATCH_ERR.

* bindings/js/JSBindingsAllInOne.cpp: Removed JSFileReaderCustom.cpp.

* bindings/js/JSCSSStyleDeclarationCustom.cpp:
(WebCore::JSCSSStyleDeclaration::putDelegate): Pass a throw scope in to
propagateException.

* bindings/js/JSCryptoAlgorithmDictionary.cpp:
(WebCore::JSCryptoAlgorithmDictionary::parseAlgorithmIdentifier):
Renamed from getAlgorithmIdentifier. Got rid of bool return value, instead
use a conventional return value and conventional JavaScript exception
handling. Added a ThrowScope argument.
(WebCore::optionalHashAlgorithm): Added. Returns an optional hash algorithm.
Also makes the same changes as above, conventional exception handling and
ThrowScope argument.
(WebCore::requiredHashAlgorithm): Added. Like the above but throws an
exception if the algorithm is omitted.
(WebCore::getHashAlgorithm): Deleted. Replaced by the two functions above.
(WebCore::createAesCbcParams): Updated for above changes.
(WebCore::createHmacParams): Ditto.
(WebCore::createHmacKeyParams): Ditto.
(WebCore::createRsaKeyGenParams): Ditto.
(WebCore::createRsaOaepParams): Ditto.
(WebCore::createRsaSsaParams): Ditto.
(WebCore::JSCryptoAlgorithmDictionary::createParametersForEncrypt): Added
a ThrowScope argument, and changed to use throwNotSupportedError instead
of setDOMException with NOT_SUPPORTED_ERROR.
(WebCore::JSCryptoAlgorithmDictionary::createParametersForDecrypt): Ditto.
(WebCore::JSCryptoAlgorithmDictionary::createParametersForSign): Ditto.
(WebCore::JSCryptoAlgorithmDictionary::createParametersForVerify):
(WebCore::JSCryptoAlgorithmDictionary::createParametersForDigest): Ditto.
(WebCore::JSCryptoAlgorithmDictionary::createParametersForGenerateKey): Ditto.
(WebCore::JSCryptoAlgorithmDictionary::createParametersForDeriveKey): Ditto.
(WebCore::JSCryptoAlgorithmDictionary::createParametersForDeriveBits): Ditto.
(WebCore::JSCryptoAlgorithmDictionary::createParametersForImportKey): Ditto.
(WebCore::JSCryptoAlgorithmDictionary::createParametersForExportKey): Ditto.
* bindings/js/JSCryptoAlgorithmDictionary.h: Updated for the above changes.

* bindings/js/JSCryptoOperationData.cpp:
(WebCore::cryptoOperationDataFromJSValue): Got rid of bool return value and
instead use a conventional return value and conventional JS exception handling.
Added a ThrowScope argument.
* bindings/js/JSCryptoOperationData.h: Updated for the above.

* bindings/js/JSCustomXPathNSResolver.cpp:
(WebCore::JSCustomXPathNSResolver::create): Use ExceptionOr.
(WebCore::JSCustomXPathNSResolver::JSCustomXPathNSResolver): Take a VM&
rather than an ExecState*.
* bindings/js/JSCustomXPathNSResolver.h: Updated for the changes above.
Also marked class final and fixed indentation.

* bindings/js/JSDOMBinding.cpp:
(WebCore::createDOMException): Updated comment.
(WebCore::throwDOMException): Deleted.
(WebCore::propagateException): Deleted non-inline overload that does not take
a throw scope, now that all callers pass a throw scope.
(WebCore::setDOMExceptionSlow): Deleted.
(WebCore::setDOMException): Deleted.
(WebCore::throwNotSupportedError): Added.
(WebCore::throwDOMSyntaxError): Added.
(WebCore::throwDataCloneError): Added.
(WebCore::throwIndexSizeError): Added.
(WebCore::throwTypeMismatchError): Added.
* bindings/js/JSDOMBinding.h: Updated for the additions and removals
above. Also grouped the standard DOM exception throwing functions separately
from the special ones for getters and setters, and sorted them alphabetically.

* bindings/js/JSDataCueCustom.cpp:
(WebCore::createJSDataCue): Added, helper function for the below.
(WebCore::constructJSDataCue): Tightened and tweaked a bit.

* bindings/js/JSFileReaderCustom.cpp: Removed.

* bindings/js/JSHTMLOptionsCollectionCustom.cpp:
(WebCore::JSHTMLOptionsCollection::setLength): Use throwIndexSizeError instead
of setDOMException with INDEX_SIZE_ERR.
* bindings/js/JSHTMLSelectElementCustom.cpp:
(WebCore::selectElementIndexSetter): Use throwTypeMismatchError instead of
setDOMExceptoin with TYPEMISMATCH_ERR.

* bindings/js/JSIDBRequestCustom.cpp:
(WebCore::JSIDBRequest::result): Pass a throw scope in to
propagateException.

* bindings/js/JSSQLResultSetRowListCustom.cpp:
(WebCore::JSSQLResultSetRowList::item): Use throwTypeMismatchError and
throwIndexSizeError instead of setDOMException with TYPE_MISMATCH_ERR and
INDEX_ERR. This required adding a throw scope.

* bindings/js/JSSQLTransactionCustom.cpp:
(WebCore::JSSQLTransaction::executeSql): Use throwDOMSyntaxError and
throwTypeMismatchError instead of setDOMException with SYNTAX_ERR and
TYPE_MISMATCH_ERR.

* bindings/js/JSStorageCustom.cpp:
(WebCore::JSStorage::nameGetter): Pass a throw scope in to
propagateException.

* bindings/js/JSSubtleCryptoCustom.cpp:
(WebCore::normalizeCryptoAlgorithmParameters): Use throwNotSupportedError
instead of setDOMException with NOT_SUPPORTED_ERR.
(WebCore::createAlgorithm): Deleted.
(WebCore::supportExportKeyThrow): Added ThrowScope argument and use
throwNotSupportedError instead of setDOMException with NOT_SUPPORTED_ERR.
(WebCore::jsSubtleCryptoFunctionEncryptPromise): Updated for above changes,
throwing a not supported exception at this level rather than in a helper.
(WebCore::jsSubtleCryptoFunctionDecryptPromise): Ditto.
(WebCore::jsSubtleCryptoFunctionSignPromise): Ditto.
(WebCore::jsSubtleCryptoFunctionVerifyPromise): Ditto.
(WebCore::jsSubtleCryptoFunctionDigestPromise): Ditto.
(WebCore::jsSubtleCryptoFunctionGenerateKeyPromise): Ditto.
(WebCore::jsSubtleCryptoFunctionImportKeyPromise): Ditto.
(WebCore::jsSubtleCryptoFunctionExportKeyPromise): Ditto.
(WebCore::jsSubtleCryptoFunctionWrapKeyPromise): Ditto.
(WebCore::jsSubtleCryptoFunctionUnwrapKeyPromise): Ditto.

* bindings/js/JSWebKitSubtleCryptoCustom.cpp:
(WebCore::createAlgorithmFromJSValue): Got rid of bool return value and
instead use a conventional return value and conventional JS exception handling.
Added a ThrowScope argument.
(WebCore::cryptoKeyFormatFromJSValue): Ditto.
(WebCore::cryptoKeyUsagesFromJSValue): Ditto.
(WebCore::JSWebKitSubtleCrypto::encrypt): Updated for above changes.
(WebCore::JSWebKitSubtleCrypto::decrypt): Ditto.
(WebCore::JSWebKitSubtleCrypto::sign): Ditto.
(WebCore::JSWebKitSubtleCrypto::verify): Ditto.
(WebCore::JSWebKitSubtleCrypto::digest): Ditto.
(WebCore::JSWebKitSubtleCrypto::generateKey): Ditto.
(WebCore::JSWebKitSubtleCrypto::importKey): Ditto.
(WebCore::JSWebKitSubtleCrypto::exportKey): Ditto.
(WebCore::JSWebKitSubtleCrypto::wrapKey): Ditto.
(WebCore::JSWebKitSubtleCrypto::unwrapKey): Ditto.

* bindings/js/JSXMLHttpRequestCustom.cpp:
(WebCore::JSXMLHttpRequest::send): Pass a throw scope in to
propagateException.
(WebCore::JSXMLHttpRequest::responseText): Ditto.

* bindings/js/JSXPathNSResolverCustom.cpp:
(WebCore::JSXPathNSResolver::toWrapped): Updated since
JSCustomXPathNSResolver::create now uses ExceptionOr.

* bindings/js/SerializedScriptValue.cpp:
(WebCore::maybeThrowExceptionIfSerializationFailed): Updated to take
a reference instead of a pointer. Fixed the handling of success to be
simpler; no need to check the code twice. Use throwDataCloneError instead
of setDOMException with DATA_CLONE_ERR.
(WebCore::SerializedScriptValue::create): Updated for above.
(WebCore::SerializedScriptValue::deserialize): Ditto.

* bindings/js/StructuredClone.cpp:
(WebCore::structuredCloneArrayBuffer): Use throwDataCloneError instead of
setDOMException with DATA_CLONE_ERR.
(WebCore::structuredCloneArrayBufferView): Ditto.

* crypto/CryptoAlgorithmParametersDeprecated.h: Removed unneeded empty
constructor.
* crypto/parameters/CryptoAlgorithmHmacKeyParamsDeprecated.h: Ditto,
moving initialization to where the data member is defined.
* crypto/parameters/CryptoAlgorithmRsaKeyGenParamsDeprecated.h: Ditto.
* crypto/parameters/CryptoAlgorithmRsaOaepParamsDeprecated.h: Ditto.

* fileapi/FileReader.cpp:
(WebCore::FileReader::result): Added. Returns a combination of optional
and variant that matches what the ID specifies. Moved the code from the
two following functions in here.
(WebCore::FileReader::arrayBufferResult): Deleted.
(WebCore::FileReader::stringResult): Deleted.
* fileapi/FileReader.h: Updated for the above.
* fileapi/FileReader.idl: Removed [Custom] from the result attribute and
declared it with the type mentioned in the specification, a nullable union.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@210217 268f45cc-cd09-0410-ab3c-d52691b4dbfc

32 files changed:
Source/WebCore/CMakeLists.txt
Source/WebCore/ChangeLog
Source/WebCore/WebCore.xcodeproj/project.pbxproj
Source/WebCore/bindings/js/CallbackFunction.cpp
Source/WebCore/bindings/js/JSBindingsAllInOne.cpp
Source/WebCore/bindings/js/JSCSSStyleDeclarationCustom.cpp
Source/WebCore/bindings/js/JSCryptoAlgorithmDictionary.cpp
Source/WebCore/bindings/js/JSCryptoAlgorithmDictionary.h
Source/WebCore/bindings/js/JSCryptoOperationData.cpp
Source/WebCore/bindings/js/JSCryptoOperationData.h
Source/WebCore/bindings/js/JSCustomXPathNSResolver.cpp
Source/WebCore/bindings/js/JSCustomXPathNSResolver.h
Source/WebCore/bindings/js/JSDOMBinding.cpp
Source/WebCore/bindings/js/JSDOMBinding.h
Source/WebCore/bindings/js/JSFileReaderCustom.cpp [deleted file]
Source/WebCore/bindings/js/JSHTMLOptionsCollectionCustom.cpp
Source/WebCore/bindings/js/JSHTMLSelectElementCustom.cpp
Source/WebCore/bindings/js/JSIDBRequestCustom.cpp
Source/WebCore/bindings/js/JSStorageCustom.cpp
Source/WebCore/bindings/js/JSSubtleCryptoCustom.cpp
Source/WebCore/bindings/js/JSWebKitSubtleCryptoCustom.cpp
Source/WebCore/bindings/js/JSXMLHttpRequestCustom.cpp
Source/WebCore/bindings/js/JSXPathNSResolverCustom.cpp
Source/WebCore/bindings/js/SerializedScriptValue.cpp
Source/WebCore/bindings/js/StructuredClone.cpp
Source/WebCore/crypto/CryptoAlgorithmParametersDeprecated.h
Source/WebCore/crypto/parameters/CryptoAlgorithmHmacKeyParamsDeprecated.h
Source/WebCore/crypto/parameters/CryptoAlgorithmRsaKeyGenParamsDeprecated.h
Source/WebCore/crypto/parameters/CryptoAlgorithmRsaOaepParamsDeprecated.h
Source/WebCore/fileapi/FileReader.cpp
Source/WebCore/fileapi/FileReader.h
Source/WebCore/fileapi/FileReader.idl

index d8cc470..0c851de 100644 (file)
@@ -1126,7 +1126,6 @@ set(WebCore_SOURCES
     bindings/js/JSEventListener.cpp
     bindings/js/JSEventTargetCustom.cpp
     bindings/js/JSExceptionBase.cpp
-    bindings/js/JSFileReaderCustom.cpp
     bindings/js/JSHTMLAllCollectionCustom.cpp
     bindings/js/JSHTMLAppletElementCustom.cpp
     bindings/js/JSHTMLCanvasElementCustom.cpp
index 4e503cb..5cd3fa5 100644 (file)
@@ -1,3 +1,189 @@
+2016-12-25  Darin Adler  <darin@apple.com>
+
+        Remove setDOMException and a few custom bindings
+        https://bugs.webkit.org/show_bug.cgi?id=166002
+
+        Reviewed by Sam Weinig.
+
+        * CMakeLists.txt: Removed JSFileReaderCustom.cpp.
+
+        * WebCore.xcodeproj/project.pbxproj: Removed JSFileReaderCustom.cpp.
+
+        * bindings/js/CallbackFunction.cpp:
+        (WebCore::checkFunctionOnlyCallback): Use throwTypeMismatchError instead
+        of calling setDOMException with TYPE_MISMATCH_ERR.
+
+        * bindings/js/JSBindingsAllInOne.cpp: Removed JSFileReaderCustom.cpp.
+
+        * bindings/js/JSCSSStyleDeclarationCustom.cpp:
+        (WebCore::JSCSSStyleDeclaration::putDelegate): Pass a throw scope in to
+        propagateException.
+
+        * bindings/js/JSCryptoAlgorithmDictionary.cpp:
+        (WebCore::JSCryptoAlgorithmDictionary::parseAlgorithmIdentifier):
+        Renamed from getAlgorithmIdentifier. Got rid of bool return value, instead
+        use a conventional return value and conventional JavaScript exception
+        handling. Added a ThrowScope argument.
+        (WebCore::optionalHashAlgorithm): Added. Returns an optional hash algorithm.
+        Also makes the same changes as above, conventional exception handling and
+        ThrowScope argument.
+        (WebCore::requiredHashAlgorithm): Added. Like the above but throws an
+        exception if the algorithm is omitted.
+        (WebCore::getHashAlgorithm): Deleted. Replaced by the two functions above.
+        (WebCore::createAesCbcParams): Updated for above changes.
+        (WebCore::createHmacParams): Ditto.
+        (WebCore::createHmacKeyParams): Ditto.
+        (WebCore::createRsaKeyGenParams): Ditto.
+        (WebCore::createRsaOaepParams): Ditto.
+        (WebCore::createRsaSsaParams): Ditto.
+        (WebCore::JSCryptoAlgorithmDictionary::createParametersForEncrypt): Added
+        a ThrowScope argument, and changed to use throwNotSupportedError instead
+        of setDOMException with NOT_SUPPORTED_ERROR.
+        (WebCore::JSCryptoAlgorithmDictionary::createParametersForDecrypt): Ditto.
+        (WebCore::JSCryptoAlgorithmDictionary::createParametersForSign): Ditto.
+        (WebCore::JSCryptoAlgorithmDictionary::createParametersForVerify):
+        (WebCore::JSCryptoAlgorithmDictionary::createParametersForDigest): Ditto.
+        (WebCore::JSCryptoAlgorithmDictionary::createParametersForGenerateKey): Ditto.
+        (WebCore::JSCryptoAlgorithmDictionary::createParametersForDeriveKey): Ditto.
+        (WebCore::JSCryptoAlgorithmDictionary::createParametersForDeriveBits): Ditto.
+        (WebCore::JSCryptoAlgorithmDictionary::createParametersForImportKey): Ditto.
+        (WebCore::JSCryptoAlgorithmDictionary::createParametersForExportKey): Ditto.
+        * bindings/js/JSCryptoAlgorithmDictionary.h: Updated for the above changes.
+
+        * bindings/js/JSCryptoOperationData.cpp:
+        (WebCore::cryptoOperationDataFromJSValue): Got rid of bool return value and
+        instead use a conventional return value and conventional JS exception handling.
+        Added a ThrowScope argument.
+        * bindings/js/JSCryptoOperationData.h: Updated for the above.
+
+        * bindings/js/JSCustomXPathNSResolver.cpp:
+        (WebCore::JSCustomXPathNSResolver::create): Use ExceptionOr.
+        (WebCore::JSCustomXPathNSResolver::JSCustomXPathNSResolver): Take a VM&
+        rather than an ExecState*.
+        * bindings/js/JSCustomXPathNSResolver.h: Updated for the changes above.
+        Also marked class final and fixed indentation.
+
+        * bindings/js/JSDOMBinding.cpp:
+        (WebCore::createDOMException): Updated comment.
+        (WebCore::throwDOMException): Deleted.
+        (WebCore::propagateException): Deleted non-inline overload that does not take
+        a throw scope, now that all callers pass a throw scope.
+        (WebCore::setDOMExceptionSlow): Deleted.
+        (WebCore::setDOMException): Deleted.
+        (WebCore::throwNotSupportedError): Added.
+        (WebCore::throwDOMSyntaxError): Added.
+        (WebCore::throwDataCloneError): Added.
+        (WebCore::throwIndexSizeError): Added.
+        (WebCore::throwTypeMismatchError): Added.
+        * bindings/js/JSDOMBinding.h: Updated for the additions and removals
+        above. Also grouped the standard DOM exception throwing functions separately
+        from the special ones for getters and setters, and sorted them alphabetically.
+
+        * bindings/js/JSDataCueCustom.cpp:
+        (WebCore::createJSDataCue): Added, helper function for the below.
+        (WebCore::constructJSDataCue): Tightened and tweaked a bit.
+
+        * bindings/js/JSFileReaderCustom.cpp: Removed.
+
+        * bindings/js/JSHTMLOptionsCollectionCustom.cpp:
+        (WebCore::JSHTMLOptionsCollection::setLength): Use throwIndexSizeError instead
+        of setDOMException with INDEX_SIZE_ERR.
+        * bindings/js/JSHTMLSelectElementCustom.cpp:
+        (WebCore::selectElementIndexSetter): Use throwTypeMismatchError instead of
+        setDOMExceptoin with TYPEMISMATCH_ERR.
+
+        * bindings/js/JSIDBRequestCustom.cpp:
+        (WebCore::JSIDBRequest::result): Pass a throw scope in to
+        propagateException.
+
+        * bindings/js/JSSQLResultSetRowListCustom.cpp:
+        (WebCore::JSSQLResultSetRowList::item): Use throwTypeMismatchError and
+        throwIndexSizeError instead of setDOMException with TYPE_MISMATCH_ERR and
+        INDEX_ERR. This required adding a throw scope.
+
+        * bindings/js/JSSQLTransactionCustom.cpp:
+        (WebCore::JSSQLTransaction::executeSql): Use throwDOMSyntaxError and
+        throwTypeMismatchError instead of setDOMException with SYNTAX_ERR and
+        TYPE_MISMATCH_ERR.
+
+        * bindings/js/JSStorageCustom.cpp:
+        (WebCore::JSStorage::nameGetter): Pass a throw scope in to
+        propagateException.
+
+        * bindings/js/JSSubtleCryptoCustom.cpp:
+        (WebCore::normalizeCryptoAlgorithmParameters): Use throwNotSupportedError
+        instead of setDOMException with NOT_SUPPORTED_ERR.
+        (WebCore::createAlgorithm): Deleted.
+        (WebCore::supportExportKeyThrow): Added ThrowScope argument and use
+        throwNotSupportedError instead of setDOMException with NOT_SUPPORTED_ERR.
+        (WebCore::jsSubtleCryptoFunctionEncryptPromise): Updated for above changes,
+        throwing a not supported exception at this level rather than in a helper.
+        (WebCore::jsSubtleCryptoFunctionDecryptPromise): Ditto.
+        (WebCore::jsSubtleCryptoFunctionSignPromise): Ditto.
+        (WebCore::jsSubtleCryptoFunctionVerifyPromise): Ditto.
+        (WebCore::jsSubtleCryptoFunctionDigestPromise): Ditto.
+        (WebCore::jsSubtleCryptoFunctionGenerateKeyPromise): Ditto.
+        (WebCore::jsSubtleCryptoFunctionImportKeyPromise): Ditto.
+        (WebCore::jsSubtleCryptoFunctionExportKeyPromise): Ditto.
+        (WebCore::jsSubtleCryptoFunctionWrapKeyPromise): Ditto.
+        (WebCore::jsSubtleCryptoFunctionUnwrapKeyPromise): Ditto.
+
+        * bindings/js/JSWebKitSubtleCryptoCustom.cpp:
+        (WebCore::createAlgorithmFromJSValue): Got rid of bool return value and
+        instead use a conventional return value and conventional JS exception handling.
+        Added a ThrowScope argument.
+        (WebCore::cryptoKeyFormatFromJSValue): Ditto.
+        (WebCore::cryptoKeyUsagesFromJSValue): Ditto.
+        (WebCore::JSWebKitSubtleCrypto::encrypt): Updated for above changes.
+        (WebCore::JSWebKitSubtleCrypto::decrypt): Ditto.
+        (WebCore::JSWebKitSubtleCrypto::sign): Ditto.
+        (WebCore::JSWebKitSubtleCrypto::verify): Ditto.
+        (WebCore::JSWebKitSubtleCrypto::digest): Ditto.
+        (WebCore::JSWebKitSubtleCrypto::generateKey): Ditto.
+        (WebCore::JSWebKitSubtleCrypto::importKey): Ditto.
+        (WebCore::JSWebKitSubtleCrypto::exportKey): Ditto.
+        (WebCore::JSWebKitSubtleCrypto::wrapKey): Ditto.
+        (WebCore::JSWebKitSubtleCrypto::unwrapKey): Ditto.
+
+        * bindings/js/JSXMLHttpRequestCustom.cpp:
+        (WebCore::JSXMLHttpRequest::send): Pass a throw scope in to
+        propagateException.
+        (WebCore::JSXMLHttpRequest::responseText): Ditto.
+
+        * bindings/js/JSXPathNSResolverCustom.cpp:
+        (WebCore::JSXPathNSResolver::toWrapped): Updated since
+        JSCustomXPathNSResolver::create now uses ExceptionOr.
+
+        * bindings/js/SerializedScriptValue.cpp:
+        (WebCore::maybeThrowExceptionIfSerializationFailed): Updated to take
+        a reference instead of a pointer. Fixed the handling of success to be
+        simpler; no need to check the code twice. Use throwDataCloneError instead
+        of setDOMException with DATA_CLONE_ERR.
+        (WebCore::SerializedScriptValue::create): Updated for above.
+        (WebCore::SerializedScriptValue::deserialize): Ditto.
+
+        * bindings/js/StructuredClone.cpp:
+        (WebCore::structuredCloneArrayBuffer): Use throwDataCloneError instead of
+        setDOMException with DATA_CLONE_ERR.
+        (WebCore::structuredCloneArrayBufferView): Ditto.
+
+        * crypto/CryptoAlgorithmParametersDeprecated.h: Removed unneeded empty
+        constructor.
+        * crypto/parameters/CryptoAlgorithmHmacKeyParamsDeprecated.h: Ditto,
+        moving initialization to where the data member is defined.
+        * crypto/parameters/CryptoAlgorithmRsaKeyGenParamsDeprecated.h: Ditto.
+        * crypto/parameters/CryptoAlgorithmRsaOaepParamsDeprecated.h: Ditto.
+
+        * fileapi/FileReader.cpp:
+        (WebCore::FileReader::result): Added. Returns a combination of optional
+        and variant that matches what the ID specifies. Moved the code from the
+        two following functions in here.
+        (WebCore::FileReader::arrayBufferResult): Deleted.
+        (WebCore::FileReader::stringResult): Deleted.
+        * fileapi/FileReader.h: Updated for the above.
+        * fileapi/FileReader.idl: Removed [Custom] from the result attribute and
+        declared it with the type mentioned in the specification, a nullable union.
+
 2016-12-30  Darin Adler  <darin@apple.com>
 
         Remove PassRefPtr use from the "dom" directory, related cleanup
index 7be631b..be96458 100644 (file)
                2E4346530F546A8200B0F1BA /* WorkerRunLoop.h in Headers */ = {isa = PBXBuildFile; fileRef = 2E4346410F546A8200B0F1BA /* WorkerRunLoop.h */; settings = {ATTRIBUTES = (Private, ); }; };
                2E4346540F546A8200B0F1BA /* WorkerThread.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 2E4346420F546A8200B0F1BA /* WorkerThread.cpp */; };
                2E4346550F546A8200B0F1BA /* WorkerThread.h in Headers */ = {isa = PBXBuildFile; fileRef = 2E4346430F546A8200B0F1BA /* WorkerThread.h */; settings = {ATTRIBUTES = (Private, ); }; };
-               2E7582EE12764F260062628B /* JSFileReaderCustom.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 2E7582ED12764F260062628B /* JSFileReaderCustom.cpp */; };
                2E75841D12779ADA0062628B /* FileReaderLoader.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 2E75841A12779ADA0062628B /* FileReaderLoader.cpp */; };
                2E75841E12779ADA0062628B /* FileReaderLoader.h in Headers */ = {isa = PBXBuildFile; fileRef = 2E75841B12779ADA0062628B /* FileReaderLoader.h */; };
                2E75841F12779ADA0062628B /* FileReaderLoaderClient.h in Headers */ = {isa = PBXBuildFile; fileRef = 2E75841C12779ADA0062628B /* FileReaderLoaderClient.h */; settings = {ATTRIBUTES = (Private, ); }; };
                2E4346410F546A8200B0F1BA /* WorkerRunLoop.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WorkerRunLoop.h; sourceTree = "<group>"; };
                2E4346420F546A8200B0F1BA /* WorkerThread.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = WorkerThread.cpp; sourceTree = "<group>"; };
                2E4346430F546A8200B0F1BA /* WorkerThread.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WorkerThread.h; sourceTree = "<group>"; };
-               2E7582ED12764F260062628B /* JSFileReaderCustom.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSFileReaderCustom.cpp; sourceTree = "<group>"; };
                2E75841A12779ADA0062628B /* FileReaderLoader.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = FileReaderLoader.cpp; sourceTree = "<group>"; };
                2E75841B12779ADA0062628B /* FileReaderLoader.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FileReaderLoader.h; sourceTree = "<group>"; };
                2E75841C12779ADA0062628B /* FileReaderLoaderClient.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FileReaderLoaderClient.h; sourceTree = "<group>"; };
                                BC64649B11D8238C006455B0 /* JSDOMStringMapCustom.cpp */,
                                BCD9C25E0C17AA67005C90A2 /* JSDOMWindowCustom.cpp */,
                                652FBBBB0DE27CB60001D386 /* JSDOMWindowCustom.h */,
-                               2E7582ED12764F260062628B /* JSFileReaderCustom.cpp */,
                                C28083411C6DC96A001451B6 /* JSFontFaceCustom.cpp */,
                                1C24EEAA1C72AA0A0080F8FC /* JSFontFaceSetCustom.cpp */,
                                BCE7B1920D4E86960075A539 /* JSHistoryCustom.cpp */,
                                898785F0122E1E87003AABDA /* JSFileException.cpp in Sources */,
                                BC00F0160E0A189500FD04E3 /* JSFileList.cpp in Sources */,
                                2E94F43B119207DA00B7F75D /* JSFileReader.cpp in Sources */,
-                               2E7582EE12764F260062628B /* JSFileReaderCustom.cpp in Sources */,
                                898785F4122E1EAC003AABDA /* JSFileReaderSync.cpp in Sources */,
                                B6D9D27C14EAC0860090D75E /* JSFocusEvent.cpp in Sources */,
                                C28083401C6DC275001451B6 /* JSFontFace.cpp in Sources */,
index a62cf95..3ad8e27 100644 (file)
@@ -31,7 +31,7 @@
 
 namespace WebCore {
 
-bool checkFunctionOnlyCallback(JSC::ExecState* exec, JSC::JSValue value, CallbackAllowedValueFlags acceptedValues)
+bool checkFunctionOnlyCallback(JSC::ExecState* state, JSC::JSValue value, CallbackAllowedValueFlags acceptedValues)
 {
     if (value.isUndefined() && (acceptedValues & CallbackAllowUndefined))
         return false;
@@ -41,7 +41,8 @@ bool checkFunctionOnlyCallback(JSC::ExecState* exec, JSC::JSValue value, Callbac
 
     JSC::CallData callData;
     if (getCallData(value, callData) == JSC::CallType::None) {
-        setDOMException(exec, TYPE_MISMATCH_ERR);
+        auto scope = DECLARE_THROW_SCOPE(state->vm());
+        throwTypeMismatchError(*state, scope);
         return false;
     }
 
index 198ea08..b1db536 100644 (file)
@@ -69,7 +69,6 @@
 #include "JSEventListener.cpp"
 #include "JSEventTargetCustom.cpp"
 #include "JSExceptionBase.cpp"
-#include "JSFileReaderCustom.cpp"
 #include "JSHTMLAllCollectionCustom.cpp"
 #include "JSHTMLAppletElementCustom.cpp"
 #include "JSHTMLCanvasElementCustom.cpp"
index f965a9c..4104a89 100644 (file)
@@ -342,7 +342,9 @@ bool JSCSSStyleDeclaration::putDelegate(ExecState* state, PropertyName propertyN
 
     auto setPropertyInternalResult = wrapped().setPropertyInternal(propertyInfo.propertyID, propertyValue, important);
     if (setPropertyInternalResult.hasException()) {
-        propagateException(*state, setPropertyInternalResult.releaseException());
+        auto& vm = state->vm();
+        auto scope = DECLARE_THROW_SCOPE(vm);
+        propagateException(*state, scope, setPropertyInternalResult.releaseException());
         return true;
     }
     putResult = setPropertyInternalResult.releaseReturnValue();
index 959f9d8..951ad2e 100644 (file)
@@ -47,31 +47,24 @@ using namespace JSC;
 
 namespace WebCore {
 
-enum class HashRequirement {
-    Optional,
-    Required, 
-};
-
 static inline JSValue getProperty(ExecState& state, JSObject* object, const char* name)
 {
     return object->get(&state, Identifier::fromString(&state, name));
 }
 
-bool JSCryptoAlgorithmDictionary::getAlgorithmIdentifier(ExecState& state, JSValue value, CryptoAlgorithmIdentifier& algorithmIdentifier)
+CryptoAlgorithmIdentifier JSCryptoAlgorithmDictionary::parseAlgorithmIdentifier(ExecState& state, ThrowScope& scope, JSValue value)
 {
-    auto scope = DECLARE_THROW_SCOPE(state.vm());
-
     // typedef (Algorithm or DOMString) AlgorithmIdentifier;
 
     String algorithmName;
 
     if (value.isString()) {
         algorithmName = asString(value)->value(&state);
-        RETURN_IF_EXCEPTION(scope, false);
+        RETURN_IF_EXCEPTION(scope, { });
     } else if (value.isObject()) {
         if (asObject(value)->inherits(StringObject::info())) {
-            algorithmName = asString(asStringObject(value)->internalValue())->value(&state);
-            RETURN_IF_EXCEPTION(scope, false);
+            algorithmName = asStringObject(value)->internalValue()->value(&state);
+            RETURN_IF_EXCEPTION(scope, { });
         } else {
             // FIXME: This doesn't perform some checks mandated by WebIDL for dictionaries:
             // - null and undefined input should be treated as if all elements in the dictionary were undefined;
@@ -82,42 +75,49 @@ bool JSCryptoAlgorithmDictionary::getAlgorithmIdentifier(ExecState& state, JSVal
             // WebCrypto doesn't yet clearly specify what to do with non-present values in most cases anyway.
 
             auto nameValue = getProperty(state, asObject(value), "name");
-            RETURN_IF_EXCEPTION(scope, false);
+            RETURN_IF_EXCEPTION(scope, { });
 
             algorithmName = convert<IDLDOMString>(state, nameValue);
-            RETURN_IF_EXCEPTION(scope, false);
+            RETURN_IF_EXCEPTION(scope, { });
         }
     }
 
     if (!algorithmName.containsOnlyASCII()) {
         throwSyntaxError(&state, scope);
-        return false;
+        return { };
     }
 
     auto identifier = CryptoAlgorithmRegistry::singleton().identifier(algorithmName);
     if (!identifier) {
-        setDOMException(&state, NOT_SUPPORTED_ERR);
-        return false;
+        throwNotSupportedError(state, scope);
+        return { };
     }
 
-    algorithmIdentifier = *identifier;
-    return true;
+    return identifier.value();
 }
 
-static bool getHashAlgorithm(ExecState& state, JSObject* object, CryptoAlgorithmIdentifier& result, HashRequirement isRequired)
+static std::optional<CryptoAlgorithmIdentifier> optionalHashAlgorithm(ExecState& state, ThrowScope& scope, JSObject* object)
 {
-    auto scope = DECLARE_THROW_SCOPE(state.vm());
-
     auto hash = getProperty(state, object, "hash");
-    RETURN_IF_EXCEPTION(scope, false);
+    RETURN_IF_EXCEPTION(scope, { });
+
+    if (hash.isUndefinedOrNull())
+        return std::nullopt;
+
+    return JSCryptoAlgorithmDictionary::parseAlgorithmIdentifier(state, scope, hash);
+}
+
+static CryptoAlgorithmIdentifier requiredHashAlgorithm(ExecState& state, ThrowScope& scope, JSObject* object)
+{
+    auto result = optionalHashAlgorithm(state, scope, object);
+    RETURN_IF_EXCEPTION(scope, { });
 
-    if (hash.isUndefinedOrNull()) {
-        if (isRequired == HashRequirement::Required)
-            setDOMException(&state, NOT_SUPPORTED_ERR);
-        return false;
+    if (!result) {
+        throwNotSupportedError(state, scope);
+        return { };
     }
 
-    return JSCryptoAlgorithmDictionary::getAlgorithmIdentifier(state, hash, result);
+    return result.value();
 }
 
 static RefPtr<CryptoAlgorithmParametersDeprecated> createAesCbcParams(ExecState& state, JSValue value)
@@ -130,15 +130,12 @@ static RefPtr<CryptoAlgorithmParametersDeprecated> createAesCbcParams(ExecState&
     }
 
     auto iv = getProperty(state, asObject(value), "iv");
-    RETURN_IF_EXCEPTION(scope, nullptr);
+    RETURN_IF_EXCEPTION(scope, { });
 
     auto result = adoptRef(*new CryptoAlgorithmAesCbcParamsDeprecated);
 
-    CryptoOperationData ivData;
-    auto success = cryptoOperationDataFromJSValue(state, iv, ivData);
-    ASSERT(scope.exception() || success);
-    if (!success)
-        return nullptr;
+    auto ivData = cryptoOperationDataFromJSValue(state, scope, iv);
+    RETURN_IF_EXCEPTION(scope, { });
 
     if (ivData.second != 16) {
         throwException(&state, scope, createError(&state, "AES-CBC initialization data must be 16 bytes"));
@@ -180,10 +177,8 @@ static RefPtr<CryptoAlgorithmParametersDeprecated> createHmacParams(ExecState& s
 
     auto result = adoptRef(*new CryptoAlgorithmHmacParamsDeprecated);
 
-    auto success = getHashAlgorithm(state, asObject(value), result->hash, HashRequirement::Required);
-    ASSERT_UNUSED(scope, scope.exception() || success);
-    if (!success)
-        return nullptr;
+    result->hash = requiredHashAlgorithm(state, scope, asObject(value));
+    RETURN_IF_EXCEPTION(scope, { });
 
     return WTFMove(result);
 }
@@ -199,10 +194,8 @@ static RefPtr<CryptoAlgorithmParametersDeprecated> createHmacKeyParams(ExecState
 
     auto result = adoptRef(*new CryptoAlgorithmHmacKeyParamsDeprecated);
 
-    auto success = getHashAlgorithm(state, asObject(value), result->hash, HashRequirement::Required);
-    ASSERT(scope.exception() || success);
-    if (!success)
-        return nullptr;
+    result->hash = requiredHashAlgorithm(state, scope, asObject(value));
+    RETURN_IF_EXCEPTION(scope, { });
 
     auto lengthValue = getProperty(state, asObject(value), "length");
     RETURN_IF_EXCEPTION(scope, nullptr);
@@ -243,7 +236,10 @@ static RefPtr<CryptoAlgorithmParametersDeprecated> createRsaKeyGenParams(ExecSta
     }
     result->publicExponent.append(publicExponentArray->data(), publicExponentArray->byteLength());
 
-    result->hasHash = getHashAlgorithm(state, asObject(value), result->hash, HashRequirement::Optional);
+    if (auto optionalHash = optionalHashAlgorithm(state, scope, asObject(value))) {
+        result->hasHash = true;
+        result->hash = optionalHash.value();
+    }
 
     return WTFMove(result);
 }
@@ -265,23 +261,18 @@ static RefPtr<CryptoAlgorithmParametersDeprecated> createRsaOaepParams(ExecState
 
     auto result = adoptRef(*new CryptoAlgorithmRsaOaepParamsDeprecated);
 
-    auto success = getHashAlgorithm(state, asObject(value), result->hash, HashRequirement::Required);
-    ASSERT(scope.exception() || success);
-    if (!success)
-        return nullptr;
+    result->hash = requiredHashAlgorithm(state, scope, asObject(value));
+    RETURN_IF_EXCEPTION(scope, { });
 
     auto labelValue = getProperty(state, asObject(value), "label");
-    RETURN_IF_EXCEPTION(scope, nullptr);
+    RETURN_IF_EXCEPTION(scope, { });
 
     result->hasLabel = !labelValue.isUndefinedOrNull();
     if (!result->hasLabel)
         return WTFMove(result);
 
-    CryptoOperationData labelData;
-    success = cryptoOperationDataFromJSValue(state, labelValue, labelData);
-    ASSERT(scope.exception() || success);
-    if (!success)
-        return nullptr;
+    auto labelData = cryptoOperationDataFromJSValue(state, scope, labelValue);
+    RETURN_IF_EXCEPTION(scope, { });
 
     result->label.append(labelData.first, labelData.second);
 
@@ -299,36 +290,34 @@ static RefPtr<CryptoAlgorithmParametersDeprecated> createRsaSsaParams(ExecState&
 
     auto result = adoptRef(*new CryptoAlgorithmRsaSsaParamsDeprecated);
 
-    auto success = getHashAlgorithm(state, asObject(value), result->hash, HashRequirement::Required);
-    ASSERT(scope.exception() || success);
-    if (!success)
-        return nullptr;
+    result->hash = requiredHashAlgorithm(state, scope, asObject(value));
+    RETURN_IF_EXCEPTION(scope, { });
 
     return WTFMove(result);
 }
 
-RefPtr<CryptoAlgorithmParametersDeprecated> JSCryptoAlgorithmDictionary::createParametersForEncrypt(ExecState& state, CryptoAlgorithmIdentifier algorithm, JSValue value)
+RefPtr<CryptoAlgorithmParametersDeprecated> JSCryptoAlgorithmDictionary::createParametersForEncrypt(ExecState& state, ThrowScope& scope, CryptoAlgorithmIdentifier algorithm, JSValue value)
 {
     switch (algorithm) {
     case CryptoAlgorithmIdentifier::RSAES_PKCS1_v1_5:
         return adoptRef(*new CryptoAlgorithmParametersDeprecated);
     case CryptoAlgorithmIdentifier::RSASSA_PKCS1_v1_5:
     case CryptoAlgorithmIdentifier::RSA_PSS:
-        setDOMException(&state, NOT_SUPPORTED_ERR);
+        throwNotSupportedError(state, scope);
         return nullptr;
     case CryptoAlgorithmIdentifier::RSA_OAEP:
         return createRsaOaepParams(state, value);
     case CryptoAlgorithmIdentifier::ECDSA:
     case CryptoAlgorithmIdentifier::ECDH:
     case CryptoAlgorithmIdentifier::AES_CTR:
-        setDOMException(&state, NOT_SUPPORTED_ERR);
+        throwNotSupportedError(state, scope);
         return nullptr;
     case CryptoAlgorithmIdentifier::AES_CBC:
         return createAesCbcParams(state, value);
     case CryptoAlgorithmIdentifier::AES_CMAC:
     case CryptoAlgorithmIdentifier::AES_GCM:
     case CryptoAlgorithmIdentifier::AES_CFB:
-        setDOMException(&state, NOT_SUPPORTED_ERR);
+        throwNotSupportedError(state, scope);
         return nullptr;
     case CryptoAlgorithmIdentifier::AES_KW:
         return adoptRef(*new CryptoAlgorithmParametersDeprecated);
@@ -342,35 +331,35 @@ RefPtr<CryptoAlgorithmParametersDeprecated> JSCryptoAlgorithmDictionary::createP
     case CryptoAlgorithmIdentifier::CONCAT:
     case CryptoAlgorithmIdentifier::HKDF_CTR:
     case CryptoAlgorithmIdentifier::PBKDF2:
-        setDOMException(&state, NOT_SUPPORTED_ERR);
+        throwNotSupportedError(state, scope);
         return nullptr;
     }
     RELEASE_ASSERT_NOT_REACHED();
     return nullptr;
 }
 
-RefPtr<CryptoAlgorithmParametersDeprecated> JSCryptoAlgorithmDictionary::createParametersForDecrypt(ExecState& state, CryptoAlgorithmIdentifier algorithm, JSValue value)
+RefPtr<CryptoAlgorithmParametersDeprecated> JSCryptoAlgorithmDictionary::createParametersForDecrypt(ExecState& state, ThrowScope& scope, CryptoAlgorithmIdentifier algorithm, JSValue value)
 {
     switch (algorithm) {
     case CryptoAlgorithmIdentifier::RSAES_PKCS1_v1_5:
         return adoptRef(*new CryptoAlgorithmParametersDeprecated);
     case CryptoAlgorithmIdentifier::RSASSA_PKCS1_v1_5:
     case CryptoAlgorithmIdentifier::RSA_PSS:
-        setDOMException(&state, NOT_SUPPORTED_ERR);
+        throwNotSupportedError(state, scope);
         return nullptr;
     case CryptoAlgorithmIdentifier::RSA_OAEP:
         return createRsaOaepParams(state, value);
     case CryptoAlgorithmIdentifier::ECDSA:
     case CryptoAlgorithmIdentifier::ECDH:
     case CryptoAlgorithmIdentifier::AES_CTR:
-        setDOMException(&state, NOT_SUPPORTED_ERR);
+        throwNotSupportedError(state, scope);
         return nullptr;
     case CryptoAlgorithmIdentifier::AES_CBC:
         return createAesCbcParams(state, value);
     case CryptoAlgorithmIdentifier::AES_CMAC:
     case CryptoAlgorithmIdentifier::AES_GCM:
     case CryptoAlgorithmIdentifier::AES_CFB:
-        setDOMException(&state, NOT_SUPPORTED_ERR);
+        throwNotSupportedError(state, scope);
         return nullptr;
     case CryptoAlgorithmIdentifier::AES_KW:
         return adoptRef(*new CryptoAlgorithmParametersDeprecated);
@@ -384,18 +373,18 @@ RefPtr<CryptoAlgorithmParametersDeprecated> JSCryptoAlgorithmDictionary::createP
     case CryptoAlgorithmIdentifier::CONCAT:
     case CryptoAlgorithmIdentifier::HKDF_CTR:
     case CryptoAlgorithmIdentifier::PBKDF2:
-        setDOMException(&state, NOT_SUPPORTED_ERR);
+        throwNotSupportedError(state, scope);
         return nullptr;
     }
     RELEASE_ASSERT_NOT_REACHED();
     return nullptr;
 }
 
-RefPtr<CryptoAlgorithmParametersDeprecated> JSCryptoAlgorithmDictionary::createParametersForSign(ExecState& state, CryptoAlgorithmIdentifier algorithm, JSValue value)
+RefPtr<CryptoAlgorithmParametersDeprecated> JSCryptoAlgorithmDictionary::createParametersForSign(ExecState& state, ThrowScope& scope, CryptoAlgorithmIdentifier algorithm, JSValue value)
 {
     switch (algorithm) {
     case CryptoAlgorithmIdentifier::RSAES_PKCS1_v1_5:
-        setDOMException(&state, NOT_SUPPORTED_ERR);
+        throwNotSupportedError(state, scope);
         return nullptr;
     case CryptoAlgorithmIdentifier::RSASSA_PKCS1_v1_5:
         return createRsaSsaParams(state, value);
@@ -409,7 +398,7 @@ RefPtr<CryptoAlgorithmParametersDeprecated> JSCryptoAlgorithmDictionary::createP
     case CryptoAlgorithmIdentifier::AES_GCM:
     case CryptoAlgorithmIdentifier::AES_CFB:
     case CryptoAlgorithmIdentifier::AES_KW:
-        setDOMException(&state, NOT_SUPPORTED_ERR);
+        throwNotSupportedError(state, scope);
         return nullptr;
     case CryptoAlgorithmIdentifier::HMAC:
         return createHmacParams(state, value);
@@ -422,18 +411,18 @@ RefPtr<CryptoAlgorithmParametersDeprecated> JSCryptoAlgorithmDictionary::createP
     case CryptoAlgorithmIdentifier::CONCAT:
     case CryptoAlgorithmIdentifier::HKDF_CTR:
     case CryptoAlgorithmIdentifier::PBKDF2:
-        setDOMException(&state, NOT_SUPPORTED_ERR);
+        throwNotSupportedError(state, scope);
         return nullptr;
     }
     RELEASE_ASSERT_NOT_REACHED();
     return nullptr;
 }
 
-RefPtr<CryptoAlgorithmParametersDeprecated> JSCryptoAlgorithmDictionary::createParametersForVerify(ExecState& state, CryptoAlgorithmIdentifier algorithm, JSValue value)
+RefPtr<CryptoAlgorithmParametersDeprecated> JSCryptoAlgorithmDictionary::createParametersForVerify(ExecState& state, ThrowScope& scope, CryptoAlgorithmIdentifier algorithm, JSValue value)
 {
     switch (algorithm) {
     case CryptoAlgorithmIdentifier::RSAES_PKCS1_v1_5:
-        setDOMException(&state, NOT_SUPPORTED_ERR);
+        throwNotSupportedError(state, scope);
         return nullptr;
     case CryptoAlgorithmIdentifier::RSASSA_PKCS1_v1_5:
         return createRsaSsaParams(state, value);
@@ -447,7 +436,7 @@ RefPtr<CryptoAlgorithmParametersDeprecated> JSCryptoAlgorithmDictionary::createP
     case CryptoAlgorithmIdentifier::AES_GCM:
     case CryptoAlgorithmIdentifier::AES_CFB:
     case CryptoAlgorithmIdentifier::AES_KW:
-        setDOMException(&state, NOT_SUPPORTED_ERR);
+        throwNotSupportedError(state, scope);
         return nullptr;
     case CryptoAlgorithmIdentifier::HMAC:
         return createHmacParams(state, value);
@@ -460,14 +449,14 @@ RefPtr<CryptoAlgorithmParametersDeprecated> JSCryptoAlgorithmDictionary::createP
     case CryptoAlgorithmIdentifier::CONCAT:
     case CryptoAlgorithmIdentifier::HKDF_CTR:
     case CryptoAlgorithmIdentifier::PBKDF2:
-        setDOMException(&state, NOT_SUPPORTED_ERR);
+        throwNotSupportedError(state, scope);
         return nullptr;
     }
     RELEASE_ASSERT_NOT_REACHED();
     return nullptr;
 }
 
-RefPtr<CryptoAlgorithmParametersDeprecated> JSCryptoAlgorithmDictionary::createParametersForDigest(ExecState& state, CryptoAlgorithmIdentifier algorithm, JSValue)
+RefPtr<CryptoAlgorithmParametersDeprecated> JSCryptoAlgorithmDictionary::createParametersForDigest(ExecState& state, ThrowScope& scope, CryptoAlgorithmIdentifier algorithm, JSValue)
 {
     switch (algorithm) {
     case CryptoAlgorithmIdentifier::RSAES_PKCS1_v1_5:
@@ -484,7 +473,7 @@ RefPtr<CryptoAlgorithmParametersDeprecated> JSCryptoAlgorithmDictionary::createP
     case CryptoAlgorithmIdentifier::AES_KW:
     case CryptoAlgorithmIdentifier::HMAC:
     case CryptoAlgorithmIdentifier::DH:
-        setDOMException(&state, NOT_SUPPORTED_ERR);
+        throwNotSupportedError(state, scope);
         return nullptr;
     case CryptoAlgorithmIdentifier::SHA_1:
     case CryptoAlgorithmIdentifier::SHA_224:
@@ -495,14 +484,14 @@ RefPtr<CryptoAlgorithmParametersDeprecated> JSCryptoAlgorithmDictionary::createP
     case CryptoAlgorithmIdentifier::CONCAT:
     case CryptoAlgorithmIdentifier::HKDF_CTR:
     case CryptoAlgorithmIdentifier::PBKDF2:
-        setDOMException(&state, NOT_SUPPORTED_ERR);
+        throwNotSupportedError(state, scope);
         return nullptr;
     }
     RELEASE_ASSERT_NOT_REACHED();
     return nullptr;
 }
 
-RefPtr<CryptoAlgorithmParametersDeprecated> JSCryptoAlgorithmDictionary::createParametersForGenerateKey(ExecState& state, CryptoAlgorithmIdentifier algorithm, JSValue value)
+RefPtr<CryptoAlgorithmParametersDeprecated> JSCryptoAlgorithmDictionary::createParametersForGenerateKey(ExecState& state, ThrowScope& scope, CryptoAlgorithmIdentifier algorithm, JSValue value)
 {
     switch (algorithm) {
     case CryptoAlgorithmIdentifier::RSAES_PKCS1_v1_5:
@@ -512,7 +501,7 @@ RefPtr<CryptoAlgorithmParametersDeprecated> JSCryptoAlgorithmDictionary::createP
         return createRsaKeyGenParams(state, value);
     case CryptoAlgorithmIdentifier::ECDSA:
     case CryptoAlgorithmIdentifier::ECDH:
-        setDOMException(&state, NOT_SUPPORTED_ERR);
+        throwNotSupportedError(state, scope);
         return nullptr;
     case CryptoAlgorithmIdentifier::AES_CTR:
     case CryptoAlgorithmIdentifier::AES_CBC:
@@ -532,14 +521,14 @@ RefPtr<CryptoAlgorithmParametersDeprecated> JSCryptoAlgorithmDictionary::createP
     case CryptoAlgorithmIdentifier::CONCAT:
     case CryptoAlgorithmIdentifier::HKDF_CTR:
     case CryptoAlgorithmIdentifier::PBKDF2:
-        setDOMException(&state, NOT_SUPPORTED_ERR);
+        throwNotSupportedError(state, scope);
         return nullptr;
     }
     RELEASE_ASSERT_NOT_REACHED();
     return nullptr;
 }
 
-RefPtr<CryptoAlgorithmParametersDeprecated> JSCryptoAlgorithmDictionary::createParametersForDeriveKey(ExecState& state, CryptoAlgorithmIdentifier algorithm, JSValue)
+RefPtr<CryptoAlgorithmParametersDeprecated> JSCryptoAlgorithmDictionary::createParametersForDeriveKey(ExecState& state, ThrowScope& scope, CryptoAlgorithmIdentifier algorithm, JSValue)
 {
     switch (algorithm) {
     case CryptoAlgorithmIdentifier::RSAES_PKCS1_v1_5:
@@ -564,14 +553,14 @@ RefPtr<CryptoAlgorithmParametersDeprecated> JSCryptoAlgorithmDictionary::createP
     case CryptoAlgorithmIdentifier::CONCAT:
     case CryptoAlgorithmIdentifier::HKDF_CTR:
     case CryptoAlgorithmIdentifier::PBKDF2:
-        setDOMException(&state, NOT_SUPPORTED_ERR);
+        throwNotSupportedError(state, scope);
         return nullptr;
     }
     RELEASE_ASSERT_NOT_REACHED();
     return nullptr;
 }
 
-RefPtr<CryptoAlgorithmParametersDeprecated> JSCryptoAlgorithmDictionary::createParametersForDeriveBits(ExecState& state, CryptoAlgorithmIdentifier algorithm, JSValue)
+RefPtr<CryptoAlgorithmParametersDeprecated> JSCryptoAlgorithmDictionary::createParametersForDeriveBits(ExecState& state, ThrowScope& scope, CryptoAlgorithmIdentifier algorithm, JSValue)
 {
     switch (algorithm) {
     case CryptoAlgorithmIdentifier::RSAES_PKCS1_v1_5:
@@ -596,14 +585,14 @@ RefPtr<CryptoAlgorithmParametersDeprecated> JSCryptoAlgorithmDictionary::createP
     case CryptoAlgorithmIdentifier::CONCAT:
     case CryptoAlgorithmIdentifier::HKDF_CTR:
     case CryptoAlgorithmIdentifier::PBKDF2:
-        setDOMException(&state, NOT_SUPPORTED_ERR);
+        throwNotSupportedError(state, scope);
         return nullptr;
     }
     RELEASE_ASSERT_NOT_REACHED();
     return nullptr;
 }
 
-RefPtr<CryptoAlgorithmParametersDeprecated> JSCryptoAlgorithmDictionary::createParametersForImportKey(ExecState& state, CryptoAlgorithmIdentifier algorithm, JSValue value)
+RefPtr<CryptoAlgorithmParametersDeprecated> JSCryptoAlgorithmDictionary::createParametersForImportKey(ExecState& state, ThrowScope& scope, CryptoAlgorithmIdentifier algorithm, JSValue value)
 {
     switch (algorithm) {
     case CryptoAlgorithmIdentifier::RSAES_PKCS1_v1_5:
@@ -632,14 +621,14 @@ RefPtr<CryptoAlgorithmParametersDeprecated> JSCryptoAlgorithmDictionary::createP
     case CryptoAlgorithmIdentifier::CONCAT:
     case CryptoAlgorithmIdentifier::HKDF_CTR:
     case CryptoAlgorithmIdentifier::PBKDF2:
-        setDOMException(&state, NOT_SUPPORTED_ERR);
+        throwNotSupportedError(state, scope);
         return nullptr;
     }
     RELEASE_ASSERT_NOT_REACHED();
     return nullptr;
 }
 
-RefPtr<CryptoAlgorithmParametersDeprecated> JSCryptoAlgorithmDictionary::createParametersForExportKey(ExecState& state, CryptoAlgorithmIdentifier algorithm, JSValue)
+RefPtr<CryptoAlgorithmParametersDeprecated> JSCryptoAlgorithmDictionary::createParametersForExportKey(ExecState& state, ThrowScope& scope, CryptoAlgorithmIdentifier algorithm, JSValue)
 {
     switch (algorithm) {
     case CryptoAlgorithmIdentifier::RSAES_PKCS1_v1_5:
@@ -665,7 +654,7 @@ RefPtr<CryptoAlgorithmParametersDeprecated> JSCryptoAlgorithmDictionary::createP
     case CryptoAlgorithmIdentifier::CONCAT:
     case CryptoAlgorithmIdentifier::HKDF_CTR:
     case CryptoAlgorithmIdentifier::PBKDF2:
-        setDOMException(&state, NOT_SUPPORTED_ERR);
+        throwNotSupportedError(state, scope);
         return nullptr;
     }
     RELEASE_ASSERT_NOT_REACHED();
index 439ccf3..64ce3db 100644 (file)
 #if ENABLE(SUBTLE_CRYPTO)
 
 #include "CryptoAlgorithmIdentifier.h"
-#include <wtf/RefPtr.h>
+#include <wtf/Forward.h>
 
 namespace JSC {
 class ExecState;
 class JSValue;
+class ThrowScope;
 }
 
 namespace WebCore {
@@ -41,18 +42,18 @@ class CryptoAlgorithmParametersDeprecated;
 
 class JSCryptoAlgorithmDictionary {
 public:
-    static bool getAlgorithmIdentifier(JSC::ExecState&, JSC::JSValue, CryptoAlgorithmIdentifier&);
-
-    static RefPtr<CryptoAlgorithmParametersDeprecated> createParametersForEncrypt(JSC::ExecState&, CryptoAlgorithmIdentifier, JSC::JSValue);
-    static RefPtr<CryptoAlgorithmParametersDeprecated> createParametersForDecrypt(JSC::ExecState&, CryptoAlgorithmIdentifier, JSC::JSValue);
-    static RefPtr<CryptoAlgorithmParametersDeprecated> createParametersForSign(JSC::ExecState&, CryptoAlgorithmIdentifier, JSC::JSValue);
-    static RefPtr<CryptoAlgorithmParametersDeprecated> createParametersForVerify(JSC::ExecState&, CryptoAlgorithmIdentifier, JSC::JSValue);
-    static RefPtr<CryptoAlgorithmParametersDeprecated> createParametersForDigest(JSC::ExecState&, CryptoAlgorithmIdentifier, JSC::JSValue);
-    static RefPtr<CryptoAlgorithmParametersDeprecated> createParametersForGenerateKey(JSC::ExecState&, CryptoAlgorithmIdentifier, JSC::JSValue);
-    static RefPtr<CryptoAlgorithmParametersDeprecated> createParametersForDeriveKey(JSC::ExecState&, CryptoAlgorithmIdentifier, JSC::JSValue);
-    static RefPtr<CryptoAlgorithmParametersDeprecated> createParametersForDeriveBits(JSC::ExecState&, CryptoAlgorithmIdentifier, JSC::JSValue);
-    static RefPtr<CryptoAlgorithmParametersDeprecated> createParametersForImportKey(JSC::ExecState&, CryptoAlgorithmIdentifier, JSC::JSValue);
-    static RefPtr<CryptoAlgorithmParametersDeprecated> createParametersForExportKey(JSC::ExecState&, CryptoAlgorithmIdentifier, JSC::JSValue);
+    static CryptoAlgorithmIdentifier parseAlgorithmIdentifier(JSC::ExecState&, JSC::ThrowScope&, JSC::JSValue);
+
+    static RefPtr<CryptoAlgorithmParametersDeprecated> createParametersForEncrypt(JSC::ExecState&, JSC::ThrowScope&, CryptoAlgorithmIdentifier, JSC::JSValue);
+    static RefPtr<CryptoAlgorithmParametersDeprecated> createParametersForDecrypt(JSC::ExecState&, JSC::ThrowScope&, CryptoAlgorithmIdentifier, JSC::JSValue);
+    static RefPtr<CryptoAlgorithmParametersDeprecated> createParametersForSign(JSC::ExecState&, JSC::ThrowScope&, CryptoAlgorithmIdentifier, JSC::JSValue);
+    static RefPtr<CryptoAlgorithmParametersDeprecated> createParametersForVerify(JSC::ExecState&, JSC::ThrowScope&, CryptoAlgorithmIdentifier, JSC::JSValue);
+    static RefPtr<CryptoAlgorithmParametersDeprecated> createParametersForDigest(JSC::ExecState&, JSC::ThrowScope&, CryptoAlgorithmIdentifier, JSC::JSValue);
+    static RefPtr<CryptoAlgorithmParametersDeprecated> createParametersForGenerateKey(JSC::ExecState&, JSC::ThrowScope&, CryptoAlgorithmIdentifier, JSC::JSValue);
+    static RefPtr<CryptoAlgorithmParametersDeprecated> createParametersForDeriveKey(JSC::ExecState&, JSC::ThrowScope&, CryptoAlgorithmIdentifier, JSC::JSValue);
+    static RefPtr<CryptoAlgorithmParametersDeprecated> createParametersForDeriveBits(JSC::ExecState&, JSC::ThrowScope&, CryptoAlgorithmIdentifier, JSC::JSValue);
+    static RefPtr<CryptoAlgorithmParametersDeprecated> createParametersForImportKey(JSC::ExecState&, JSC::ThrowScope&, CryptoAlgorithmIdentifier, JSC::JSValue);
+    static RefPtr<CryptoAlgorithmParametersDeprecated> createParametersForExportKey(JSC::ExecState&, JSC::ThrowScope&, CryptoAlgorithmIdentifier, JSC::JSValue);
 };
 
 } // namespace WebCore
index f078565..169d934 100644 (file)
@@ -34,19 +34,16 @@ using namespace JSC;
 
 namespace WebCore {
 
-bool cryptoOperationDataFromJSValue(ExecState& state, JSValue value, CryptoOperationData& result)
+CryptoOperationData cryptoOperationDataFromJSValue(ExecState& state, ThrowScope& scope, JSValue value)
 {
-    auto scope = DECLARE_THROW_SCOPE(state.vm());
-
-    if (ArrayBuffer* buffer = toUnsharedArrayBuffer(value))
-        result = std::make_pair(static_cast<uint8_t*>(buffer->data()), buffer->byteLength());
-    else if (RefPtr<ArrayBufferView> bufferView = toUnsharedArrayBufferView(value))
-        result = std::make_pair(static_cast<uint8_t*>(bufferView->baseAddress()), bufferView->byteLength());
-    else {
-        throwTypeError(&state, scope, ASCIILiteral("Only ArrayBuffer and ArrayBufferView objects can be passed as CryptoOperationData"));
-        return false;
-    }
-    return true;
+    if (auto* buffer = toUnsharedArrayBuffer(value))
+        return { static_cast<uint8_t*>(buffer->data()), buffer->byteLength() };
+
+    if (auto bufferView = toUnsharedArrayBufferView(value))
+        return { static_cast<uint8_t*>(bufferView->baseAddress()), bufferView->byteLength() };
+
+    throwTypeError(&state, scope, ASCIILiteral("Only ArrayBuffer and ArrayBufferView objects can be passed as CryptoOperationData"));
+    return { };
 }
 
 } // namespace WebCore
index ecbadc7..909e132 100644 (file)
 namespace JSC {
 class ExecState;
 class JSValue;
+class ThrowScope;
 }
 
 namespace WebCore {
 
-typedef std::pair<const uint8_t*, size_t> CryptoOperationData;
+using CryptoOperationData = std::pair<const uint8_t*, size_t>;
 
-bool cryptoOperationDataFromJSValue(JSC::ExecState&, JSC::JSValue, CryptoOperationData&);
+CryptoOperationData cryptoOperationDataFromJSValue(JSC::ExecState&, JSC::ThrowScope&, JSC::JSValue);
 
 } // namespace WebCore
 
index c6cf031..8a8ecdf 100644 (file)
@@ -42,23 +42,21 @@ namespace WebCore {
 
 using namespace JSC;
 
-RefPtr<JSCustomXPathNSResolver> JSCustomXPathNSResolver::create(ExecState* exec, JSValue value)
+ExceptionOr<Ref<JSCustomXPathNSResolver>> JSCustomXPathNSResolver::create(ExecState& state, JSValue value)
 {
     if (value.isUndefinedOrNull())
-        return nullptr;
+        return Exception { TypeError };
 
-    JSObject* resolverObject = value.getObject();
-    if (!resolverObject) {
-        setDOMException(exec, TYPE_MISMATCH_ERR);
-        return nullptr;
-    }
+    auto* resolverObject = value.getObject();
+    if (!resolverObject)
+        return Exception { TYPE_MISMATCH_ERR };
 
-    return adoptRef(*new JSCustomXPathNSResolver(exec, resolverObject, asJSDOMWindow(exec->vmEntryGlobalObject())));
+    return adoptRef(*new JSCustomXPathNSResolver(state.vm(), resolverObject, asJSDOMWindow(state.vmEntryGlobalObject())));
 }
 
-JSCustomXPathNSResolver::JSCustomXPathNSResolver(ExecState* exec, JSObject* customResolver, JSDOMWindow* globalObject)
-    : m_customResolver(exec->vm(), customResolver)
-    , m_globalObject(exec->vm(), globalObject)
+JSCustomXPathNSResolver::JSCustomXPathNSResolver(VM& vm, JSObject* customResolver, JSDOMWindow* globalObject)
+    : m_customResolver(vm, customResolver)
+    , m_globalObject(vm, globalObject)
 {
 }
 
index 0441f54..4cee8d3 100644 (file)
 
 #pragma once
 
+#include "ExceptionOr.h"
 #include "XPathNSResolver.h"
 #include <heap/Strong.h>
 #include <heap/StrongInlines.h>
 #include <runtime/JSCInlines.h>
 #include <runtime/JSCJSValue.h>
-#include <wtf/Forward.h>
-#include <wtf/RefPtr.h>
-
-namespace JSC {
-    class ExecState;
-    class JSObject;
-}
 
 namespace WebCore {
 
-    class Frame;
-    class JSDOMWindow;
+class JSDOMWindow;
 
-    class JSCustomXPathNSResolver : public XPathNSResolver {
-    public:
-        static RefPtr<JSCustomXPathNSResolver> create(JSC::ExecState*, JSC::JSValue);
-        
-        virtual ~JSCustomXPathNSResolver();
+class JSCustomXPathNSResolver final : public XPathNSResolver {
+public:
+    static ExceptionOr<Ref<JSCustomXPathNSResolver>> create(JSC::ExecState&, JSC::JSValue);
+    virtual ~JSCustomXPathNSResolver();
 
-        String lookupNamespaceURI(const String& prefix) override;
+private:
+    JSCustomXPathNSResolver(JSC::VM&, JSC::JSObject*, JSDOMWindow*);
 
-    private:
-        JSCustomXPathNSResolver(JSC::ExecState*, JSC::JSObject*, JSDOMWindow*);
+    String lookupNamespaceURI(const String& prefix) final;
 
-        // JSCustomXPathNSResolvers are always temporary so using a Strong reference is safe here.
-        JSC::Strong<JSC::JSObject> m_customResolver;
-        JSC::Strong<JSDOMWindow> m_globalObject;
-    };
+    // JSCustomXPathNSResolvers are always temporary so using a Strong reference is safe here.
+    JSC::Strong<JSC::JSObject> m_customResolver;
+    JSC::Strong<JSDOMWindow> m_globalObject;
+};
 
 } // namespace WebCore
index 5504000..1ac0f19 100644 (file)
@@ -290,9 +290,9 @@ static JSValue createDOMException(ExecState* exec, ExceptionCode ec, const Strin
     if (ec == StackOverflowError)
         return createStackOverflowError(exec);
 
-    // FIXME: All callers to setDOMException need to pass in the right global object
-    // for now, we're going to assume the lexicalGlobalObject. Which is wrong in cases like this:
-    // frames[0].document.createElement(null, null); // throws an exception which should have the subframes prototypes.
+    // FIXME: All callers to createDOMException need to pass in the correct global object.
+    // For now, we're going to assume the lexicalGlobalObject. Which is wrong in cases like this:
+    // frames[0].document.createElement(null, null); // throws an exception which should have the subframe's prototypes.
     JSDOMGlobalObject* globalObject = deprecatedGlobalObjectForPrototype(exec);
 
     ExceptionCodeDescription description(ec);
@@ -342,41 +342,12 @@ JSValue createDOMException(ExecState& state, Exception&& exception)
     return createDOMException(&state, exception.code(), exception.releaseMessage());
 }
 
-ALWAYS_INLINE static void throwDOMException(ExecState* exec, ThrowScope& throwScope, ExceptionCode ec)
-{
-    ASSERT(ec && !throwScope.exception());
-    throwException(exec, throwScope, createDOMException(exec, ec));
-}
-
 void propagateExceptionSlowPath(JSC::ExecState& state, JSC::ThrowScope& throwScope, Exception&& exception)
 {
     ASSERT(!throwScope.exception());
     throwException(&state, throwScope, createDOMException(state, WTFMove(exception)));
 }
 
-void propagateException(JSC::ExecState& state, Exception&& exception)
-{
-    auto throwScope = DECLARE_THROW_SCOPE(state.vm());
-    if (!throwScope.exception())
-        propagateExceptionSlowPath(state, throwScope, WTFMove(exception));
-}
-
-void setDOMExceptionSlow(ExecState* exec, ThrowScope& throwScope, ExceptionCode ec)
-{
-    throwDOMException(exec, throwScope, ec);
-}
-
-void setDOMException(ExecState* exec, ExceptionCode ec)
-{
-    VM& vm = exec->vm();
-    auto scope = DECLARE_THROW_SCOPE(vm);
-
-    if (!ec || scope.exception())
-        return;
-
-    throwDOMException(exec, scope, ec);
-}
-
 bool hasIteratorMethod(JSC::ExecState& state, JSC::JSValue value)
 {
     auto& vm = state.vm();
@@ -871,6 +842,12 @@ void reportDeprecatedSetterError(JSC::ExecState& state, const char* interfaceNam
     context.addConsoleMessage(MessageSource::JS, MessageLevel::Error, makeString("Deprecated attempt to set property '", attributeName, "' on a non-", interfaceName, " object."));
 }
 
+void throwNotSupportedError(JSC::ExecState& state, JSC::ThrowScope& scope)
+{
+    ASSERT(!scope.exception());
+    throwException(&state, scope, createDOMException(&state, NOT_SUPPORTED_ERR));
+}
+
 void throwNotSupportedError(JSC::ExecState& state, JSC::ThrowScope& scope, const char* message)
 {
     ASSERT(!scope.exception());
@@ -1030,4 +1007,28 @@ CallType DOMConstructorObject::getCallData(JSCell*, CallData& callData)
     return CallType::Host;
 }
 
+void throwDOMSyntaxError(JSC::ExecState& state, JSC::ThrowScope& scope)
+{
+    ASSERT(!scope.exception());
+    throwException(&state, scope, createDOMException(&state, SYNTAX_ERR));
+}
+
+void throwDataCloneError(JSC::ExecState& state, JSC::ThrowScope& scope)
+{
+    ASSERT(!scope.exception());
+    throwException(&state, scope, createDOMException(&state, DATA_CLONE_ERR));
+}
+
+void throwIndexSizeError(JSC::ExecState& state, JSC::ThrowScope& scope)
+{
+    ASSERT(!scope.exception());
+    throwException(&state, scope, createDOMException(&state, INDEX_SIZE_ERR));
+}
+
+void throwTypeMismatchError(JSC::ExecState& state, JSC::ThrowScope& scope)
+{
+    ASSERT(!scope.exception());
+    throwException(&state, scope, createDOMException(&state, TYPE_MISMATCH_ERR));
+}
+
 } // namespace WebCore
index 296e79a..9af16ae 100644 (file)
@@ -116,14 +116,20 @@ DOMWindow& firstDOMWindow(JSC::ExecState*);
 WEBCORE_EXPORT JSC::EncodedJSValue reportDeprecatedGetterError(JSC::ExecState&, const char* interfaceName, const char* attributeName);
 WEBCORE_EXPORT void reportDeprecatedSetterError(JSC::ExecState&, const char* interfaceName, const char* attributeName);
 
-void throwNotSupportedError(JSC::ExecState&, JSC::ThrowScope&, const char* message);
-void throwInvalidStateError(JSC::ExecState&, JSC::ThrowScope&, const char* message);
-void throwArrayElementTypeError(JSC::ExecState&, JSC::ThrowScope&);
 void throwAttributeTypeError(JSC::ExecState&, JSC::ThrowScope&, const char* interfaceName, const char* attributeName, const char* expectedType);
-WEBCORE_EXPORT void throwSequenceTypeError(JSC::ExecState&, JSC::ThrowScope&);
 WEBCORE_EXPORT bool throwSetterTypeError(JSC::ExecState&, JSC::ThrowScope&, const char* interfaceName, const char* attributeName);
+
+void throwArrayElementTypeError(JSC::ExecState&, JSC::ThrowScope&);
+void throwDataCloneError(JSC::ExecState&, JSC::ThrowScope&);
+void throwDOMSyntaxError(JSC::ExecState&, JSC::ThrowScope&); // Not the same as a JavaScript syntax error.
+void throwIndexSizeError(JSC::ExecState&, JSC::ThrowScope&);
+void throwInvalidStateError(JSC::ExecState&, JSC::ThrowScope&, const char* message);
 WEBCORE_EXPORT void throwNonFiniteTypeError(JSC::ExecState&, JSC::ThrowScope&);
+void throwNotSupportedError(JSC::ExecState&, JSC::ThrowScope&);
+void throwNotSupportedError(JSC::ExecState&, JSC::ThrowScope&, const char* message);
 void throwSecurityError(JSC::ExecState&, JSC::ThrowScope&, const String& message);
+WEBCORE_EXPORT void throwSequenceTypeError(JSC::ExecState&, JSC::ThrowScope&);
+void throwTypeMismatchError(JSC::ExecState&, JSC::ThrowScope&);
 
 WEBCORE_EXPORT JSC::EncodedJSValue throwArgumentMustBeEnumError(JSC::ExecState&, JSC::ThrowScope&, unsigned argumentIndex, const char* argumentName, const char* functionInterfaceName, const char* functionName, const char* expectedValues);
 JSC::EncodedJSValue throwArgumentMustBeFunctionError(JSC::ExecState&, JSC::ThrowScope&, unsigned argumentIndex, const char* argumentName, const char* functionInterfaceName, const char* functionName);
@@ -192,15 +198,7 @@ JSC::JSValue createDOMException(JSC::ExecState*, ExceptionCode, const String&);
 
 // Convert a DOM implementation exception into a JavaScript exception in the execution state.
 void propagateException(JSC::ExecState&, JSC::ThrowScope&, Exception&&);
-void setDOMException(JSC::ExecState*, JSC::ThrowScope&, ExceptionCode);
-
-// Slower versions of the above for use when the caller doesn't have a ThrowScope.
-void propagateException(JSC::ExecState&, Exception&&);
-WEBCORE_EXPORT void setDOMException(JSC::ExecState*, ExceptionCode);
-
-// Implementation details of the above.
 WEBCORE_EXPORT void propagateExceptionSlowPath(JSC::ExecState&, JSC::ThrowScope&, Exception&&);
-WEBCORE_EXPORT void setDOMExceptionSlow(JSC::ExecState*, JSC::ThrowScope&, ExceptionCode);
 
 JSC::JSValue jsString(JSC::ExecState*, const URL&); // empty if the URL is null
 
@@ -776,13 +774,6 @@ ALWAYS_INLINE void propagateException(JSC::ExecState& state, JSC::ThrowScope& th
     propagateExceptionSlowPath(state, throwScope, WTFMove(exception));
 }
 
-ALWAYS_INLINE void setDOMException(JSC::ExecState* exec, JSC::ThrowScope& throwScope, ExceptionCode ec)
-{
-    if (LIKELY(!ec || throwScope.exception()))
-        return;
-    setDOMExceptionSlow(exec, throwScope, ec);
-}
-
 inline void propagateException(JSC::ExecState& state, JSC::ThrowScope& throwScope, ExceptionOr<void>&& value)
 {
     if (UNLIKELY(value.hasException()))
diff --git a/Source/WebCore/bindings/js/JSFileReaderCustom.cpp b/Source/WebCore/bindings/js/JSFileReaderCustom.cpp
deleted file mode 100644 (file)
index 2ab7dd7..0000000
+++ /dev/null
@@ -1,52 +0,0 @@
-/*
- * Copyright (C) 2010 Google 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:
- *
- *     * Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- *     * 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.
- *     * Neither the name of Google Inc. nor the names of its
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 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 THE COPYRIGHT
- * OWNER OR 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 "JSFileReader.h"
-
-#include "FileReader.h"
-#include "JSDOMBinding.h"
-#include <runtime/ArrayBuffer.h>
-#include <runtime/JSArrayBuffer.h>
-
-using namespace JSC;
-
-namespace WebCore {
-
-JSValue JSFileReader::result(ExecState& state) const
-{
-    FileReader& imp = wrapped();
-    if (imp.readType() == FileReaderLoader::ReadAsArrayBuffer)
-        return toJS(&state, globalObject(), imp.arrayBufferResult().get());
-    return jsOwnedStringOrNull(&state, imp.stringResult());
-}
-
-} // namespace WebCore
index 40174fa..7355f31 100644 (file)
@@ -59,7 +59,7 @@ void JSHTMLOptionsCollection::setLength(ExecState& state, JSValue value)
     if (!std::isfinite(number))
         length = 0;
     else if (number < 0)
-        return setDOMException(&state, throwScope, INDEX_SIZE_ERR);
+        return throwIndexSizeError(state, throwScope);
     else
         length = static_cast<unsigned>(std::min<double>(number, UINT_MAX));
     propagateException(state, throwScope, wrapped().setLength(length));
index 9b0b81b..90384ad 100644 (file)
@@ -46,7 +46,7 @@ void selectElementIndexSetter(JSC::ExecState& state, HTMLSelectElement& element,
 
     auto* option = JSHTMLOptionElement::toWrapped(value);
     if (!option) {
-        setDOMException(&state, throwScope, TYPE_MISMATCH_ERR);
+        throwTypeMismatchError(state, throwScope);
         return;
     }
 
index 01faeab..b7491c0 100644 (file)
@@ -42,7 +42,9 @@ JSValue JSIDBRequest::result(ExecState& state) const
     auto& request = wrapped();
 
     if (!request.isDone()) {
-        propagateException(state, Exception { IDBDatabaseException::InvalidStateError, ASCIILiteral("Failed to read the 'result' property from 'IDBRequest': The request has not finished.") });
+        auto& vm = state.vm();
+        auto scope = DECLARE_THROW_SCOPE(vm);
+        propagateException(state, scope, Exception { IDBDatabaseException::InvalidStateError, ASCIILiteral("Failed to read the 'result' property from 'IDBRequest': The request has not finished.") });
         return { };
     }
 
index bdfb06b..7cbb6f5 100644 (file)
@@ -41,8 +41,12 @@ bool JSStorage::nameGetter(ExecState* state, PropertyName propertyName, JSValue&
         return false;
 
     auto item = wrapped().getItem(propertyNameToString(propertyName));
-    if (item.hasException())
-        propagateException(*state, item.releaseException());
+    if (item.hasException()) {
+        auto& vm = state->vm();
+        auto scope = DECLARE_THROW_SCOPE(vm);
+        propagateException(*state, scope, item.releaseException());
+        return false;
+    }
 
     auto string = item.releaseReturnValue();
     if (string.isNull())
index dca660a..7d89458 100644 (file)
@@ -95,8 +95,8 @@ static std::unique_ptr<CryptoAlgorithmParameters> normalizeCryptoAlgorithmParame
         RETURN_IF_EXCEPTION(scope, nullptr);
 
         auto identifier = CryptoAlgorithmRegistry::singleton().identifier(params.name);
-        if (!identifier) {
-            setDOMException(&state, NOT_SUPPORTED_ERR);
+        if (UNLIKELY(!identifier)) {
+            throwNotSupportedError(state, scope);
             return nullptr;
         }
 
@@ -121,7 +121,7 @@ static std::unique_ptr<CryptoAlgorithmParameters> normalizeCryptoAlgorithmParame
                 break;
             }
             default:
-                setDOMException(&state, NOT_SUPPORTED_ERR);
+                throwNotSupportedError(state, scope);
                 return nullptr;
             }
             break;
@@ -133,7 +133,7 @@ static std::unique_ptr<CryptoAlgorithmParameters> normalizeCryptoAlgorithmParame
                 result = std::make_unique<CryptoAlgorithmParameters>(params);
                 break;
             default:
-                setDOMException(&state, NOT_SUPPORTED_ERR);
+                throwNotSupportedError(state, scope);
                 return nullptr;
             }
             break;
@@ -147,13 +147,13 @@ static std::unique_ptr<CryptoAlgorithmParameters> normalizeCryptoAlgorithmParame
                 result = std::make_unique<CryptoAlgorithmParameters>(params);
                 break;
             default:
-                setDOMException(&state, NOT_SUPPORTED_ERR);
+                throwNotSupportedError(state, scope);
                 return nullptr;
             }
             break;
         case Operations::DeriveKey:
         case Operations::DeriveBits:
-            setDOMException(&state, NOT_SUPPORTED_ERR);
+            throwNotSupportedError(state, scope);
             return nullptr;
         case Operations::GenerateKey:
             switch (*identifier) {
@@ -193,7 +193,7 @@ static std::unique_ptr<CryptoAlgorithmParameters> normalizeCryptoAlgorithmParame
                 break;
             }
             default:
-                setDOMException(&state, NOT_SUPPORTED_ERR);
+                throwNotSupportedError(state, scope);
                 return nullptr;
             }
             break;
@@ -229,7 +229,7 @@ static std::unique_ptr<CryptoAlgorithmParameters> normalizeCryptoAlgorithmParame
                 break;
             }
             default:
-                setDOMException(&state, NOT_SUPPORTED_ERR);
+                throwNotSupportedError(state, scope);
                 return nullptr;
             }
             break;
@@ -240,7 +240,7 @@ static std::unique_ptr<CryptoAlgorithmParameters> normalizeCryptoAlgorithmParame
                 result = std::make_unique<CryptoAlgorithmParameters>(params);
                 break;
             default:
-                setDOMException(&state, NOT_SUPPORTED_ERR);
+                throwNotSupportedError(state, scope);
                 return nullptr;
             }
             break;
@@ -297,14 +297,6 @@ static CryptoKeyUsageBitmap cryptoKeyUsageBitmapFromJSValue(ExecState& state, JS
     return result;
 }
 
-static RefPtr<CryptoAlgorithm> createAlgorithm(ExecState& state, CryptoAlgorithmIdentifier identifier)
-{
-    auto result = CryptoAlgorithmRegistry::singleton().create(identifier);
-    if (!result)
-        setDOMException(&state, NOT_SUPPORTED_ERR);
-    return result;
-}
-
 // Maybe we want more specific error messages?
 static void rejectWithException(Ref<DeferredPromise>&& passedPromise, ExceptionCode ec)
 {
@@ -449,7 +441,7 @@ static Vector<uint8_t> toVector(ExecState& state, JSValue value)
     return dataVector;
 }
 
-static void supportExportKeyThrow(ExecState& state, CryptoAlgorithmIdentifier identifier)
+static void supportExportKeyThrow(ExecState& state, ThrowScope& scope, CryptoAlgorithmIdentifier identifier)
 {
     switch (identifier) {
     case CryptoAlgorithmIdentifier::RSAES_PKCS1_v1_5:
@@ -465,7 +457,7 @@ static void supportExportKeyThrow(ExecState& state, CryptoAlgorithmIdentifier id
     case CryptoAlgorithmIdentifier::HMAC:
         return;
     default:
-        setDOMException(&state, NOT_SUPPORTED_ERR);
+        throwNotSupportedError(state, scope);
     }
 }
 
@@ -498,8 +490,11 @@ static void jsSubtleCryptoFunctionEncryptPromise(ExecState& state, Ref<DeferredP
         return;
     }
 
-    auto algorithm = createAlgorithm(state, key->algorithmIdentifier());
-    RETURN_IF_EXCEPTION(scope, void());
+    auto algorithm = CryptoAlgorithmRegistry::singleton().create(key->algorithmIdentifier());
+    if (UNLIKELY(!algorithm)) {
+        throwNotSupportedError(state, scope);
+        return;
+    }
 
     auto callback = [capturedPromise = promise.copyRef()](const Vector<uint8_t>& cipherText) mutable {
         fulfillPromiseWithArrayBuffer(WTFMove(capturedPromise), cipherText.data(), cipherText.size());
@@ -543,8 +538,11 @@ static void jsSubtleCryptoFunctionDecryptPromise(ExecState& state, Ref<DeferredP
         return;
     }
 
-    auto algorithm = createAlgorithm(state, key->algorithmIdentifier());
-    RETURN_IF_EXCEPTION(scope, void());
+    auto algorithm = CryptoAlgorithmRegistry::singleton().create(key->algorithmIdentifier());
+    if (UNLIKELY(!algorithm)) {
+        throwNotSupportedError(state, scope);
+        return;
+    }
 
     auto callback = [capturedPromise = promise.copyRef()](const Vector<uint8_t>& plainText) mutable {
         fulfillPromiseWithArrayBuffer(WTFMove(capturedPromise), plainText.data(), plainText.size());
@@ -588,8 +586,11 @@ static void jsSubtleCryptoFunctionSignPromise(ExecState& state, Ref<DeferredProm
         return;
     }
 
-    auto algorithm = createAlgorithm(state, key->algorithmIdentifier());
-    RETURN_IF_EXCEPTION(scope, void());
+    auto algorithm = CryptoAlgorithmRegistry::singleton().create(key->algorithmIdentifier());
+    if (UNLIKELY(!algorithm)) {
+        throwNotSupportedError(state, scope);
+        return;
+    }
 
     auto callback = [capturedPromise = promise.copyRef()](const Vector<uint8_t>& signature) mutable {
         fulfillPromiseWithArrayBuffer(WTFMove(capturedPromise), signature.data(), signature.size());
@@ -636,8 +637,11 @@ static void jsSubtleCryptoFunctionVerifyPromise(ExecState& state, Ref<DeferredPr
         return;
     }
 
-    auto algorithm = createAlgorithm(state, key->algorithmIdentifier());
-    RETURN_IF_EXCEPTION(scope, void());
+    auto algorithm = CryptoAlgorithmRegistry::singleton().create(key->algorithmIdentifier());
+    if (UNLIKELY(!algorithm)) {
+        throwNotSupportedError(state, scope);
+        return;
+    }
 
     auto callback = [capturedPromise = promise.copyRef()](bool result) mutable {
         capturedPromise->resolve<IDLBoolean>(result);
@@ -668,8 +672,11 @@ static void jsSubtleCryptoFunctionDigestPromise(ExecState& state, Ref<DeferredPr
     auto data = toVector(state, state.uncheckedArgument(1));
     RETURN_IF_EXCEPTION(scope, void());
 
-    auto algorithm = createAlgorithm(state, params->identifier);
-    RETURN_IF_EXCEPTION(scope, void());
+    auto algorithm = CryptoAlgorithmRegistry::singleton().create(params->identifier);
+    if (UNLIKELY(!algorithm)) {
+        throwNotSupportedError(state, scope);
+        return;
+    }
 
     auto callback = [capturedPromise = promise.copyRef()](const Vector<uint8_t>& digest) mutable {
         fulfillPromiseWithArrayBuffer(WTFMove(capturedPromise), digest.data(), digest.size());
@@ -737,8 +744,11 @@ static void jsSubtleCryptoFunctionGenerateKeyPromise(ExecState& state, Ref<Defer
     auto keyUsages = cryptoKeyUsageBitmapFromJSValue(state, state.uncheckedArgument(2));
     RETURN_IF_EXCEPTION(scope, void());
 
-    auto algorithm = createAlgorithm(state, params->identifier);
-    RETURN_IF_EXCEPTION(scope, void());
+    auto algorithm = CryptoAlgorithmRegistry::singleton().create(params->identifier);
+    if (UNLIKELY(!algorithm)) {
+        throwNotSupportedError(state, scope);
+        return;
+    }
 
     auto callback = [capturedPromise = promise.copyRef()](KeyOrKeyPair&& keyOrKeyPair) mutable {
         WTF::switchOn(keyOrKeyPair,
@@ -793,8 +803,11 @@ static void jsSubtleCryptoFunctionImportKeyPromise(ExecState& state, Ref<Deferre
     auto keyUsages = cryptoKeyUsageBitmapFromJSValue(state, state.uncheckedArgument(4));
     RETURN_IF_EXCEPTION(scope, void());
 
-    auto algorithm = createAlgorithm(state, params->identifier);
-    RETURN_IF_EXCEPTION(scope, void());
+    auto algorithm = CryptoAlgorithmRegistry::singleton().create(params->identifier);
+    if (UNLIKELY(!algorithm)) {
+        throwNotSupportedError(state, scope);
+        return;
+    }
 
     auto callback = [capturedPromise = promise.copyRef()](CryptoKey& key) mutable {
         if ((key.type() == CryptoKeyType::Private || key.type() == CryptoKeyType::Secret) && !key.usagesBitmap()) {
@@ -829,7 +842,7 @@ static void jsSubtleCryptoFunctionExportKeyPromise(ExecState& state, Ref<Deferre
     auto key = toCryptoKey(state, state.uncheckedArgument(1));
     RETURN_IF_EXCEPTION(scope, void());
 
-    supportExportKeyThrow(state, key->algorithmIdentifier());
+    supportExportKeyThrow(state, scope, key->algorithmIdentifier());
     RETURN_IF_EXCEPTION(scope, void());
 
     if (!key->extractable()) {
@@ -837,8 +850,11 @@ static void jsSubtleCryptoFunctionExportKeyPromise(ExecState& state, Ref<Deferre
         return;
     }
 
-    auto algorithm = createAlgorithm(state, key->algorithmIdentifier());
-    RETURN_IF_EXCEPTION(scope, void());
+    auto algorithm = CryptoAlgorithmRegistry::singleton().create(key->algorithmIdentifier());
+    if (UNLIKELY(!algorithm)) {
+        throwNotSupportedError(state, scope);
+        return;
+    }
 
     auto callback = [capturedPromise = promise.copyRef()](SubtleCrypto::KeyFormat format, KeyData&& key) mutable {
         switch (format) {
@@ -904,7 +920,7 @@ static void jsSubtleCryptoFunctionWrapKeyPromise(ExecState& state, Ref<DeferredP
         return;
     }
 
-    supportExportKeyThrow(state, key->algorithmIdentifier());
+    supportExportKeyThrow(state, scope, key->algorithmIdentifier());
     RETURN_IF_EXCEPTION(scope, void());
 
     if (!key->extractable()) {
@@ -912,11 +928,17 @@ static void jsSubtleCryptoFunctionWrapKeyPromise(ExecState& state, Ref<DeferredP
         return;
     }
 
-    auto exportAlgorithm = createAlgorithm(state, key->algorithmIdentifier());
-    RETURN_IF_EXCEPTION(scope, void());
+    auto exportAlgorithm = CryptoAlgorithmRegistry::singleton().create(key->algorithmIdentifier());
+    if (UNLIKELY(!exportAlgorithm)) {
+        throwNotSupportedError(state, scope);
+        return;
+    }
 
-    auto wrapAlgorithm = createAlgorithm(state, wrappingKey->algorithmIdentifier());
-    RETURN_IF_EXCEPTION(scope, void());
+    auto wrapAlgorithm = CryptoAlgorithmRegistry::singleton().create(wrappingKey->algorithmIdentifier());
+    if (UNLIKELY(!wrapAlgorithm)) {
+        throwNotSupportedError(state, scope);
+        return;
+    }
 
     auto context = scriptExecutionContextFromExecState(&state);
 
@@ -1014,11 +1036,17 @@ static void jsSubtleCryptoFunctionUnwrapKeyPromise(ExecState& state, Ref<Deferre
         return;
     }
 
-    auto importAlgorithm = createAlgorithm(state, unwrappedKeyAlgorithm->identifier);
-    RETURN_IF_EXCEPTION(scope, void());
+    auto importAlgorithm = CryptoAlgorithmRegistry::singleton().create(unwrappedKeyAlgorithm->identifier);
+    if (UNLIKELY(!importAlgorithm)) {
+        throwNotSupportedError(state, scope);
+        return;
+    }
 
-    auto unwrapAlgorithm = createAlgorithm(state, unwrappingKey->algorithmIdentifier());
-    RETURN_IF_EXCEPTION(scope, void());
+    auto unwrapAlgorithm = CryptoAlgorithmRegistry::singleton().create(unwrappingKey->algorithmIdentifier());
+    if (UNLIKELY(!unwrapAlgorithm)) {
+        throwNotSupportedError(state, scope);
+        return;
+    }
 
     auto callback = [promise = promise.copyRef(), format, importAlgorithm, unwrappedKeyAlgorithm = WTFMove(unwrappedKeyAlgorithm), extractable, keyUsages](const Vector<uint8_t>& bytes) mutable {
         ExecState& state = *(promise->globalObject()->globalExec());
index 75a27d0..e792fc7 100644 (file)
@@ -62,62 +62,48 @@ enum class CryptoKeyFormat {
     JWK
 };
 
-static RefPtr<CryptoAlgorithm> createAlgorithmFromJSValue(ExecState& state, JSValue value)
+static RefPtr<CryptoAlgorithm> createAlgorithmFromJSValue(ExecState& state, ThrowScope& scope, JSValue value)
 {
-    VM& vm = state.vm();
-    auto scope = DECLARE_THROW_SCOPE(vm);
-
-    CryptoAlgorithmIdentifier algorithmIdentifier;
-    auto success = JSCryptoAlgorithmDictionary::getAlgorithmIdentifier(state, value, algorithmIdentifier);
-    ASSERT_UNUSED(scope, scope.exception() || success);
-    if (!success)
-        return nullptr;
+    auto algorithmIdentifier = JSCryptoAlgorithmDictionary::parseAlgorithmIdentifier(state, scope, value);
+    RETURN_IF_EXCEPTION(scope, { });
 
     auto result = CryptoAlgorithmRegistry::singleton().create(algorithmIdentifier);
     if (!result)
-        setDOMException(&state, scope, NOT_SUPPORTED_ERR);
+        throwNotSupportedError(state, scope);
+
     return result;
 }
 
-static bool cryptoKeyFormatFromJSValue(ExecState& state, JSValue value, CryptoKeyFormat& result)
+static CryptoKeyFormat cryptoKeyFormatFromJSValue(ExecState& state, ThrowScope& scope, JSValue value)
 {
-    VM& vm = state.vm();
-    auto scope = DECLARE_THROW_SCOPE(vm);
+    auto keyFormatString = value.toWTFString(&state);
+    RETURN_IF_EXCEPTION(scope, { });
 
-    String keyFormatString = value.toWTFString(&state);
-    RETURN_IF_EXCEPTION(scope, false);
     if (keyFormatString == "raw")
-        result = CryptoKeyFormat::Raw;
-    else if (keyFormatString == "pkcs8")
-        result = CryptoKeyFormat::PKCS8;
-    else if (keyFormatString == "spki")
-        result = CryptoKeyFormat::SPKI;
-    else if (keyFormatString == "jwk")
-        result = CryptoKeyFormat::JWK;
-    else {
-        throwTypeError(&state, scope, ASCIILiteral("Unknown key format"));
-        return false;
-    }
-    return true;
+        return CryptoKeyFormat::Raw;
+    if (keyFormatString == "pkcs8")
+        return CryptoKeyFormat::PKCS8;
+    if (keyFormatString == "spki")
+        return CryptoKeyFormat::SPKI;
+    if (keyFormatString == "jwk")
+        return CryptoKeyFormat::JWK;
+
+    throwTypeError(&state, scope, ASCIILiteral("Unknown key format"));
+    return { };
 }
 
-static bool cryptoKeyUsagesFromJSValue(ExecState& state, JSValue value, CryptoKeyUsageBitmap& result)
+static CryptoKeyUsageBitmap cryptoKeyUsagesFromJSValue(ExecState& state, ThrowScope& scope, JSValue value)
 {
-    VM& vm = state.vm();
-    auto scope = DECLARE_THROW_SCOPE(vm);
-
     if (!isJSArray(value)) {
         throwTypeError(&state, scope);
-        return false;
+        return { };
     }
 
-    result = 0;
-
+    CryptoKeyUsageBitmap result = 0;
     JSArray* array = asArray(value);
-    for (size_t i = 0; i < array->length(); ++i) {
-        JSValue element = array->getIndex(&state, i);
-        String usageString = element.toWTFString(&state);
-        RETURN_IF_EXCEPTION(scope, false);
+    for (unsigned i = 0; i < array->length(); ++i) {
+        auto usageString = array->getIndex(&state, i).toWTFString(&state);
+        RETURN_IF_EXCEPTION(scope, { });
         if (usageString == "encrypt")
             result |= CryptoKeyUsageEncrypt;
         else if (usageString == "decrypt")
@@ -135,7 +121,7 @@ static bool cryptoKeyUsagesFromJSValue(ExecState& state, JSValue value, CryptoKe
         else if (usageString == "unwrapKey")
             result |= CryptoKeyUsageUnwrapKey;
     }
-    return true;
+    return result;
 }
 
 JSValue JSWebKitSubtleCrypto::encrypt(ExecState& state)
@@ -146,15 +132,11 @@ JSValue JSWebKitSubtleCrypto::encrypt(ExecState& state)
     if (state.argumentCount() < 3)
         return throwException(&state, scope, createNotEnoughArgumentsError(&state));
 
-    auto algorithm = createAlgorithmFromJSValue(state, state.uncheckedArgument(0));
-    ASSERT(scope.exception() || algorithm);
-    if (!algorithm)
-        return jsUndefined();
+    auto algorithm = createAlgorithmFromJSValue(state, scope, state.uncheckedArgument(0));
+    RETURN_IF_EXCEPTION(scope, { });
 
-    auto parameters = JSCryptoAlgorithmDictionary::createParametersForEncrypt(state, algorithm->identifier(), state.uncheckedArgument(0));
-    ASSERT(scope.exception() || parameters);
-    if (!parameters)
-        return jsUndefined();
+    auto parameters = JSCryptoAlgorithmDictionary::createParametersForEncrypt(state, scope, algorithm->identifier(), state.uncheckedArgument(0));
+    RETURN_IF_EXCEPTION(scope, { });
 
     RefPtr<CryptoKey> key = JSCryptoKey::toWrapped(state.uncheckedArgument(1));
     if (!key)
@@ -162,15 +144,12 @@ JSValue JSWebKitSubtleCrypto::encrypt(ExecState& state)
 
     if (!key->allows(CryptoKeyUsageEncrypt)) {
         wrapped().document()->addConsoleMessage(MessageSource::JS, MessageLevel::Error, ASCIILiteral("Key usages do not include 'encrypt'"));
-        setDOMException(&state, scope, NOT_SUPPORTED_ERR);
+        throwNotSupportedError(state, scope);
         return jsUndefined();
     }
 
-    CryptoOperationData data;
-    auto success = cryptoOperationDataFromJSValue(state, state.uncheckedArgument(2), data);
-    ASSERT(scope.exception() || success);
-    if (!success)
-        return jsUndefined();
+    auto data = cryptoOperationDataFromJSValue(state, scope, state.uncheckedArgument(2));
+    RETURN_IF_EXCEPTION(scope, { });
 
     RefPtr<DeferredPromise> wrapper = createDeferredPromise(state, domWindow());
     auto promise = wrapper->promise();
@@ -198,15 +177,11 @@ JSValue JSWebKitSubtleCrypto::decrypt(ExecState& state)
     if (state.argumentCount() < 3)
         return throwException(&state, scope, createNotEnoughArgumentsError(&state));
 
-    auto algorithm = createAlgorithmFromJSValue(state, state.uncheckedArgument(0));
-    ASSERT(scope.exception() || algorithm);
-    if (!algorithm)
-        return jsUndefined();
+    auto algorithm = createAlgorithmFromJSValue(state, scope, state.uncheckedArgument(0));
+    RETURN_IF_EXCEPTION(scope, { });
 
-    auto parameters = JSCryptoAlgorithmDictionary::createParametersForDecrypt(state, algorithm->identifier(), state.uncheckedArgument(0));
-    ASSERT(scope.exception() || parameters);
-    if (!parameters)
-        return jsUndefined();
+    auto parameters = JSCryptoAlgorithmDictionary::createParametersForDecrypt(state, scope, algorithm->identifier(), state.uncheckedArgument(0));
+    RETURN_IF_EXCEPTION(scope, { });
 
     RefPtr<CryptoKey> key = JSCryptoKey::toWrapped(state.uncheckedArgument(1));
     if (!key)
@@ -214,15 +189,12 @@ JSValue JSWebKitSubtleCrypto::decrypt(ExecState& state)
 
     if (!key->allows(CryptoKeyUsageDecrypt)) {
         wrapped().document()->addConsoleMessage(MessageSource::JS, MessageLevel::Error, ASCIILiteral("Key usages do not include 'decrypt'"));
-        setDOMException(&state, NOT_SUPPORTED_ERR);
+        throwNotSupportedError(state, scope);
         return jsUndefined();
     }
 
-    CryptoOperationData data;
-    auto success = cryptoOperationDataFromJSValue(state, state.uncheckedArgument(2), data);
-    ASSERT(scope.exception() || success);
-    if (!success)
-        return jsUndefined();
+    auto data = cryptoOperationDataFromJSValue(state, scope, state.uncheckedArgument(2));
+    RETURN_IF_EXCEPTION(scope, { });
 
     RefPtr<DeferredPromise> wrapper = createDeferredPromise(state, domWindow());
     auto promise = wrapper->promise();
@@ -250,15 +222,11 @@ JSValue JSWebKitSubtleCrypto::sign(ExecState& state)
     if (state.argumentCount() < 3)
         return throwException(&state, scope, createNotEnoughArgumentsError(&state));
 
-    auto algorithm = createAlgorithmFromJSValue(state, state.uncheckedArgument(0));
-    ASSERT(scope.exception() || algorithm);
-    if (!algorithm)
-        return jsUndefined();
+    auto algorithm = createAlgorithmFromJSValue(state, scope, state.uncheckedArgument(0));
+    RETURN_IF_EXCEPTION(scope, { });
 
-    auto parameters = JSCryptoAlgorithmDictionary::createParametersForSign(state, algorithm->identifier(), state.uncheckedArgument(0));
-    ASSERT(scope.exception() || parameters);
-    if (!parameters)
-        return jsUndefined();
+    auto parameters = JSCryptoAlgorithmDictionary::createParametersForSign(state, scope, algorithm->identifier(), state.uncheckedArgument(0));
+    RETURN_IF_EXCEPTION(scope, { });
 
     RefPtr<CryptoKey> key = JSCryptoKey::toWrapped(state.uncheckedArgument(1));
     if (!key)
@@ -266,15 +234,12 @@ JSValue JSWebKitSubtleCrypto::sign(ExecState& state)
 
     if (!key->allows(CryptoKeyUsageSign)) {
         wrapped().document()->addConsoleMessage(MessageSource::JS, MessageLevel::Error, ASCIILiteral("Key usages do not include 'sign'"));
-        setDOMException(&state, NOT_SUPPORTED_ERR);
+        throwNotSupportedError(state, scope);
         return jsUndefined();
     }
 
-    CryptoOperationData data;
-    auto success = cryptoOperationDataFromJSValue(state, state.uncheckedArgument(2), data);
-    ASSERT(scope.exception() || success);
-    if (!success)
-        return jsUndefined();
+    auto data = cryptoOperationDataFromJSValue(state, scope, state.uncheckedArgument(2));
+    RETURN_IF_EXCEPTION(scope, { });
 
     RefPtr<DeferredPromise> wrapper = createDeferredPromise(state, domWindow());
     auto promise = wrapper->promise();
@@ -302,15 +267,11 @@ JSValue JSWebKitSubtleCrypto::verify(ExecState& state)
     if (state.argumentCount() < 4)
         return throwException(&state, scope, createNotEnoughArgumentsError(&state));
 
-    auto algorithm = createAlgorithmFromJSValue(state, state.uncheckedArgument(0));
-    ASSERT(scope.exception() || algorithm);
-    if (!algorithm)
-        return jsUndefined();
+    auto algorithm = createAlgorithmFromJSValue(state, scope, state.uncheckedArgument(0));
+    RETURN_IF_EXCEPTION(scope, { });
 
-    auto parameters = JSCryptoAlgorithmDictionary::createParametersForVerify(state, algorithm->identifier(), state.uncheckedArgument(0));
-    ASSERT(scope.exception() || parameters);
-    if (!parameters)
-        return jsUndefined();
+    auto parameters = JSCryptoAlgorithmDictionary::createParametersForVerify(state, scope, algorithm->identifier(), state.uncheckedArgument(0));
+    RETURN_IF_EXCEPTION(scope, { });
 
     RefPtr<CryptoKey> key = JSCryptoKey::toWrapped(state.uncheckedArgument(1));
     if (!key)
@@ -318,21 +279,15 @@ JSValue JSWebKitSubtleCrypto::verify(ExecState& state)
 
     if (!key->allows(CryptoKeyUsageVerify)) {
         wrapped().document()->addConsoleMessage(MessageSource::JS, MessageLevel::Error, ASCIILiteral("Key usages do not include 'verify'"));
-        setDOMException(&state, NOT_SUPPORTED_ERR);
+        throwNotSupportedError(state, scope);
         return jsUndefined();
     }
 
-    CryptoOperationData signature;
-    auto success = cryptoOperationDataFromJSValue(state, state.uncheckedArgument(2), signature);
-    ASSERT(scope.exception() || success);
-    if (!success)
-        return jsUndefined();
+    auto signature = cryptoOperationDataFromJSValue(state, scope, state.uncheckedArgument(2));
+    RETURN_IF_EXCEPTION(scope, { });
 
-    CryptoOperationData data;
-    success = cryptoOperationDataFromJSValue(state, state.uncheckedArgument(3), data);
-    ASSERT(scope.exception() || success);
-    if (!success)
-        return jsUndefined();
+    auto data = cryptoOperationDataFromJSValue(state, scope, state.uncheckedArgument(3));
+    RETURN_IF_EXCEPTION(scope, { });
 
     RefPtr<DeferredPromise> wrapper = createDeferredPromise(state, domWindow());
     auto promise = wrapper->promise();
@@ -360,21 +315,14 @@ JSValue JSWebKitSubtleCrypto::digest(ExecState& state)
     if (state.argumentCount() < 2)
         return throwException(&state, scope, createNotEnoughArgumentsError(&state));
 
-    auto algorithm = createAlgorithmFromJSValue(state, state.uncheckedArgument(0));
-    ASSERT(scope.exception() || algorithm);
-    if (!algorithm)
-        return jsUndefined();
+    auto algorithm = createAlgorithmFromJSValue(state, scope, state.uncheckedArgument(0));
+    RETURN_IF_EXCEPTION(scope, { });
 
-    auto parameters = JSCryptoAlgorithmDictionary::createParametersForDigest(state, algorithm->identifier(), state.uncheckedArgument(0));
-    ASSERT(scope.exception() || parameters);
-    if (!parameters)
-        return jsUndefined();
+    auto parameters = JSCryptoAlgorithmDictionary::createParametersForDigest(state, scope, algorithm->identifier(), state.uncheckedArgument(0));
+    RETURN_IF_EXCEPTION(scope, { });
 
-    CryptoOperationData data;
-    auto success = cryptoOperationDataFromJSValue(state, state.uncheckedArgument(1), data);
-    ASSERT(scope.exception() || success);
-    if (!success)
-        return jsUndefined();
+    auto data = cryptoOperationDataFromJSValue(state, scope, state.uncheckedArgument(1));
+    RETURN_IF_EXCEPTION(scope, { });
 
     RefPtr<DeferredPromise> wrapper = createDeferredPromise(state, domWindow());
     auto promise = wrapper->promise();
@@ -402,28 +350,19 @@ JSValue JSWebKitSubtleCrypto::generateKey(ExecState& state)
     if (state.argumentCount() < 1)
         return throwException(&state, scope, createNotEnoughArgumentsError(&state));
 
-    auto algorithm = createAlgorithmFromJSValue(state, state.uncheckedArgument(0));
-    ASSERT(scope.exception() || algorithm);
-    if (!algorithm)
-        return jsUndefined();
+    auto algorithm = createAlgorithmFromJSValue(state, scope, state.uncheckedArgument(0));
+    RETURN_IF_EXCEPTION(scope, { });
 
-    auto parameters = JSCryptoAlgorithmDictionary::createParametersForGenerateKey(state, algorithm->identifier(), state.uncheckedArgument(0));
-    ASSERT(scope.exception() || parameters);
-    if (!parameters)
-        return jsUndefined();
+    auto parameters = JSCryptoAlgorithmDictionary::createParametersForGenerateKey(state, scope, algorithm->identifier(), state.uncheckedArgument(0));
+    RETURN_IF_EXCEPTION(scope, { });
 
-    bool extractable = false;
-    if (state.argumentCount() >= 2) {
-        extractable = state.uncheckedArgument(1).toBoolean(&state);
-        RETURN_IF_EXCEPTION(scope, JSValue());
-    }
+    bool extractable = state.argument(1).toBoolean(&state);
+    RETURN_IF_EXCEPTION(scope, { });
 
     CryptoKeyUsageBitmap keyUsages = 0;
     if (state.argumentCount() >= 3) {
-        auto success = cryptoKeyUsagesFromJSValue(state, state.argument(2), keyUsages);
-        ASSERT(scope.exception() || success);
-        if (!success)
-            return jsUndefined();
+        keyUsages = cryptoKeyUsagesFromJSValue(state, scope, state.uncheckedArgument(2));
+        RETURN_IF_EXCEPTION(scope, { });
     }
 
     RefPtr<DeferredPromise> wrapper = createDeferredPromise(state, domWindow());
@@ -514,44 +453,29 @@ JSValue JSWebKitSubtleCrypto::importKey(ExecState& state)
     if (state.argumentCount() < 3)
         return throwException(&state, scope, createNotEnoughArgumentsError(&state));
 
-    CryptoKeyFormat keyFormat;
-    auto success = cryptoKeyFormatFromJSValue(state, state.argument(0), keyFormat);
-    ASSERT(scope.exception() || success);
-    if (!success)
-        return jsUndefined();
+    auto keyFormat = cryptoKeyFormatFromJSValue(state, scope, state.uncheckedArgument(0));
+    RETURN_IF_EXCEPTION(scope, { });
 
-    CryptoOperationData data;
-    success = cryptoOperationDataFromJSValue(state, state.uncheckedArgument(1), data);
-    ASSERT(scope.exception() || success);
-    if (!success)
-        return jsUndefined();
+    auto data = cryptoOperationDataFromJSValue(state, scope, state.uncheckedArgument(1));
+    RETURN_IF_EXCEPTION(scope, { });
 
     RefPtr<CryptoAlgorithm> algorithm;
     RefPtr<CryptoAlgorithmParametersDeprecated> parameters;
     if (!state.uncheckedArgument(2).isNull()) {
-        algorithm = createAlgorithmFromJSValue(state, state.uncheckedArgument(2));
-        ASSERT(scope.exception() || algorithm);
-        if (!algorithm)
-            return jsUndefined();
-
-        parameters = JSCryptoAlgorithmDictionary::createParametersForImportKey(state, algorithm->identifier(), state.uncheckedArgument(2));
-        ASSERT(scope.exception() || parameters);
-        if (!parameters)
-            return jsUndefined();
-    }
+        algorithm = createAlgorithmFromJSValue(state, scope, state.uncheckedArgument(2));
+        RETURN_IF_EXCEPTION(scope, { });
 
-    bool extractable = false;
-    if (state.argumentCount() >= 4) {
-        extractable = state.uncheckedArgument(3).toBoolean(&state);
-        RETURN_IF_EXCEPTION(scope, JSValue());
+        parameters = JSCryptoAlgorithmDictionary::createParametersForImportKey(state, scope, algorithm->identifier(), state.uncheckedArgument(2));
+        RETURN_IF_EXCEPTION(scope, { });
     }
 
+    bool extractable = state.argument(3).toBoolean(&state);
+    RETURN_IF_EXCEPTION(scope, JSValue());
+
     CryptoKeyUsageBitmap keyUsages = 0;
     if (state.argumentCount() >= 5) {
-        auto success = cryptoKeyUsagesFromJSValue(state, state.argument(4), keyUsages);
-        ASSERT(scope.exception() || success);
-        if (!success)
-            return jsUndefined();
+        keyUsages = cryptoKeyUsagesFromJSValue(state, scope, state.uncheckedArgument(4));
+        RETURN_IF_EXCEPTION(scope, { });
     }
 
     RefPtr<DeferredPromise> wrapper = createDeferredPromise(state, domWindow());
@@ -611,11 +535,8 @@ JSValue JSWebKitSubtleCrypto::exportKey(ExecState& state)
     if (state.argumentCount() < 2)
         return throwException(&state, scope, createNotEnoughArgumentsError(&state));
 
-    CryptoKeyFormat keyFormat;
-    auto success = cryptoKeyFormatFromJSValue(state, state.argument(0), keyFormat);
-    ASSERT(scope.exception() || success);
-    if (!success)
-        return jsUndefined();
+    auto keyFormat = cryptoKeyFormatFromJSValue(state, scope, state.uncheckedArgument(0));
+    RETURN_IF_EXCEPTION(scope, { });
 
     RefPtr<CryptoKey> key = JSCryptoKey::toWrapped(state.uncheckedArgument(1));
     if (!key)
@@ -644,11 +565,8 @@ JSValue JSWebKitSubtleCrypto::wrapKey(ExecState& state)
     if (state.argumentCount() < 4)
         return throwException(&state, scope, createNotEnoughArgumentsError(&state));
 
-    CryptoKeyFormat keyFormat;
-    auto success = cryptoKeyFormatFromJSValue(state, state.argument(0), keyFormat);
-    ASSERT(scope.exception() || success);
-    if (!success)
-        return jsUndefined();
+    auto keyFormat = cryptoKeyFormatFromJSValue(state, scope, state.uncheckedArgument(0));
+    RETURN_IF_EXCEPTION(scope, { });
 
     RefPtr<CryptoKey> key = JSCryptoKey::toWrapped(state.uncheckedArgument(1));
     if (!key)
@@ -660,19 +578,15 @@ JSValue JSWebKitSubtleCrypto::wrapKey(ExecState& state)
 
     if (!wrappingKey->allows(CryptoKeyUsageWrapKey)) {
         wrapped().document()->addConsoleMessage(MessageSource::JS, MessageLevel::Error, ASCIILiteral("Key usages do not include 'wrapKey'"));
-        setDOMException(&state, NOT_SUPPORTED_ERR);
+        throwNotSupportedError(state, scope);
         return jsUndefined();
     }
 
-    auto algorithm = createAlgorithmFromJSValue(state, state.uncheckedArgument(3));
-    ASSERT(scope.exception() || algorithm);
-    if (!algorithm)
-        return jsUndefined();
+    auto algorithm = createAlgorithmFromJSValue(state, scope, state.uncheckedArgument(3));
+    RETURN_IF_EXCEPTION(scope, { });
 
-    auto parameters = JSCryptoAlgorithmDictionary::createParametersForEncrypt(state, algorithm->identifier(), state.uncheckedArgument(3));
-    ASSERT(scope.exception() || parameters);
-    if (!parameters)
-        return jsUndefined();
+    auto parameters = JSCryptoAlgorithmDictionary::createParametersForEncrypt(state, scope, algorithm->identifier(), state.uncheckedArgument(3));
+    RETURN_IF_EXCEPTION(scope, { });
 
     RefPtr<DeferredPromise> wrapper = createDeferredPromise(state, domWindow());
     auto promise = wrapper->promise();
@@ -708,17 +622,11 @@ JSValue JSWebKitSubtleCrypto::unwrapKey(ExecState& state)
     if (state.argumentCount() < 5)
         return throwException(&state, scope, createNotEnoughArgumentsError(&state));
 
-    CryptoKeyFormat keyFormat;
-    auto success = cryptoKeyFormatFromJSValue(state, state.argument(0), keyFormat);
-    ASSERT(scope.exception() || success);
-    if (!success)
-        return jsUndefined();
+    auto keyFormat = cryptoKeyFormatFromJSValue(state, scope, state.uncheckedArgument(0));
+    RETURN_IF_EXCEPTION(scope, { });
 
-    CryptoOperationData wrappedKeyData;
-    success = cryptoOperationDataFromJSValue(state, state.uncheckedArgument(1), wrappedKeyData);
-    ASSERT(scope.exception() || success);
-    if (!success)
-        return jsUndefined();
+    auto wrappedKeyData = cryptoOperationDataFromJSValue(state, scope, state.uncheckedArgument(1));
+    RETURN_IF_EXCEPTION(scope, { });
 
     RefPtr<CryptoKey> unwrappingKey = JSCryptoKey::toWrapped(state.uncheckedArgument(2));
     if (!unwrappingKey)
@@ -726,45 +634,33 @@ JSValue JSWebKitSubtleCrypto::unwrapKey(ExecState& state)
 
     if (!unwrappingKey->allows(CryptoKeyUsageUnwrapKey)) {
         wrapped().document()->addConsoleMessage(MessageSource::JS, MessageLevel::Error, ASCIILiteral("Key usages do not include 'unwrapKey'"));
-        setDOMException(&state, NOT_SUPPORTED_ERR);
+        throwNotSupportedError(state, scope);
         return jsUndefined();
     }
 
-    auto unwrapAlgorithm = createAlgorithmFromJSValue(state, state.uncheckedArgument(3));
-    ASSERT(scope.exception() || unwrapAlgorithm);
-    if (!unwrapAlgorithm)
-        return jsUndefined();
-    auto unwrapAlgorithmParameters = JSCryptoAlgorithmDictionary::createParametersForDecrypt(state, unwrapAlgorithm->identifier(), state.uncheckedArgument(3));
-    ASSERT(scope.exception() || unwrapAlgorithmParameters);
-    if (!unwrapAlgorithmParameters)
-        return jsUndefined();
+    auto unwrapAlgorithm = createAlgorithmFromJSValue(state, scope, state.uncheckedArgument(3));
+    RETURN_IF_EXCEPTION(scope, { });
+
+    auto unwrapAlgorithmParameters = JSCryptoAlgorithmDictionary::createParametersForDecrypt(state, scope, unwrapAlgorithm->identifier(), state.uncheckedArgument(3));
+    RETURN_IF_EXCEPTION(scope, { });
 
     RefPtr<CryptoAlgorithm> unwrappedKeyAlgorithm;
     RefPtr<CryptoAlgorithmParametersDeprecated> unwrappedKeyAlgorithmParameters;
     if (!state.uncheckedArgument(4).isNull()) {
-        unwrappedKeyAlgorithm = createAlgorithmFromJSValue(state, state.uncheckedArgument(4));
-        ASSERT(scope.exception() || unwrappedKeyAlgorithm);
-        if (!unwrappedKeyAlgorithm)
-            return jsUndefined();
-
-        unwrappedKeyAlgorithmParameters = JSCryptoAlgorithmDictionary::createParametersForImportKey(state, unwrappedKeyAlgorithm->identifier(), state.uncheckedArgument(4));
-        ASSERT(scope.exception() || unwrappedKeyAlgorithmParameters);
-        if (!unwrappedKeyAlgorithmParameters)
-            return jsUndefined();
-    }
+        unwrappedKeyAlgorithm = createAlgorithmFromJSValue(state, scope, state.uncheckedArgument(4));
+        RETURN_IF_EXCEPTION(scope, { });
 
-    bool extractable = false;
-    if (state.argumentCount() >= 6) {
-        extractable = state.uncheckedArgument(5).toBoolean(&state);
-        RETURN_IF_EXCEPTION(scope, JSValue());
+        unwrappedKeyAlgorithmParameters = JSCryptoAlgorithmDictionary::createParametersForImportKey(state, scope, unwrappedKeyAlgorithm->identifier(), state.uncheckedArgument(4));
+        RETURN_IF_EXCEPTION(scope, { });
     }
 
+    bool extractable = state.argument(5).toBoolean(&state);
+    RETURN_IF_EXCEPTION(scope, { });
+
     CryptoKeyUsageBitmap keyUsages = 0;
     if (state.argumentCount() >= 7) {
-        auto success = cryptoKeyUsagesFromJSValue(state, state.argument(6), keyUsages);
-        ASSERT(scope.exception() || success);
-        if (!success)
-            return jsUndefined();
+        keyUsages = cryptoKeyUsagesFromJSValue(state, scope, state.uncheckedArgument(6));
+        RETURN_IF_EXCEPTION(scope, { });
     }
 
     RefPtr<DeferredPromise> wrapper = createDeferredPromise(state, domWindow());
index de94c5f..f770380 100644 (file)
@@ -134,7 +134,9 @@ JSValue JSXMLHttpRequest::send(ExecState& state)
 
     // FIXME: Is it correct to do this only after the paragraph code of code just above, or should we exit earlier?
     if (UNLIKELY(result.hasException())) {
-        propagateException(state, result.releaseException());
+        auto& vm = state.vm();
+        auto scope = DECLARE_THROW_SCOPE(vm);
+        propagateException(state, scope, result.releaseException());
         return { };
     }
 
@@ -146,7 +148,9 @@ JSValue JSXMLHttpRequest::responseText(ExecState& state) const
     auto result = wrapped().responseText();
 
     if (UNLIKELY(result.hasException())) {
-        propagateException(state, result.releaseException());
+        auto& vm = state.vm();
+        auto scope = DECLARE_THROW_SCOPE(vm);
+        propagateException(state, scope, result.releaseException());
         return { };
     }
 
index faed13a..9093c38 100644 (file)
@@ -27,6 +27,7 @@
 #include "JSXPathNSResolver.h"
 
 #include "JSCustomXPathNSResolver.h"
+#include "JSDOMBinding.h"
 
 using namespace JSC;
 
@@ -37,7 +38,14 @@ RefPtr<XPathNSResolver> JSXPathNSResolver::toWrapped(ExecState& state, JSValue v
     if (value.inherits(JSXPathNSResolver::info()))
         return &jsCast<JSXPathNSResolver*>(asObject(value))->wrapped();
 
-    return JSCustomXPathNSResolver::create(&state, value);
+    auto result = JSCustomXPathNSResolver::create(state, value);
+    if (UNLIKELY(result.hasException())) {
+        VM& vm = state.vm();
+        auto scope = DECLARE_THROW_SCOPE(vm);
+        propagateException(state, scope, result.releaseException());
+        return nullptr;
+    }
+    return result.releaseReturnValue();
 }
 
 } // namespace WebCore
index ebf0494..211c24b 100644 (file)
@@ -2683,29 +2683,26 @@ static ExceptionOr<std::unique_ptr<ArrayBufferContentsArray>> transferArrayBuffe
     return WTFMove(contents);
 }
 
-static void maybeThrowExceptionIfSerializationFailed(ExecState* exec, SerializationReturnCode code)
+static void maybeThrowExceptionIfSerializationFailed(ExecState& state, SerializationReturnCode code)
 {
-    auto& vm = exec->vm();
+    auto& vm = state.vm();
     auto scope = DECLARE_THROW_SCOPE(vm);
 
-    if (code == SerializationReturnCode::SuccessfullyCompleted)
-        return;
-    
     switch (code) {
+    case SerializationReturnCode::SuccessfullyCompleted:
+        break;
     case SerializationReturnCode::StackOverflowError:
-        throwException(exec, scope, createStackOverflowError(exec));
+        throwException(&state, scope, createStackOverflowError(&state));
         break;
     case SerializationReturnCode::ValidationError:
-        throwTypeError(exec, scope, ASCIILiteral("Unable to deserialize data."));
+        throwTypeError(&state, scope, ASCIILiteral("Unable to deserialize data."));
         break;
     case SerializationReturnCode::DataCloneError:
-        setDOMException(exec, DATA_CLONE_ERR);
+        throwDataCloneError(state, scope);
         break;
     case SerializationReturnCode::ExistingExceptionError:
     case SerializationReturnCode::UnspecifiedError:
         break;
-        break;
-    case SerializationReturnCode::SuccessfullyCompleted:
     case SerializationReturnCode::InterruptedExecutionError:
         ASSERT_NOT_REACHED();
     }
@@ -2744,7 +2741,7 @@ RefPtr<SerializedScriptValue> SerializedScriptValue::create(ExecState& exec, JSV
     auto code = CloneSerializer::serialize(&exec, value, dummyMessagePorts, dummyArrayBuffers, blobURLs, buffer);
 
     if (throwExceptions == Throwing)
-        maybeThrowExceptionIfSerializationFailed(&exec, code);
+        maybeThrowExceptionIfSerializationFailed(exec, code);
 
     if (code != SerializationReturnCode::SuccessfullyCompleted)
         return nullptr;
@@ -2834,7 +2831,7 @@ JSValue SerializedScriptValue::deserialize(ExecState& exec, JSGlobalObject* glob
 {
     DeserializationResult result = CloneDeserializer::deserialize(&exec, globalObject, messagePorts, m_arrayBufferContentsArray.get(), m_data, blobURLs, blobFilePaths);
     if (throwExceptions == Throwing)
-        maybeThrowExceptionIfSerializationFailed(&exec, result.second);
+        maybeThrowExceptionIfSerializationFailed(exec, result.second);
     return result.first ? result.first : jsNull();
 }
 
index 52614e5..f37e7bc 100644 (file)
@@ -34,57 +34,60 @@ using namespace JSC;
 
 namespace WebCore {
 
-EncodedJSValue JSC_HOST_CALL structuredCloneArrayBuffer(ExecState* execState)
+EncodedJSValue JSC_HOST_CALL structuredCloneArrayBuffer(ExecState* state)
 {
-    ASSERT(execState);
-    ASSERT(execState->argumentCount());
-    ASSERT(execState->lexicalGlobalObject());
+    ASSERT(state);
+    ASSERT(state->argumentCount());
+    ASSERT(state->lexicalGlobalObject());
 
-    ArrayBuffer* buffer = toUnsharedArrayBuffer(execState->uncheckedArgument(0));
+    auto* buffer = toUnsharedArrayBuffer(state->uncheckedArgument(0));
     if (!buffer) {
-        setDOMException(execState, DATA_CLONE_ERR);
-        return JSValue::encode(jsUndefined());
+        VM& vm = state->vm();
+        auto scope = DECLARE_THROW_SCOPE(vm);
+        throwDataCloneError(*state, scope);
+        return { };
     }
-
-    return JSValue::encode(JSArrayBuffer::create(execState->vm(), execState->lexicalGlobalObject()->arrayBufferStructure(ArrayBufferSharingMode::Default), ArrayBuffer::tryCreate(buffer->data(), buffer->byteLength())));
+    return JSValue::encode(JSArrayBuffer::create(state->vm(), state->lexicalGlobalObject()->arrayBufferStructure(ArrayBufferSharingMode::Default), ArrayBuffer::tryCreate(buffer->data(), buffer->byteLength())));
 }
 
-EncodedJSValue JSC_HOST_CALL structuredCloneArrayBufferView(ExecState* execState)
+EncodedJSValue JSC_HOST_CALL structuredCloneArrayBufferView(ExecState* state)
 {
-    ASSERT(execState);
-    ASSERT(execState->argumentCount());
+    ASSERT(state);
+    ASSERT(state->argumentCount());
 
-    JSValue value = execState->uncheckedArgument(0);
+    JSValue value = state->uncheckedArgument(0);
     auto* bufferView = jsDynamicDowncast<JSArrayBufferView*>(value);
     ASSERT(bufferView);
 
     auto* buffer = bufferView->unsharedBuffer();
     if (!buffer) {
-        setDOMException(execState, DATA_CLONE_ERR);
-        return JSValue::encode(jsUndefined());
+        VM& vm = state->vm();
+        auto scope = DECLARE_THROW_SCOPE(vm);
+        throwDataCloneError(*state, scope);
+        return { };
     }
     auto bufferClone = ArrayBuffer::tryCreate(buffer->data(), buffer->byteLength());
 
     if (jsDynamicDowncast<JSInt8Array*>(value))
-        return JSValue::encode(JSInt8Array::create(execState, bufferView->structure(), WTFMove(bufferClone), bufferView->byteOffset(), bufferView->length()));
+        return JSValue::encode(JSInt8Array::create(state, bufferView->structure(), WTFMove(bufferClone), bufferView->byteOffset(), bufferView->length()));
     if (jsDynamicDowncast<JSInt16Array*>(value))
-        return JSValue::encode(JSInt16Array::create(execState, bufferView->structure(), WTFMove(bufferClone), bufferView->byteOffset(), bufferView->length()));
+        return JSValue::encode(JSInt16Array::create(state, bufferView->structure(), WTFMove(bufferClone), bufferView->byteOffset(), bufferView->length()));
     if (jsDynamicDowncast<JSInt32Array*>(value))
-        return JSValue::encode(JSInt32Array::create(execState, bufferView->structure(), WTFMove(bufferClone), bufferView->byteOffset(), bufferView->length()));
+        return JSValue::encode(JSInt32Array::create(state, bufferView->structure(), WTFMove(bufferClone), bufferView->byteOffset(), bufferView->length()));
     if (jsDynamicDowncast<JSUint8Array*>(value))
-        return JSValue::encode(JSUint8Array::create(execState, bufferView->structure(), WTFMove(bufferClone), bufferView->byteOffset(), bufferView->length()));
+        return JSValue::encode(JSUint8Array::create(state, bufferView->structure(), WTFMove(bufferClone), bufferView->byteOffset(), bufferView->length()));
     if (jsDynamicDowncast<JSUint8ClampedArray*>(value))
-        return JSValue::encode(JSUint8ClampedArray::create(execState, bufferView->structure(), WTFMove(bufferClone), bufferView->byteOffset(), bufferView->length()));
+        return JSValue::encode(JSUint8ClampedArray::create(state, bufferView->structure(), WTFMove(bufferClone), bufferView->byteOffset(), bufferView->length()));
     if (jsDynamicDowncast<JSUint16Array*>(value))
-        return JSValue::encode(JSUint16Array::create(execState, bufferView->structure(), WTFMove(bufferClone), bufferView->byteOffset(), bufferView->length()));
+        return JSValue::encode(JSUint16Array::create(state, bufferView->structure(), WTFMove(bufferClone), bufferView->byteOffset(), bufferView->length()));
     if (jsDynamicDowncast<JSUint32Array*>(value))
-        return JSValue::encode(JSUint32Array::create(execState, bufferView->structure(), WTFMove(bufferClone), bufferView->byteOffset(), bufferView->length()));
+        return JSValue::encode(JSUint32Array::create(state, bufferView->structure(), WTFMove(bufferClone), bufferView->byteOffset(), bufferView->length()));
     if (jsDynamicDowncast<JSFloat32Array*>(value))
-        return JSValue::encode(JSFloat32Array::create(execState, bufferView->structure(), WTFMove(bufferClone), bufferView->byteOffset(), bufferView->length()));
+        return JSValue::encode(JSFloat32Array::create(state, bufferView->structure(), WTFMove(bufferClone), bufferView->byteOffset(), bufferView->length()));
     if (jsDynamicDowncast<JSFloat64Array*>(value))
-        return JSValue::encode(JSFloat64Array::create(execState, bufferView->structure(), WTFMove(bufferClone), bufferView->byteOffset(), bufferView->length()));
+        return JSValue::encode(JSFloat64Array::create(state, bufferView->structure(), WTFMove(bufferClone), bufferView->byteOffset(), bufferView->length()));
     if (jsDynamicDowncast<JSDataView*>(value))
-        return JSValue::encode(JSDataView::create(execState, bufferView->structure(), WTFMove(bufferClone), bufferView->byteOffset(), bufferView->length()));
+        return JSValue::encode(JSDataView::create(state, bufferView->structure(), WTFMove(bufferClone), bufferView->byteOffset(), bufferView->length()));
 
     ASSERT_NOT_REACHED();
     return JSValue::encode(jsUndefined());
index 7a5f694..24a5e8f 100644 (file)
 
 #pragma once
 
-#include <wtf/Noncopyable.h>
+#if ENABLE(SUBTLE_CRYPTO)
+
 #include <wtf/RefCounted.h>
 #include <wtf/TypeCasts.h>
 
-#if ENABLE(SUBTLE_CRYPTO)
-
 namespace WebCore {
 
 class CryptoAlgorithmParametersDeprecated : public RefCounted<CryptoAlgorithmParametersDeprecated> {
 public:
-    CryptoAlgorithmParametersDeprecated() { }
     virtual ~CryptoAlgorithmParametersDeprecated() { }
 
     enum class Class {
index 7797009..8c198a5 100644 (file)
@@ -34,17 +34,12 @@ namespace WebCore {
 
 class CryptoAlgorithmHmacKeyParamsDeprecated final : public CryptoAlgorithmParametersDeprecated {
 public:
-    CryptoAlgorithmHmacKeyParamsDeprecated()
-        : hasLength(false)
-    {
-    }
-
     // The inner hash function to use.
     CryptoAlgorithmIdentifier hash;
 
     // The length (in bytes) of the key to generate. If unspecified, the recommended length will be used,
     // which is the size of the associated hash function's block size.
-    bool hasLength;
+    bool hasLength { false };
     unsigned length;
 
     Class parametersClass() const override { return Class::HmacKeyParams; }
index 408187c..3f3c77a 100644 (file)
@@ -34,16 +34,12 @@ namespace WebCore {
 
 class CryptoAlgorithmRsaKeyGenParamsDeprecated final : public CryptoAlgorithmParametersDeprecated {
 public:
-    CryptoAlgorithmRsaKeyGenParamsDeprecated()
-        : hasHash(false)
-    {
-    }
     // The length, in bits, of the RSA modulus.
     unsigned modulusLength;
     // The RSA public exponent, encoded as BigInteger.
     Vector<uint8_t> publicExponent;
     // The hash algorith identifier
-    bool hasHash;
+    bool hasHash { false };
     CryptoAlgorithmIdentifier hash;
 
     Class parametersClass() const override { return Class::RsaKeyGenParams; }
index 255238d..d35f2bc 100644 (file)
@@ -34,17 +34,12 @@ namespace WebCore {
 
 class CryptoAlgorithmRsaOaepParamsDeprecated final : public CryptoAlgorithmParametersDeprecated {
 public:
-    CryptoAlgorithmRsaOaepParamsDeprecated()
-        : hasLabel(false)
-    {
-    }
-
     // The hash function to apply to the message.
     CryptoAlgorithmIdentifier hash;
 
     // The optional label/application data to associate with the message.
     // FIXME: Is there a difference between a missing label and an empty one? Perhaps we don't need the hasLabel member.
-    bool hasLabel;
+    bool hasLabel { false };
     Vector<uint8_t> label;
 
     Class parametersClass() const override { return Class::RsaOaepParams; }
index 51d9d47..ea46dd9 100644 (file)
@@ -228,18 +228,20 @@ void FileReader::fireEvent(const AtomicString& type)
     dispatchEvent(ProgressEvent::create(type, true, m_loader ? m_loader->bytesLoaded() : 0, m_loader ? m_loader->totalBytes() : 0));
 }
 
-RefPtr<ArrayBuffer> FileReader::arrayBufferResult() const
+std::optional<Variant<String, RefPtr<JSC::ArrayBuffer>>> FileReader::result() const
 {
     if (!m_loader || m_error)
-        return nullptr;
-    return m_loader->arrayBufferResult();
-}
-
-String FileReader::stringResult()
-{
-    if (!m_loader || m_error)
-        return String();
-    return m_loader->stringResult();
+        return std::nullopt;
+    if (m_readType == FileReaderLoader::ReadAsArrayBuffer) {
+        auto result = m_loader->arrayBufferResult();
+        if (!result)
+            return std::nullopt;
+        return { result };
+    }
+    String result = m_loader->stringResult();
+    if (result.isNull())
+        return std::nullopt;
+    return { WTFMove(result) };
 }
 
 } // namespace WebCore
index 6765416..c13a592 100644 (file)
@@ -45,7 +45,6 @@ class ArrayBuffer;
 namespace WebCore {
 
 class Blob;
-class ScriptExecutionContext;
 
 class FileReader final : public RefCounted<FileReader>, public ActiveDOMObject, public EventTargetWithInlineData, private FileReaderLoaderClient {
 public:
@@ -70,8 +69,7 @@ public:
     ReadyState readyState() const { return m_state; }
     RefPtr<FileError> error() { return m_error; }
     FileReaderLoader::ReadType readType() const { return m_readType; }
-    RefPtr<JSC::ArrayBuffer> arrayBufferResult() const;
-    String stringResult();
+    std::optional<Variant<String, RefPtr<JSC::ArrayBuffer>>> result() const;
 
     using RefCounted::ref;
     using RefCounted::deref;
index 86403bc..a033a3b 100644 (file)
@@ -50,8 +50,7 @@
 
     void abort();
 
-    // file data
-    [Custom] readonly attribute any result;
+    readonly attribute (DOMString or ArrayBuffer)? result;
 
     readonly attribute FileError error;