{"action":"created","comment":{"url":"https://api.github.com/repos/nodejs/nan/pulls/comments/39467876","id":39467876,"diff_hunk":"@@ -0,0 +1,82 @@\n+// Copyright Joyent, Inc. and other Node contributors.\n+//\n+// Permission is hereby granted, free of charge, to any person obtaining a\n+// copy of this software and associated documentation files (the\n+// \"Software\"), to deal in the Software without restriction, including\n+// without limitation the rights to use, copy, modify, merge, publish,\n+// distribute, sublicense, and/or sell copies of the Software, and to permit\n+// persons to whom the Software is furnished to do so, subject to the\n+// following conditions:\n+//\n+// The above copyright notice and this permission notice shall be included\n+// in all copies or substantial portions of the Software.\n+//\n+// THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS\n+// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF\n+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN\n+// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,\n+// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR\n+// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE\n+// USE OR OTHER DEALINGS IN THE SOFTWARE.\n+\n+#ifndef NAN_TYPEDARRAY_CONTENTS_H_\n+#define NAN_TYPEDARRAY_CONTENTS_H_\n+\n+template<typename T>\n+class TypedArrayContents {\n+ public:\n+  NAN_INLINE explicit TypedArrayContents(v8::Local<v8::Value> from) :\n+      length_(0), data_(NULL) {\n+\n+#if defined(V8_MAJOR_VERSION) && (V8_MAJOR_VERSION > 4 ||                      \\\n+  (V8_MAJOR_VERSION == 4 && defined(V8_MINOR_VERSION) && V8_MINOR_VERSION >= 3))\n+\n+    if(from->IsArrayBufferView()) {\n+      v8::Local<v8::ArrayBufferView> array =\n+        v8::Local<v8::ArrayBufferView>::Cast(from);\n+\n+      int byteLength = array->ByteLength();\n+      int byteOffset = array->ByteOffset();\n+      v8::Local<v8::ArrayBuffer> buffer = array->Buffer();\n+\n+      void* data = buffer->GetContents().Data();\n+      length_ = byteLength / sizeof(T);\n+      data_   = (T*)((void*)((char*)data + byteOffset));","path":"nan_typedarray_contents.h","position":44,"original_position":44,"commit_id":"94ad886626554f26b81ff426ce5aebfbc45e52bd","original_commit_id":"94ad886626554f26b81ff426ce5aebfbc45e52bd","user":{"login":"mikolalysenko","id":231686,"avatar_url":"https://avatars.githubusercontent.com/u/231686?v=3","gravatar_id":"","url":"https://api.github.com/users/mikolalysenko","html_url":"https://github.com/mikolalysenko","followers_url":"https://api.github.com/users/mikolalysenko/followers","following_url":"https://api.github.com/users/mikolalysenko/following{/other_user}","gists_url":"https://api.github.com/users/mikolalysenko/gists{/gist_id}","starred_url":"https://api.github.com/users/mikolalysenko/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mikolalysenko/subscriptions","organizations_url":"https://api.github.com/users/mikolalysenko/orgs","repos_url":"https://api.github.com/users/mikolalysenko/repos","events_url":"https://api.github.com/users/mikolalysenko/events{/privacy}","received_events_url":"https://api.github.com/users/mikolalysenko/received_events","type":"User","site_admin":false},"body":"Using C++ casts is no big deal.  Regarding alignment, what do you think the right behavior should be?  I can think of at least 3 options:\r\n\r\n1.  Do nothing.\r\n2.  Detect bad alignment at run time and return NULL.\r\n3.  Make a local copy with the correct alignment.","created_at":"2015-09-15T02:02:58Z","updated_at":"2015-09-15T02:02:58Z","html_url":"https://github.com/nodejs/nan/pull/459#discussion_r39467876","pull_request_url":"https://api.github.com/repos/nodejs/nan/pulls/459","_links":{"self":{"href":"https://api.github.com/repos/nodejs/nan/pulls/comments/39467876"},"html":{"href":"https://github.com/nodejs/nan/pull/459#discussion_r39467876"},"pull_request":{"href":"https://api.github.com/repos/nodejs/nan/pulls/459"}}},"pull_request":{"url":"https://api.github.com/repos/nodejs/nan/pulls/459","id":44978258,"html_url":"https://github.com/nodejs/nan/pull/459","diff_url":"https://github.com/nodejs/nan/pull/459.diff","patch_url":"https://github.com/nodejs/nan/pull/459.patch","issue_url":"https://api.github.com/repos/nodejs/nan/issues/459","number":459,"state":"open","locked":false,"title":"Add helper method for accessing contents of typedarrays","user":{"login":"mikolalysenko","id":231686,"avatar_url":"https://avatars.githubusercontent.com/u/231686?v=3","gravatar_id":"","url":"https://api.github.com/users/mikolalysenko","html_url":"https://github.com/mikolalysenko","followers_url":"https://api.github.com/users/mikolalysenko/followers","following_url":"https://api.github.com/users/mikolalysenko/following{/other_user}","gists_url":"https://api.github.com/users/mikolalysenko/gists{/gist_id}","starred_url":"https://api.github.com/users/mikolalysenko/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mikolalysenko/subscriptions","organizations_url":"https://api.github.com/users/mikolalysenko/orgs","repos_url":"https://api.github.com/users/mikolalysenko/repos","events_url":"https://api.github.com/users/mikolalysenko/events{/privacy}","received_events_url":"https://api.github.com/users/mikolalysenko/received_events","type":"User","site_admin":false},"body":"This PR adds a portable helper method for reading the contents of a typedarray (ArrayBufferView) from C++, fixing https://github.com/nodejs/nan/issues/455.\r\n\r\nI tried to follow the API conventions from `Utf8String` for this module closely.  Note that this does not make a copy of the typedarray data or hold a reference to the underlying array object, so it would require the user to know what they are doing and not try to access these bytes outside the natural lifetime of the object.","created_at":"2015-09-14T20:42:25Z","updated_at":"2015-09-15T02:02:59Z","closed_at":null,"merged_at":null,"merge_commit_sha":"a1a1efe230662e492f614b7a4e82202e820ad350","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/nodejs/nan/pulls/459/commits","review_comments_url":"https://api.github.com/repos/nodejs/nan/pulls/459/comments","review_comment_url":"https://api.github.com/repos/nodejs/nan/pulls/comments{/number}","comments_url":"https://api.github.com/repos/nodejs/nan/issues/459/comments","statuses_url":"https://api.github.com/repos/nodejs/nan/statuses/94ad886626554f26b81ff426ce5aebfbc45e52bd","head":{"label":"mikolalysenko:typedarray_contents","ref":"typedarray_contents","sha":"94ad886626554f26b81ff426ce5aebfbc45e52bd","user":{"login":"mikolalysenko","id":231686,"avatar_url":"https://avatars.githubusercontent.com/u/231686?v=3","gravatar_id":"","url":"https://api.github.com/users/mikolalysenko","html_url":"https://github.com/mikolalysenko","followers_url":"https://api.github.com/users/mikolalysenko/followers","following_url":"https://api.github.com/users/mikolalysenko/following{/other_user}","gists_url":"https://api.github.com/users/mikolalysenko/gists{/gist_id}","starred_url":"https://api.github.com/users/mikolalysenko/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mikolalysenko/subscriptions","organizations_url":"https://api.github.com/users/mikolalysenko/orgs","repos_url":"https://api.github.com/users/mikolalysenko/repos","events_url":"https://api.github.com/users/mikolalysenko/events{/privacy}","received_events_url":"https://api.github.com/users/mikolalysenko/received_events","type":"User","site_admin":false},"repo":{"id":42475642,"name":"nan","full_name":"mikolalysenko/nan","owner":{"login":"mikolalysenko","id":231686,"avatar_url":"https://avatars.githubusercontent.com/u/231686?v=3","gravatar_id":"","url":"https://api.github.com/users/mikolalysenko","html_url":"https://github.com/mikolalysenko","followers_url":"https://api.github.com/users/mikolalysenko/followers","following_url":"https://api.github.com/users/mikolalysenko/following{/other_user}","gists_url":"https://api.github.com/users/mikolalysenko/gists{/gist_id}","starred_url":"https://api.github.com/users/mikolalysenko/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mikolalysenko/subscriptions","organizations_url":"https://api.github.com/users/mikolalysenko/orgs","repos_url":"https://api.github.com/users/mikolalysenko/repos","events_url":"https://api.github.com/users/mikolalysenko/events{/privacy}","received_events_url":"https://api.github.com/users/mikolalysenko/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/mikolalysenko/nan","description":"Native Abstractions for Node.js","fork":true,"url":"https://api.github.com/repos/mikolalysenko/nan","forks_url":"https://api.github.com/repos/mikolalysenko/nan/forks","keys_url":"https://api.github.com/repos/mikolalysenko/nan/keys{/key_id}","collaborators_url":"https://api.github.com/repos/mikolalysenko/nan/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/mikolalysenko/nan/teams","hooks_url":"https://api.github.com/repos/mikolalysenko/nan/hooks","issue_events_url":"https://api.github.com/repos/mikolalysenko/nan/issues/events{/number}","events_url":"https://api.github.com/repos/mikolalysenko/nan/events","assignees_url":"https://api.github.com/repos/mikolalysenko/nan/assignees{/user}","branches_url":"https://api.github.com/repos/mikolalysenko/nan/branches{/branch}","tags_url":"https://api.github.com/repos/mikolalysenko/nan/tags","blobs_url":"https://api.github.com/repos/mikolalysenko/nan/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/mikolalysenko/nan/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/mikolalysenko/nan/git/refs{/sha}","trees_url":"https://api.github.com/repos/mikolalysenko/nan/git/trees{/sha}","statuses_url":"https://api.github.com/repos/mikolalysenko/nan/statuses/{sha}","languages_url":"https://api.github.com/repos/mikolalysenko/nan/languages","stargazers_url":"https://api.github.com/repos/mikolalysenko/nan/stargazers","contributors_url":"https://api.github.com/repos/mikolalysenko/nan/contributors","subscribers_url":"https://api.github.com/repos/mikolalysenko/nan/subscribers","subscription_url":"https://api.github.com/repos/mikolalysenko/nan/subscription","commits_url":"https://api.github.com/repos/mikolalysenko/nan/commits{/sha}","git_commits_url":"https://api.github.com/repos/mikolalysenko/nan/git/commits{/sha}","comments_url":"https://api.github.com/repos/mikolalysenko/nan/comments{/number}","issue_comment_url":"https://api.github.com/repos/mikolalysenko/nan/issues/comments{/number}","contents_url":"https://api.github.com/repos/mikolalysenko/nan/contents/{+path}","compare_url":"https://api.github.com/repos/mikolalysenko/nan/compare/{base}...{head}","merges_url":"https://api.github.com/repos/mikolalysenko/nan/merges","archive_url":"https://api.github.com/repos/mikolalysenko/nan/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/mikolalysenko/nan/downloads","issues_url":"https://api.github.com/repos/mikolalysenko/nan/issues{/number}","pulls_url":"https://api.github.com/repos/mikolalysenko/nan/pulls{/number}","milestones_url":"https://api.github.com/repos/mikolalysenko/nan/milestones{/number}","notifications_url":"https://api.github.com/repos/mikolalysenko/nan/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/mikolalysenko/nan/labels{/name}","releases_url":"https://api.github.com/repos/mikolalysenko/nan/releases{/id}","created_at":"2015-09-14T20:37:52Z","updated_at":"2015-09-14T20:37:52Z","pushed_at":"2015-09-14T20:40:29Z","git_url":"git://github.com/mikolalysenko/nan.git","ssh_url":"git@github.com:mikolalysenko/nan.git","clone_url":"https://github.com/mikolalysenko/nan.git","svn_url":"https://github.com/mikolalysenko/nan","homepage":"","size":5578,"stargazers_count":0,"watchers_count":0,"language":"C++","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"nodejs:master","ref":"master","sha":"40754451bb304d7b78ffdecfd9c8b6e5e56b4093","user":{"login":"nodejs","id":9950313,"avatar_url":"https://avatars.githubusercontent.com/u/9950313?v=3","gravatar_id":"","url":"https://api.github.com/users/nodejs","html_url":"https://github.com/nodejs","followers_url":"https://api.github.com/users/nodejs/followers","following_url":"https://api.github.com/users/nodejs/following{/other_user}","gists_url":"https://api.github.com/users/nodejs/gists{/gist_id}","starred_url":"https://api.github.com/users/nodejs/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nodejs/subscriptions","organizations_url":"https://api.github.com/users/nodejs/orgs","repos_url":"https://api.github.com/users/nodejs/repos","events_url":"https://api.github.com/users/nodejs/events{/privacy}","received_events_url":"https://api.github.com/users/nodejs/received_events","type":"Organization","site_admin":false},"repo":{"id":11545928,"name":"nan","full_name":"nodejs/nan","owner":{"login":"nodejs","id":9950313,"avatar_url":"https://avatars.githubusercontent.com/u/9950313?v=3","gravatar_id":"","url":"https://api.github.com/users/nodejs","html_url":"https://github.com/nodejs","followers_url":"https://api.github.com/users/nodejs/followers","following_url":"https://api.github.com/users/nodejs/following{/other_user}","gists_url":"https://api.github.com/users/nodejs/gists{/gist_id}","starred_url":"https://api.github.com/users/nodejs/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nodejs/subscriptions","organizations_url":"https://api.github.com/users/nodejs/orgs","repos_url":"https://api.github.com/users/nodejs/repos","events_url":"https://api.github.com/users/nodejs/events{/privacy}","received_events_url":"https://api.github.com/users/nodejs/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/nodejs/nan","description":"Native Abstractions for Node.js","fork":false,"url":"https://api.github.com/repos/nodejs/nan","forks_url":"https://api.github.com/repos/nodejs/nan/forks","keys_url":"https://api.github.com/repos/nodejs/nan/keys{/key_id}","collaborators_url":"https://api.github.com/repos/nodejs/nan/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/nodejs/nan/teams","hooks_url":"https://api.github.com/repos/nodejs/nan/hooks","issue_events_url":"https://api.github.com/repos/nodejs/nan/issues/events{/number}","events_url":"https://api.github.com/repos/nodejs/nan/events","assignees_url":"https://api.github.com/repos/nodejs/nan/assignees{/user}","branches_url":"https://api.github.com/repos/nodejs/nan/branches{/branch}","tags_url":"https://api.github.com/repos/nodejs/nan/tags","blobs_url":"https://api.github.com/repos/nodejs/nan/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/nodejs/nan/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/nodejs/nan/git/refs{/sha}","trees_url":"https://api.github.com/repos/nodejs/nan/git/trees{/sha}","statuses_url":"https://api.github.com/repos/nodejs/nan/statuses/{sha}","languages_url":"https://api.github.com/repos/nodejs/nan/languages","stargazers_url":"https://api.github.com/repos/nodejs/nan/stargazers","contributors_url":"https://api.github.com/repos/nodejs/nan/contributors","subscribers_url":"https://api.github.com/repos/nodejs/nan/subscribers","subscription_url":"https://api.github.com/repos/nodejs/nan/subscription","commits_url":"https://api.github.com/repos/nodejs/nan/commits{/sha}","git_commits_url":"https://api.github.com/repos/nodejs/nan/git/commits{/sha}","comments_url":"https://api.github.com/repos/nodejs/nan/comments{/number}","issue_comment_url":"https://api.github.com/repos/nodejs/nan/issues/comments{/number}","contents_url":"https://api.github.com/repos/nodejs/nan/contents/{+path}","compare_url":"https://api.github.com/repos/nodejs/nan/compare/{base}...{head}","merges_url":"https://api.github.com/repos/nodejs/nan/merges","archive_url":"https://api.github.com/repos/nodejs/nan/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/nodejs/nan/downloads","issues_url":"https://api.github.com/repos/nodejs/nan/issues{/number}","pulls_url":"https://api.github.com/repos/nodejs/nan/pulls{/number}","milestones_url":"https://api.github.com/repos/nodejs/nan/milestones{/number}","notifications_url":"https://api.github.com/repos/nodejs/nan/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/nodejs/nan/labels{/name}","releases_url":"https://api.github.com/repos/nodejs/nan/releases{/id}","created_at":"2013-07-20T11:12:03Z","updated_at":"2015-09-14T17:13:50Z","pushed_at":"2015-09-14T20:42:26Z","git_url":"git://github.com/nodejs/nan.git","ssh_url":"git@github.com:nodejs/nan.git","clone_url":"https://github.com/nodejs/nan.git","svn_url":"https://github.com/nodejs/nan","homepage":"","size":5578,"stargazers_count":878,"watchers_count":878,"language":"C++","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":129,"mirror_url":null,"open_issues_count":20,"forks":129,"open_issues":20,"watchers":878,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/nodejs/nan/pulls/459"},"html":{"href":"https://github.com/nodejs/nan/pull/459"},"issue":{"href":"https://api.github.com/repos/nodejs/nan/issues/459"},"comments":{"href":"https://api.github.com/repos/nodejs/nan/issues/459/comments"},"review_comments":{"href":"https://api.github.com/repos/nodejs/nan/pulls/459/comments"},"review_comment":{"href":"https://api.github.com/repos/nodejs/nan/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/nodejs/nan/pulls/459/commits"},"statuses":{"href":"https://api.github.com/repos/nodejs/nan/statuses/94ad886626554f26b81ff426ce5aebfbc45e52bd"}}}}