From: Gabriel Ivăncescu gabrielopcode@gmail.com
Signed-off-by: Gabriel Ivăncescu gabrielopcode@gmail.com --- dlls/jscript/arraybuf.c | 11 +++++++++++ dlls/jscript/jscript.h | 1 + dlls/jscript/object.c | 1 + dlls/mshtml/tests/documentmode.js | 2 +- dlls/mshtml/tests/es5.js | 13 +++++++++++++ 5 files changed, 27 insertions(+), 1 deletion(-)
diff --git a/dlls/jscript/arraybuf.c b/dlls/jscript/arraybuf.c index 560cb46ed5d..0ee3e79516c 100644 --- a/dlls/jscript/arraybuf.c +++ b/dlls/jscript/arraybuf.c @@ -17,6 +17,7 @@ */
+#include <math.h> #include <limits.h> #include <assert.h>
@@ -732,12 +733,21 @@ static void set_f32(void *p, double v) { *(float *)p = v; } static double get_f64(const void *p) { return *(const double *)p; } static void set_f64(void *p, double v) { *(double *)p = v; }
+static void set_clamped_u8(void *p, double v) +{ + if(!isfinite(v)) + *(UINT8 *)p = (v == INFINITY ? 255 : 0); + else + *(UINT8 *)p = (v >= 255.0 ? 255 : v <= 0 ? 0 : lround(v)); +} + /* NOTE: Keep in sync with the JSCLASS ordering of typed arrays */ #define ALL_TYPED_ARRAYS \ X(Int8Array) \ X(Int16Array) \ X(Int32Array) \ X(Uint8Array) \ +X(Uint8ClampedArray) \ X(Uint16Array) \ X(Uint32Array) \ X(Float32Array) \ @@ -754,6 +764,7 @@ static const struct typed_array_desc typed_array_descs[NUM_TYPEDARRAY_TYPES] = { [Int16Array_desc_idx] = { 2, get_s16, set_s16 }, [Int32Array_desc_idx] = { 4, get_s32, set_s32 }, [Uint8Array_desc_idx] = { 1, get_u8, set_u8 }, + [Uint8ClampedArray_desc_idx] = { 1, get_u8, set_clamped_u8 }, [Uint16Array_desc_idx] = { 2, get_u16, set_u16 }, [Uint32Array_desc_idx] = { 4, get_u32, set_u32 }, [Float32Array_desc_idx] = { 4, get_f32, set_f32 }, diff --git a/dlls/jscript/jscript.h b/dlls/jscript/jscript.h index 5c3478f1295..a1f2f80205a 100644 --- a/dlls/jscript/jscript.h +++ b/dlls/jscript/jscript.h @@ -117,6 +117,7 @@ typedef enum { JSCLASS_INT16ARRAY, JSCLASS_INT32ARRAY, JSCLASS_UINT8ARRAY, + JSCLASS_UINT8CLAMPEDARRAY, JSCLASS_UINT16ARRAY, JSCLASS_UINT32ARRAY, JSCLASS_FLOAT32ARRAY, diff --git a/dlls/jscript/object.c b/dlls/jscript/object.c index bda4d28ecef..836b49e684c 100644 --- a/dlls/jscript/object.c +++ b/dlls/jscript/object.c @@ -57,6 +57,7 @@ HRESULT Object_toString(script_ctx_t *ctx, jsval_t vthis, WORD flags, unsigned a L"[object Int16Array]", L"[object Int32Array]", L"[object Uint8Array]", + L"[object Uint8ClampedArray]", L"[object Uint16Array]", L"[object Uint32Array]", L"[object Float32Array]", diff --git a/dlls/mshtml/tests/documentmode.js b/dlls/mshtml/tests/documentmode.js index d8dc6763167..19baab64076 100644 --- a/dlls/mshtml/tests/documentmode.js +++ b/dlls/mshtml/tests/documentmode.js @@ -4663,7 +4663,7 @@ async_test("window own props", function() { "SVGScriptElement", "SVGStopElement", "SVGStringList", "SVGStyleElement", "SVGSwitchElement", "SVGSymbolElement", "SVGTextElement", "SVGTextPathElement", "SVGTitleElement", "SVGTransform", "SVGTransformList", "SVGUnitTypes", "SVGUseElement", "SVGViewElement", "SVGZoomAndPan", "SVGZoomEvent", "TextEvent", "TextMetrics", "TextRangeCollection", ["TextTrack",10], ["TextTrackCue",10], ["TextTrackCueList",10], ["TextTrackList",10], "TimeRanges", ["TrackEvent",10], ["TransitionEvent",10], "TreeWalker", ["Uint16Array",9,9], ["Uint32Array",9,9], - ["Uint8Array",9,9], ["Uint8ClampedArray",11], ["URL",10], ["ValidityState",10], ["VideoPlaybackQuality",11], ["WebGLActiveInfo",11], ["WebGLBuffer",11], ["WebGLContextEvent",11], + ["Uint8Array",9,9], ["Uint8ClampedArray",9,10], ["URL",10], ["ValidityState",10], ["VideoPlaybackQuality",11], ["WebGLActiveInfo",11], ["WebGLBuffer",11], ["WebGLContextEvent",11], ["WebGLFramebuffer",11], ["WebGLObject",11], ["WebGLProgram",11], ["WebGLRenderbuffer",11], ["WebGLRenderingContext",11], ["WebGLShader",11], ["WebGLShaderPrecisionFormat",11], ["WebGLTexture",11], ["WebGLUniformLocation",11], ["WEBGL_compressed_texture_s3tc",11], ["WEBGL_debug_renderer_info",11], ["WebSocket",10], "WheelEvent", ["Worker",10], ["XMLHttpRequestEventTarget",10], "XMLSerializer" diff --git a/dlls/mshtml/tests/es5.js b/dlls/mshtml/tests/es5.js index 5be512671e5..b426ab347c4 100644 --- a/dlls/mshtml/tests/es5.js +++ b/dlls/mshtml/tests/es5.js @@ -2550,6 +2550,18 @@ sync_test("ArrayBuffers & Views", function() { var n = ex.number >>> 0; ok(n === JS_E_NOT_TYPEDARRAY, "calling Uint32Array's subarray with Int32Array context threw " + n); } + + /* clamped array */ + arr = new Uint8ClampedArray(7); + arr2 = new Uint8Array(7); + arr.set ([42, -1, 999, 0.9, NaN, Infinity, -Infinity]); + arr2.set([42, -1, 999, 0.9, NaN, Infinity, -Infinity]); + for(var j = 0; j < 7; j++) { + ok(arr[j] === [42, 0, 255, 1, 0, 255, 0][j], "clamped arr[" + j + "] = " + arr[j]); + ok(arr2[j] === [42, 255, 231, 0, 0, 0, 0][j], "non-clamped arr[" + j + "] = " + arr2[j]); + } + r = Object.prototype.toString.call(arr); + ok(r === "[object Uint8ClampedArray]", "Object toString for Uint8ClampedArray = " + r); });
sync_test("builtin_context", function() { @@ -2672,6 +2684,7 @@ sync_test("globals override", function() { "SyntaxError", "TypeError", "Uint8Array", + "Uint8ClampedArray", "Uint16Array", "Uint32Array", "unescape",