Created
May 8, 2013 12:13
-
-
Save mnaamani/5540054 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module.exports = { | |
makeArrayBuffer:function(){ | |
var arr = new ArrayBuffer(2); | |
arr[0]=1;arr[1]=2; | |
return arr; | |
}, | |
makeUint8Array:function(n){ | |
var arr = new ArrayBuffer(2); | |
arr[0]=3;arr[1]=4; | |
return new Uint8Array(arr); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!doctype html> | |
<html> | |
<head> | |
<script src="./main.js"></script> | |
</head> | |
<body> | |
</body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var A = require("./arr.js"); | |
var arr = A.makeArrayBuffer(); | |
console.log(arr instanceof ArrayBuffer);/* prints: false ,should be true*/ | |
//in node-webkit arr is not recognised as an ArrayBuffer so the Array view is not created properly. | |
console.log(arr.byteLength);/*correctly prints: 2*/ | |
var u8 = new Uint8Array(arr); | |
console.log("u8 length:",u8.length);/* should be 2, prints 0 */ | |
console.log(u8[0],u8[1]);/* prints 'undefined undefined' it should print: 1 2 */ | |
var view = A.makeUint8Array(); | |
console.log(view instanceof Uint8Array);/*prints false, should be true*/ | |
console.log(view[0],view[1]); /*correctly prints: 3 4 */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"name":"typed-arrays-test", | |
"main":"index.html" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment