Darshan Sen
f91dcc205d
src: delete AllocatedBuffer
...
Since all its uses are now gone, it's time to say goodbye to
AllocatedBuffer.
Refs: https://github.com/nodejs/node/pull/39941
Signed-off-by: Darshan Sen <raisinten@gmail.com >
PR-URL: https://github.com/nodejs/node/pull/43008
Reviewed-By: Tobias Nießen <tniessen@tnie.de >
Reviewed-By: Rich Trott <rtrott@gmail.com >
Reviewed-By: Mohammed Keyvanzadeh <mohammadkeyvanzade94@gmail.com >
Reviewed-By: James M Snell <jasnell@gmail.com >
Reviewed-By: Luigi Pinca <luigipinca@gmail.com >
Reviewed-By: Zeyu "Alex" Yang <himself65@outlook.com >
Reviewed-By: Anna Henningsen <anna@addaleax.net >
2022-05-13 15:24:13 +01:00
liuxingbaoyu
ce29d2847b
src: fix memory leak for v8.serialize
...
When Buffer::New passes in existing data,
it cannot be garbage collected in js synchronous execution.
Fixes: https://github.com/nodejs/node/issues/40828
Refs: https://github.com/nodejs/node/issues/38300
PR-URL: https://github.com/nodejs/node/pull/42695
Reviewed-By: Anna Henningsen <anna@addaleax.net >
Reviewed-By: James M Snell <jasnell@gmail.com >
Reviewed-By: Minwoo Jung <nodecorelab@gmail.com >
2022-05-02 20:45:47 +01:00
Tobias Nießen
afcfaa07ac
src: simplify bound check in ParseArrayIndex
...
PR-URL: https://github.com/nodejs/node/pull/42306
Reviewed-By: Anna Henningsen <anna@addaleax.net >
Reviewed-By: Darshan Sen <raisinten@gmail.com >
Reviewed-By: James M Snell <jasnell@gmail.com >
2022-03-14 16:36:39 +00:00
Darshan Sen
5edad38328
src,buffer: evaluate THROW_AND_RETURN_IF_OOB() expression only once
...
There's no need to evaluate the expression passed into the macro more
than once.
Fixes: https://github.com/nodejs/node/issues/41935
Signed-off-by: Darshan Sen <raisinten@gmail.com >
PR-URL: https://github.com/nodejs/node/pull/41945
Reviewed-By: James M Snell <jasnell@gmail.com >
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com >
Reviewed-By: Evan Lucas <evanlucas@me.com >
Reviewed-By: Anna Henningsen <anna@addaleax.net >
2022-02-18 00:05:42 +01:00
Ray Wang
7b49e29939
src: throw error instead of assertion
...
PR-URL: https://github.com/nodejs/node/pull/40243
Fixes: https://github.com/nodejs/node/issues/40059
Reviewed-By: James M Snell <jasnell@gmail.com >
Reviewed-By: Michaël Zasso <targos@protonmail.com >
2021-10-23 08:47:13 +02:00
Darshan Sen
7cc96b2eaf
src: remove usage of AllocatedBuffer from src/node_buffer.cc
...
Since AllocatedBuffer is just a thin wrapper around v8::BackingStore, we
should prefer using v8::BackingStore directly.
Refs: https://github.com/nodejs/node/blob/52abf271c563ddffdc93b444ea05e5347a7f2784/src/allocated_buffer.h#L30-L31
Signed-off-by: Darshan Sen <darshan.sen@postman.com >
PR-URL: https://github.com/nodejs/node/pull/39941
Reviewed-By: Anna Henningsen <anna@addaleax.net >
Reviewed-By: James M Snell <jasnell@gmail.com >
2021-09-03 07:42:27 -07:00
James M Snell
31d1d0c4c1
url,buffer: implement URL.createObjectURL
...
Signed-off-by: James M Snell <jasnell@gmail.com >
PR-URL: https://github.com/nodejs/node/pull/39693
Reviewed-By: Anna Henningsen <anna@addaleax.net >
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com >
Reviewed-By: Bradley Farias <bradley.meck@gmail.com >
Reviewed-By: Stephen Belanger <admin@stephenbelanger.com >
2021-08-12 07:23:15 -07:00
James M Snell
fa0c6883a6
stream: implement WHATWG streams
...
Experimental implementation of the WHATWG streams standard.
Signed-off-by: James M Snell <jasnell@gmail.com >
PR-URL: https://github.com/nodejs/node/pull/39062
Reviewed-By: Matteo Collina <matteo.collina@gmail.com >
Reviewed-By: Michaël Zasso <targos@protonmail.com >
2021-06-30 12:54:41 -07:00
Darshan Sen
7766b3853a
src: fix compiler warnings in node_buffer.cc
...
The variables could be initialized to `0` to avoid the warnings from
`-Wmaybe-uninitialized`.
Fixes: https://github.com/nodejs/node/issues/38718
PR-URL: https://github.com/nodejs/node/pull/38722
Reviewed-By: Anna Henningsen <anna@addaleax.net >
Reviewed-By: Michaël Zasso <targos@protonmail.com >
Reviewed-By: Richard Lau <rlau@redhat.com >
Reviewed-By: James M Snell <jasnell@gmail.com >
Reviewed-By: Minwoo Jung <nodecorelab@gmail.com >
2021-05-24 07:37:18 -07:00
James M Snell
720fdf2f80
src: avoid deferred gc/cleanup for Buffer.from
...
Previously, the code path would allocated a tracked ArrayBuffer
that defers cleanup and deallocation of the underlying data with
a SetImmediate. Avoid the unnecessary deferral by just allocating
a `BackingStore` directly and writing into it.
Fixes: https://github.com/nodejs/node/issues/38300
Refs: https://github.com/nodejs/node/pull/38336
PR-URL: https://github.com/nodejs/node/pull/38337
Reviewed-By: Anna Henningsen <anna@addaleax.net >
Reviewed-By: Khaidi Chu <i@2333.moe >
Reviewed-By: Matteo Collina <matteo.collina@gmail.com >
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com >
2021-04-24 10:22:38 +02:00
James M Snell
d4bea09a0a
buffer: introduce Blob
...
The `Blob` object is an immutable data buffer. This is a first step
towards alignment with the `Blob` Web API.
Signed-off-by: James M Snell <jasnell@gmail.com >
PR-URL: https://github.com/nodejs/node/pull/36811
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com >
Reviewed-By: Matteo Collina <matteo.collina@gmail.com >
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com >
2021-01-18 13:55:25 -08:00
Filip Skokan
f8ab632d56
buffer: add base64url encoding option
...
PR-URL: https://github.com/nodejs/node/pull/36952
Reviewed-By: James M Snell <jasnell@gmail.com >
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com >
Reviewed-By: Rich Trott <rtrott@gmail.com >
Reviewed-By: Anna Henningsen <anna@addaleax.net >
2021-01-18 12:08:20 +01:00
Daniel Bevenius
eb14b10370
src: remove unnecessary ToLocalChecked call
...
PR-URL: https://github.com/nodejs/node/pull/36523
Reviewed-By: Michaël Zasso <targos@protonmail.com >
Reviewed-By: Richard Lau <rlau@redhat.com >
Reviewed-By: James M Snell <jasnell@gmail.com >
Reviewed-By: Colin Ihrig <cjihrig@gmail.com >
2020-12-17 05:06:57 +01:00
Rich Trott
1d6bed9e19
src: fix label indentation
...
In preparation for a cpplint version bump, move labels to be unindented.
The one space indentation we use now is flagged in cpplint 1.5.2.
Refs: https://softwareengineering.stackexchange.com/q/151806/26510
PR-URL: https://github.com/nodejs/node/pull/36213
Reviewed-By: Richard Lau <rlau@redhat.com >
Reviewed-By: Michaël Zasso <targos@protonmail.com >
Reviewed-By: Daijiro Wachi <daijiro.wachi@gmail.com >
Reviewed-By: Franziska Hinkelmann <franziska.hinkelmann@gmail.com >
2020-11-23 07:15:55 -08:00
Daniel Bevenius
ba465c5ff6
src: use MaybeLocal.ToLocal instead of IsEmpty
...
PR-URL: https://github.com/nodejs/node/pull/35716
Reviewed-By: Richard Lau <rlau@redhat.com >
Reviewed-By: Colin Ihrig <cjihrig@gmail.com >
Reviewed-By: David Carlier <devnexen@gmail.com >
Reviewed-By: Rich Trott <rtrott@gmail.com >
2020-10-26 12:32:03 +01:00
Joyee Cheung
7a447bcd54
src: snapshot node
...
This runs `lib/internal/bootstrap/node.js` before creating
the builtin snapshot and deserialize the loaders from the
snapshot in deserialization mode.
PR-URL: https://github.com/nodejs/node/pull/32984
Reviewed-By: Anna Henningsen <anna@addaleax.net >
Reviewed-By: Daniel Bevenius <daniel.bevenius@gmail.com >
2020-07-18 11:23:21 +08:00
Joyee Cheung
c943cb4809
src: reset zero fill toggle at pre-execution
...
The connection between the JS land zero fill toggle and the
C++ one in the NodeArrayBufferAllocator gets lost if the toggle
is deserialized from the snapshot, because V8 owns the underlying
memory of this toggle. This resets the connection at pre-execution.
PR-URL: https://github.com/nodejs/node/pull/32984
Reviewed-By: Anna Henningsen <anna@addaleax.net >
Reviewed-By: Daniel Bevenius <daniel.bevenius@gmail.com >
2020-07-18 11:23:16 +08:00
Anna Henningsen
88fb5a5c79
worker: add public method for marking objects as untransferable
...
We currently mark a number of `ArrayBuffer`s as not transferable,
including the `Buffer` pool and ones with finalizers provided
by C++ addons.
There is no good reason to assume that userland code might not
encounter similar problems, for example when doing `ArrayBuffer`
pooling similar to ours. Therefore, provide an API that lets
userland code also mark objects as not transferable.
PR-URL: https://github.com/nodejs/node/pull/33979
Reviewed-By: James M Snell <jasnell@gmail.com >
Reviewed-By: Gus Caplan <me@gus.host >
2020-06-25 08:33:29 -07:00
James M Snell
e2cd715361
src: turn AllocatedBuffer into thin wrapper around v8::BackingStore
...
Alternative to https://github.com/nodejs/node/pull/33381 that
reimplements that change on top of moving AllocatedBuffer out
of env.h
PR-URL: https://github.com/nodejs/node/pull/33291
Reviewed-By: Anna Henningsen <anna@addaleax.net >
Reviewed-By: David Carlier <devnexen@gmail.com >
2020-05-30 16:20:02 -07:00
James M Snell
56ff1ee55a
src: extract AllocatedBuffer from env.h
...
Cleanup up env.h by removing things that are not
specific to `Environment`.
PR-URL: https://github.com/nodejs/node/pull/33291
Reviewed-By: Anna Henningsen <anna@addaleax.net >
Reviewed-By: David Carlier <devnexen@gmail.com >
2020-05-30 16:20:00 -07:00
Anna Henningsen
c1ee70ec16
buffer,n-api: release external buffers from BackingStore callback
...
Release `Buffer` and `ArrayBuffer` instances that were created through
our addon APIs and have finalizers attached to them only after V8 has
called the deleter callback passed to the `BackingStore`, instead of
relying on our own GC callback(s).
This fixes the following race condition:
1. Addon code allocates pointer P via `malloc`.
2. P is passed into `napi_create_external_buffer` with a finalization
callback which calls `free(P)`. P is inserted into V8’s global array
buffer table for tracking.
3. The finalization callback is executed on GC. P is freed and returned
to the allocator. P is not yet removed from V8’s global array
buffer table. (!)
4. Addon code attempts to allocate memory once again. The allocator
returns P, as it is now available.
5. P is passed into `napi_create_external_buffer`. P still has not been
removed from the v8 global array buffer table.
6. The world ends with `Check failed: result.second`.
Since our API contract is to call the finalizer on the JS thread on
which the `ArrayBuffer` was created, but V8 may call the `BackingStore`
deleter callback on another thread, fixing this requires posting
a task back to the JS thread.
Refs: https://github.com/nodejs/node/issues/32463#issuecomment-625877175
Fixes: https://github.com/nodejs/node/issues/32463
PR-URL: https://github.com/nodejs/node/pull/33321
Reviewed-By: James M Snell <jasnell@gmail.com >
2020-05-16 12:15:07 +02:00
Anna Henningsen
36993c0566
buffer,n-api: fix double ArrayBuffer::Detach() during cleanup
...
These calls could fail if the `ArrayBuffer` had already been explicitly
detached at some point in the past.
The necessary test changes already came with 4f523c2c1a and could
be ported back to v12.x with a backport of this PR.
Fixes: https://github.com/nodejs/node/issues/33022
Refs: https://github.com/nodejs/node/pull/30551
PR-URL: https://github.com/nodejs/node/pull/33039
Reviewed-By: James M Snell <jasnell@gmail.com >
Reviewed-By: Chengzhong Wu <legendecas@gmail.com >
Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com >
Reviewed-By: Gerhard Stöbich <deb2001-github@yahoo.de >
Reviewed-By: David Carlier <devnexen@gmail.com >
Reviewed-By: Juan José Arboleda <soyjuanarbol@gmail.com >
2020-04-27 11:16:51 +02:00
Anna Henningsen
678e1be6aa
src: delete CallbackInfo when cleared from cleanup hook
...
Fixes: https://github.com/nodejs/node/issues/32400
PR-URL: https://github.com/nodejs/node/pull/32405
Reviewed-By: Matheus Marchini <mat@mmarchini.me >
Reviewed-By: Jiawen Geng <technicalcute@gmail.com >
Reviewed-By: Michaël Zasso <targos@protonmail.com >
Reviewed-By: Colin Ihrig <cjihrig@gmail.com >
Reviewed-By: James M Snell <jasnell@gmail.com >
2020-03-23 11:02:04 -07:00
Michaël Zasso
d23eed256b
src: remove calls to deprecated ArrayBuffer methods
...
v8::ArrayBuffer::IsExternal and v8::ArrayBuffer::Externalize are
no longer necessary.
PR-URL: https://github.com/nodejs/node/pull/32358
Reviewed-By: James M Snell <jasnell@gmail.com >
Reviewed-By: Gus Caplan <me@gus.host >
Reviewed-By: Luigi Pinca <luigipinca@gmail.com >
Reviewed-By: Matheus Marchini <mat@mmarchini.me >
Reviewed-By: David Carlier <devnexen@gmail.com >
Reviewed-By: Anna Henningsen <anna@addaleax.net >
Reviewed-By: Jiawen Geng <technicalcute@gmail.com >
2020-03-21 12:00:57 +01:00
ConorDavenport and Rich Trott
d4660aba63
src: change Fill() to use ParseArrayIndex()
...
Changed Fill() to use ParseArrayIndex() when getting start and end
of buffers instead of Uint32Value, supporting buffers of greater
than 2**32
Fixes: https://github.com/nodejs/node/issues/31514
Co-Authored-By: Rich Trott <rtrott@gmail.com >
PR-URL: https://github.com/nodejs/node/pull/31591
Reviewed-By: Anna Henningsen <anna@addaleax.net >
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl >
Reviewed-By: Rich Trott <rtrott@gmail.com >
Reviewed-By: James M Snell <jasnell@gmail.com >
2020-02-03 12:00:41 -08:00
Ben Noordhuis
5005c3c72c
lib,src: switch Buffer::kMaxLength to size_t
...
Change the type of `Buffer::kMaxLength` to size_t because upcoming
changes in V8 will allow typed arrays > 2 GB on 64 bits platforms.
Not all platforms handle file reads and writes > 2 GB though so keep
enforcing the 2 GB typed array limit for I/O operations.
Fixes: https://github.com/nodejs/node/issues/31399
Refs: https://github.com/libuv/libuv/pull/1501
PR-URL: https://github.com/nodejs/node/pull/31406
Reviewed-By: Richard Lau <riclau@uk.ibm.com >
Reviewed-By: David Carlier <devnexen@gmail.com >
Reviewed-By: Colin Ihrig <cjihrig@gmail.com >
Reviewed-By: Luigi Pinca <luigipinca@gmail.com >
Reviewed-By: Anna Henningsen <anna@addaleax.net >
Reviewed-By: Rich Trott <rtrott@gmail.com >
Reviewed-By: Tobias Nießen <tniessen@tnie.de >
Reviewed-By: Shelley Vohr <codebytere@gmail.com >
2020-01-21 13:55:40 -08:00
Thang Tran
90f7a5c010
src: set arraybuffer_untransferable_private_symbol
...
for `ArrayBuffer` whose buffers are not own by `BackingStore`. This
would help us avoid problem with the new V8 BackingStore API where new
`ArrayBuffer` is allocated at the same place of previous `ArrayBuffer`
that is still being tracked in `BackingStore` table.
PR-URL: https://github.com/nodejs/node/pull/31053
Refs: https://github.com/nodejs/node/issues/31052
Reviewed-By: Anna Henningsen <anna@addaleax.net >
Reviewed-By: Colin Ihrig <cjihrig@gmail.com >
Reviewed-By: Rich Trott <rtrott@gmail.com >
2019-12-25 12:01:56 +01:00
Thang Tran
4f523c2c1a
src: migrate to new V8 ArrayBuffer API
...
ArrayBuffer without BackingStore will soon be deprecated.
Fixes:https://github.com/nodejs/node/issues/30529
PR-URL: https://github.com/nodejs/node/pull/30782
Fixes: https://github.com/nodejs/node/issues/30529
Reviewed-By: Anna Henningsen <anna@addaleax.net >
Reviewed-By: Rich Trott <rtrott@gmail.com >
2019-12-12 10:05:44 -05:00
Anna Henningsen
b7ef593744
buffer: release buffers with free callbacks on env exit
...
Invoke the free callback for a given `Buffer` if it was created
with one, and mark the underlying `ArrayBuffer` as detached.
This makes sure that the memory is released e.g. when addons inside
Workers create such `Buffer`s.
PR-URL: https://github.com/nodejs/node/pull/30551
Reviewed-By: Gabriel Schulhof <gabriel.schulhof@intel.com >
Reviewed-By: Colin Ihrig <cjihrig@gmail.com >
Reviewed-By: Denys Otrishko <shishugi@gmail.com >
Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com >
2019-11-30 02:02:50 +01:00
Alexandre Ferrando
7686b5a34f
src: cleanup unused headers
...
Node codebase has evolved a lot in the more than 10 years of its
existence. As more features (and code) have been added, changed,
removed, it's sometimes hard to keep track of what gets used and what
not.
This commits attempts to clean some of those potentially left-over
headers using suggestions from include-what-you-use
Refs: https://github.com/nodejs/node/issues/27531
PR-URL: https://github.com/nodejs/node/pull/30328
Reviewed-By: Anna Henningsen <anna@addaleax.net >
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com >
Reviewed-By: James M Snell <jasnell@gmail.com >
2019-11-28 23:21:08 +01:00
Anna Henningsen
e5d3c8121d
src: expose ArrayBuffer version of Buffer::New()
...
This can be useful to create `Buffer` instances for already-existing
`ArrayBuffer`s, e.g. ones created manually from a backing store
with a free callback (of which our variant in the public API has
some limitations).
PR-URL: https://github.com/nodejs/node/pull/30476
Reviewed-By: Colin Ihrig <cjihrig@gmail.com >
Reviewed-By: David Carlier <devnexen@gmail.com >
Reviewed-By: James M Snell <jasnell@gmail.com >
2019-11-19 14:02:22 +01:00
Anna Henningsen
6cb8e4b12c
src: mark ArrayBuffers with free callbacks as untransferable
...
More precisely, make them untransferable if they were created through
*our* APIs, because those do not follow the improved free callback
mechanism that V8 uses now. All other ArrayBuffers can be transferred
between threads now, the assumption being that they were created in a
clean way that follows the V8 API on this.
This addresses a TODO comment.
Refs: https://github.com/nodejs/node/pull/30339#issuecomment-552225353
PR-URL: https://github.com/nodejs/node/pull/30475
Reviewed-By: Colin Ihrig <cjihrig@gmail.com >
Reviewed-By: James M Snell <jasnell@gmail.com >
Reviewed-By: David Carlier <devnexen@gmail.com >
2019-11-19 14:01:32 +01:00
Anna Henningsen
e66a2acc4c
src: migrate off ArrayBuffer::GetContents
...
V8 deprecates `GetContents()` in favour of `GetBackingStore()`.
Update our code to reflect that.
V8 also deprecates `Externalize()` and `IsExternal()`; we should
be able to remove all usage of this once V8 8.0 is there.
PR-URL: https://github.com/nodejs/node/pull/30339
Refs: https://github.com/v8/v8/commit/bfe3d6bce734e596e312465e207bcfd55a59fe34
Reviewed-By: Gus Caplan <me@gus.host >
Reviewed-By: Michaël Zasso <targos@protonmail.com >
Reviewed-By: Colin Ihrig <cjihrig@gmail.com >
Reviewed-By: Jiawen Geng <technicalcute@gmail.com >
Reviewed-By: David Carlier <devnexen@gmail.com >
2019-11-12 06:29:23 +01:00
Anna Henningsen
237be2ed9e
encoding: make TextDecoder handle BOM correctly
...
Do not accept the BOM if it comes from a different encoding, and
only discard the BOM after it has actually been read (including
when it is spread over multiple chunks in streaming mode).
Fixes: https://github.com/nodejs/node/issues/25315
PR-URL: https://github.com/nodejs/node/pull/30132
Reviewed-By: Gus Caplan <me@gus.host >
2019-11-05 20:19:09 +01:00
Anna Henningsen and AtticusYang
7c9ee6dd88
util: add encodeInto to TextEncoder
...
Add function encodeInto to TextEncoder, and add MessageChannel
to the encodeInto.any.js test.
Fixes: https://github.com/nodejs/node/issues/28851
Fixes: https://github.com/nodejs/node/issues/26904
Refs: https://github.com/nodejs/node/pull/28862
Co-authored-by: AtticusYang <yyongtai@163.com >
PR-URL: https://github.com/nodejs/node/pull/29524
Reviewed-By: David Carlier <devnexen@gmail.com >
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com >
Reviewed-By: James M Snell <jasnell@gmail.com >
2019-09-13 20:27:18 +02:00
Anna Henningsen
5a52bdad9b
src: inline SLICE_START_END() in node_buffer.cc
...
This macro is only used once, so it doesn’t need to be a macro.
PR-URL: https://github.com/nodejs/node/pull/29357
Reviewed-By: Jiawen Geng <technicalcute@gmail.com >
Reviewed-By: Masashi Hirano <shisama07@gmail.com >
Reviewed-By: Colin Ihrig <cjihrig@gmail.com >
Reviewed-By: Luigi Pinca <luigipinca@gmail.com >
Reviewed-By: James M Snell <jasnell@gmail.com >
Reviewed-By: Richard Lau <riclau@uk.ibm.com >
Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com >
2019-09-02 07:56:56 +02:00
Brian White
bb1af6c82f
buffer: consolidate encoding parsing
...
PR-URL: https://github.com/nodejs/node/pull/29217
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl >
Reviewed-By: Anna Henningsen <anna@addaleax.net >
2019-08-28 15:13:38 -04:00
Yaniv Friedensohn
a0e2c6d284
src: add error codes to errors thrown in C++
...
PR-URL: https://github.com/nodejs/node/pull/27700
Reviewed-By: James M Snell <jasnell@gmail.com >
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com >
Reviewed-By: Matteo Collina <matteo.collina@gmail.com >
Reviewed-By: Rich Trott <rtrott@gmail.com >
2019-08-09 15:58:58 -07:00
Anna Henningsen
5026db142a
src: use ArrayBufferViewContents more frequently
...
Using `ArrayBufferViewContents` over
`Buffer::Data()`/`Buffer::Length()` or `SPREAD_BUFFER_ARG` has the
advantages of creating fewer individual variables to keep track off,
not being a “magic” macro that creates variables, reducing code size,
and being faster when receiving on-heap TypedArrays.
PR-URL: https://github.com/nodejs/node/pull/27920
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl >
Reviewed-By: Sam Roberts <vieuxtech@gmail.com >
Reviewed-By: Colin Ihrig <cjihrig@gmail.com >
2019-05-29 19:28:38 +02:00
Anna Henningsen
723d5c058f
src: prefer v8::Global over node::Persistent
...
`v8::Global` is essentially a nicer variant of `node::Persistent` that,
in addition to reset-on-destroy, also implements move semantics.
This commit makes the necessary replacements, removes
`node::Persistent` and (now-)unnecessary inclusions of the
`node_persistent.h` header, and makes some of the functions that
take Persistents as arguments more generic so that they work with all
`v8::PersistentBase` flavours.
PR-URL: https://github.com/nodejs/node/pull/27287
Reviewed-By: Gus Caplan <me@gus.host >
Reviewed-By: Eugene Ostroukhov <eostroukhov@google.com >
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com >
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl >
Reviewed-By: Colin Ihrig <cjihrig@gmail.com >
2019-04-30 00:23:33 +02:00
Anna Henningsen
427fce711f
src: fix check for accepting Buffers into Node’s allocator
...
This condition was incorrect. We currently take the fallback
path in default Node builds, which always works, but may come with
some overhead, whereas the intention was that we use the fast path
in this condition.
This is causing issues for embedders, because we would erroneously
try to take the fast path when they don’t provide a Node.js-style
`ArrayBufferAlloactor`, and crash as a consequence of that.
This also requires us to relax the check in the debugging ArrayBuffer
allocator a bit, because since d117e41e50 , 0-sized ArrayBuffers
may actually point to allocations of size 1. Previously, that wasn’t
caught because the fallback path circumvented our ArrayBufferAllocator.
Refs: https://github.com/nodejs/node/commit/84e02b178ad14fae0df2a514e8a39bfa50ffdc2d#r33116006
PR-URL: https://github.com/nodejs/node/pull/27174
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com >
Reviewed-By: Richard Lau <riclau@uk.ibm.com >
Reviewed-By: Colin Ihrig <cjihrig@gmail.com >
Reviewed-By: James M Snell <jasnell@gmail.com >
Reviewed-By: Gus Caplan <me@gus.host >
2019-04-14 23:06:48 +02:00
Sam Roberts
060d901f87
src: replace FromJust() with Check() when possible
...
FromJust() is often used not for its return value, but for its
side-effects. In these cases, Check() exists, and is more clear as to
the intent. From its comment:
To be used, where the actual value of the Maybe is not needed, like
Object::Set.
See: https://github.com/nodejs/node/pull/26929/files#r269256335
PR-URL: https://github.com/nodejs/node/pull/27162
Reviewed-By: Anatoli Papirovski <apapirovski@mac.com >
Reviewed-By: Michaël Zasso <targos@protonmail.com >
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl >
Reviewed-By: Gus Caplan <me@gus.host >
Reviewed-By: Yongsheng Zhang <zyszys98@gmail.com >
2019-04-12 12:33:37 -07:00
gengjiawen
b215bf9dac
src: inline macro DISALLOW_COPY_AND_ASSIGN
...
PR-URL: https://github.com/nodejs/node/pull/26634
Reviewed-By: Anna Henningsen <anna@addaleax.net >
Reviewed-By: Refael Ackermann <refack@gmail.com >
2019-03-17 21:58:22 -04:00
Anna Henningsen
0e3adddd0d
embedding: refactor public ArrayBufferAllocator API
...
Use a RAII approach by default, and make it possible for embedders
to use the `ArrayBufferAllocator` directly as a V8
`ArrayBuffer::Allocator`, e.g. when passing to `Isolate::CreateParams`
manually.
PR-URL: https://github.com/nodejs/node/pull/26525
Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com >
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com >
2019-03-13 09:14:14 +00:00
gengjiawen
8137668c53
src: apply clang-tidy rule modernize-deprecated-headers
...
PR-URL: https://github.com/nodejs/node/pull/26159
Reviewed-By: Daniel Bevenius <daniel.bevenius@gmail.com >
Reviewed-By: James M Snell <jasnell@gmail.com >
2019-02-27 05:35:53 +01:00
Anna Henningsen
84e02b178a
src: allocate Buffer memory using ArrayBuffer allocator
...
Always use the right allocator for memory that is turned into
an `ArrayBuffer` at a later point.
This enables embedders to use their own `ArrayBuffer::Allocator`s,
and is inspired by Electron’s electron/node@f61bae3440 . It should
render their downstream patch unnecessary.
Refs: https://github.com/electron/node/commit/f61bae3440e1bfcc83bba6ff0785adfb89b4045e
PR-URL: https://github.com/nodejs/node/pull/26207
Reviewed-By: James M Snell <jasnell@gmail.com >
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com >
2019-02-25 02:01:11 +01:00
Ben Noordhuis
24f3f11606
src: move function from header to source file
...
This particular Buffer::New() overload used to live in node_internals.h
to work around a cyclic header dependency (IIRC) but that is no longer
necessary.
PR-URL: https://github.com/nodejs/node/pull/26173
Reviewed-By: Richard Lau <riclau@uk.ibm.com >
Reviewed-By: Luigi Pinca <luigipinca@gmail.com >
Reviewed-By: Anna Henningsen <anna@addaleax.net >
Reviewed-By: Minwoo Jung <minwoo@nodesource.com >
Reviewed-By: Colin Ihrig <cjihrig@gmail.com >
Reviewed-By: James M Snell <jasnell@gmail.com >
Reviewed-By: Yuta Hiroto <hello@hiroppy.me >
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de >
2019-02-21 07:23:30 +01:00
gengjiawen
2fa6376ec9
src: refactor macro to std::min in node_buffer.cc
...
PR-URL: https://github.com/nodejs/node/pull/25919
Reviewed-By: Anna Henningsen <anna@addaleax.net >
Reviewed-By: Colin Ihrig <cjihrig@gmail.com >
Reviewed-By: Refael Ackermann <refack@gmail.com >
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl >
Reviewed-By: James M Snell <jasnell@gmail.com >
Reviewed-By: Luigi Pinca <luigipinca@gmail.com >
Reviewed-By: Сковорода Никита Андреевич <chalkerx@gmail.com >
2019-02-09 17:16:22 +01:00
Daniel Bevenius
d310d8df62
src: fix compiler warnings in node_buffer.cc
...
Currently the following compiler warnings are generated on Linux:
../src/node_buffer.cc:
In function 'void node::Buffer::{anonymous}::StringSlice(
const v8::FunctionCallbackInfo<v8::Value>&)
[with node::encoding encoding = (node::encoding)1]':
../src/node_buffer.cc:54:20: warning:
'start' may be used uninitialized in this function
[-Wmaybe-uninitialized]
if (end < start) end = start;
^~~
../src/node_buffer.cc:50:10: note: 'start' was declared here
size_t start;
^~~~~
This commit initializes start and end to zero to avoid these warnings.
PR-URL: https://github.com/nodejs/node/pull/25665
Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com >
Reviewed-By: Richard Lau <riclau@uk.ibm.com >
Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com >
Reviewed-By: James M Snell <jasnell@gmail.com >
2019-02-07 05:33:11 +01:00
gengjiawen
66f08fdf8b
src: use nullptr in node_buffer.cc
...
Signed-off-by: gengjiawen <technicalcute@gmail.com >
PR-URL: https://github.com/nodejs/node/pull/25820
Reviewed-By: Anna Henningsen <anna@addaleax.net >
Reviewed-By: James M Snell <jasnell@gmail.com >
Reviewed-By: Richard Lau <riclau@uk.ibm.com >
Reviewed-By: Luigi Pinca <luigipinca@gmail.com >
Reviewed-By: Colin Ihrig <cjihrig@gmail.com >
2019-02-04 07:21:53 +01:00