Browse Source

Merge pull request #1242 from svaarala/arraybuffer-allocplain-plainof-fixes

Fix some ArrayBuffer.{allocPlain,plainOf} -> Uint8Array references
pull/1114/merge
Sami Vaarala 8 years ago
committed by GitHub
parent
commit
ad732827d6
  1. 4
      RELEASES.rst
  2. 8
      debugger/duk_debug_proxy.js
  3. 2
      dukweb/dukweb.html
  4. 4
      examples/debug-trans-dvalue/test.c
  5. 12
      polyfills/duktape-buffer.js
  6. 4
      src-input/duk_bi_buffer.c

4
RELEASES.rst

@ -1696,8 +1696,8 @@ Planned
* Incompatible change: remove Duktape.Buffer custom built-in, ArrayBuffer
now serves its place; the following new bindings provide functionality
roughly equivalent to Duktape.Buffer: ArrayBuffer.allocPlain() and
ArrayBuffer.plainOf(), however, the ability of doing a 1:1 buffer-to-string
roughly equivalent to Duktape.Buffer: Uint8Array.allocPlain() and
Uint8Array.plainOf(), however, the ability of doing a 1:1 buffer-to-string
coercion (using buffer data directly as the internal string representation)
has been removed (GH-875, GH-1005)

8
debugger/duk_debug_proxy.js

@ -35,10 +35,10 @@ var TORTURE = false; // for manual testing of binary/json parsing robustness
* Duktape 1.x and 2.x buffer harmonization
*/
var allocPlain = (typeof ArrayBuffer.allocPlain === 'function' ?
ArrayBuffer.allocPlain : Duktape.Buffer);
var plainOf = (typeof ArrayBuffer.plainOf === 'function' ?
ArrayBuffer.plainOf : Duktape.Buffer);
var allocPlain = (typeof Uint8Array.allocPlain === 'function' ?
Uint8Array.allocPlain : Duktape.Buffer);
var plainOf = (typeof Uint8Array.plainOf === 'function' ?
Uint8Array.plainOf : Duktape.Buffer);
var bufferToString = (typeof String.fromBuffer === 'function' ?
String.fromBuffer : String);

2
dukweb/dukweb.html

@ -26,7 +26,7 @@ fragment identifier: <a href="http://duktape.org/dukweb.html#print('Hello%20worl
print('Duktape version is ' + Duktape.version);
alert('alert from Duktape code');
print(Duktape.enc('jx', { foo: 1, bar: 'xxx', quux: ArrayBuffer.allocPlain('foo') }));
print(Duktape.enc('jx', { foo: 1, bar: 'xxx', quux: Uint8Array.allocPlain('foo') }));
var obj = {};
Duktape.fin(obj, function () { print('obj finalized'); });

4
examples/debug-trans-dvalue/test.c

@ -217,7 +217,7 @@ int main(int argc, char *argv[]) {
"\n"
"print('Hello world!');\n"
"[ undefined, null, true, false, 123, -123, 123.1, 0, -0, 1/0, 0/0, -1/0, \n"
" 'foo', ArrayBuffer.allocPlain('bar'), Duktape.Pointer('dummy'), Math.cos, \n"
" 'foo', Uint8Array.allocPlain('bar'), Duktape.Pointer('dummy'), Math.cos, \n"
"].forEach(function (val) {\n"
" print(val);\n"
" evalMe = val;\n"
@ -227,7 +227,7 @@ int main(int argc, char *argv[]) {
"for (i = 0; i < 10; i++) {\n"
" print(i, str);\n"
" evalMe = str;\n"
" evalMe = ArrayBuffer.allocPlain(str);\n"
" evalMe = Uint8Array.allocPlain(str);\n"
" str = str + str;\n"
"}\n"
);

12
polyfills/duktape-buffer.js

@ -9,8 +9,8 @@ if (typeof Duktape === 'object' && typeof Duktape.Buffer === 'undefined') {
(function () {
function isBufferOrView(v) {
return v instanceof Buffer ||
v instanceof ArrayBuffer || // also matches plain buffer in 2.x
v instanceof Uint8Array ||
v instanceof ArrayBuffer ||
v instanceof Uint8Array || // also matches plain buffer in 2.x
v instanceof Uint8ClampedArray ||
v instanceof Int8Array ||
v instanceof Uint16Array ||
@ -28,18 +28,18 @@ if (typeof Duktape === 'object' && typeof Duktape.Buffer === 'undefined') {
// the ArrayBuffer shares the argument's storage with any slice
//offset/length lost.
if (isBufferOrView(arg)) {
return Object(ArrayBuffer.plainOf(arg));
return Object(Uint8Array.plainOf(arg));
} else {
return Object(ArrayBuffer.allocPlain(arg));
return Object(Uint8Array.allocPlain(arg));
}
} else {
// Normal call; result is a plain buffer. For a buffer argument the
// underlying buffer is returned (shared, not copy). Otherwise a
// new plain buffer is created.
if (isBufferOrView(arg)) {
return ArrayBuffer.plainOf(arg);
return Uint8Array.plainOf(arg);
} else {
return ArrayBuffer.allocPlain(arg);
return Uint8Array.allocPlain(arg);
}
}
};

4
src-input/duk_bi_buffer.c

@ -1178,7 +1178,7 @@ DUK_INTERNAL duk_ret_t duk_bi_arraybuffer_isview(duk_context *ctx) {
#endif /* DUK_USE_BUFFEROBJECT_SUPPORT */
/*
* ArrayBuffer.allocPlain()
* Uint8Array.allocPlain()
*/
#if defined(DUK_USE_BUFFEROBJECT_SUPPORT)
@ -1189,7 +1189,7 @@ DUK_INTERNAL duk_ret_t duk_bi_uint8array_allocplain(duk_context *ctx) {
#endif /* DUK_USE_BUFFEROBJECT_SUPPORT */
/*
* ArrayBuffer.plainOf()
* Uint8Array.plainOf()
*/
#if defined(DUK_USE_BUFFEROBJECT_SUPPORT)

Loading…
Cancel
Save