Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add String type, constructor functions for it and Value.AsString to cast to it #277

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

dylanahsmith
Copy link
Collaborator

Problem

#266 is attempting to add a constructor function for a V8 string, but we don't yet have a v8go.String type for it to return. It is also adding a constructor function with a NewString prefix for the edge case of binary strings, but there isn't yet a NewString function for the normal case. These seem like short-sighted API design decisions that are biased by what is currently available.

Solution

Add a String type, so that it can be used in APIs to better match the V8 APIs. We can latter extend this with v8::String methods, but this will still inherit all the Value methods through the embedded Value field.

The NewString function was added to use instead of NewValue, since individual constructors provide better type safety and are more in line with V8's API.

The MustNewString was added as a convenience method for constructing a V8 string from a Go literal string, where we know the function won't fail.

Value.AsString was also added for converting a Value to a String.

@codecov
Copy link

codecov bot commented Jan 14, 2022

Codecov Report

Merging #277 (c6b856e) into master (5e91d3d) will decrease coverage by 1.09%.
The diff coverage is 56.25%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #277      +/-   ##
==========================================
- Coverage   95.86%   94.76%   -1.10%     
==========================================
  Files          17       18       +1     
  Lines         580      592      +12     
==========================================
+ Hits          556      561       +5     
- Misses         15       20       +5     
- Partials        9       11       +2     
Impacted Files Coverage Δ
value.go 93.14% <40.00%> (-1.69%) ⬇️
string.go 63.63% <63.63%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 5e91d3d...c6b856e. Read the comment docs.

Copy link
Collaborator

@genevieve genevieve left a comment

Choose a reason for hiding this comment

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

Missing some test coverage otherwise lgtm

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants