diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-06-12 05:35:29 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-06-12 05:35:29 +0000 |
commit | 59203c63bb777a3bacec32fb8830fba33540e809 (patch) | |
tree | 58298e711c0ff0575818c30485b44a2f21bf28a0 /js/src/builtin/DataViewObject.cpp | |
parent | Adding upstream version 126.0.1. (diff) | |
download | firefox-59203c63bb777a3bacec32fb8830fba33540e809.tar.xz firefox-59203c63bb777a3bacec32fb8830fba33540e809.zip |
Adding upstream version 127.0.upstream/127.0
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'js/src/builtin/DataViewObject.cpp')
-rw-r--r-- | js/src/builtin/DataViewObject.cpp | 80 |
1 files changed, 79 insertions, 1 deletions
diff --git a/js/src/builtin/DataViewObject.cpp b/js/src/builtin/DataViewObject.cpp index 425fdce51d..9c3e8edcc6 100644 --- a/js/src/builtin/DataViewObject.cpp +++ b/js/src/builtin/DataViewObject.cpp @@ -27,6 +27,7 @@ #include "util/DifferentialTesting.h" #include "vm/ArrayBufferObject.h" #include "vm/Compartment.h" +#include "vm/Float16.h" #include "vm/GlobalObject.h" #include "vm/Interpreter.h" #include "vm/JSContext.h" @@ -416,6 +417,16 @@ NativeType DataViewObject::read(uint64_t offset, size_t length, return val; } +#ifdef NIGHTLY_BUILD +template <> +float16 DataViewObject::read(uint64_t offset, size_t length, + bool isLittleEndian) { + float16 val{}; + val.val = read<uint16_t>(offset, length, isLittleEndian); + return val; +} +#endif + template uint32_t DataViewObject::read(uint64_t offset, size_t length, bool isLittleEndian); @@ -499,6 +510,19 @@ inline bool WebIDLCast<uint64_t>(JSContext* cx, HandleValue value, return true; } +#ifdef NIGHTLY_BUILD +template <> +inline bool WebIDLCast<float16>(JSContext* cx, HandleValue value, + float16* out) { + double temp; + if (!ToNumber(cx, value, &temp)) { + return false; + } + *out = float16(temp); + return true; +} +#endif + template <> inline bool WebIDLCast<float>(JSContext* cx, HandleValue value, float* out) { double temp; @@ -537,7 +561,11 @@ bool DataViewObject::write(JSContext* cx, Handle<DataViewObject*> obj, // See the comment in ElementSpecific::doubleToNative. if (js::SupportDifferentialTesting() && TypeIsFloatingPoint<NativeType>()) { - value = JS::CanonicalizeNaN(value); + if constexpr (std::is_same_v<NativeType, float16>) { + value = JS::CanonicalizeNaN(value.toDouble()); + } else { + value = JS::CanonicalizeNaN(value); + } } // Step 6. @@ -739,6 +767,28 @@ bool DataViewObject::fun_getBigUint64(JSContext* cx, unsigned argc, Value* vp) { return CallNonGenericMethod<IsDataView, getBigUint64Impl>(cx, args); } +#ifdef NIGHTLY_BUILD +bool DataViewObject::getFloat16Impl(JSContext* cx, const CallArgs& args) { + MOZ_ASSERT(IsDataView(args.thisv())); + + Rooted<DataViewObject*> thisView( + cx, &args.thisv().toObject().as<DataViewObject>()); + + float16 val{}; + if (!read(cx, thisView, args, &val)) { + return false; + } + + args.rval().setDouble(CanonicalizeNaN(val.toDouble())); + return true; +} + +bool DataViewObject::fun_getFloat16(JSContext* cx, unsigned argc, Value* vp) { + CallArgs args = CallArgsFromVp(argc, vp); + return CallNonGenericMethod<IsDataView, getFloat16Impl>(cx, args); +} +#endif + bool DataViewObject::getFloat32Impl(JSContext* cx, const CallArgs& args) { MOZ_ASSERT(IsDataView(args.thisv())); @@ -927,6 +977,26 @@ bool DataViewObject::fun_setBigUint64(JSContext* cx, unsigned argc, Value* vp) { return CallNonGenericMethod<IsDataView, setBigUint64Impl>(cx, args); } +#ifdef NIGHTLY_BUILD +bool DataViewObject::setFloat16Impl(JSContext* cx, const CallArgs& args) { + MOZ_ASSERT(IsDataView(args.thisv())); + + Rooted<DataViewObject*> thisView( + cx, &args.thisv().toObject().as<DataViewObject>()); + + if (!write<float16>(cx, thisView, args)) { + return false; + } + args.rval().setUndefined(); + return true; +} + +bool DataViewObject::fun_setFloat16(JSContext* cx, unsigned argc, Value* vp) { + CallArgs args = CallArgsFromVp(argc, vp); + return CallNonGenericMethod<IsDataView, setFloat16Impl>(cx, args); +} +#endif + bool DataViewObject::setFloat32Impl(JSContext* cx, const CallArgs& args) { MOZ_ASSERT(IsDataView(args.thisv())); @@ -1083,6 +1153,10 @@ const JSFunctionSpec DataViewObject::methods[] = { DataViewGetInt32), JS_INLINABLE_FN("getUint32", DataViewObject::fun_getUint32, 1, 0, DataViewGetUint32), +#ifdef NIGHTLY_BUILD + // TODO: See Bug 1835034 for JIT support for Float16Array + JS_FN("getFloat16", DataViewObject::fun_getFloat16, 1, 0), +#endif JS_INLINABLE_FN("getFloat32", DataViewObject::fun_getFloat32, 1, 0, DataViewGetFloat32), JS_INLINABLE_FN("getFloat64", DataViewObject::fun_getFloat64, 1, 0, @@ -1103,6 +1177,10 @@ const JSFunctionSpec DataViewObject::methods[] = { DataViewSetInt32), JS_INLINABLE_FN("setUint32", DataViewObject::fun_setUint32, 2, 0, DataViewSetUint32), +#ifdef NIGHTLY_BUILD + // TODO: See Bug 1835034 for JIT support for Float16Array + JS_FN("setFloat16", DataViewObject::fun_setFloat16, 2, 0), +#endif JS_INLINABLE_FN("setFloat32", DataViewObject::fun_setFloat32, 2, 0, DataViewSetFloat32), JS_INLINABLE_FN("setFloat64", DataViewObject::fun_setFloat64, 2, 0, |