Skip to content
This repository has been archived by the owner on Oct 15, 2020. It is now read-only.

Commit

Permalink
meta: merge node/master into node-chakracore/master
Browse files Browse the repository at this point in the history
Merge d4b605b as of 2018-02-05
This commit was automatically generated. For any problems, please contact jackhorton

Reviewed-By: Jimmy Thomson <jithomso@microsoft.com>
  • Loading branch information
chakrabot committed Feb 11, 2018
2 parents 588f568 + d4b605b commit 6385fdc
Show file tree
Hide file tree
Showing 20 changed files with 205 additions and 49 deletions.
2 changes: 1 addition & 1 deletion deps/chakrashim/include/v8-version.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#define V8_MAJOR_VERSION 6
#define V8_MINOR_VERSION 4
#define V8_BUILD_NUMBER 388
#define V8_PATCH_LEVEL 40
#define V8_PATCH_LEVEL 41

// Use 1 for candidates and 0 otherwise.
// (Boolean macro values are not supported by all preprocessors.)
Expand Down
2 changes: 1 addition & 1 deletion deps/v8/include/v8-version.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#define V8_MAJOR_VERSION 6
#define V8_MINOR_VERSION 4
#define V8_BUILD_NUMBER 388
#define V8_PATCH_LEVEL 40
#define V8_PATCH_LEVEL 41

// Use 1 for candidates and 0 otherwise.
// (Boolean macro values are not supported by all preprocessors.)
Expand Down
1 change: 1 addition & 0 deletions deps/v8/src/factory.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1613,6 +1613,7 @@ Handle<JSFunction> Factory::NewFunction(const NewFunctionArgs& args) {
}
Handle<Map> initial_map = NewMap(args.type_, args.instance_size_,
elements_kind, args.inobject_properties_);
result->shared()->set_expected_nof_properties(args.inobject_properties_);
// TODO(littledan): Why do we have this is_generator test when
// NewFunctionPrototype already handles finding an appropriately
// shared prototype?
Expand Down
22 changes: 22 additions & 0 deletions deps/v8/test/mjsunit/regress/regress-crbug-800032.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// Copyright 2018 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: --allow-natives-syntax --expose-gc


class Derived extends RegExp {
constructor(a) {
// Syntax Error
const a = 1;
}
}

let o = Reflect.construct(RegExp, [], Derived);
%HeapObjectVerify(o);
// Check that we can properly access lastIndex.
assertEquals(o.lastIndex, 0);
o.lastIndex = 1;
assertEquals(o.lastIndex, 1);
o.lastIndex = 0;
gc();
8 changes: 4 additions & 4 deletions doc/api/assert.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ For more information about the used equality comparisons see
added: REPLACEME
changes:
- version: REPLACEME
pr-url: https://github.com/nodejs/node/pull/REPLACEME
pr-url: https://github.com/nodejs/node/pull/17615
description: Added error diffs to the strict mode
- version: REPLACEME
pr-url: https://github.com/nodejs/node/pull/17002
Expand Down Expand Up @@ -445,7 +445,7 @@ See below for further details.
added: v0.1.21
changes:
- version: REPLACEME
pr-url: https://github.com/nodejs/node/pull/REPLACEME
pr-url: https://github.com/nodejs/node/pull/18418
description: Calling `assert.fail` with more than one argument is deprecated
and emits a warning.
-->
Expand Down Expand Up @@ -728,7 +728,7 @@ parameter is an instance of an [`Error`][] then it will be thrown instead of the
added: v0.1.21
changes:
- version: REPLACEME
pr-url: https://github.com/nodejs/node/pull/REPLACEME
pr-url: https://github.com/nodejs/node/pull/18319
description: assert.ok() (no arguments) will now use a predefined error msg.
-->
* `value` {any}
Expand Down Expand Up @@ -834,7 +834,7 @@ instead of the `AssertionError`.
added: v0.1.21
changes:
- version: REPLACEME
pr-url: https://github.com/nodejs/node/pull/REPLACEME
pr-url: https://github.com/nodejs/node/pull/17584
description: The `error` parameter can now be an object as well.
- version: v4.2.0
pr-url: https://github.com/nodejs/node/pull/3276
Expand Down
56 changes: 56 additions & 0 deletions doc/api/async_hooks.md
Original file line number Diff line number Diff line change
Expand Up @@ -509,6 +509,9 @@ const server = net.createServer(function onConnection(conn) {
});
```

Note that promise contexts may not get precise executionAsyncIds by default.
See the section on [promise execution tracking][].

#### `async_hooks.triggerAsyncId()`

* Returns: {number} The ID of the resource responsible for calling the callback
Expand All @@ -531,6 +534,57 @@ const server = net.createServer((conn) => {
});
```

Note that promise contexts may not get valid triggerAsyncIds by default. See
the section on [promise execution tracking][].

## Promise execution tracking

By default, promise executions are not assigned asyncIds due to the relatively
expensive nature of the [promise introspection API][PromiseHooks] provided by
V8. This means that programs using promises or `async`/`await` will not get
correct execution and trigger ids for promise callback contexts by default.

Here's an example:

```js
const ah = require('async_hooks');
Promise.resolve(1729).then(() => {
console.log(`eid ${ah.executionAsyncId()} tid ${ah.triggerAsyncId()}`);
});
// produces:
// eid 1 tid 0
```

Observe that the `then` callback claims to have executed in the context of the
outer scope even though there was an asynchronous hop involved. Also note that
the triggerAsyncId value is 0, which means that we are missing context about the
resource that caused (triggered) the `then` callback to be executed.

Installing async hooks via `async_hooks.createHook` enables promise execution
tracking. Example:

```js
const ah = require('async_hooks');
ah.createHook({ init() {} }).enable(); // forces PromiseHooks to be enabled.
Promise.resolve(1729).then(() => {
console.log(`eid ${ah.executionAsyncId()} tid ${ah.triggerAsyncId()}`);
});
// produces:
// eid 7 tid 6
```

In this example, adding any actual hook function enabled the tracking of
promises. There are two promises in the example above; the promise created by
`Promise.resolve()` and the promise returned by the call to `then`. In the
example above, the first promise got the asyncId 6 and the latter got asyncId 7.
During the execution of the `then` callback, we are executing in the context of
promise with asyncId 7. This promise was triggered by async resource 6.

Another subtlety with promises is that `before` and `after` callbacks are run
only on chained promises. That means promises not created by `then`/`catch` will
not have the `before` and `after` callbacks fired on them. For more details see
the details of the V8 [PromiseHooks][] API.

## JavaScript Embedder API

Library developers that handle their own asynchronous resources performing tasks
Expand Down Expand Up @@ -655,3 +709,5 @@ constructor.
[`destroy` callback]: #async_hooks_destroy_asyncid
[`init` callback]: #async_hooks_init_asyncid_type_triggerasyncid_resource
[Hook Callbacks]: #async_hooks_hook_callbacks
[PromiseHooks]: https://docs.google.com/document/d/1rda3yKGHimKIhg5YeoAmCOtyURgsbTH_qaYR79FELlk
[promise execution tracking]: #async_hooks_promise_execution_tracking
2 changes: 1 addition & 1 deletion doc/api/console.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ new Console(process.stdout, process.stderr);
added: v0.1.101
changes:
- version: REPLACEME
pr-url: https://github.com/nodejs/node/pull/REPLACEME
pr-url: https://github.com/nodejs/node/pull/17706
description: The implementation is now spec compliant and does not throw
anymore.
-->
Expand Down
2 changes: 1 addition & 1 deletion doc/api/util.md
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,7 @@ changes:
pr-url: https://github.com/nodejs/node/pull/17907
description: The `depth` default changed to Infinity.
- version: REPLACEME
pr-url: https://github.com/nodejs/node/pull/REPLACEME
pr-url: https://github.com/nodejs/node/pull/17576
description: The `compact` option is supported now.
- version: v6.6.0
pr-url: https://github.com/nodejs/node/pull/8174
Expand Down
2 changes: 1 addition & 1 deletion lib/_stream_readable.js
Original file line number Diff line number Diff line change
Expand Up @@ -751,7 +751,7 @@ Readable.prototype.unpipe = function(dest) {
state.flowing = false;

for (var i = 0; i < len; i++)
dests[i].emit('unpipe', this, unpipeInfo);
dests[i].emit('unpipe', this, { hasUnpiped: false });
return this;
}

Expand Down
5 changes: 5 additions & 0 deletions lib/internal/loader/ModuleWrap.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
'use strict';

// exposes ModuleWrap for testing

module.exports = internalBinding('module_wrap').ModuleWrap;
36 changes: 18 additions & 18 deletions lib/internal/vm/Module.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ const {
getConstructorOf,
customInspectSymbol,
} = require('internal/util');
const { SafePromise } = require('internal/safe_globals');

const {
ModuleWrap,
Expand Down Expand Up @@ -131,27 +132,26 @@ class Module {
const wrap = wrapMap.get(this);
if (wrap.getStatus() !== kUninstantiated)
throw new errors.Error('ERR_VM_MODULE_STATUS', 'must be uninstantiated');

linkingStatusMap.set(this, 'linking');
const promises = [];
wrap.link((specifier) => {
const p = (async () => {
const m = await linker(specifier, this);
if (!m || !wrapMap.has(m))
throw new errors.Error('ERR_VM_MODULE_NOT_MODULE');
if (m.context !== this.context)
throw new errors.Error('ERR_VM_MODULE_DIFFERENT_CONTEXT');
const childLinkingStatus = linkingStatusMap.get(m);
if (childLinkingStatus === 'errored')
throw new errors.Error('ERR_VM_MODULE_LINKING_ERRORED');
if (childLinkingStatus === 'unlinked')
await m.link(linker);
return wrapMap.get(m);
})();
promises.push(p);
return p;

const promises = wrap.link(async (specifier) => {
const m = await linker(specifier, this);
if (!m || !wrapMap.has(m))
throw new errors.Error('ERR_VM_MODULE_NOT_MODULE');
if (m.context !== this.context)
throw new errors.Error('ERR_VM_MODULE_DIFFERENT_CONTEXT');
const childLinkingStatus = linkingStatusMap.get(m);
if (childLinkingStatus === 'errored')
throw new errors.Error('ERR_VM_MODULE_LINKING_ERRORED');
if (childLinkingStatus === 'unlinked')
await m.link(linker);
return wrapMap.get(m);
});

try {
await Promise.all(promises);
if (promises !== undefined)
await SafePromise.all(promises);
linkingStatusMap.set(this, 'linked');
} catch (err) {
linkingStatusMap.set(this, 'errored');
Expand Down
1 change: 1 addition & 0 deletions node.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@
'lib/internal/loader/DefaultResolve.js',
'lib/internal/loader/ModuleJob.js',
'lib/internal/loader/ModuleMap.js',
'lib/internal/loader/ModuleWrap.js',
'lib/internal/loader/Translators.js',
'lib/internal/safe_globals.js',
'lib/internal/net.js',
Expand Down
2 changes: 1 addition & 1 deletion src/module_wrap.cc
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ void ModuleWrap::Link(const FunctionCallbackInfo<Value>& args) {
Local<Promise> resolve_promise = resolve_return_value.As<Promise>();
obj->resolve_cache_[specifier_std].Reset(env->isolate(), resolve_promise);

promises->Set(mod_context, specifier, resolve_promise).FromJust();
promises->Set(mod_context, i, resolve_promise).FromJust();
}

args.GetReturnValue().Set(promises);
Expand Down
10 changes: 6 additions & 4 deletions src/node_api.cc
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,12 @@ struct napi_env__ {
} \
} while (0)

#define CHECK_ENV(env) \
if ((env) == nullptr) { \
return napi_invalid_arg; \
}
#define CHECK_ENV(env) \
do { \
if ((env) == nullptr) { \
return napi_invalid_arg; \
} \
} while (0)

#define CHECK_ARG(env, arg) \
RETURN_STATUS_IF_FALSE((env), ((arg) != nullptr), napi_invalid_arg)
Expand Down
5 changes: 0 additions & 5 deletions test/cctest/node_test_fixture.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,6 @@ class NodeTestFixture : public ::testing::Test {
protected:
v8::Isolate* isolate_;

~NodeTestFixture() {
TearDown();
}

virtual void SetUp() {
CHECK_EQ(0, uv_loop_init(&current_loop));
platform_ = new node::NodePlatform(8, nullptr);
Expand All @@ -86,7 +82,6 @@ class NodeTestFixture : public ::testing::Test {
}

virtual void TearDown() {
if (platform_ == nullptr) return;
platform_->Shutdown();
while (uv_loop_alive(&current_loop)) {
uv_run(&current_loop, UV_RUN_ONCE);
Expand Down
11 changes: 1 addition & 10 deletions test/cctest/test_aliased_buffer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,7 @@

using node::AliasedBuffer;

class AliasBufferTest : public NodeTestFixture {
protected:
void SetUp() override {
NodeTestFixture::SetUp();
}

void TearDown() override {
NodeTestFixture::TearDown();
}
};
class AliasBufferTest : public NodeTestFixture {};

template<class NativeT>
void CreateOracleValues(NativeT* buf, size_t count) {
Expand Down
2 changes: 1 addition & 1 deletion test/cctest/test_node_postmortem_metadata.cc
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ TEST_F(DebugSymbolsTest, ReqWrapList) {
// NOTE (mmarchini): Workaround to fix failing tests on ARM64 machines with
// older GCC. Should be removed once we upgrade the GCC version used on our
// ARM64 CI machinies.
for (auto it : *(*env)->req_wrap_queue()) {}
for (auto it : *(*env)->req_wrap_queue()) (void) &it;

auto queue = reinterpret_cast<uintptr_t>((*env)->req_wrap_queue());
auto head = queue +
Expand Down
29 changes: 29 additions & 0 deletions test/parallel/test-internal-module-wrap.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
'use strict';

// Flags: --expose-internals

const common = require('../common');
common.crashOnUnhandledRejection();
const assert = require('assert');

const ModuleWrap = require('internal/loader/ModuleWrap');
const { getPromiseDetails, isPromise } = process.binding('util');
const setTimeoutAsync = require('util').promisify(setTimeout);

const foo = new ModuleWrap('export * from "bar"; 6;', 'foo');
const bar = new ModuleWrap('export const five = 5', 'bar');

(async () => {
const promises = foo.link(() => setTimeoutAsync(1000).then(() => bar));
assert.strictEqual(promises.length, 1);
assert(isPromise(promises[0]));

await Promise.all(promises);

assert.strictEqual(getPromiseDetails(promises[0])[1], bar);

foo.instantiate();

assert.strictEqual(await foo.evaluate(), 6);
assert.strictEqual(foo.namespace().five, 5);
})();
Loading

0 comments on commit 6385fdc

Please sign in to comment.