Skip to content

Commit 3b2bb9b

Browse files
committed
src: remove decodeLatin1 function and related tests
1 parent 6a6c3c8 commit 3b2bb9b

File tree

4 files changed

+5
-87
lines changed

4 files changed

+5
-87
lines changed

src/encoding_binding.cc

Lines changed: 3 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ void BindingData::CreatePerIsolateProperties(IsolateData* isolate_data,
221221
SetMethodNoSideEffect(isolate, target, "decodeUTF8", DecodeUTF8);
222222
SetMethodNoSideEffect(isolate, target, "toASCII", ToASCII);
223223
SetMethodNoSideEffect(isolate, target, "toUnicode", ToUnicode);
224-
SetMethodNoSideEffect(isolate, target, "decodeLatin1", DecodeLatin1);
224+
// decodeLatin1 binding removed
225225
SetMethodNoSideEffect(
226226
isolate, target, "decodeWindows1252", DecodeWindows1252);
227227
}
@@ -241,55 +241,11 @@ void BindingData::RegisterTimerExternalReferences(
241241
registry->Register(DecodeUTF8);
242242
registry->Register(ToASCII);
243243
registry->Register(ToUnicode);
244-
registry->Register(DecodeLatin1);
244+
// DecodeLatin1 registration removed
245245
registry->Register(DecodeWindows1252);
246246
}
247247

248-
void BindingData::DecodeLatin1(const FunctionCallbackInfo<Value>& args) {
249-
Environment* env = Environment::GetCurrent(args);
250-
251-
CHECK_GE(args.Length(), 1);
252-
if (!(args[0]->IsArrayBuffer() || args[0]->IsSharedArrayBuffer() ||
253-
args[0]->IsArrayBufferView())) {
254-
return node::THROW_ERR_INVALID_ARG_TYPE(
255-
env->isolate(),
256-
"The \"input\" argument must be an instance of ArrayBuffer, "
257-
"SharedArrayBuffer, or ArrayBufferView.");
258-
}
259-
260-
bool ignore_bom = args[1]->IsTrue();
261-
bool has_fatal = args[2]->IsTrue();
262-
263-
ArrayBufferViewContents<uint8_t> buffer(args[0]);
264-
const uint8_t* data = buffer.data();
265-
size_t length = buffer.length();
266-
267-
if (ignore_bom && length > 0 && data[0] == 0xFF) {
268-
data++;
269-
length--;
270-
}
271-
272-
if (length == 0) {
273-
return args.GetReturnValue().SetEmptyString();
274-
}
275-
276-
std::string result(length * 2, '\0');
277-
278-
size_t written = simdutf::convert_latin1_to_utf8(
279-
reinterpret_cast<const char*>(data), length, result.data());
280-
281-
if (has_fatal && written == 0) {
282-
return node::THROW_ERR_ENCODING_INVALID_ENCODED_DATA(
283-
env->isolate(), "The encoded data was not valid for encoding latin1");
284-
}
285-
286-
std::string_view view(result.c_str(), written);
287-
288-
Local<Value> ret;
289-
if (ToV8Value(env->context(), view, env->isolate()).ToLocal(&ret)) {
290-
args.GetReturnValue().Set(ret);
291-
}
292-
}
248+
// DecodeLatin1 implementation removed
293249

294250
void BindingData::DecodeWindows1252(const FunctionCallbackInfo<Value>& args) {
295251
Environment* env = Environment::GetCurrent(args);

src/encoding_binding.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ class BindingData : public SnapshotableObject {
3131
static void EncodeInto(const v8::FunctionCallbackInfo<v8::Value>& args);
3232
static void EncodeUtf8String(const v8::FunctionCallbackInfo<v8::Value>& args);
3333
static void DecodeUTF8(const v8::FunctionCallbackInfo<v8::Value>& args);
34-
static void DecodeLatin1(const v8::FunctionCallbackInfo<v8::Value>& args);
34+
// DecodeLatin1 removed: no longer used
3535
static void DecodeWindows1252(
3636
const v8::FunctionCallbackInfo<v8::Value>& args);
3737

test/parallel/test-internal-encoding-binding.js

Lines changed: 1 addition & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -8,44 +8,7 @@ const assert = require('node:assert');
88
const { internalBinding } = require('internal/test/binding');
99
const binding = internalBinding('encoding_binding');
1010

11-
{
12-
// Valid input
13-
const buf = Uint8Array.from([0xC1, 0xE9, 0xF3]);
14-
assert.strictEqual(binding.decodeLatin1(buf, false, false), 'Áéó');
15-
}
16-
17-
{
18-
// Empty input
19-
const buf = Uint8Array.from([]);
20-
assert.strictEqual(binding.decodeLatin1(buf, false, false), '');
21-
}
22-
23-
{
24-
// Invalid input, but Latin1 has no invalid chars and should never throw.
25-
const buf = new TextEncoder().encode('Invalid Latin1 🧑‍🧑‍🧒‍🧒');
26-
assert.strictEqual(
27-
binding.decodeLatin1(buf, false, false),
28-
'Invalid Latin1 ð\x9F§\x91â\x80\x8Dð\x9F§\x91â\x80\x8Dð\x9F§\x92â\x80\x8Dð\x9F§\x92'
29-
);
30-
}
31-
32-
{
33-
// IgnoreBOM with BOM
34-
const buf = Uint8Array.from([0xFE, 0xFF, 0xC1, 0xE9, 0xF3]);
35-
assert.strictEqual(binding.decodeLatin1(buf, true, false), 'þÿÁéó');
36-
}
37-
38-
{
39-
// Fatal and InvalidInput, but Latin1 has no invalid chars and should never throw.
40-
const buf = Uint8Array.from([0xFF, 0xFF, 0xFF]);
41-
assert.strictEqual(binding.decodeLatin1(buf, false, true), 'ÿÿÿ');
42-
}
43-
44-
{
45-
// IgnoreBOM and Fatal, but Latin1 has no invalid chars and should never throw.
46-
const buf = Uint8Array.from([0xFE, 0xFF, 0xC1, 0xE9, 0xF3]);
47-
assert.strictEqual(binding.decodeLatin1(buf, true, true), 'þÿÁéó');
48-
}
11+
// decodeLatin1 tests removed: function no longer exists
4912

5013
// Windows-1252 specific tests
5114
{

typings/internalBinding/encoding_binding.d.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,5 @@ export interface EncodingBinding {
44
decodeUTF8(buffer: ArrayBufferView | ArrayBuffer | SharedArrayBuffer, ignoreBOM?: boolean, hasFatal?: boolean): string;
55
toASCII(input: string): string;
66
toUnicode(input: string): string;
7-
decodeLatin1(buffer: ArrayBufferView | ArrayBuffer | SharedArrayBuffer, ignoreBOM?: boolean, hasFatal?: boolean): string;
87
decodeWindows1252(buffer: ArrayBufferView | ArrayBuffer | SharedArrayBuffer, ignoreBOM?: boolean, hasFatal?: boolean): string;
98
}

0 commit comments

Comments
 (0)