Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions indexeddb/idbblob/blob.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,15 @@ func newBlob(buf js.Value) *Blob {
return b
}

// jsWrapper is implemented by types that are backed by a JavaScript value.
type jsWrapper interface {
// JSValue returns a JavaScript value associated with an object.
JSValue() js.Value
}

// FromBlob creates a Blob from the given blob.Blob, either wrapping the JS value or copying the bytes if incompatible.
func FromBlob(b blob.Blob) *Blob {
if b, ok := b.(js.Wrapper); ok {
if b, ok := b.(jsWrapper); ok {
return newBlob(b.JSValue())
}
buf := b.Bytes()
Expand Down Expand Up @@ -90,7 +96,7 @@ func (b *Blob) Bytes() []byte {
return buf
}

// JSValue implements js.Wrapper
// JSValue implements JSWrapper
func (b *Blob) JSValue() js.Value {
return b.jsValue.Load().(js.Value)
}
Expand Down