svaarala / duktape

Duktape - embeddable Javascript engine with a focus on portability and compact footprint
MIT License
5.97k stars 515 forks source link

Return string/buffer data for both plain values and boxed values #167

Open svaarala opened 9 years ago

svaarala commented 9 years ago

Currently e.g. duk_get_string() and duk_get_buffer() only operate on plain string/buffer values. If they're used with a String or Duktape.Buffer object they'll return NULL and zero length.

It might be more useful if the calls accepted String and Duktape.Buffer objects like plain values.

With Node.js Buffer and TypedArray bindings, they should similarly return pointers and lengths for Node.js Buffer, ArrayBuffer, and TypedArray/DataView values. Same boxed/unboxed issue also affects Number and Boolean types (e.g. duk_get_number() and duk_get_boolean()).

svaarala commented 9 years ago

A non-breaking change would be to add separate calls to get string/buffer data, with the calls accepting both plain and boxed strings/buffers, e.g.:

char *buf;
duk_size_t sz;

buf = (char *) duk_get_buffer_data(ctx, idx_mybuf, &sz);

The obvious question then is whether to deprecate duk_get_buffer() etc in Duktape 2.x.

svaarala commented 9 years ago

Related issue: #190.

svaarala commented 9 years ago

A solution for Duktape 1.4.0 would also be nice, but not mandatory.