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

lib,src: remove vm.runInDebugContext() #13295

Merged
merged 2 commits into from
Nov 23, 2017

Conversation

bnoordhuis
Copy link
Member

The V8 API it is based on is deprecated and scheduled for removal later this year. Remove it.

The first commit replaces the Debug.MakeMirror() call in lib/util.js with something else.

The most important reason for doing this is of course to have a deprecation warning-free build again!

@bnoordhuis bnoordhuis added the semver-major PRs that contain breaking changes and should be released in the next major version. label May 30, 2017
@nodejs-github-bot nodejs-github-bot added build Issues and PRs related to build files or the CI. c++ Issues and PRs that require attention from people who are familiar with C++. lib / src Issues and PRs related to general changes in the lib or src directory. tools Issues and PRs related to the tools directory. labels May 30, 2017
@addaleax
Copy link
Member

I think @joshgav or @ofrobots had the plan of removing this after Node 9 (i.e. in Node 10)?

@@ -1,3 +1,4 @@
lib/internal/v8.js
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The file is whitelisted because the V8 builtins don't lint. They're not legal JS syntax, eslint can't parse them.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should be able add comments by starting lines with # – if you comment here in the PR, that sounds like a good indicator that it makes sense to do so. :)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are other lib/internal/v8 files whitelisted. I don't think we need a comment. But either way is fine.

lib/util.js Outdated
const mirror = Debug.MakeMirror(value, true);
function formatMapIterator(ctx, value, recurseTimes, visibleKeys, keys) {
var nextRecurseTimes = recurseTimes === null ? null : recurseTimes - 1;
var vals = previewMapIterator(value, 100);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is a minor change in behavior here in that the preview is now limited to 100 elements. Before, it would show them all but that is (IMO) rather annoying with large maps and sets (and it's basically equivalent to printing the map or set minus the already iterated over elements.)

I'm planning to follow up with a PR that prints a nice "..." if there are more elements but I can restore the old behavior if people prefer that.

@bnoordhuis
Copy link
Member Author

I think @joshgav or @ofrobots had the plan of removing this after Node 9 (i.e. in Node 10)?

In a LTS release? That doesn't make sense. Removing it in node 9 gives people the chance to update their code bases before entering the next LTS.

@targos
Copy link
Member

targos commented May 30, 2017

Documentation says Node 10+: https://github.com/nodejs/node/blob/master/doc/api/deprecations.md#dep0069-vmrunindebugcontextstring

According to our deprecation policy, we should first emit a warning in Node 9 and remove the feature in Node 10 or higher. I guess it would have to be 10 here because V8 will remove the API by the end of the year.

@addaleax
Copy link
Member

CITGM: https://ci.nodejs.org/view/Node.js-citgm/job/citgm-smoker/845/

I don’t know about the reasons behind not going for a runtime deprecation in Node 8, I was just pretty sure I read somewhere that it was intentional. ¯\_(ツ)_/¯

@targos
Copy link
Member

targos commented May 30, 2017

Most of the discussion is here: #12243
PR for the runtime deprecation: #12815

@@ -1,3 +1,4 @@
lib/internal/v8.js
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should be able add comments by starting lines with # – if you comment here in the PR, that sounds like a good indicator that it makes sense to do so. :)

doc/api/vm.md Outdated
added: v0.11.14
-->

> Stability: 0 - Deprecated. An alternative is in development.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You’ll also want to update the entry in deprecations.md to say Type: End-of-Life

@bnoordhuis
Copy link
Member Author

According to our deprecation policy, we should first emit a warning in Node 9 and remove the feature in Node 10 or higher.

That doesn't apply to vm.runInDebugContext(), its documentation has always stated very clearly that it could disappear at any time.

@jasnell
Copy link
Member

jasnell commented May 30, 2017

We really ought to have had a deprecation message added in 8.0.0 for this but it's rather too late now. If the plan is to remove it in 9.0, then we should get a runtime deprecation into an 8.x minor.

Copy link
Member

@TimothyGu TimothyGu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For context: the first part of this PR which removes the use of Debug Mirrors is, well, hacky as heck. But there is no other solution as I have found out when investigating #11875, other than convincing V8 devs to add C++ APIs for Map- and SetIterators.

@bnoordhuis can you attach a Fixes: https://github.com/nodejs/node/issues/11875 to the commit message as well?

while (n-- > 0) {
const rc = %MapIteratorNext(it, out);
if (rc === 0) break;
if (rc === 1) result.push(out[0]); // it.keys()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can the 0/1/2/3 magic numbers be constants instead? V8 is using

define ITERATOR_KIND_KEYS = 1;
define ITERATOR_KIND_VALUES = 2;
define ITERATOR_KIND_ENTRIES = 3;

which looks good to me.

it = %MapIteratorClone(it);
const result = [];
const out = [,,];
while (n-- > 0) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can a for-of loop be used directly on the cloned it?

Copy link
Member

@fhinkel fhinkel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM with nit

@@ -1,3 +1,4 @@
lib/internal/v8.js
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are other lib/internal/v8 files whitelisted. I don't think we need a comment. But either way is fine.

'use strict';
const common = require('../common');
const assert = require('assert');
const util = require('util');
const vm = require('vm');
const { previewMapIterator } = require('internal/v8');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we test the SetIterator as well?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't add a test here, I just updated an existing test that was using internals.

@fhinkel fhinkel mentioned this pull request Aug 3, 2017
4 tasks
@TimothyGu
Copy link
Member

@fhinkel Do you have a better way to preserve the Iterator support w/o using V8 natives syntax?

@fhinkel
Copy link
Member

fhinkel commented Aug 4, 2017

Maybe we could add these methods to the V8 API. Relying on intrinsic functions (%) is somewhat dangerous. They are not part of the API and we might change/delete them without a deprecation period.

@bnoordhuis
Copy link
Member Author

Yes, that's my longer-term goal. Using natives syntax is a short-term + least-effort solution.

@BridgeAR
Copy link
Member

This needs a rebase.

Copy link
Member

@TimothyGu TimothyGu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM once #13295 (comment) is addressed.

@BridgeAR BridgeAR added stalled Issues and PRs that are stalled. and removed stalled Issues and PRs that are stalled. labels Sep 8, 2017
@BridgeAR
Copy link
Member

@bnoordhuis do you still want to follow up on this?

@bnoordhuis
Copy link
Member Author

Updated. CI for a change: https://ci.nodejs.org/job/node-test-pull-request/10379/

@ofrobots
Copy link
Contributor

I would like to formally request that we do NOT land this in Node 9. We have been migrating some of the code we use in https://github.com/GoogleCloudPlatform/cloud-debug-nodejs to the inspector module. At this point we do not think the inspector API is a complete replacement for the Debug context, at least for our use cases. See V8 bug: https://bugs.chromium.org/p/v8/issues/detail?id=6945.

Since there is no pressing need to remove the API just yet, let's not accelerate the removal.

@mcollina
Copy link
Member

👍 in waiting.

@addaleax addaleax added this to the 10.0.0 milestone Oct 22, 2017
@addaleax
Copy link
Member

This would need to be rebased now that the runtime deprecation has been merged.

@BridgeAR
Copy link
Member

Ping @bnoordhuis this could land after a rebase

@bnoordhuis
Copy link
Member Author

bnoordhuis commented Nov 22, 2017

@BridgeAR BridgeAR added the author ready PRs that have at least one approval, no pending requests for changes, and a CI started. label Nov 22, 2017
@@ -1,15 +1,7 @@
'use strict';

// Hack to load the js-yaml module from eslint.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unrelated change?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

grr... this one is becoming quite annoying.

@jasnell
Copy link
Member

jasnell commented Nov 22, 2017

@bnoordhuis ... the extraneous js-yaml change is causing CI to fail on this.

@bnoordhuis
Copy link
Member Author

With js-yaml change undone: https://ci.nodejs.org/job/node-test-pull-request/11679/

This paves the way for removing `vm.runInDebugContext()`.  Inspection
of Map and Set iterators is now done through V8 instrinsics.

Fixes: nodejs#11875
PR-URL: nodejs#13295
Reviewed-By: Anna Henningsen <[email protected]>
Reviewed-By: Franziska Hinkelmann <[email protected]>
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Robert Jefe Lindstaedt <[email protected]>
Reviewed-By: Ruben Bridgewater <[email protected]>
Reviewed-By: Timothy Gu <[email protected]>
The V8 API it is based on is deprecated and scheduled for removal later
this year.  Remove it.

PR-URL: nodejs#13295
Reviewed-By: Anna Henningsen <[email protected]>
Reviewed-By: Franziska Hinkelmann <[email protected]>
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Robert Jefe Lindstaedt <[email protected]>
Reviewed-By: Ruben Bridgewater <[email protected]>
Reviewed-By: Timothy Gu <[email protected]>
@bnoordhuis bnoordhuis closed this Nov 23, 2017
@bnoordhuis bnoordhuis deleted the remove-runindebugcontext branch November 23, 2017 23:16
@bnoordhuis bnoordhuis merged commit 6f724e1 into nodejs:master Nov 23, 2017
@addaleax addaleax removed the author ready PRs that have at least one approval, no pending requests for changes, and a CI started. label Nov 28, 2017
@addaleax
Copy link
Member

addaleax commented Dec 4, 2017

Btw: This breaks gulp because it uses [email protected] and their parsing of process.binding('natives') doesn’t expect the --allow_natives_syntax cleverness.

That’s nothing we can do anything about, we need this patch in order to avoid breakage ourselves, so it’s graceful-fs that needs to work around this, but I wanted to leave that information here.

blattersturm pushed a commit to citizenfx/node that referenced this pull request Apr 22, 2018
The V8 API it is based on is deprecated and scheduled for removal later
this year.  Remove it.

PR-URL: nodejs#13295
Reviewed-By: Anna Henningsen <[email protected]>
Reviewed-By: Franziska Hinkelmann <[email protected]>
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Robert Jefe Lindstaedt <[email protected]>
Reviewed-By: Ruben Bridgewater <[email protected]>
Reviewed-By: Timothy Gu <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
build Issues and PRs related to build files or the CI. c++ Issues and PRs that require attention from people who are familiar with C++. lib / src Issues and PRs related to general changes in the lib or src directory. semver-major PRs that contain breaking changes and should be released in the next major version. tools Issues and PRs related to the tools directory.
Projects
None yet
Development

Successfully merging this pull request may close these issues.