-
Notifications
You must be signed in to change notification settings - Fork 29.8k
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
Native buf checks #3080
Native buf checks #3080
Conversation
31366e1
to
ab00906
Compare
I'd say |
Agreed. |
@indutny mind giving this a review? Should I leave in the old function signatures for ABI compatibility? /cc @bnoordhuis |
char* Data(Local<Object> obj) { | ||
CHECK(obj->IsUint8Array()); | ||
Local<Uint8Array> ui = obj.As<Uint8Array>(); | ||
CHECK(HasInstance(val)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd use CHECK(val->IsUint8Array())
here like you do below.
I'd keep the function signatures for now, else it's a semver-major change. |
Prefer using Object.setPrototypeOf() instead.
Native Buffer method calls do not require anything from the prototype. So it is unnecessary to check if the Object's prototype is equal to Buffer.prototype. This fixes an issue that prevents Buffer from being inherited the ES5 way. Now the following will work: function A(n) { const b = new Buffer(n); Object.setPrototypeOf(b, A.prototype); return b; } Object.setPrototypeOf(A.prototype, Buffer.prototype); Object.setPrototypeOf(A, Buffer); console.log(new A(4)); Fix: nodejs#2882
ab00906
to
b7eb4f1
Compare
@bnoordhuis Thanks. Comments addressed. |
LGTM but can you do s/Only/only/ in the second commit log for consistency? EDIT: And while I'm being pedantic, s/cleanup/clean up/. |
Prefer using Object.setPrototypeOf() instead. PR-URL: #3080 Reviewed-By: Ben Noordhuis <[email protected]>
Native Buffer method calls do not require anything from the prototype. So it is unnecessary to check if the Object's prototype is equal to Buffer.prototype. This fixes an issue that prevents Buffer from being inherited the ES5 way. Now the following will work: function A(n) { const b = new Buffer(n); Object.setPrototypeOf(b, A.prototype); return b; } Object.setPrototypeOf(A.prototype, Buffer.prototype); Object.setPrototypeOf(A, Buffer); console.log(new A(4)); Fix: #2882 PR-URL: #3080 Reviewed-By: Ben Noordhuis <[email protected]>
Belated LGTM |
Prefer using Object.setPrototypeOf() instead. PR-URL: #3080 Reviewed-By: Ben Noordhuis <[email protected]>
Native Buffer method calls do not require anything from the prototype. So it is unnecessary to check if the Object's prototype is equal to Buffer.prototype. This fixes an issue that prevents Buffer from being inherited the ES5 way. Now the following will work: function A(n) { const b = new Buffer(n); Object.setPrototypeOf(b, A.prototype); return b; } Object.setPrototypeOf(A.prototype, Buffer.prototype); Object.setPrototypeOf(A, Buffer); console.log(new A(4)); Fix: #2882 PR-URL: #3080 Reviewed-By: Ben Noordhuis <[email protected]>
I'm seeing an assertion failure (at https://github.com/nodejs/node/blob/master/src/node_buffer.cc#L151) that I think is related to this change while testing https://github.com/mapbox/mapbox-gl-native against Node.js v4.2.0 (was previously passing on v4.1.2). Compiled using nan 2.1.0, stack trace follows, can try to distill a simpler test case if there isn't a clear fix here.
|
Argh... I guess I know what's happening |
`CallbackInfo` is now bound to `ArrayBuffer` instance, not `Uint8Array`, therefore `SPREAD_ARG` will abort with: Assertion failed: ((object)->IsUint8Array()) Make changes necessary to migrate it to `ArrayBuffer`. See: nodejs#3080 (comment)
@mikemorris I'm terribly sorry for this, it should be fixed by #3329 |
`CallbackInfo` is now bound to `ArrayBuffer` instance, not `Uint8Array`, therefore `SPREAD_ARG` will abort with: Assertion failed: ((object)->IsUint8Array()) Make changes necessary to migrate it to `ArrayBuffer`. See: #3080 (comment) Reviewed-By: James M Snell <[email protected]> Reviewed-By: Trevor Norris <[email protected]> PR-URL: #3329
`CallbackInfo` is now bound to `ArrayBuffer` instance, not `Uint8Array`, therefore `SPREAD_ARG` will abort with: Assertion failed: ((object)->IsUint8Array()) Make changes necessary to migrate it to `ArrayBuffer`. See: #3080 (comment) Reviewed-By: James M Snell <[email protected]> Reviewed-By: Trevor Norris <[email protected]> PR-URL: #3329
landed in v4.x-staging as e0fffca...651a5b5 |
Native Buffer method calls do not require anything from the prototype.
So it is unnecessary to check if the Object's prototype is equal to
Buffer.prototype.
This fixes an issue that prevents Buffer from being inherited the ES5
way. Now the following will work:
R=@bnoordhuis
Also, will those native buffer functions need to be re-added for this to land on v4?