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 c858281b6e9..73c556c3ed7 100644 --- a/dlls/jscript/arraybuf.c +++ b/dlls/jscript/arraybuf.c @@ -18,6 +18,7 @@
#include <limits.h> +#include <math.h>
#include "jscript.h"
@@ -715,6 +716,7 @@ static const builtin_info_t DataViewConstr_info = { X(Int16Array) \ X(Int32Array) \ X(Uint8Array) \ + X(Uint8ClampedArray) \ X(Uint16Array) \ X(Uint32Array) \ X(Float32Array) \ @@ -746,11 +748,20 @@ 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)); +} + static const struct typed_array_desc typed_array_descs[NUM_TYPEDARRAY_TYPES] = { [Int8Array_desc_idx] = { 1, get_s8, set_u8 }, [Int16Array_desc_idx] = { 2, get_s16, set_u16 }, [Int32Array_desc_idx] = { 4, get_s32, set_u32 }, [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 e5182fe4df0..42d52898892 100644 --- a/dlls/jscript/jscript.h +++ b/dlls/jscript/jscript.h @@ -104,6 +104,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 dcd8fa77663..e683dcf5f7b 100644 --- a/dlls/mshtml/tests/documentmode.js +++ b/dlls/mshtml/tests/documentmode.js @@ -4689,7 +4689,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", - ["Uint8ClampedArray",11], ["URL",10], ["ValidityState",10], ["VideoPlaybackQuality",11], ["WebGLActiveInfo",11], ["WebGLBuffer",11], ["WebGLContextEvent",11], + ["Uint8ClampedArray",10,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 7602ea96adb..150736dc438 100644 --- a/dlls/mshtml/tests/es5.js +++ b/dlls/mshtml/tests/es5.js @@ -2561,6 +2561,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() { @@ -2683,6 +2695,7 @@ sync_test("globals override", function() { "SyntaxError", "TypeError", "Uint8Array", + "Uint8ClampedArray", "Uint16Array", "Uint32Array", "unescape",
From: Gabriel Ivăncescu gabrielopcode@gmail.com
Signed-off-by: Gabriel Ivăncescu gabrielopcode@gmail.com --- dlls/jscript/arraybuf.c | 35 ++++++++++++++++++++++++------- dlls/mshtml/tests/documentmode.js | 2 +- 2 files changed, 28 insertions(+), 9 deletions(-)
diff --git a/dlls/jscript/arraybuf.c b/dlls/jscript/arraybuf.c index 73c556c3ed7..bbafe027e19 100644 --- a/dlls/jscript/arraybuf.c +++ b/dlls/jscript/arraybuf.c @@ -1242,9 +1242,9 @@ static const builtin_info_t TypedArrayConstr_info = { .call = Function_value, };
-static HRESULT init_typed_array_constructor(script_ctx_t *ctx, builtin_invoke_t func, const WCHAR *name, - const builtin_info_t *info, unsigned int type_idx) +static HRESULT init_typed_array_constructor(script_ctx_t *ctx, builtin_invoke_t func, const WCHAR *name, const builtin_info_t *info) { + const unsigned type_idx = info->class - FIRST_TYPEDARRAY_JSCLASS; TypedArrayInstance *prototype; HRESULT hres;
@@ -1280,6 +1280,20 @@ static HRESULT init_typed_array_constructor(script_ctx_t *ctx, builtin_invoke_t
HRESULT init_arraybuf_constructors(script_ctx_t *ctx) { + static const struct { + const WCHAR *name; + builtin_invoke_t constr_func; + const builtin_info_t *prototype_info; + } typed_arrays[] = { + { L"Int8Array", Int8ArrayConstr_value, &Int8Array_info }, + { L"Int16Array", Int16ArrayConstr_value, &Int16Array_info }, + { L"Int32Array", Int32ArrayConstr_value, &Int32Array_info }, + { L"Uint8Array", Uint8ArrayConstr_value, &Uint8Array_info }, + { L"Uint16Array", Uint16ArrayConstr_value, &Uint16Array_info }, + { L"Uint32Array", Uint32ArrayConstr_value, &Uint32Array_info }, + { L"Float32Array", Float32ArrayConstr_value, &Float32Array_info }, + { L"Float64Array", Float64ArrayConstr_value, &Float64Array_info }, + }; static const struct { const WCHAR *name; builtin_invoke_t get; @@ -1363,12 +1377,17 @@ HRESULT init_arraybuf_constructors(script_ctx_t *ctx) if(FAILED(hres)) return hres;
-#define X(name) \ - hres = init_typed_array_constructor(ctx, name##Constr_value, L"" #name, &name##_info, name##_desc_idx); \ - if(FAILED(hres)) \ - return hres; - ALL_TYPED_ARRAYS -#undef X + for(i = 0; i < ARRAY_SIZE(typed_arrays); i++) { + hres = init_typed_array_constructor(ctx, typed_arrays[i].constr_func, typed_arrays[i].name, typed_arrays[i].prototype_info); + if(FAILED(hres)) + return hres; + } + + if(ctx->version >= SCRIPTLANGUAGEVERSION_ES6) { + hres = init_typed_array_constructor(ctx, Uint8ClampedArrayConstr_value, L"Uint8ClampedArray", &Uint8ClampedArray_info); + if(FAILED(hres)) + return hres; + }
return hres; } diff --git a/dlls/mshtml/tests/documentmode.js b/dlls/mshtml/tests/documentmode.js index e683dcf5f7b..faabc7a3475 100644 --- a/dlls/mshtml/tests/documentmode.js +++ b/dlls/mshtml/tests/documentmode.js @@ -4689,7 +4689,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", - ["Uint8ClampedArray",10,10], ["URL",10], ["ValidityState",10], ["VideoPlaybackQuality",11], ["WebGLActiveInfo",11], ["WebGLBuffer",11], ["WebGLContextEvent",11], + ["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"
From: Gabriel Ivăncescu gabrielopcode@gmail.com
Signed-off-by: Gabriel Ivăncescu gabrielopcode@gmail.com --- dlls/jscript/object.c | 6 ++++-- dlls/mshtml/tests/documentmode.js | 18 ++++++++++++++++++ 2 files changed, 22 insertions(+), 2 deletions(-)
diff --git a/dlls/jscript/object.c b/dlls/jscript/object.c index 836b49e684c..353b22b528a 100644 --- a/dlls/jscript/object.c +++ b/dlls/jscript/object.c @@ -146,8 +146,10 @@ static HRESULT Object_valueOf(script_ctx_t *ctx, jsval_t vthis, WORD flags, unsi
TRACE("\n");
- if(is_null_disp(vthis)) { - if(r) *r = jsval_null_disp(); + if(is_null(vthis)) { + if(!ctx->html_mode || ctx->version >= SCRIPTLANGUAGEVERSION_ES5_1) + return JS_E_OBJECT_EXPECTED; + if(r) *r = vthis; return S_OK; }
diff --git a/dlls/mshtml/tests/documentmode.js b/dlls/mshtml/tests/documentmode.js index faabc7a3475..a930e216b5a 100644 --- a/dlls/mshtml/tests/documentmode.js +++ b/dlls/mshtml/tests/documentmode.js @@ -3264,6 +3264,24 @@ sync_test("nullDisp", function() { r = (nullDisp instanceof Object); ok(r === false, "nullDisp instance of Object");
+ try { + r = Object.prototype.valueOf.call(null); + ok(v < 10, "expected exception calling valueOf on null"); + ok(r === null, "valueOf null != null"); + }catch(e) { + ok(v >= 10, "did not expect exception calling valueOf on null"); + ok(e.number === 0xa138f - 0x80000000, "valueOf on null threw " + e.number); + } + + try { + r = Object.prototype.valueOf.call(nullDisp); + ok(v < 10, "expected exception calling valueOf on nullDisp"); + ok(r === nullDisp, "valueOf on nullDisp != nullDisp"); + }catch(e) { + ok(v >= 10, "did not expect exception calling valueOf on nullDisp"); + ok(e.number === 0xa138f - 0x80000000, "valueOf on nullDisp threw " + e.number); + } + if(v >= 8) { r = JSON.stringify.call(null, nullDisp); ok(r === "null", "JSON.stringify(nullDisp) returned " + r);