Skip to content

Conversation

@krichprollsch
Copy link
Member

@krichprollsch krichprollsch commented May 12, 2025

Depends on #627

return error.InvalidUtf8Input;
}

// raw copy b/c we know the input is utf-8
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think you'll need to allocate, and can use v directly:

pub fn _encode(_: *const TextEncoder, v: []const u8) !Env.TypedArray(u8) {
  ....
  return .{.values = v}
}

If you did need to allocate, you could use the call_arena, which is shorter-lived, since the data gets copied into v8 anyways.

try runner.testCases(&.{
.{ "var encoder = new TextEncoder();", "undefined" },
.{ "encoder.encoding;", "utf-8" },
.{ "encoder.encode('€');", "Uint8Array(3) [226, 130, 172]" },
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Worth testing the error case.

@krichprollsch krichprollsch force-pushed the text-encoder branch 2 times, most recently from 71f8583 to e792257 Compare May 13, 2025 14:29
Copy link
Collaborator

@karlseguin karlseguin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@@ -0,0 +1,65 @@
// Copyright (C) 2023-2024 Lightpanda (Selecy SAS)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

2025?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good question. for now all the headers are to 2024. idk if we should update ti. I will talk that with @francisbouvier

const std = @import("std");

const Env = @import("../env.zig").Env;
const SessionState = @import("../env.zig").SessionState;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unused

@karlseguin karlseguin merged commit 0421420 into main May 13, 2025
9 checks passed
@karlseguin karlseguin deleted the text-encoder branch May 13, 2025 14:49
@github-actions github-actions bot locked and limited conversation to collaborators May 13, 2025
@krichprollsch krichprollsch changed the title WIP implement TextEncoder implement TextEncoder May 13, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants