Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 7964849

Browse filesBrowse files
fhinkelevanlucas
authored andcommitted
src: explain implementation of vm module
The vm module uses interceptors on the object template. This is not straight forward and a comment in the source will help the next person working on this. PR-URL: #16962 Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Michaël Zasso <targos@protonmail.com> Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net>
1 parent c179254 commit 7964849
Copy full SHA for 7964849

File tree

Expand file treeCollapse file tree

1 file changed

+21
-0
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

1 file changed

+21
-0
lines changed
Open diff view settings
Collapse file

‎src/node_contextify.cc‎

Copy file name to clipboardExpand all lines: src/node_contextify.cc
+21Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,29 @@ using v8::UnboundScript;
6464
using v8::Value;
6565
using v8::WeakCallbackInfo;
6666

67+
// The vm module executes code in a sandboxed environment with a different
68+
// global object than the rest of the code. This is achieved by applying
69+
// every call that changes or queries a property on the global `this` in the
70+
// sandboxed code, to the sandbox object.
71+
//
72+
// The implementation uses V8's interceptors for methods like `set`, `get`,
73+
// `delete`, `defineProperty`, and for any query of the property attributes.
74+
// Property handlers with interceptors are set on the object template for
75+
// the sandboxed code. Handlers for both named properties and for indexed
76+
// properties are used. Their functionality is almost identical, the indexed
77+
// interceptors mostly just call the named interceptors.
78+
//
79+
// For every `get` of a global property in the sandboxed context, the
80+
// interceptor callback checks the sandbox object for the property.
81+
// If the property is defined on the sandbox, that result is returned to
82+
// the original call instead of finishing the query on the global object.
83+
//
84+
// For every `set` of a global property, the interceptor callback defines or
85+
// changes the property both on the sandbox and the global proxy.
86+
6787
namespace {
6888

89+
// Convert an int to a V8 Name (String or Symbol).
6990
Local<Name> Uint32ToName(Local<Context> context, uint32_t index) {
7091
return Uint32::New(context->GetIsolate(), index)->ToString(context)
7192
.ToLocalChecked();

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.