diff --git a/builtins/web/blob.cpp b/builtins/web/blob.cpp index 22854c2..b1491df 100644 --- a/builtins/web/blob.cpp +++ b/builtins/web/blob.cpp @@ -299,11 +299,13 @@ bool Blob::append_value(JSContext *cx, HandleObject self, HandleValue val) { if (Blob::is_instance(obj)) { auto src = Blob::blob(obj); blob->insert(blob->end(), src->begin(), src->end()); + return true; } else if (JS_IsArrayBufferViewObject(obj) || JS::IsArrayBufferObject(obj)) { auto span = value_to_buffer(cx, val, "Blob Parts"); if (span.has_value()) { blob->insert(blob->end(), span->begin(), span->end()); } + return true; } } else if (val.isString()) { auto s = val.toString(); @@ -327,18 +329,17 @@ bool Blob::append_value(JSContext *cx, HandleObject self, HandleValue val) { auto src = reinterpret_cast(JS::GetTwoByteLinearStringChars(nogc, str)); blob->insert(blob->end(), src, src + twoBytesLen); } - } else { - // convert to string by default - auto str = JS::ToString(cx, val); - if (!str) { - return false; - } + return true; + } - RootedValue str_val(cx, JS::StringValue(str)); - return append_value(cx, self, str_val); + // FALLBACK: if we ever get here convert, to string and call append again + auto str = JS::ToString(cx, val); + if (!str) { + return false; } - return true; + RootedValue str_val(cx, JS::StringValue(str)); + return append_value(cx, self, str_val); } bool Blob::init_blob_parts(JSContext *cx, HandleObject self, HandleValue value) { diff --git a/tests/wpt-harness/expectations/FileAPI/blob/Blob-constructor.any.js.json b/tests/wpt-harness/expectations/FileAPI/blob/Blob-constructor.any.js.json index 8158050..6da6233 100644 --- a/tests/wpt-harness/expectations/FileAPI/blob/Blob-constructor.any.js.json +++ b/tests/wpt-harness/expectations/FileAPI/blob/Blob-constructor.any.js.json @@ -45,13 +45,13 @@ "status": "FAIL" }, "Changes to the blobParts array should be reflected in the returned Blob (pop).": { - "status": "FAIL" + "status": "PASS" }, "Changes to the blobParts array should be reflected in the returned Blob (unshift).": { - "status": "FAIL" + "status": "PASS" }, "ToString should be called on elements of the blobParts array.": { - "status": "FAIL" + "status": "PASS" }, "ArrayBuffer elements of the blobParts array should be supported.": { "status": "PASS" @@ -188,4 +188,4 @@ "Blob with type \"image/png\"": { "status": "PASS" } -} +} \ No newline at end of file