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

Update for ch5.md (Section - Multiple Views) #1090

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

WispProxy
Copy link

If we try using of "buf" = 2 bits, we will have exceptions for all variables.

Browser: Chrome latest

Exception:

VM200:2 Uncaught RangeError: Invalid typed array length: 2
at typedArrayConstructByArrayBuffer ()
at new Uint16Array (native)
at :2:13

Valid example:

var buf1 = new ArrayBuffer( 4 );
var first = new Uint16Array( buf1, 0, 2 )[0];

var buf2 = new ArrayBuffer( 3 );
var second = new Uint8Array( buf2, 2, 1 )[0];

var buf3 = new ArrayBuffer( 4 );
var third = new Uint8Array( buf3, 3, 1 )[0];

var buf4 = new ArrayBuffer( 20 );
var fourth = new Float32Array( buf4, 4, 4 )[0];

=========================
Need add to example "buf" = 20 or set custom "buf" for each variable.
After that please update the text if this remark is correct.

If we try using of "buf" = 2 bits, we will have exceptions for all variables.

Browser: Chrome latest

Exception:
=========================
VM200:2 Uncaught RangeError: Invalid typed array length: 2
    at typedArrayConstructByArrayBuffer (<anonymous>)
    at new Uint16Array (native)
    at <anonymous>:2:13
=========================

Valid example:
=========================
var buf1 = new ArrayBuffer( 4 );
var first = new Uint16Array( buf1, 0, 2 )[0];

var buf2 = new ArrayBuffer( 3 );
var second = new Uint8Array( buf2, 2, 1 )[0];

var buf3 = new ArrayBuffer( 4 );
var third = new Uint8Array( buf3, 3, 1 )[0];

var buf4 = new ArrayBuffer( 20 );
var fourth = new Float32Array( buf4, 4, 4 )[0];
=========================

Need add to example "buf" = 20 or set custom "buf" for each variable.
After that please update the text if this remark is correct.
@getify
Copy link
Owner

getify commented Aug 15, 2017

It's true that buf actually has to be an array... and the snippet doesn't show that. But the paragraph above explains that you have to assume buf already has specific contents. Your addition only makes an empty buf which actually conflicts with what the paragraph says.

A perhaps clearer approach would be to have a code comment in the snippet (in place of that buf declaration) that reinforces that buf is assumed to already exist as a buffer.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants