@@ -3366,45 +3366,8 @@ uint8_t *output_buffer(JSObject *self) {
3366
3366
}
3367
3367
3368
3368
const unsigned ctor_length = 1 ;
3369
- JSObject *create (JSContext *cx, Format format);
3370
3369
bool check_receiver (JSContext *cx, HandleValue receiver, const char *method_name);
3371
3370
3372
- /* *
3373
- * https://wicg.github.io/compression/#dom-compressionstream-compressionstream
3374
- */
3375
- bool constructor (JSContext *cx, unsigned argc, Value *vp) {
3376
- // 1. If _format_ is unsupported in `CompressionStream`, then throw a
3377
- // `TypeError`.
3378
- CTOR_HEADER (" CompressionStream" , 1 );
3379
-
3380
- size_t format_len;
3381
- UniqueChars format_chars = encode (cx, args[0 ], &format_len);
3382
- if (!format_chars)
3383
- return false ;
3384
-
3385
- Format format;
3386
- if (!strcmp (format_chars.get (), " deflate" )) {
3387
- format = Format::Deflate;
3388
- } else if (!strcmp (format_chars.get (), " gzip" )) {
3389
- format = Format::GZIP;
3390
- } else {
3391
- JS_ReportErrorUTF8 (cx,
3392
- " 'format' has to be \" deflate\" or \" gzip\" , "
3393
- " but got \" %s\" " ,
3394
- format_chars.get ());
3395
- return false ;
3396
- }
3397
-
3398
- // Steps 2-6.
3399
- RootedObject stream (cx, create (cx, format));
3400
- if (!stream) {
3401
- return false ;
3402
- }
3403
-
3404
- args.rval ().setObject (*stream);
3405
- return true ;
3406
- }
3407
-
3408
3371
// Steps 1-5 of the transform algorithm, and 1-4 of the flush algorithm.
3409
3372
bool deflate_chunk (JSContext *cx, HandleObject self, HandleValue chunk, bool finished) {
3410
3373
z_stream *zstream = state (self);
@@ -3549,36 +3512,15 @@ const JSFunctionSpec methods[] = {JS_FS_END};
3549
3512
const JSPropertySpec properties[] = {JS_PSG (" readable" , readable_get, JSPROP_ENUMERATE),
3550
3513
JS_PSG (" writable" , writable_get, JSPROP_ENUMERATE), JS_PS_END};
3551
3514
3515
+ bool constructor (JSContext *cx, unsigned argc, Value *vp);
3516
+
3552
3517
CLASS_BOILERPLATE_CUSTOM_INIT (CompressionStream)
3553
3518
3554
3519
static PersistentRooted<JSObject *> transformAlgo;
3555
3520
static PersistentRooted<JSObject *> flushAlgo;
3556
3521
3557
- bool init_class (JSContext *cx, HandleObject global) {
3558
- if (!init_class_impl (cx, global)) {
3559
- return false ;
3560
- }
3561
-
3562
- JSFunction *transformFun = JS_NewFunction (cx, transformAlgorithm, 1 , 0 , " CS Transform" );
3563
- if (!transformFun)
3564
- return false ;
3565
- transformAlgo.init (cx, JS_GetFunctionObject (transformFun));
3566
-
3567
- JSFunction *flushFun = JS_NewFunction (cx, flushAlgorithm, 1 , 0 , " CS Flush" );
3568
- if (!flushFun)
3569
- return false ;
3570
- flushAlgo.init (cx, JS_GetFunctionObject (flushFun));
3571
-
3572
- return true ;
3573
- }
3574
-
3575
3522
// Steps 2-6 of `new CompressionStream()`.
3576
- JSObject *create (JSContext *cx, Format format) {
3577
- RootedObject stream (cx, JS_NewObjectWithGivenProto (cx, &class_, proto_obj));
3578
- if (!stream) {
3579
- return nullptr ;
3580
- }
3581
-
3523
+ JSObject *create (JSContext *cx, HandleObject stream, Format format) {
3582
3524
RootedValue stream_val (cx, ObjectValue (*stream));
3583
3525
3584
3526
// 2. Set this's format to _format_.
@@ -3640,6 +3582,62 @@ JSObject *create(JSContext *cx, Format format) {
3640
3582
3641
3583
return stream;
3642
3584
}
3585
+
3586
+ /* *
3587
+ * https://wicg.github.io/compression/#dom-compressionstream-compressionstream
3588
+ */
3589
+ bool constructor (JSContext *cx, unsigned argc, Value *vp) {
3590
+ // 1. If _format_ is unsupported in `CompressionStream`, then throw a
3591
+ // `TypeError`.
3592
+ CTOR_HEADER (" CompressionStream" , 1 );
3593
+
3594
+ size_t format_len;
3595
+ UniqueChars format_chars = encode (cx, args[0 ], &format_len);
3596
+ if (!format_chars)
3597
+ return false ;
3598
+
3599
+ Format format;
3600
+ if (!strcmp (format_chars.get (), " deflate" )) {
3601
+ format = Format::Deflate;
3602
+ } else if (!strcmp (format_chars.get (), " gzip" )) {
3603
+ format = Format::GZIP;
3604
+ } else {
3605
+ JS_ReportErrorUTF8 (cx,
3606
+ " 'format' has to be \" deflate\" or \" gzip\" , "
3607
+ " but got \" %s\" " ,
3608
+ format_chars.get ());
3609
+ return false ;
3610
+ }
3611
+
3612
+ RootedObject compressionStreamInstance (cx, JS_NewObjectForConstructor (cx, &class_, args));
3613
+ // Steps 2-6.
3614
+ RootedObject stream (cx, create (cx, compressionStreamInstance, format));
3615
+ if (!stream) {
3616
+ return false ;
3617
+ }
3618
+
3619
+ args.rval ().setObject (*stream);
3620
+ return true ;
3621
+ }
3622
+
3623
+ bool init_class (JSContext *cx, HandleObject global) {
3624
+ if (!init_class_impl (cx, global)) {
3625
+ return false ;
3626
+ }
3627
+
3628
+ JSFunction *transformFun = JS_NewFunction (cx, transformAlgorithm, 1 , 0 , " CS Transform" );
3629
+ if (!transformFun)
3630
+ return false ;
3631
+ transformAlgo.init (cx, JS_GetFunctionObject (transformFun));
3632
+
3633
+ JSFunction *flushFun = JS_NewFunction (cx, flushAlgorithm, 1 , 0 , " CS Flush" );
3634
+ if (!flushFun)
3635
+ return false ;
3636
+ flushAlgo.init (cx, JS_GetFunctionObject (flushFun));
3637
+
3638
+ return true ;
3639
+ }
3640
+
3643
3641
} // namespace CompressionStream
3644
3642
3645
3643
namespace CacheOverride {
0 commit comments