return NJS_ERROR;
}
+ if (nargs > 2) {
+ options = njs_argument(args, 2);
+
+ if (njs_slow_path(!njs_is_object(options))) {
+ njs_type_error(vm, "The \"options\" argument must be "
+ "of type object");
+ return NJS_ERROR;
+ }
+
+ ret = njs_value_property(vm, options, NJS_ATOM_STRING_stream, retval);
+ if (njs_slow_path(ret == NJS_ERROR)) {
+ return ret;
+ }
+
+ stream = njs_bool(retval);
+ }
+
if (njs_fast_path(nargs > 1)) {
value = njs_argument(args, 1);
}
}
- if (nargs > 2) {
- options = njs_argument(args, 2);
-
- if (njs_slow_path(!njs_is_object(options))) {
- njs_type_error(vm, "The \"options\" argument must be "
- "of type object");
- return NJS_ERROR;
- }
-
- ret = njs_value_property(vm, options, NJS_ATOM_STRING_stream, retval);
- if (njs_slow_path(ret == NJS_ERROR)) {
- return ret;
- }
-
- stream = njs_bool(retval);
- }
-
data = njs_object_data(this);
if (!data->stream) {
return JS_ThrowTypeError(cx, "'this' is not a TextDecoder");
}
- ret = qjs_typed_array_data(cx, argv[0], &data);
- if (JS_IsException(ret)) {
- return ret;
- }
-
stream = 0;
if (argc > 1) {
JS_FreeValue(cx, ret);
}
+ ret = qjs_typed_array_data(cx, argv[0], &data);
+ if (JS_IsException(ret)) {
+ return ret;
+ }
+
end = data.start + data.length;
if (!td->stream) {
],
};
+let detached_options_tsuite = {
+ name: "TextDecoder() detach in options test",
+ skip: () => !is_detach_available(),
+
+ T: async (params) => {
+ let td = new TextDecoder('utf-8');
+ let uint8 = new Uint8Array(4096);
+ let input = params.buffer ? uint8.buffer : uint8;
+ let options = {
+ get stream() {
+ detach(uint8.buffer);
+ return false;
+ }
+ };
+
+ try {
+ td.decode(input, options);
+
+ } catch (e) {
+ if (e.toString().startsWith('TypeError:')) {
+ return 'SUCCESS';
+ }
+
+ throw e;
+ }
+
+ throw Error('Expected TypeError not thrown');
+ },
+
+ tests: [
+ { buffer: false },
+ { buffer: true },
+ ],
+};
+
run([
stream_tsuite,
reuse_tsuite,
ignoreBOM_tsuite,
detached_tsuite,
+ detached_options_tsuite,
])
.then($DONE, $DONE);