@@ -314,7 +314,7 @@ DUK_LOCAL void duk__resolve_offset_opt_length(duk_context *ctx,
314314 return ;
315315
316316 fail_range :
317- DUK_ERROR_RANGE (thr , DUK_STR_INVALID_CALL_ARGS );
317+ DUK_ERROR_RANGE (thr , DUK_STR_INVALID_ARGS );
318318}
319319
320320/* Shared lenient buffer length clamping helper. No negative indices, no
@@ -618,7 +618,7 @@ DUK_INTERNAL duk_ret_t duk_bi_arraybuffer_constructor(duk_context *ctx) {
618618
619619 /* XXX: function flag to make this automatic? */
620620 if (!duk_is_constructor_call (ctx )) {
621- return DUK_RET_TYPE_ERROR ;
621+ DUK_DCERROR_TYPE_INVALID_ARGS ( thr ); /* reworked in another branch... */
622622 }
623623
624624 len = duk_to_int (ctx , 0 );
@@ -650,7 +650,7 @@ DUK_INTERNAL duk_ret_t duk_bi_arraybuffer_constructor(duk_context *ctx) {
650650 return 1 ;
651651
652652 fail_length :
653- return DUK_RET_RANGE_ERROR ;
653+ DUK_DCERROR_RANGE_INVALID_LENGTH ( thr ) ;
654654}
655655#endif /* DUK_USE_BUFFEROBJECT_SUPPORT */
656656
@@ -692,7 +692,7 @@ DUK_INTERNAL duk_ret_t duk_bi_typedarray_constructor(duk_context *ctx) {
692692
693693 /* XXX: function flag to make this automatic? */
694694 if (!duk_is_constructor_call (ctx )) {
695- return DUK_RET_TYPE_ERROR ;
695+ DUK_DCERROR_TYPE_INVALID_ARGS ( thr ); /* reworked in another branch... */
696696 }
697697
698698 /* We could fit built-in index into magic but that'd make the magic
@@ -795,7 +795,7 @@ DUK_INTERNAL duk_ret_t duk_bi_typedarray_constructor(duk_context *ctx) {
795795 proto_bidx );
796796 h_val = h_bufarg -> buf ;
797797 if (h_val == NULL ) {
798- return DUK_RET_TYPE_ERROR ;
798+ DUK_DCERROR_TYPE_INVALID_ARGS ( thr ) ;
799799 }
800800 h_bufobj -> buf = h_val ;
801801 DUK_HBUFFER_INCREF (thr , h_val );
@@ -821,7 +821,7 @@ DUK_INTERNAL duk_ret_t duk_bi_typedarray_constructor(duk_context *ctx) {
821821 DUK_ASSERT_HBUFOBJ_VALID (h_bufarg );
822822 elem_length_signed = (duk_int_t ) (h_bufarg -> length >> h_bufarg -> shift );
823823 if (h_bufarg -> buf == NULL ) {
824- return DUK_RET_TYPE_ERROR ;
824+ DUK_DCERROR_TYPE_INVALID_ARGS ( thr ) ;
825825 }
826826
827827 /* Select copy mode. Must take into account element
@@ -1026,7 +1026,7 @@ DUK_INTERNAL duk_ret_t duk_bi_typedarray_constructor(duk_context *ctx) {
10261026 return 1 ;
10271027
10281028 fail_arguments :
1029- return DUK_RET_RANGE_ERROR ;
1029+ DUK_DCERROR_RANGE_INVALID_ARGS ( thr ) ;
10301030}
10311031#endif /* DUK_USE_BUFFEROBJECT_SUPPORT */
10321032
@@ -1040,7 +1040,7 @@ DUK_INTERNAL duk_ret_t duk_bi_dataview_constructor(duk_context *ctx) {
10401040
10411041 /* XXX: function flag to make this automatic? */
10421042 if (!duk_is_constructor_call (ctx )) {
1043- return DUK_RET_TYPE_ERROR ;
1043+ DUK_DCERROR_TYPE_INVALID_ARGS (( duk_hthread * ) ctx ); /* reworked in another branch... */
10441044 }
10451045
10461046 h_bufarg = duk__require_bufobj_value (ctx , 0 );
@@ -1058,7 +1058,7 @@ DUK_INTERNAL duk_ret_t duk_bi_dataview_constructor(duk_context *ctx) {
10581058
10591059 h_val = h_bufarg -> buf ;
10601060 if (h_val == NULL ) {
1061- return DUK_RET_TYPE_ERROR ;
1061+ DUK_DCERROR_TYPE_INVALID_ARGS (( duk_hthread * ) ctx ) ;
10621062 }
10631063 h_bufobj -> buf = h_val ;
10641064 DUK_HBUFFER_INCREF (thr , h_val );
@@ -1183,7 +1183,7 @@ DUK_INTERNAL duk_ret_t duk_bi_nodejs_buffer_tostring(duk_context *ctx) {
11831183 DUK_ASSERT (buf_slice != NULL );
11841184
11851185 if (h_this -> buf == NULL ) {
1186- goto type_error ;
1186+ DUK_DCERROR_TYPE_INVALID_ARGS ( thr ) ;
11871187 }
11881188
11891189 /* XXX: it'd be tempting to duk_push_lstring() the data, but technically
@@ -1210,9 +1210,6 @@ DUK_INTERNAL duk_ret_t duk_bi_nodejs_buffer_tostring(duk_context *ctx) {
12101210 */
12111211 (void ) duk_buffer_to_string (ctx , -1 );
12121212 return 1 ;
1213-
1214- type_error :
1215- return DUK_RET_TYPE_ERROR ;
12161213}
12171214#endif /* DUK_USE_BUFFEROBJECT_SUPPORT */
12181215
@@ -1345,7 +1342,7 @@ DUK_INTERNAL duk_ret_t duk_bi_nodejs_buffer_fill(duk_context *ctx) {
13451342 h_this = duk__require_bufobj_this (ctx );
13461343 DUK_ASSERT (h_this != NULL );
13471344 if (h_this -> buf == NULL ) {
1348- return DUK_RET_TYPE_ERROR ;
1345+ DUK_DCERROR_TYPE_INVALID_ARGS ( thr ) ;
13491346 }
13501347
13511348 /* [ value offset end ] */
@@ -1553,7 +1550,7 @@ DUK_INTERNAL duk_ret_t duk_bi_nodejs_buffer_copy(duk_context *ctx) {
15531550 return 1 ;
15541551
15551552 fail_bounds :
1556- return DUK_RET_RANGE_ERROR ;
1553+ DUK_DCERROR_RANGE_INVALID_ARGS ( thr ) ;
15571554}
15581555#endif /* DUK_USE_BUFFEROBJECT_SUPPORT */
15591556
@@ -1625,21 +1622,22 @@ DUK_INTERNAL duk_ret_t duk_bi_typedarray_set(duk_context *ctx) {
16251622 */
16261623 offset_signed = duk_to_int (ctx , 1 );
16271624 if (offset_signed < 0 ) {
1628- return DUK_RET_TYPE_ERROR ;
1625+ /* For some reason this is a TypeError (at least in V8). */
1626+ DUK_DCERROR_TYPE_INVALID_ARGS (thr );
16291627 }
16301628 offset_elems = (duk_uint_t ) offset_signed ;
16311629 offset_bytes = offset_elems << h_this -> shift ;
16321630 if ((offset_bytes >> h_this -> shift ) != offset_elems ) {
16331631 /* Byte length would overflow. */
16341632 /* XXX: easier check with less code? */
1635- return DUK_RET_RANGE_ERROR ;
1633+ goto fail_args ;
16361634 }
16371635 if (offset_bytes > h_this -> length ) {
16381636 /* Equality may be OK but >length not. Checking
16391637 * this explicitly avoids some overflow cases
16401638 * below.
16411639 */
1642- return DUK_RET_RANGE_ERROR ;
1640+ goto fail_args ;
16431641 }
16441642 DUK_ASSERT (offset_bytes <= h_this -> length );
16451643
@@ -1677,7 +1675,7 @@ DUK_INTERNAL duk_ret_t duk_bi_typedarray_set(duk_context *ctx) {
16771675 if ((dst_length >> h_this -> shift ) != dst_length_elems ) {
16781676 /* Byte length would overflow. */
16791677 /* XXX: easier check with less code? */
1680- return DUK_RET_RANGE_ERROR ;
1678+ goto fail_args ;
16811679 }
16821680 DUK_DDD (DUK_DDDPRINT ("nominal size check: src_length=%ld, dst_length=%ld" ,
16831681 (long ) src_length , (long ) dst_length ));
@@ -1687,7 +1685,7 @@ DUK_INTERNAL duk_ret_t duk_bi_typedarray_set(duk_context *ctx) {
16871685 * side and guaranteed to be >= 0.
16881686 */
16891687 DUK_DDD (DUK_DDDPRINT ("copy exceeds target buffer nominal length" ));
1690- return DUK_RET_RANGE_ERROR ;
1688+ goto fail_args ;
16911689 }
16921690 if (!DUK_HBUFOBJ_VALID_BYTEOFFSET_EXCL (h_this , offset_bytes + dst_length )) {
16931691 DUK_DDD (DUK_DDDPRINT ("copy not covered by underlying target buffer, ignore" ));
@@ -1830,7 +1828,7 @@ DUK_INTERNAL duk_ret_t duk_bi_typedarray_set(duk_context *ctx) {
18301828 * side and guaranteed to be >= 0.
18311829 */
18321830 DUK_DDD (DUK_DDDPRINT ("copy exceeds target buffer nominal length" ));
1833- return DUK_RET_RANGE_ERROR ;
1831+ goto fail_args ;
18341832 }
18351833
18361834 /* There's no need to check for buffer validity status for the
@@ -1850,6 +1848,9 @@ DUK_INTERNAL duk_ret_t duk_bi_typedarray_set(duk_context *ctx) {
18501848 }
18511849
18521850 return 0 ;
1851+
1852+ fail_args :
1853+ DUK_DCERROR_RANGE_INVALID_ARGS (thr );
18531854}
18541855#endif /* DUK_USE_BUFFEROBJECT_SUPPORT */
18551856
@@ -1950,13 +1951,8 @@ DUK_INTERNAL duk_ret_t duk_bi_buffer_slice_shared(duk_context *ctx) {
19501951 * buffer (handled automatically by duk__require_bufobj_this()).
19511952 */
19521953
1953- #if 1
19541954 DUK_DDD (DUK_DDDPRINT ("slice() doesn't handle view into plain buffer, coerce 'this' to ArrayBuffer object" ));
19551955 /* fall through */
1956- #else
1957- DUK_DDD (DUK_DDDPRINT ("slice() doesn't handle view into plain buffer, refuse slice" ));
1958- return DUK_RET_TYPE_ERROR ;
1959- #endif
19601956 }
19611957 }
19621958 tv = NULL ; /* No longer valid nor needed. */
@@ -2016,7 +2012,7 @@ DUK_INTERNAL duk_ret_t duk_bi_buffer_slice_shared(duk_context *ctx) {
20162012
20172013 h_val = h_this -> buf ;
20182014 if (h_val == NULL ) {
2019- return DUK_RET_TYPE_ERROR ;
2015+ DUK_DCERROR_TYPE_INVALID_ARGS ( thr ) ;
20202016 }
20212017
20222018 if (magic & 0x02 ) {
@@ -2169,7 +2165,7 @@ DUK_INTERNAL duk_ret_t duk_bi_nodejs_buffer_concat(duk_context *ctx) {
21692165 /* Node.js accepts only actual Arrays. */
21702166 h_arg = duk_require_hobject (ctx , 0 );
21712167 if (DUK_HOBJECT_GET_CLASS_NUMBER (h_arg ) != DUK_HOBJECT_CLASS_ARRAY ) {
2172- return DUK_RET_TYPE_ERROR ;
2168+ DUK_DCERROR_TYPE_INVALID_ARGS ( thr ) ;
21732169 }
21742170
21752171 /* Compute result length and validate argument buffers. */
@@ -2201,7 +2197,7 @@ DUK_INTERNAL duk_ret_t duk_bi_nodejs_buffer_concat(duk_context *ctx) {
22012197 total_length = duk_to_int (ctx , 1 );
22022198 }
22032199 if (total_length < 0 ) {
2204- return DUK_RET_RANGE_ERROR ;
2200+ DUK_DCERROR_RANGE_INVALID_ARGS ( thr ) ;
22052201 }
22062202
22072203 h_bufres = duk_push_bufobj_raw (ctx ,
@@ -2533,8 +2529,7 @@ DUK_INTERNAL duk_ret_t duk_bi_buffer_readfield(duk_context *ctx) {
25332529 duk_push_nan (ctx );
25342530 return 1 ;
25352531 }
2536-
2537- return DUK_RET_RANGE_ERROR ;
2532+ DUK_DCERROR_RANGE_INVALID_ARGS (thr );
25382533}
25392534#endif /* DUK_USE_BUFFEROBJECT_SUPPORT */
25402535
@@ -2812,6 +2807,6 @@ DUK_INTERNAL duk_ret_t duk_bi_buffer_writefield(duk_context *ctx) {
28122807 duk_push_uint (ctx , offset + nbytes );
28132808 return 1 ;
28142809 }
2815- return DUK_RET_RANGE_ERROR ;
2810+ DUK_DCERROR_RANGE_INVALID_ARGS ( thr ) ;
28162811}
28172812#endif /* DUK_USE_BUFFEROBJECT_SUPPORT */
0 commit comments