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

[18.x] vm: backport vm-related fixes #51004

Closed
wants to merge 22 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
a6524dd
deps: V8: cherry-pick c400af48b5ef
joyeecheung Dec 1, 2023
990caf3
deps: V8: cherry-pick 7f5daed62d47
joyeecheung Dec 1, 2023
8ade4aa
deps: V8: cherry-pick 9a98f96b6d68
joyeecheung Dec 1, 2023
80f54b7
deps: V8: cherry-pick 94e8282325a1
joyeecheung Dec 1, 2023
213e73b
deps: V8: cherry-pick 3dd9576ce336
joyeecheung Dec 1, 2023
0f33b00
deps: V8: cherry-pick 1fada6b36f8d
joyeecheung Dec 1, 2023
59cf71f
deps: V8: cherry-pick 705e374124ae
joyeecheung Dec 1, 2023
86d8b58
deps: V8: cherry-pick 71ff68830279
joyeecheung Dec 1, 2023
c8ed93a
lib: fix compileFunction throws range error for negative numbers
MrJithil Oct 6, 2023
f1251ef
src: cast v8::Object::GetInternalField() return value to v8::Value
joyeecheung Aug 2, 2023
af9edb4
deps: add v8::Object::SetInternalFieldForNodeCore()
joyeecheung Sep 26, 2023
9e8629c
src: set ModuleWrap internal fields only once
joyeecheung Sep 8, 2023
bb3462a
module: use symbol in WeakMap to manage host defined options
joyeecheung Jun 21, 2023
05778c4
module: fix leak of vm.SyntheticModule
joyeecheung Jun 21, 2023
0849599
module: fix the leak in SourceTextModule and ContextifySript
joyeecheung Jun 23, 2023
2feffae
test: add checkIfCollectable to test/common/gc.js
joyeecheung Sep 16, 2023
466c304
test: use checkIfCollectable in vm leak tests
joyeecheung Sep 16, 2023
fc003be
test: deflake test-vm-contextified-script-leak
joyeecheung Sep 23, 2023
d183187
vm: use default HDO when importModuleDynamically is not set
joyeecheung Oct 5, 2023
c8be386
vm: unify host-defined option generation in vm.compileFunction
joyeecheung Oct 5, 2023
222877e
vm: use internal versions of compileFunction and Script
joyeecheung Oct 11, 2023
a2b3f6e
vm: reject in importModuleDynamically without --experimental-vm-modules
joyeecheung Oct 5, 2023
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
35 changes: 35 additions & 0 deletions benchmark/vm/compile-script-in-isolate-cache.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
'use strict';

// This benchmarks compiling scripts that hit the in-isolate compilation
// cache (by having the same source).
const common = require('../common.js');
const fs = require('fs');
const vm = require('vm');
const fixtures = require('../../test/common/fixtures.js');
const scriptPath = fixtures.path('snapshot', 'typescript.js');

const bench = common.createBenchmark(main, {
type: ['with-dynamic-import-callback', 'without-dynamic-import-callback'],
n: [100],
});

const scriptSource = fs.readFileSync(scriptPath, 'utf8');

function main({ n, type }) {
let script;
bench.start();
const options = {};
switch (type) {
case 'with-dynamic-import-callback':
// Use a dummy callback for now until we really need to benchmark it.
options.importModuleDynamically = async () => {};
break;
case 'without-dynamic-import-callback':
break;
}
for (let i = 0; i < n; i++) {
script = new vm.Script(scriptSource, options);
}
bench.end(n);
script.runInThisContext();
}
2 changes: 1 addition & 1 deletion common.gypi
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@

# Reset this number to 0 on major V8 upgrades.
# Increment by one for each non-official patch applied to deps/v8.
'v8_embedder_string': '-node.28',
'v8_embedder_string': '-node.29',

##### V8 defaults for Node.js #####

Expand Down
17 changes: 17 additions & 0 deletions deps/v8/include/v8-object.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ class Function;
class FunctionTemplate;
template <typename T>
class PropertyCallbackInfo;
class Module;
class UnboundScript;

/**
* A private symbol
Expand Down Expand Up @@ -480,6 +482,21 @@ class V8_EXPORT Object : public Value {
/** Sets the value in an internal field. */
void SetInternalField(int index, Local<Value> value);

/**
* Warning: These are Node.js-specific extentions used to avoid breaking
* changes in Node.js v18.x. They do not exist in V8 upstream and will
* not exist in Node.js v21.x. Node.js embedders and addon authors should
* not use them from v18.x.
*/
#ifndef NODE_WANT_INTERNALS
V8_DEPRECATED("This extention should only be used by Node.js core")
#endif
void SetInternalFieldForNodeCore(int index, Local<Module> value);
#ifndef NODE_WANT_INTERNALS
V8_DEPRECATED("This extention should only be used by Node.js core")
#endif
void SetInternalFieldForNodeCore(int index, Local<UnboundScript> value);

/**
* Gets a 2-byte-aligned native pointer from an internal field. This field
* must have been set by SetAlignedPointerInInternalField, everything else
Expand Down
23 changes: 21 additions & 2 deletions deps/v8/src/api/api.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5948,14 +5948,33 @@ Local<Value> v8::Object::SlowGetInternalField(int index) {
return Utils::ToLocal(value);
}

void v8::Object::SetInternalField(int index, v8::Local<Value> value) {
i::Handle<i::JSReceiver> obj = Utils::OpenHandle(this);
template<typename T>
void SetInternalFieldImpl(v8::Object* receiver, int index, v8::Local<T> value) {
i::Handle<i::JSReceiver> obj = Utils::OpenHandle(receiver);
const char* location = "v8::Object::SetInternalField()";
if (!InternalFieldOK(obj, index, location)) return;
i::Handle<i::Object> val = Utils::OpenHandle(*value);
i::Handle<i::JSObject>::cast(obj)->SetEmbedderField(index, *val);
}

void v8::Object::SetInternalField(int index, v8::Local<Value> value) {
SetInternalFieldImpl(this, index, value);
}

/**
* These are Node.js-specific extentions used to avoid breaking changes in
* Node.js v20.x.
*/
void v8::Object::SetInternalFieldForNodeCore(int index,
v8::Local<Module> value) {
SetInternalFieldImpl(this, index, value);
}

void v8::Object::SetInternalFieldForNodeCore(int index,
v8::Local<UnboundScript> value) {
SetInternalFieldImpl(this, index, value);
}

void* v8::Object::SlowGetAlignedPointerFromInternalField(int index) {
i::Handle<i::JSReceiver> obj = Utils::OpenHandle(this);
const char* location = "v8::Object::GetAlignedPointerFromInternalField()";
Expand Down
10 changes: 5 additions & 5 deletions deps/v8/src/builtins/base.tq
Original file line number Diff line number Diff line change
Expand Up @@ -438,9 +438,9 @@ extern enum MessageTemplate {
kWasmTrapArrayOutOfBounds,
kWasmTrapArrayTooLarge,
kWeakRefsRegisterTargetAndHoldingsMustNotBeSame,
kWeakRefsRegisterTargetMustBeObject,
kWeakRefsUnregisterTokenMustBeObject,
kWeakRefsWeakRefConstructorTargetMustBeObject,
kInvalidWeakRefsRegisterTarget,
kInvalidWeakRefsUnregisterToken,
kInvalidWeakRefsWeakRefConstructorTarget,
...
}

Expand Down Expand Up @@ -906,10 +906,10 @@ macro Float64IsNaN(n: float64): bool {
// The type of all tagged values that can safely be compared with TaggedEqual.
@if(V8_ENABLE_WEBASSEMBLY)
type TaggedWithIdentity = JSReceiver | FixedArrayBase | Oddball | Map |
WeakCell | Context | EmptyString | WasmInternalFunction;
WeakCell | Context | EmptyString | Symbol | WasmInternalFunction;
@ifnot(V8_ENABLE_WEBASSEMBLY)
type TaggedWithIdentity = JSReceiver | FixedArrayBase | Oddball | Map |
WeakCell | Context | EmptyString;
WeakCell | Context | EmptyString | Symbol;

extern operator '==' macro TaggedEqual(TaggedWithIdentity, Object): bool;
extern operator '==' macro TaggedEqual(Object, TaggedWithIdentity): bool;
Expand Down
Loading