Implementing Blobs

32 views
Skip to first unread message

Christian Plesner Hansen

unread,
Aug 3, 2009, 9:00:53 AM8/3/09
to r...@tinyclouds.org, v8-...@googlegroups.com
Hi ry
It's great that you want to take a shot at this. The approach to
implementing Blobs outlined in the bug report
(http://code.google.com/p/v8/issues/detail?id=270) uses the internal
ByteArray type the same way the api's External type is backed by the
internal Proxy type. This means that you won't be able to pass a Blob
into javascript directly but have to wrap it as an internal object
field in an Object.

Since this is the same approach used to implement External you can use
that implementation as a guide. At the api level (include/v8.h) you
need at least the following:

- A class Blob which is a subclass of Value.
- A cast operator, Blob::Cast
- An allocation operation, Blob::New
- A query operator, Value::IsBlob.
- Methods for operating on Blobs
- Unit tests in test/cctest/test-api.cc

The implementation of these methods should be in api.h and api.cc. In
those files you can see how External is implemented on top of Proxy
and the implementation of Blob should follow the same pattern, based
on ByteArray. Some of the operations, Blob::New, Blob::Cast and
Value::IsBlob should be almost identical to the corresponding External
methods. The methods that operate on blobs can be implemented using
the member methods on ByteArray which is defined in objects.h.

This is just a short overview but I'm available to answer any
questions you might have. When you're ready to create a changlist you
can set me as the reviewer (see
http://dev.chromium.org/developers/contributing-code).


-- Christian

r...@tinyclouds.org

unread,
Nov 13, 2009, 9:36:02 AM11/13/09
to Christian Plesner Hansen, v8-...@googlegroups.com
Hi Christian

I finally got around to implementing Blob. It seems like its pretty
straight forward - I'm still missing a few methods but I thought I
should check to make sure it looks okay before continuing. In
particular, is using uint8_t for value okay?

Patch is attached.

On a side note: I just discovered
SetIndexedPropertiesToExternalArrayData() and
SetIndexedPropertiesToPixelData() which might serve me better than a
Blob. (I need to read/write data from a socket and I don't want to
memcpy.)

Ryan

blob.gitdiff

r...@tinyclouds.org

unread,
Nov 13, 2009, 2:30:50 PM11/13/09
to Christian Plesner Hansen, v8-...@googlegroups.com
Please look at this attached patch instead of the original. I've
cleaned it up and added a method GetAddress(). I assume that these
addresses could change on garbage collection (?), but it would be very
helpful to have such access so that I could recv() directly into the
V8 heap.

Are ByteArrays still uint8_t on x64?

blob2.gitdiff

Christian Plesner Hansen

unread,
Nov 14, 2009, 1:45:05 PM11/14/09
to r...@tinyclouds.org, v8-...@googlegroups.com
Thanks for the patch! I'll look it over on monday. Can I convince
you to upload it to our code review server? You can either use the
standard way (http://www.chromium.org/developers/contributing-code) or
git-cl (http://neugierig.org/software/git/?url=git-cl/).


-- Christian

Reply all
Reply to author
Forward
0 new messages