Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
f3fcad2
doc: note that path.normalize deviates from POSIX
tniessen Jan 29, 2024
d4eb03f
meta: add .mailmap entry for lemire
lemire Jan 29, 2024
44476be
tools: update lint-md-dependencies to [email protected]
nodejs-github-bot Jan 30, 2024
0f461aa
doc: fix `dns.lookup` and `dnsPromises.lookup` description
duncanchiu409 Jan 30, 2024
a501315
repl: fix `NO_COLORS` env var is ignored
MoLow Jan 31, 2024
8b28366
src: support multi-line values for .env file
IlyasShabi Jan 31, 2024
4ab63db
tools: run `build-windows` workflow only on source changes
aduh95 Jan 31, 2024
ec9c785
deps: update ngtcp2 to 1.2.0
nodejs-github-bot Jan 31, 2024
ce56887
lib: define FormData and fetch etc. in the built-in snapshot
joyeecheung Jan 31, 2024
a64a866
deps: update ada to 2.7.5
nodejs-github-bot Jan 22, 2024
7a1267c
deps: update ada to 2.7.6
nodejs-github-bot Jan 30, 2024
39d3f42
deps: update corepack to 0.24.1
nodejs-github-bot Jan 31, 2024
3fbe157
esm: improve error when calling `import.meta.resolve` from `data:` URL
aduh95 Jan 31, 2024
a7eb72d
test: remove test-fs-rmdir-recursive flaky designation
lpinca Feb 1, 2024
1cd9a95
src: fix vm bug for configurable globalThis
fhinkel Feb 1, 2024
dd4767f
deps: update undici to 6.4.0
nodejs-github-bot Feb 1, 2024
ad0bcb9
vm: support using the default loader to handle dynamic import()
joyeecheung Feb 1, 2024
a3e0834
deps: V8: cherry-pick efb1133eb894
joyeecheung Feb 1, 2024
d1114c4
http2: close idle connections when allowHTTP1 is true
xsbchen Feb 1, 2024
68885d5
deps: update nghttp2 to 1.59.0
nodejs-github-bot Feb 1, 2024
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
Prev Previous commit
Next Next commit
deps: V8: cherry-pick efb1133eb894
Original commit message:

    [api] Add v8::ScriptCompiler::CachedData::CompatibilityCheck()

    This patch adds a new API v8::ScriptCompiler::CachedData::CompatibilityCheck()
    in order to allow embedders to check if the code cache can be used in
    the current isolate without looking up for the source code. It also returns more detailed reasons about why the code cache cannot be used
    when it's bound to be rejected. This makes it possible to enforce
    portability checks in case code code becomes CPU-dependent in the
    future.

    Refs: #42566 (comment)

    Change-Id: Ia1d677b949050add961af6fbf62c44342c061312
    Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/4905290
    Reviewed-by: Marja Hölttä <[email protected]>
    Reviewed-by: Toon Verwaest <[email protected]>
    Commit-Queue: Joyee Cheung <[email protected]>
    Cr-Commit-Position: refs/heads/main@{#90833}

Refs: v8/v8@efb1133
PR-URL: #51551
Reviewed-By: Richard Lau <[email protected]>
Reviewed-By: Michaël Zasso <[email protected]>
Reviewed-By: Luigi Pinca <[email protected]>
  • Loading branch information
joyeecheung authored Feb 1, 2024
commit a3e0834ee407342f9335bd7d1d65934a781e8b59
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.12',
'v8_embedder_string': '-node.13',

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

Expand Down
21 changes: 21 additions & 0 deletions deps/v8/include/v8-script.h
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,27 @@ class V8_EXPORT ScriptCompiler {
CachedData(const uint8_t* data, int length,
BufferPolicy buffer_policy = BufferNotOwned);
~CachedData();

enum CompatibilityCheckResult {
// Don't change order/existing values of this enum since it keys into the
// `code_cache_reject_reason` histogram. Append-only!
kSuccess = 0,
kMagicNumberMismatch = 1,
kVersionMismatch = 2,
kSourceMismatch = 3,
kFlagsMismatch = 5,
kChecksumMismatch = 6,
kInvalidHeader = 7,
kLengthMismatch = 8,
kReadOnlySnapshotChecksumMismatch = 9,

// This should always point at the last real enum value.
kLast = kReadOnlySnapshotChecksumMismatch
};

// Check if the CachedData can be loaded in the given isolate.
CompatibilityCheckResult CompatibilityCheck(Isolate* isolate);

// TODO(marja): Async compilation; add constructors which take a callback
// which will be called when V8 no longer needs the data.
const uint8_t* data;
Expand Down
12 changes: 12 additions & 0 deletions deps/v8/src/api/api.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1951,6 +1951,18 @@ ScriptCompiler::CachedData::~CachedData() {
}
}

ScriptCompiler::CachedData::CompatibilityCheckResult
ScriptCompiler::CachedData::CompatibilityCheck(Isolate* isolate) {
i::AlignedCachedData aligned(data, length);
i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
i::SerializedCodeSanityCheckResult result;
i::SerializedCodeData scd =
i::SerializedCodeData::FromCachedDataWithoutSource(
i_isolate->AsLocalIsolate(), &aligned, &result);
return static_cast<ScriptCompiler::CachedData::CompatibilityCheckResult>(
result);
}

ScriptCompiler::StreamedSource::StreamedSource(
std::unique_ptr<ExternalSourceStream> stream, Encoding encoding)
: impl_(new i::ScriptStreamingData(std::move(stream), encoding)) {}
Expand Down
19 changes: 3 additions & 16 deletions deps/v8/src/snapshot/code-serializer.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,22 +49,9 @@ class V8_EXPORT_PRIVATE AlignedCachedData {
int length_;
};

enum class SerializedCodeSanityCheckResult {
// Don't change order/existing values of this enum since it keys into the
// `code_cache_reject_reason` histogram. Append-only!
kSuccess = 0,
kMagicNumberMismatch = 1,
kVersionMismatch = 2,
kSourceMismatch = 3,
kFlagsMismatch = 5,
kChecksumMismatch = 6,
kInvalidHeader = 7,
kLengthMismatch = 8,
kReadOnlySnapshotChecksumMismatch = 9,

// This should always point at the last real enum value.
kLast = kReadOnlySnapshotChecksumMismatch
};
typedef v8::ScriptCompiler::CachedData::CompatibilityCheckResult
SerializedCodeSanityCheckResult;

// If this fails, update the static_assert AND the code_cache_reject_reason
// histogram definition.
static_assert(static_cast<int>(SerializedCodeSanityCheckResult::kLast) == 9);
Expand Down
72 changes: 72 additions & 0 deletions deps/v8/test/cctest/test-serialize.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2799,6 +2799,78 @@ TEST(CodeSerializerFlagChange) {
isolate2->Dispose();
}

TEST(CachedDataCompatibilityCheck) {
{
v8::Isolate::CreateParams create_params;
create_params.array_buffer_allocator = CcTest::array_buffer_allocator();
v8::Isolate* isolate = v8::Isolate::New(create_params);
// Hand-craft a zero-filled cached data which cannot be valid.
int length = 64;
uint8_t* payload = new uint8_t[length];
memset(payload, 0, length);
v8::ScriptCompiler::CachedData cache(
payload, length, v8::ScriptCompiler::CachedData::BufferOwned);
{
v8::Isolate::Scope iscope(isolate);
v8::ScriptCompiler::CachedData::CompatibilityCheckResult result =
cache.CompatibilityCheck(isolate);
CHECK_NE(result, v8::ScriptCompiler::CachedData::kSuccess);
}
isolate->Dispose();
}

const char* js_source = "function f() { return 'abc'; }; f() + 'def'";
std::unique_ptr<v8::ScriptCompiler::CachedData> cache;
{
v8::Isolate::CreateParams create_params;
create_params.array_buffer_allocator = CcTest::array_buffer_allocator();
v8::Isolate* isolate = v8::Isolate::New(create_params);
{
v8::Isolate::Scope iscope(isolate);
v8::HandleScope scope(isolate);
v8::Local<v8::Context> context = v8::Context::New(isolate);
v8::Context::Scope context_scope(context);
v8::ScriptCompiler::Source source(v8_str(js_source),
{isolate, v8_str("test")});
v8::Local<v8::UnboundScript> script =
v8::ScriptCompiler::CompileUnboundScript(
isolate, &source, v8::ScriptCompiler::kEagerCompile)
.ToLocalChecked();
cache.reset(ScriptCompiler::CreateCodeCache(script));
}
isolate->Dispose();
}

{
v8::Isolate::CreateParams create_params;
create_params.array_buffer_allocator = CcTest::array_buffer_allocator();
v8::Isolate* isolate = v8::Isolate::New(create_params);
{
v8::Isolate::Scope iscope(isolate);
v8::ScriptCompiler::CachedData::CompatibilityCheckResult result =
cache->CompatibilityCheck(isolate);
CHECK_EQ(result, v8::ScriptCompiler::CachedData::kSuccess);
}
isolate->Dispose();
}

{
v8_flags.allow_natives_syntax =
true; // Flag change should trigger cache reject.
FlagList::EnforceFlagImplications();
v8::Isolate::CreateParams create_params;
create_params.array_buffer_allocator = CcTest::array_buffer_allocator();
v8::Isolate* isolate = v8::Isolate::New(create_params);
{
v8::Isolate::Scope iscope(isolate);
v8::ScriptCompiler::CachedData::CompatibilityCheckResult result =
cache->CompatibilityCheck(isolate);
CHECK_EQ(result, v8::ScriptCompiler::CachedData::kFlagsMismatch);
}
isolate->Dispose();
}
}

TEST(CodeSerializerBitFlip) {
i::v8_flags.verify_snapshot_checksum = true;
const char* js_source = "function f() { return 'abc'; }; f() + 'def'";
Expand Down