Skip to content

Clamping versus trapping for invalid offsets #19

@wingo

Description

@wingo

stringview_wtf16.get_codeunit will trap on an invalid offset. However stringview_wtf16.encode or stringview_wtf16.slice will clamp operands within range. Should we make these more consistent?

One thing is that for stringview_wtf16.encode, there is a reasonable "null" answer that overlaps with the normal behavior: encoding nothing. Similar with slices. Whereas for stringview_wtf16.get_codeunit I guess you would define that -1 would be the exceptional answer, which, maybe it could "leak" to other parts of your program, e.g. if you mindlessly store it via i32.store16 to write U+FFFF. Also, the compiler can use the fact that out-of-range would throw to make an inference about the string length. But, these are relatively minor concerns, I think.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions