Add String type, constructor functions for it and Value.AsString to cast to it
Problem
https://github.com/rogchap/v8go/pull/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 Report
Merging #277 (c6b856e) into master (5e91d3d) will decrease coverage by
1.09%. The diff coverage is56.25%.
@@ 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%) |
:arrow_down: |
| 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 dataPowered by Codecov. Last update 5e91d3d...c6b856e. Read the comment docs.