1
1
#include " request-response.h"
2
2
#include " ../../../StarlingMonkey/builtins/web/base64.h"
3
- // #include "../../../StarlingMonkey/builtins/web/blob.h"
3
+ #include " ../../../StarlingMonkey/builtins/web/blob.h"
4
4
#include " ../../../StarlingMonkey/builtins/web/dom-exception.h"
5
5
#include " ../../../StarlingMonkey/builtins/web/streams/native-stream-source.h"
6
6
#include " ../../../StarlingMonkey/builtins/web/streams/transform-stream.h"
34
34
#pragma clang diagnostic pop
35
35
36
36
using builtins::web::base64::valueToJSByteString;
37
- // using builtins::web::blob::Blob;
38
- // using builtins::web::blob::BlobReader;
37
+ using builtins::web::blob::Blob;
38
+ using builtins::web::blob::BlobReader;
39
39
using builtins::web::dom_exception::DOMException;
40
40
41
41
// We use the StarlingMonkey Headers implementation, despite it supporting features that we do
@@ -360,9 +360,7 @@ bool RequestOrResponse::extract_body(JSContext *cx, JS::HandleObject self,
360
360
361
361
host_api::HostString host_type_str;
362
362
363
- // Blob support disabled pending bug fix in test
364
- // /override-content-length/request/init/object-literal/true
365
- /* if (body_obj && Blob::is_instance(body_obj)) {
363
+ if (Blob::is_instance (body_obj)) {
366
364
auto native_stream = NativeStreamSource::create (cx, body_obj, JS::UndefinedHandleValue,
367
365
Blob::stream_pull, Blob::stream_cancel);
368
366
if (!native_stream) {
@@ -396,8 +394,7 @@ bool RequestOrResponse::extract_body(JSContext *cx, JS::HandleObject self,
396
394
MOZ_ASSERT (host_type_str);
397
395
content_type = host_type_str.ptr .get ();
398
396
}
399
- } else */
400
- if (body_obj && JS::IsReadableStream (body_obj)) {
397
+ } else if (body_obj && JS::IsReadableStream (body_obj)) {
401
398
if (RequestOrResponse::body_unusable (cx, body_obj)) {
402
399
JS_ReportErrorNumberLatin1 (cx, FastlyGetErrorMessage, nullptr ,
403
400
JSMSG_READABLE_STREAM_LOCKED_OR_DISTRUBED);
@@ -584,9 +581,7 @@ bool RequestOrResponse::parse_body(JSContext *cx, JS::HandleObject self, JS::Uni
584
581
}
585
582
static_cast <void >(buf.release ());
586
583
result.setObject (*array_buffer);
587
- }
588
- // TODO: Blob support disabled pending bug fix
589
- /* else if constexpr (result_type == RequestOrResponse::BodyReadResult::Blob) {
584
+ } else if constexpr (result_type == RequestOrResponse::BodyReadResult::Blob) {
590
585
JS::RootedString contentType (cx, JS_GetEmptyString (cx));
591
586
JS::RootedObject blob (cx, Blob::create (cx, std::move (buf), len, contentType));
592
587
@@ -595,8 +590,7 @@ bool RequestOrResponse::parse_body(JSContext *cx, JS::HandleObject self, JS::Uni
595
590
}
596
591
597
592
result.setObject (*blob);
598
- } */
599
- else {
593
+ } else {
600
594
JS::RootedString text (cx, JS_NewStringCopyUTF8N (cx, JS::UTF8Chars (buf.get (), len)));
601
595
if (!text) {
602
596
return RejectPromiseWithPendingError (cx, result_promise);
@@ -1692,8 +1686,7 @@ const JSPropertySpec Request::static_properties[] = {
1692
1686
const JSFunctionSpec Request::methods[] = {
1693
1687
JS_FN (" arrayBuffer" , Request::bodyAll<RequestOrResponse::BodyReadResult::ArrayBuffer>, 0 ,
1694
1688
JSPROP_ENUMERATE),
1695
- // JS_FN("blob", Request::bodyAll<RequestOrResponse::BodyReadResult::Blob>, 0,
1696
- // JSPROP_ENUMERATE),
1689
+ JS_FN (" blob" , Request::bodyAll<RequestOrResponse::BodyReadResult::Blob>, 0 , JSPROP_ENUMERATE),
1697
1690
JS_FN (" json" , Request::bodyAll<RequestOrResponse::BodyReadResult::JSON>, 0 , JSPROP_ENUMERATE),
1698
1691
JS_FN (" text" , Request::bodyAll<RequestOrResponse::BodyReadResult::Text>, 0 , JSPROP_ENUMERATE),
1699
1692
JS_FN (" setCacheOverride" , Request::setCacheOverride, 3 , JSPROP_ENUMERATE),
@@ -1910,9 +1903,10 @@ JSObject *Request::create(JSContext *cx, JS::HandleObject requestInstance, JS::H
1910
1903
JS::RootedValue cache_override (cx);
1911
1904
JS::RootedValue cache_key (cx);
1912
1905
JS::RootedValue fastly_val (cx);
1913
- JS::RootedValue manualFramingHeaders (cx) ;
1914
- bool hasmanualFramingHeaders ;
1906
+ bool hasManualFramingHeaders = false ;
1907
+ bool setManualFramingHeaders = false ;
1915
1908
if (init_val.isObject ()) {
1909
+ JS::RootedValue manualFramingHeaders (cx);
1916
1910
JS::RootedObject init (cx, init_val.toObjectOrNull ());
1917
1911
if (!JS_GetProperty (cx, init, " method" , &method_val) ||
1918
1912
!JS_GetProperty (cx, init, " headers" , &headers_val) ||
@@ -1921,10 +1915,11 @@ JSObject *Request::create(JSContext *cx, JS::HandleObject requestInstance, JS::H
1921
1915
!JS_GetProperty (cx, init, " cacheOverride" , &cache_override) ||
1922
1916
!JS_GetProperty (cx, init, " cacheKey" , &cache_key) ||
1923
1917
!JS_GetProperty (cx, init, " fastly" , &fastly_val) ||
1924
- !JS_HasOwnProperty (cx, init, " manualFramingHeaders" , &hasmanualFramingHeaders ) ||
1918
+ !JS_HasOwnProperty (cx, init, " manualFramingHeaders" , &hasManualFramingHeaders ) ||
1925
1919
!JS_GetProperty (cx, init, " manualFramingHeaders" , &manualFramingHeaders)) {
1926
1920
return nullptr ;
1927
1921
}
1922
+ setManualFramingHeaders = manualFramingHeaders.isBoolean () && manualFramingHeaders.toBoolean ();
1928
1923
} else if (!init_val.isNullOrUndefined ()) {
1929
1924
JS_ReportErrorLatin1 (cx, " Request constructor: |init| parameter can't be converted to "
1930
1925
" a dictionary" );
@@ -2229,18 +2224,17 @@ JSObject *Request::create(JSContext *cx, JS::HandleObject requestInstance, JS::H
2229
2224
JS::BooleanValue (false ));
2230
2225
}
2231
2226
2232
- if (!hasmanualFramingHeaders ) {
2227
+ if (!hasManualFramingHeaders ) {
2233
2228
if (input_request) {
2234
- manualFramingHeaders.set (
2235
- JS::GetReservedSlot (input_request, static_cast <uint32_t >(Slots::ManualFramingHeaders)));
2236
- } else {
2237
- manualFramingHeaders.setBoolean (false );
2229
+ auto val =
2230
+ JS::GetReservedSlot (input_request, static_cast <uint32_t >(Slots::ManualFramingHeaders));
2231
+ setManualFramingHeaders = val.isBoolean () && val.toBoolean ();
2238
2232
}
2239
2233
}
2240
2234
JS::SetReservedSlot (request, static_cast <uint32_t >(Slots::ManualFramingHeaders),
2241
- JS::BooleanValue (JS::ToBoolean (manualFramingHeaders) ));
2235
+ JS::BooleanValue (setManualFramingHeaders ));
2242
2236
2243
- if (JS::ToBoolean (manualFramingHeaders) ) {
2237
+ if (setManualFramingHeaders ) {
2244
2238
auto res =
2245
2239
request_handle.set_framing_headers_mode (host_api::FramingHeadersMode::ManuallyFromHeaders);
2246
2240
if (auto *err = res.to_err ()) {
@@ -2947,7 +2941,7 @@ const JSPropertySpec Response::static_properties[] = {
2947
2941
const JSFunctionSpec Response::methods[] = {
2948
2942
JS_FN (" arrayBuffer" , bodyAll<RequestOrResponse::BodyReadResult::ArrayBuffer>, 0 ,
2949
2943
JSPROP_ENUMERATE),
2950
- // JS_FN("blob", bodyAll<RequestOrResponse::BodyReadResult::Blob>, 0, JSPROP_ENUMERATE),
2944
+ JS_FN (" blob" , bodyAll<RequestOrResponse::BodyReadResult::Blob>, 0 , JSPROP_ENUMERATE),
2951
2945
JS_FN (" json" , bodyAll<RequestOrResponse::BodyReadResult::JSON>, 0 , JSPROP_ENUMERATE),
2952
2946
JS_FN (" text" , bodyAll<RequestOrResponse::BodyReadResult::Text>, 0 , JSPROP_ENUMERATE),
2953
2947
JS_FN (" setManualFramingHeaders" , Response::setManualFramingHeaders, 1 , JSPROP_ENUMERATE),
0 commit comments