diff options
Diffstat (limited to 'Source/JavaScriptCore/runtime/ToNativeFromValue.h')
-rw-r--r-- | Source/JavaScriptCore/runtime/ToNativeFromValue.h | 16 |
1 files changed, 11 insertions, 5 deletions
diff --git a/Source/JavaScriptCore/runtime/ToNativeFromValue.h b/Source/JavaScriptCore/runtime/ToNativeFromValue.h index 1d871a607..fd6184327 100644 --- a/Source/JavaScriptCore/runtime/ToNativeFromValue.h +++ b/Source/JavaScriptCore/runtime/ToNativeFromValue.h @@ -23,8 +23,7 @@ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#ifndef ToNativeFromValue_h -#define ToNativeFromValue_h +#pragma once #include "JSCJSValue.h" @@ -48,7 +47,14 @@ typename Adaptor::Type toNativeFromValue(ExecState* exec, JSValue value) return Adaptor::toNativeFromDouble(value.toNumber(exec)); } -} // namespace JSC - -#endif // ToNativeFromValue_h +template<typename Adaptor> +std::optional<typename Adaptor::Type> toNativeFromValueWithoutCoercion(JSValue value) +{ + if (!value.isNumber()) + return std::nullopt; + if (value.isInt32()) + return Adaptor::toNativeFromInt32WithoutCoercion(value.asInt32()); + return Adaptor::toNativeFromDoubleWithoutCoercion(value.asDouble()); +} +} // namespace JSC |