Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/nodejs/node into nodeDocs
Browse files Browse the repository at this point in the history
  • Loading branch information
vipul kumar committed Sep 4, 2021
2 parents b8b8401 + f26c2ce commit 117a6ac
Show file tree
Hide file tree
Showing 890 changed files with 10,008 additions and 8,404 deletions.
2 changes: 2 additions & 0 deletions .eslintrc.js
Expand Up @@ -18,6 +18,7 @@ const hacks = [
'eslint-plugin-markdown',
'@babel/eslint-parser',
'@babel/plugin-syntax-class-properties',
'@babel/plugin-syntax-import-assertions',
'@babel/plugin-syntax-top-level-await',
];
Module._findPath = (request, paths, isMain) => {
Expand All @@ -41,6 +42,7 @@ module.exports = {
babelOptions: {
plugins: [
Module._findPath('@babel/plugin-syntax-class-properties'),
Module._findPath('@babel/plugin-syntax-import-assertions'),
Module._findPath('@babel/plugin-syntax-top-level-await'),
],
},
Expand Down
18 changes: 18 additions & 0 deletions doc/api/fs.md
Expand Up @@ -664,6 +664,9 @@ exist. `data` can be a string or a {Buffer}.
If `options` is a string, then it specifies the `encoding`.
The `mode` option only affects the newly created file. See [`fs.open()`][]
for more details.
The `path` may be specified as a {FileHandle} that has been opened
for appending (using `fsPromises.open()`).
Expand Down Expand Up @@ -1379,6 +1382,9 @@ The `encoding` option is ignored if `data` is a buffer.
If `options` is a string, then it specifies the encoding.
The `mode` option only affects the newly created file. See [`fs.open()`][]
for more details.
Any specified {FileHandle} has to support writing.
It is unsafe to use `fsPromises.writeFile()` multiple times on the same file
Expand Down Expand Up @@ -1645,6 +1651,9 @@ changes:
Asynchronously append data to a file, creating the file if it does not yet
exist. `data` can be a string or a {Buffer}.
The `mode` option only affects the newly created file. See [`fs.open()`][]
for more details.
```mjs
import { appendFile } from 'fs';
Expand Down Expand Up @@ -4086,6 +4095,9 @@ a file descriptor.
The `encoding` option is ignored if `data` is a buffer.
The `mode` option only affects the newly created file. See [`fs.open()`][]
for more details.
If `data` is a plain object, it must have an own (not inherited) `toString`
function property.
Expand Down Expand Up @@ -4260,6 +4272,9 @@ changes:
Synchronously append data to a file, creating the file if it does not yet
exist. `data` can be a string or a {Buffer}.
The `mode` option only affects the newly created file. See [`fs.open()`][]
for more details.
```mjs
import { appendFileSync } from 'fs';

Expand Down Expand Up @@ -5216,6 +5231,9 @@ Returns `undefined`.
If `data` is a plain object, it must have an own (not inherited) `toString`
function property.
The `mode` option only affects the newly created file. See [`fs.open()`][]
for more details.
For detailed information, see the documentation of the asynchronous version of
this API: [`fs.writeFile()`][].
Expand Down
74 changes: 57 additions & 17 deletions src/node_buffer.cc
Expand Up @@ -352,16 +352,31 @@ MaybeLocal<Object> New(Isolate* isolate, size_t length) {


MaybeLocal<Object> New(Environment* env, size_t length) {
EscapableHandleScope scope(env->isolate());
Isolate* isolate(env->isolate());
EscapableHandleScope scope(isolate);

// V8 currently only allows a maximum Typed Array index of max Smi.
if (length > kMaxLength) {
env->isolate()->ThrowException(ERR_BUFFER_TOO_LARGE(env->isolate()));
isolate->ThrowException(ERR_BUFFER_TOO_LARGE(isolate));
return Local<Object>();
}

return scope.EscapeMaybe(
AllocatedBuffer::AllocateManaged(env, length).ToBuffer());
Local<ArrayBuffer> ab;
{
NoArrayBufferZeroFillScope no_zero_fill_scope(env->isolate_data());
std::unique_ptr<BackingStore> bs =
ArrayBuffer::NewBackingStore(isolate, length);

CHECK(bs);

ab = ArrayBuffer::New(isolate, std::move(bs));
}

MaybeLocal<Object> obj =
New(env, ab, 0, ab->ByteLength())
.FromMaybe(Local<Uint8Array>());

return scope.EscapeMaybe(obj);
}


Expand All @@ -380,20 +395,33 @@ MaybeLocal<Object> Copy(Isolate* isolate, const char* data, size_t length) {


MaybeLocal<Object> Copy(Environment* env, const char* data, size_t length) {
EscapableHandleScope scope(env->isolate());
Isolate* isolate(env->isolate());
EscapableHandleScope scope(isolate);

// V8 currently only allows a maximum Typed Array index of max Smi.
if (length > kMaxLength) {
env->isolate()->ThrowException(ERR_BUFFER_TOO_LARGE(env->isolate()));
isolate->ThrowException(ERR_BUFFER_TOO_LARGE(isolate));
return Local<Object>();
}

AllocatedBuffer ret = AllocatedBuffer::AllocateManaged(env, length);
if (length > 0) {
memcpy(ret.data(), data, length);
Local<ArrayBuffer> ab;
{
NoArrayBufferZeroFillScope no_zero_fill_scope(env->isolate_data());
std::unique_ptr<BackingStore> bs =
ArrayBuffer::NewBackingStore(isolate, length);

CHECK(bs);

memcpy(bs->Data(), data, length);

ab = ArrayBuffer::New(isolate, std::move(bs));
}

return scope.EscapeMaybe(ret.ToBuffer());
MaybeLocal<Object> obj =
New(env, ab, 0, ab->ByteLength())
.FromMaybe(Local<Uint8Array>());

return scope.EscapeMaybe(obj);
}


Expand Down Expand Up @@ -1077,13 +1105,25 @@ static void EncodeUtf8String(const FunctionCallbackInfo<Value>& args) {

Local<String> str = args[0].As<String>();
size_t length = str->Utf8Length(isolate);
AllocatedBuffer buf = AllocatedBuffer::AllocateManaged(env, length);
str->WriteUtf8(isolate,
buf.data(),
-1, // We are certain that `data` is sufficiently large
nullptr,
String::NO_NULL_TERMINATION | String::REPLACE_INVALID_UTF8);
auto array = Uint8Array::New(buf.ToArrayBuffer(), 0, length);

Local<ArrayBuffer> ab;
{
NoArrayBufferZeroFillScope no_zero_fill_scope(env->isolate_data());
std::unique_ptr<BackingStore> bs =
ArrayBuffer::NewBackingStore(isolate, length);

CHECK(bs);

str->WriteUtf8(isolate,
static_cast<char*>(bs->Data()),
-1, // We are certain that `data` is sufficiently large
nullptr,
String::NO_NULL_TERMINATION | String::REPLACE_INVALID_UTF8);

ab = ArrayBuffer::New(isolate, std::move(bs));
}

auto array = Uint8Array::New(ab, 0, length);
args.GetReturnValue().Set(array);
}

Expand Down
4 changes: 3 additions & 1 deletion tools/node_modules/@babel/core/lib/config/partial.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion tools/node_modules/@babel/core/lib/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 117a6ac

Please sign in to comment.