Skip to content
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

[v9.x backport] backport 18607, 18953 #19194

Closed
wants to merge 25 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
819ff1a
deps: cherry-pick 46c4979e86 from upstream v8
bnoordhuis Feb 21, 2018
62dc43d
src: clean up process.dlopen()
bnoordhuis Feb 22, 2018
86fa308
src: make process.dlopen() load well-known symbol
bnoordhuis Feb 22, 2018
6bd8c10
build: fix gocvr version used for coverage
mhdawson Mar 2, 2018
a3b9542
module: fix cyclical dynamic import
bmeck Feb 23, 2018
57ddfd1
doc: add simple example to rename function
punteek Feb 16, 2018
6ad9be0
doc: new team for bundlers or delivery of Node.js
mhdawson Mar 2, 2018
dc25929
deps: cherry-pick 0bcb1d6f from upstream V8
jakobkummerow Dec 5, 2017
d268061
doc: add introduced_in metadata to _toc.md
Trott Mar 4, 2018
15281b0
doc: update cc list
BridgeAR Mar 2, 2018
83c912a
doc: remove tentativeness in pull-requests.md
Trott Mar 4, 2018
7861df9
doc: remove subsystem from pull request template
Trott Mar 4, 2018
d6153e9
src: refactor GetPeerCertificate
danbev Mar 2, 2018
0b22bab
src: use std::unique_ptr for STACK_OF(X509)
bnoordhuis Mar 2, 2018
7448712
test: move require http2 to after crypto check
danbev Mar 3, 2018
4829469
src: #include <stdio.h>" to iculslocs
srl295 Mar 5, 2018
c89e8f3
perf_hooks: fix timing
TimothyGu Feb 25, 2018
c81a391
test: add more information to assert.strictEqual
ryzokuken Mar 6, 2018
03784d7
src: handle exceptions in env->SetImmediates
jasnell Jan 26, 2018
6e1bed1
src: prevent persistent handle resource leaks
bnoordhuis Feb 21, 2018
5b4eeb8
src: remove unnecessary Reset() calls
bnoordhuis Feb 21, 2018
d3eaf77
src: don't touch js object in Http2Session dtor
bnoordhuis Feb 21, 2018
4e9ac10
http2: no stream destroy while its data is on the wire
addaleax Feb 26, 2018
23807d7
net: inline and simplify onSocketEnd
addaleax Feb 6, 2018
64746c7
stream: add no-half-open enforcer only if needed
lpinca Feb 23, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,3 @@ Contributors guide: https://github.com/nodejs/node/blob/master/CONTRIBUTING.md
- [ ] tests and/or benchmarks are included
- [ ] documentation is changed or added
- [ ] commit message follows [commit guidelines](https://github.com/nodejs/node/blob/master/doc/guides/contributing/pull-requests.md#commit-message-guidelines)

##### Affected core subsystem(s)
<!-- Provide affected core subsystem(s) (like doc, cluster, crypto, etc). -->
10 changes: 5 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -172,13 +172,13 @@ coverage-build: all
$(NODE) ./deps/npm install istanbul-merge --no-save --no-package-lock; fi
if [ ! -d node_modules/nyc ]; then \
$(NODE) ./deps/npm install nyc --no-save --no-package-lock; fi
if [ ! -d gcovr ]; then git clone --depth=1 \
if [ ! -d gcovr ]; then git clone -b 3.4 --depth=1 \
--single-branch git://github.com/gcovr/gcovr.git; fi
if [ ! -d build ]; then git clone --depth=1 \
--single-branch https://github.com/nodejs/build.git; fi
if [ ! -f gcovr/gcovr/gcov.py.orig ]; then \
(cd gcovr && patch -b -N -p1 < \
"$(CURDIR)/build/jenkins/scripts/coverage/gcovr-patches.diff"); fi
if [ ! -f gcovr/scripts/gcovr.orig ]; then \
(cd gcovr && patch -N -p1 < \
"$(CURDIR)/build/jenkins/scripts/coverage/gcovr-patches-3.4.diff"); fi
if [ -d lib_ ]; then $(RM) -r lib; mv lib_ lib; fi
mv lib lib_
$(NODE) ./node_modules/.bin/nyc instrument --extension .js --extension .mjs lib_/ lib/
Expand All @@ -203,7 +203,7 @@ coverage-test: coverage-build
(cd lib && .$(NODE) ../node_modules/.bin/nyc report \
--temp-directory "$(CURDIR)/.cov_tmp" \
--report-dir "../coverage")
-(cd out && PYTHONPATH=$(CURDIR)/gcovr $(PYTHON) -m gcovr --gcov-exclude='.*deps' \
-(cd out && "../gcovr/scripts/gcovr" --gcov-exclude='.*deps' \
--gcov-exclude='.*usr' -v -r Release/obj.target \
--html --html-detail -o ../coverage/cxxcoverage.html \
--gcov-executable="$(GCOV)")
Expand Down
2 changes: 1 addition & 1 deletion common.gypi
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@

# Reset this number to 0 on major V8 upgrades.
# Increment by one for each non-official patch applied to deps/v8.
'v8_embedder_string': '-node.20',
'v8_embedder_string': '-node.22',

# Enable disassembler for `--print-code` v8 options
'v8_enable_disassembler': 1,
Expand Down
7 changes: 4 additions & 3 deletions deps/v8/src/api.cc
Original file line number Diff line number Diff line change
Expand Up @@ -889,8 +889,7 @@ void ResourceConstraints::ConfigureDefaults(uint64_t physical_memory,
uint64_t virtual_memory_limit) {
set_max_semi_space_size_in_kb(
i::Heap::ComputeMaxSemiSpaceSize(physical_memory));
set_max_old_space_size(
static_cast<int>(i::Heap::ComputeMaxOldGenerationSize(physical_memory)));
set_max_old_space_size(i::Heap::ComputeMaxOldGenerationSize(physical_memory));
set_max_zone_pool_size(i::AccountingAllocator::kMaxPoolSize);

if (virtual_memory_limit > 0 && i::kRequiresCodeRange) {
Expand All @@ -905,7 +904,9 @@ void ResourceConstraints::ConfigureDefaults(uint64_t physical_memory,
void SetResourceConstraints(i::Isolate* isolate,
const ResourceConstraints& constraints) {
size_t semi_space_size = constraints.max_semi_space_size_in_kb();
int old_space_size = constraints.max_old_space_size();
size_t old_space_size =
static_cast<size_t>(
static_cast<unsigned int>(constraints.max_old_space_size()));
size_t code_range_size = constraints.code_range_size();
size_t max_pool_size = constraints.max_zone_pool_size();
if (semi_space_size != 0 || old_space_size != 0 || code_range_size != 0) {
Expand Down
5 changes: 5 additions & 0 deletions deps/v8/src/bootstrapper.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5299,6 +5299,11 @@ Genesis::Genesis(
if (!InstallDebuggerNatives()) return;
}

if (FLAG_disallow_code_generation_from_strings) {
native_context()->set_allow_code_gen_from_strings(
isolate->heap()->false_value());
}

ConfigureUtilsObject(context_type);

// Check that the script context table is empty except for the 'this' binding.
Expand Down
20 changes: 12 additions & 8 deletions deps/v8/src/flag-definitions.h
Original file line number Diff line number Diff line change
Expand Up @@ -161,12 +161,14 @@ struct MaybeBoolFlag {
#define DEFINE_INT(nam, def, cmt) FLAG(INT, int, nam, def, cmt)
#define DEFINE_UINT(nam, def, cmt) FLAG(UINT, unsigned int, nam, def, cmt)
#define DEFINE_FLOAT(nam, def, cmt) FLAG(FLOAT, double, nam, def, cmt)
#define DEFINE_SIZE_T(nam, def, cmt) FLAG(SIZE_T, size_t, nam, def, cmt)
#define DEFINE_STRING(nam, def, cmt) FLAG(STRING, const char*, nam, def, cmt)
#define DEFINE_ARGS(nam, cmt) FLAG(ARGS, JSArguments, nam, {0 COMMA NULL}, cmt)

#define DEFINE_ALIAS_BOOL(alias, nam) FLAG_ALIAS(BOOL, bool, alias, nam)
#define DEFINE_ALIAS_INT(alias, nam) FLAG_ALIAS(INT, int, alias, nam)
#define DEFINE_ALIAS_FLOAT(alias, nam) FLAG_ALIAS(FLOAT, double, alias, nam)
#define DEFINE_ALIAS_SIZE_T(alias, nam) FLAG_ALIAS(SIZE_T, size_t, alias, nam)
#define DEFINE_ALIAS_STRING(alias, nam) \
FLAG_ALIAS(STRING, const char*, alias, nam)
#define DEFINE_ALIAS_ARGS(alias, nam) FLAG_ALIAS(ARGS, JSArguments, alias, nam)
Expand Down Expand Up @@ -553,18 +555,18 @@ DEFINE_BOOL(trace_opt_verbose, false, "extra verbose compilation tracing")
DEFINE_IMPLICATION(trace_opt_verbose, trace_opt)

// Garbage collections flags.
DEFINE_INT(min_semi_space_size, 0,
"min size of a semi-space (in MBytes), the new space consists of two"
"semi-spaces")
DEFINE_INT(max_semi_space_size, 0,
"max size of a semi-space (in MBytes), the new space consists of two"
"semi-spaces")
DEFINE_SIZE_T(min_semi_space_size, 0,
"min size of a semi-space (in MBytes), the new space consists of "
"two semi-spaces")
DEFINE_SIZE_T(max_semi_space_size, 0,
"max size of a semi-space (in MBytes), the new space consists of "
"two semi-spaces")
DEFINE_INT(semi_space_growth_factor, 2, "factor by which to grow the new space")
DEFINE_BOOL(experimental_new_space_growth_heuristic, false,
"Grow the new space based on the percentage of survivors instead "
"of their absolute value.")
DEFINE_INT(max_old_space_size, 0, "max size of the old space (in Mbytes)")
DEFINE_INT(initial_old_space_size, 0, "initial old space size (in Mbytes)")
DEFINE_SIZE_T(max_old_space_size, 0, "max size of the old space (in Mbytes)")
DEFINE_SIZE_T(initial_old_space_size, 0, "initial old space size (in Mbytes)")
DEFINE_BOOL(gc_global, false, "always perform global GCs")
DEFINE_INT(gc_interval, -1, "garbage collect after <n> allocations")
DEFINE_INT(retain_maps_for_n_gc, 2,
Expand Down Expand Up @@ -732,6 +734,8 @@ DEFINE_BOOL(expose_trigger_failure, false, "expose trigger-failure extension")
DEFINE_INT(stack_trace_limit, 10, "number of stack frames to capture")
DEFINE_BOOL(builtins_in_stack_traces, false,
"show built-in functions in stack traces")
DEFINE_BOOL(disallow_code_generation_from_strings, false,
"disallow eval and friends")

// builtins.cc
DEFINE_BOOL(allow_unsafe_function_constructor, false,
Expand Down
67 changes: 52 additions & 15 deletions deps/v8/src/flags.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include "src/flags.h"

#include <cctype>
#include <cerrno>
#include <cstdlib>
#include <sstream>

Expand Down Expand Up @@ -40,6 +41,7 @@ struct Flag {
TYPE_INT,
TYPE_UINT,
TYPE_FLOAT,
TYPE_SIZE_T,
TYPE_STRING,
TYPE_ARGS
};
Expand Down Expand Up @@ -82,6 +84,11 @@ struct Flag {
return reinterpret_cast<double*>(valptr_);
}

size_t* size_t_variable() const {
DCHECK(type_ == TYPE_SIZE_T);
return reinterpret_cast<size_t*>(valptr_);
}

const char* string_value() const {
DCHECK(type_ == TYPE_STRING);
return *reinterpret_cast<const char**>(valptr_);
Expand Down Expand Up @@ -120,6 +127,11 @@ struct Flag {
return *reinterpret_cast<const double*>(defptr_);
}

size_t size_t_default() const {
DCHECK(type_ == TYPE_SIZE_T);
return *reinterpret_cast<const size_t*>(defptr_);
}

const char* string_default() const {
DCHECK(type_ == TYPE_STRING);
return *reinterpret_cast<const char* const *>(defptr_);
Expand All @@ -143,6 +155,8 @@ struct Flag {
return *uint_variable() == uint_default();
case TYPE_FLOAT:
return *float_variable() == float_default();
case TYPE_SIZE_T:
return *size_t_variable() == size_t_default();
case TYPE_STRING: {
const char* str1 = string_value();
const char* str2 = string_default();
Expand Down Expand Up @@ -174,6 +188,9 @@ struct Flag {
case TYPE_FLOAT:
*float_variable() = float_default();
break;
case TYPE_SIZE_T:
*size_t_variable() = size_t_default();
break;
case TYPE_STRING:
set_string_value(string_default(), false);
break;
Expand Down Expand Up @@ -202,6 +219,8 @@ static const char* Type2String(Flag::FlagType type) {
case Flag::TYPE_UINT:
return "uint";
case Flag::TYPE_FLOAT: return "float";
case Flag::TYPE_SIZE_T:
return "size_t";
case Flag::TYPE_STRING: return "string";
case Flag::TYPE_ARGS: return "arguments";
}
Expand All @@ -228,6 +247,9 @@ std::ostream& operator<<(std::ostream& os, const Flag& flag) { // NOLINT
case Flag::TYPE_FLOAT:
os << *flag.float_variable();
break;
case Flag::TYPE_SIZE_T:
os << *flag.size_t_variable();
break;
case Flag::TYPE_STRING: {
const char* str = flag.string_value();
os << (str ? str : "NULL");
Expand Down Expand Up @@ -360,6 +382,27 @@ static Flag* FindFlag(const char* name) {
return NULL;
}

template <typename T>
bool TryParseUnsigned(Flag* flag, const char* arg, const char* value,
char** endp, T* out_val) {
// We do not use strtoul because it accepts negative numbers.
// Rejects values >= 2**63 when T is 64 bits wide but that
// seems like an acceptable trade-off.
uint64_t max = static_cast<uint64_t>(std::numeric_limits<T>::max());
errno = 0;
int64_t val = static_cast<int64_t>(strtoll(value, endp, 10));
if (val < 0 || static_cast<uint64_t>(val) > max || errno != 0) {
PrintF(stderr,
"Error: Value for flag %s of type %s is out of bounds "
"[0-%" PRIu64
"]\n"
"Try --help for options\n",
arg, Type2String(flag->type()), max);
return false;
}
*out_val = static_cast<T>(val);
return true;
}

// static
int FlagList::SetFlagsFromCommandLine(int* argc,
Expand Down Expand Up @@ -425,27 +468,21 @@ int FlagList::SetFlagsFromCommandLine(int* argc,
case Flag::TYPE_INT:
*flag->int_variable() = static_cast<int>(strtol(value, &endp, 10));
break;
case Flag::TYPE_UINT: {
// We do not use strtoul because it accepts negative numbers.
int64_t val = static_cast<int64_t>(strtoll(value, &endp, 10));
if (val < 0 || val > std::numeric_limits<unsigned int>::max()) {
PrintF(stderr,
"Error: Value for flag %s of type %s is out of bounds "
"[0-%" PRIu64
"]\n"
"Try --help for options\n",
arg, Type2String(flag->type()),
static_cast<uint64_t>(
std::numeric_limits<unsigned int>::max()));
case Flag::TYPE_UINT:
if (!TryParseUnsigned(flag, arg, value, &endp,
flag->uint_variable())) {
return_code = j;
break;
}
*flag->uint_variable() = static_cast<unsigned int>(val);
break;
}
case Flag::TYPE_FLOAT:
*flag->float_variable() = strtod(value, &endp);
break;
case Flag::TYPE_SIZE_T:
if (!TryParseUnsigned(flag, arg, value, &endp,
flag->size_t_variable())) {
return_code = j;
}
break;
case Flag::TYPE_STRING:
flag->set_string_value(value ? StrDup(value) : NULL, true);
break;
Expand Down
4 changes: 2 additions & 2 deletions deps/v8/src/heap/heap.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5463,8 +5463,8 @@ bool Heap::ConfigureHeap(size_t max_semi_space_size_in_kb,

// The new space size must be a power of two to support single-bit testing
// for containment.
max_semi_space_size_ = base::bits::RoundUpToPowerOfTwo32(
static_cast<uint32_t>(max_semi_space_size_));
max_semi_space_size_ = static_cast<size_t>(base::bits::RoundUpToPowerOfTwo64(
static_cast<uint64_t>(max_semi_space_size_)));

if (max_semi_space_size_ == kMaxSemiSpaceSizeInKB * KB) {
// Start with at least 1*MB semi-space on machines with a lot of memory.
Expand Down
26 changes: 13 additions & 13 deletions deps/v8/src/heap/heap.h
Original file line number Diff line number Diff line change
Expand Up @@ -584,15 +584,15 @@ class Heap {
#endif

// Semi-space size needs to be a multiple of page size.
static const int kMinSemiSpaceSizeInKB =
static const size_t kMinSemiSpaceSizeInKB =
1 * kPointerMultiplier * ((1 << kPageSizeBits) / KB);
static const int kMaxSemiSpaceSizeInKB =
static const size_t kMaxSemiSpaceSizeInKB =
16 * kPointerMultiplier * ((1 << kPageSizeBits) / KB);

// The old space size has to be a multiple of Page::kPageSize.
// Sizes are in MB.
static const int kMinOldGenerationSize = 128 * kPointerMultiplier;
static const int kMaxOldGenerationSize = 1024 * kPointerMultiplier;
static const size_t kMinOldGenerationSize = 128 * kPointerMultiplier;
static const size_t kMaxOldGenerationSize = 1024 * kPointerMultiplier;

static const int kTraceRingBufferSize = 512;
static const int kStacktraceBufferSize = 512;
Expand Down Expand Up @@ -1293,10 +1293,10 @@ class Heap {
size_t MaxOldGenerationSize() { return max_old_generation_size_; }

static size_t ComputeMaxOldGenerationSize(uint64_t physical_memory) {
const int old_space_physical_memory_factor = 4;
int computed_size =
static_cast<int>(physical_memory / i::MB /
old_space_physical_memory_factor * kPointerMultiplier);
const size_t old_space_physical_memory_factor = 4;
size_t computed_size = static_cast<size_t>(
physical_memory / i::MB / old_space_physical_memory_factor *
kPointerMultiplier);
return Max(Min(computed_size, kMaxOldGenerationSize),
kMinOldGenerationSize);
}
Expand All @@ -1308,11 +1308,11 @@ class Heap {
uint64_t capped_physical_memory =
Max(Min(physical_memory, max_physical_memory), min_physical_memory);
// linearly scale max semi-space size: (X-A)/(B-A)*(D-C)+C
int semi_space_size_in_kb =
static_cast<int>(((capped_physical_memory - min_physical_memory) *
(kMaxSemiSpaceSizeInKB - kMinSemiSpaceSizeInKB)) /
(max_physical_memory - min_physical_memory) +
kMinSemiSpaceSizeInKB);
size_t semi_space_size_in_kb =
static_cast<size_t>(((capped_physical_memory - min_physical_memory) *
(kMaxSemiSpaceSizeInKB - kMinSemiSpaceSizeInKB)) /
(max_physical_memory - min_physical_memory) +
kMinSemiSpaceSizeInKB);
return RoundUp(semi_space_size_in_kb, (1 << kPageSizeBits) / KB);
}

Expand Down
9 changes: 9 additions & 0 deletions deps/v8/test/mjsunit/disallow-codegen-from-strings.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// Copyright 2017 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

// Flags: --disallow-code-generation-from-strings

assertThrows("1 + 1", EvalError);
assertThrows(() => eval("1 + 1"), EvalError);
assertThrows(() => Function("x", "return x + 1"), EvalError);
4 changes: 4 additions & 0 deletions doc/api/_toc.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
@// NB(chrisdickinson): if you move this file, be sure to update tools/doc/html.js to
@// point at the new location.
@// tools/doc/html.js to point at the new location.

<!--introduced_in=v0.10.0-->

* [About these Docs](documentation.html)
* [Usage & Example](synopsis.html)

Expand Down
15 changes: 13 additions & 2 deletions doc/api/fs.md
Original file line number Diff line number Diff line change
Expand Up @@ -2529,8 +2529,19 @@ changes:
* `callback` {Function}
* `err` {Error}

Asynchronous rename(2). No arguments other than a possible exception are given
to the completion callback.
Asynchronously rename file at `oldPath` to the pathname provided
as `newPath`. In the case that `newPath` already exists, it will
be overwritten. No arguments other than a possible exception are
given to the completion callback.

See also: rename(2).

```js
fs.rename('oldFile.txt', 'newFile.txt', (err) => {
if (err) throw err;
console.log('Rename complete!');
});
```

## fs.renameSync(oldPath, newPath)
<!-- YAML
Expand Down
Loading