Skip to content

Commit

Permalink
Fix calling ToString on blob parts
Browse files Browse the repository at this point in the history
  • Loading branch information
andreiltd committed Nov 4, 2024
1 parent c64f6a1 commit 873c9ef
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 13 deletions.
19 changes: 10 additions & 9 deletions builtins/web/blob.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -327,18 +329,17 @@ bool Blob::append_value(JSContext *cx, HandleObject self, HandleValue val) {
auto src = reinterpret_cast<const uint8_t *>(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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -188,4 +188,4 @@
"Blob with type \"image/png\"": {
"status": "PASS"
}
}
}

0 comments on commit 873c9ef

Please sign in to comment.