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: support returning Safe collections from C++ #36989

Conversation

ExE-Boss
Copy link
Contributor

Refs: #36652

This works similarly to what’s done to support constructing Buffer instances from C++, but unlike Buffer.prototype, the Safe* collection prototypes can be captured as soon as InitializePrimordials has finished running lib/internal/per_context/primordials.js.

@nodejs-github-bot nodejs-github-bot added 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. labels Jan 19, 2021
@ExE-Boss ExE-Boss force-pushed the lib/primordials/support-returning-safe-collections-from-cpp branch 3 times, most recently from ccec24a to e5c872f Compare January 19, 2021 04:47
Copy link
Contributor

@aduh95 aduh95 left a comment

Choose a reason for hiding this comment

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

I think it'd interesting to add a check that we're no longer using user-mutable methods:

const assert = require('assert');
const { options } = require('internal/options');

assert.notStrictEqual(options.get, Map.prototype.get);
const assert = require('assert');
const { getOptionValue } = require('internal/options');

Map.prototype.get = function get() { return 'polluted result'; };
assert.strictEqual(getOptionValue('--expose-internals'), true);

test/parallel/test-options-binding.js Outdated Show resolved Hide resolved
test/parallel/test-options-binding.js Outdated Show resolved Hide resolved
test/parallel/test-options-binding.js Outdated Show resolved Hide resolved
@ExE-Boss ExE-Boss force-pushed the lib/primordials/support-returning-safe-collections-from-cpp branch from e5c872f to ad9b5a5 Compare January 19, 2021 10:30
@ExE-Boss
Copy link
Contributor Author

const assert = require('assert');
const { options } = require('internal/options');

assert.notStrictEqual(options.get, Map.prototype.get);

That will fail unless Map.prototype.get gets mutated, because the Safe* collections are initialised by having their descriptors copied from the unsafe collections, and thus SafeMap.prototype.get === Map.prototype.get is guaranteed until user code runs.

test/parallel/test-options-binding.js Outdated Show resolved Hide resolved
Co-authored-by: Antoine du Hamel <duhamelantoine1995@gmail.com>
@ExE-Boss ExE-Boss force-pushed the lib/primordials/support-returning-safe-collections-from-cpp branch from fd622d9 to b427d33 Compare January 20, 2021 12:02
test/parallel/test-options-binding.js Outdated Show resolved Hide resolved
test/parallel/test-options-binding.js Outdated Show resolved Hide resolved
Co-authored-by: Antoine du Hamel <duhamelantoine1995@gmail.com>
@nodejs-github-bot
Copy link
Collaborator

@aduh95 aduh95 added the author ready PRs that have at least one approval, no pending requests for changes, and a CI started. label Jan 20, 2021
@nodejs-github-bot
Copy link
Collaborator

jasnell pushed a commit that referenced this pull request Jan 23, 2021
Co-authored-by: Antoine du Hamel <duhamelantoine1995@gmail.com>

PR-URL: #36989
Refs: #36652
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
@jasnell
Copy link
Member

jasnell commented Jan 23, 2021

Landed in 3ec7114

@jasnell jasnell closed this Jan 23, 2021
@ExE-Boss ExE-Boss deleted the lib/primordials/support-returning-safe-collections-from-cpp branch January 23, 2021 04:50
targos pushed a commit that referenced this pull request Feb 2, 2021
Co-authored-by: Antoine du Hamel <duhamelantoine1995@gmail.com>

PR-URL: #36989
Refs: #36652
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
@targos targos mentioned this pull request Feb 2, 2021
targos pushed a commit that referenced this pull request May 25, 2021
Co-authored-by: Antoine du Hamel <duhamelantoine1995@gmail.com>

PR-URL: #36989
Refs: #36652
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
targos pushed a commit that referenced this pull request May 30, 2021
Co-authored-by: Antoine du Hamel <duhamelantoine1995@gmail.com>

PR-URL: #36989
Refs: #36652
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
targos pushed a commit that referenced this pull request Jun 5, 2021
Co-authored-by: Antoine du Hamel <duhamelantoine1995@gmail.com>

PR-URL: #36989
Refs: #36652
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
targos pushed a commit that referenced this pull request Jun 11, 2021
Co-authored-by: Antoine du Hamel <duhamelantoine1995@gmail.com>

PR-URL: #36989
Refs: #36652
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
author ready PRs that have at least one approval, no pending requests for changes, and a CI started. 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.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants