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

Implement set, get internal fields, & set internal field count #145

Merged
merged 6 commits into from
Oct 18, 2021

Conversation

wisepythagoras
Copy link
Contributor

I've implemented the Object.SetInternalField, Object.GetInternalField, and the ObjectTemplate.SetInternalFieldCount functions.

Is this a viable solution or am I missing something?

iso, _ := v8go.NewIsolate()
ctx, _ := v8go.NewContext(iso)

tmpl, _ := v8go.NewObjectTemplate(iso)
tmpl.SetInternalFieldCount(1)

obj, _ := tmpl.NewInstance(ctx)

obj.SetInternal(0, "baz")
v, err := obj.GetInternal(0)

v8go.cc Outdated Show resolved Hide resolved
@wisepythagoras
Copy link
Contributor Author

Could I get a review on this as well, @dylanahsmith or @rogchap?

v8go.cc Outdated Show resolved Hide resolved
object.go Outdated
inserted := C.ObjectSetInternal(o.ptr, C.uint32_t(idx), value.ptr)

if inserted == 0 {
return errors.New("v8go: index exceeded internal field count")
Copy link
Collaborator

Choose a reason for hiding this comment

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

These fields are internal to host/go code, so getting and setting them should be more like getting and setting a go slice. An index out of range error in Go is reported as a panic, so I think we should do the same here. This is because the error isn't something that we expect the caller to handle, but more an indication of a bug in the caller.
Likely the caller would be using these fields more like struct field anyways.

If the library user happens to be using these internal fields as a bounded array, then we could expose InternalFieldCount so the assignment can be conditional (similar using the len function on a slice)

Copy link
Collaborator

Choose a reason for hiding this comment

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

I pushed a commit to fix this, adding the panic and exposing the internal field count.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thank you, @dylanahsmith. I forgot to look into this.

v8go.cc Outdated Show resolved Hide resolved
@codecov
Copy link

codecov bot commented Oct 16, 2021

Codecov Report

Merging #145 (da656e5) into master (f75f288) will increase coverage by 0.14%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #145      +/-   ##
==========================================
+ Coverage   95.23%   95.38%   +0.14%     
==========================================
  Files          12       12              
  Lines         483      498      +15     
==========================================
+ Hits          460      475      +15     
  Misses         14       14              
  Partials        9        9              
Impacted Files Coverage Δ
object.go 100.00% <100.00%> (ø)
object_template.go 100.00% <100.00%> (ø)

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 f75f288...da656e5. Read the comment docs.

@dylanahsmith dylanahsmith merged commit 19ec71c into rogchap:master Oct 18, 2021
genevieve pushed a commit to Shopify/v8go that referenced this pull request Dec 14, 2021
…ap#145)

Co-authored-by: Dylan Thacker-Smith <[email protected]>
(cherry picked from commit 19ec71c)
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