vm,src: add property query interceptors by legendecas · Pull Request #53517 · nodejs/node · GitHub
Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
128 changes: 116 additions & 12 deletions src/node_contextify.cc
8 changes: 7 additions & 1 deletion src/node_contextify.h
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,9 @@ class ContextifyContext : public BaseObject {
bool produce_cached_data,
v8::Local<v8::Symbol> id_symbol,
const errors::TryCatchScope& try_catch);
static void WeakCallback(const v8::WeakCallbackInfo<ContextifyContext>& data);
static v8::Intercepted PropertyQueryCallback(
v8::Local<v8::Name> property,
const v8::PropertyCallbackInfo<v8::Integer>& args);
static v8::Intercepted PropertyGetterCallback(
v8::Local<v8::Name> property,
const v8::PropertyCallbackInfo<v8::Value>& args);
Expand All @@ -114,6 +116,8 @@ class ContextifyContext : public BaseObject {
const v8::PropertyCallbackInfo<v8::Boolean>& args);
static void PropertyEnumeratorCallback(
const v8::PropertyCallbackInfo<v8::Array>& args);
static v8::Intercepted IndexedPropertyQueryCallback(
uint32_t index, const v8::PropertyCallbackInfo<v8::Integer>& args);
static v8::Intercepted IndexedPropertyGetterCallback(
uint32_t index, const v8::PropertyCallbackInfo<v8::Value>& args);
static v8::Intercepted IndexedPropertySetterCallback(
Expand All @@ -128,6 +132,8 @@ class ContextifyContext : public BaseObject {
const v8::PropertyCallbackInfo<void>& args);
static v8::Intercepted IndexedPropertyDeleterCallback(
uint32_t index, const v8::PropertyCallbackInfo<v8::Boolean>& args);
static void IndexedPropertyEnumeratorCallback(
const v8::PropertyCallbackInfo<v8::Array>& args);

v8::Global<v8::Context> context_;
std::unique_ptr<v8::MicrotaskQueue> microtask_queue_;
Expand Down
49 changes: 49 additions & 0 deletions test/parallel/test-vm-global-property-enumerator.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
'use strict';
require('../common');
const vm = require('vm');
const assert = require('assert');

// Regression of https://github.com/nodejs/node/issues/53346

const cases = [
{
get key() {
return 'value';
},
},
{
// Intentionally single setter.
// eslint-disable-next-line accessor-pairs
set key(value) {},
},
{},
{
key: 'value',
},
(new class GetterObject {
get key() {
return 'value';
}
}()),
(new class SetterObject {
// Intentionally single setter.
// eslint-disable-next-line accessor-pairs
set key(value) {
// noop
}
}()),
[],
[['key', 'value']],
{
__proto__: {
key: 'value',
},
},
];

for (const [idx, obj] of cases.entries()) {
const ctx = vm.createContext(obj);
const globalObj = vm.runInContext('this', ctx);
const keys = Object.keys(globalObj);
assert.deepStrictEqual(keys, Object.keys(obj), `Case ${idx} failed`);
}
83 changes: 83 additions & 0 deletions test/parallel/test-vm-global-property-prototype.js