Add String type, constructor functions for it and Value.AsString to cast to it #277
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.