| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 6603d32 commit 2ad665e
5 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -36,7 +36,7 @@ | |||
| 36 | 36 | ||
| 37 | 37 | # Reset this number to 0 on major V8 upgrades. | |
| 38 | 38 | # Increment by one for each non-official patch applied to deps/v8. | |
| 39 | - 'v8_embedder_string': '-node.19', | ||
| 39 | + 'v8_embedder_string': '-node.20', | ||
| 40 | 40 | ||
| 41 | 41 | ##### V8 defaults for Node.js ##### | |
| 42 | 42 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -388,6 +388,27 @@ class V8_EXPORT ScriptCompiler { | |||
| 388 | 388 | CachedData(const uint8_t* data, int length, | |
| 389 | 389 | BufferPolicy buffer_policy = BufferNotOwned); | |
| 390 | 390 | ~CachedData(); | |
| 391 | + | ||
| 392 | + enum CompatibilityCheckResult { | ||
| 393 | + // Don't change order/existing values of this enum since it keys into the | ||
| 394 | + // `code_cache_reject_reason` histogram. Append-only! | ||
| 395 | + kSuccess = 0, | ||
| 396 | + kMagicNumberMismatch = 1, | ||
| 397 | + kVersionMismatch = 2, | ||
| 398 | + kSourceMismatch = 3, | ||
| 399 | + kFlagsMismatch = 5, | ||
| 400 | + kChecksumMismatch = 6, | ||
| 401 | + kInvalidHeader = 7, | ||
| 402 | + kLengthMismatch = 8, | ||
| 403 | + kReadOnlySnapshotChecksumMismatch = 9, | ||
| 404 | + | ||
| 405 | + // This should always point at the last real enum value. | ||
| 406 | + kLast = kReadOnlySnapshotChecksumMismatch | ||
| 407 | + }; | ||
| 408 | + | ||
| 409 | + // Check if the CachedData can be loaded in the given isolate. | ||
| 410 | + CompatibilityCheckResult CompatibilityCheck(Isolate* isolate); | ||
| 411 | + | ||
| 391 | 412 | // TODO(marja): Async compilation; add constructors which take a callback | |
| 392 | 413 | // which will be called when V8 no longer needs the data. | |
| 393 | 414 | const uint8_t* data; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1950,6 +1950,18 @@ ScriptCompiler::CachedData::~CachedData() { | |||
| 1950 | 1950 | } | |
| 1951 | 1951 | } | |
| 1952 | 1952 | ||
| 1953 | + ScriptCompiler::CachedData::CompatibilityCheckResult | ||
| 1954 | + ScriptCompiler::CachedData::CompatibilityCheck(Isolate* isolate) { | ||
| 1955 | + i::AlignedCachedData aligned(data, length); | ||
| 1956 | + i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate); | ||
| 1957 | + i::SerializedCodeSanityCheckResult result; | ||
| 1958 | + i::SerializedCodeData scd = | ||
| 1959 | + i::SerializedCodeData::FromCachedDataWithoutSource( | ||
| 1960 | + i_isolate->AsLocalIsolate(), &aligned, &result); | ||
| 1961 | + return static_cast<ScriptCompiler::CachedData::CompatibilityCheckResult>( | ||
| 1962 | + result); | ||
| 1963 | + } | ||
| 1964 | + | ||
| 1953 | 1965 | ScriptCompiler::StreamedSource::StreamedSource( | |
| 1954 | 1966 | std::unique_ptr<ExternalSourceStream> stream, Encoding encoding) | |
| 1955 | 1967 | : impl_(new i::ScriptStreamingData(std::move(stream), encoding)) {} | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -49,22 +49,9 @@ class V8_EXPORT_PRIVATE AlignedCachedData { | |||
| 49 | 49 | int length_; | |
| 50 | 50 | }; | |
| 51 | 51 | ||
| 52 | - enum class SerializedCodeSanityCheckResult { | ||
| 53 | - // Don't change order/existing values of this enum since it keys into the | ||
| 54 | - // `code_cache_reject_reason` histogram. Append-only! | ||
| 55 | - kSuccess = 0, | ||
| 56 | - kMagicNumberMismatch = 1, | ||
| 57 | - kVersionMismatch = 2, | ||
| 58 | - kSourceMismatch = 3, | ||
| 59 | - kFlagsMismatch = 5, | ||
| 60 | - kChecksumMismatch = 6, | ||
| 61 | - kInvalidHeader = 7, | ||
| 62 | - kLengthMismatch = 8, | ||
| 63 | - kReadOnlySnapshotChecksumMismatch = 9, | ||
| 64 | - | ||
| 65 | - // This should always point at the last real enum value. | ||
| 66 | - kLast = kReadOnlySnapshotChecksumMismatch | ||
| 67 | - }; | ||
| 52 | + typedef v8::ScriptCompiler::CachedData::CompatibilityCheckResult | ||
| 53 | + SerializedCodeSanityCheckResult; | ||
| 54 | + | ||
| 68 | 55 | // If this fails, update the static_assert AND the code_cache_reject_reason | |
| 69 | 56 | // histogram definition. | |
| 70 | 57 | static_assert(static_cast<int>(SerializedCodeSanityCheckResult::kLast) == 9); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -2790,6 +2790,78 @@ TEST(CodeSerializerFlagChange) { | |||
| 2790 | 2790 | isolate2->Dispose(); | |
| 2791 | 2791 | } | |
| 2792 | 2792 | ||
| 2793 | + TEST(CachedDataCompatibilityCheck) { | ||
| 2794 | + { | ||
| 2795 | + v8::Isolate::CreateParams create_params; | ||
| 2796 | + create_params.array_buffer_allocator = CcTest::array_buffer_allocator(); | ||
| 2797 | + v8::Isolate* isolate = v8::Isolate::New(create_params); | ||
| 2798 | + // Hand-craft a zero-filled cached data which cannot be valid. | ||
| 2799 | + int length = 64; | ||
| 2800 | + uint8_t* payload = new uint8_t[length]; | ||
| 2801 | + memset(payload, 0, length); | ||
| 2802 | + v8::ScriptCompiler::CachedData cache( | ||
| 2803 | + payload, length, v8::ScriptCompiler::CachedData::BufferOwned); | ||
| 2804 | + { | ||
| 2805 | + v8::Isolate::Scope iscope(isolate); | ||
| 2806 | + v8::ScriptCompiler::CachedData::CompatibilityCheckResult result = | ||
| 2807 | + cache.CompatibilityCheck(isolate); | ||
| 2808 | + CHECK_NE(result, v8::ScriptCompiler::CachedData::kSuccess); | ||
| 2809 | + } | ||
| 2810 | + isolate->Dispose(); | ||
| 2811 | + } | ||
| 2812 | + | ||
| 2813 | + const char* js_source = "function f() { return 'abc'; }; f() + 'def'"; | ||
| 2814 | + std::unique_ptr<v8::ScriptCompiler::CachedData> cache; | ||
| 2815 | + { | ||
| 2816 | + v8::Isolate::CreateParams create_params; | ||
| 2817 | + create_params.array_buffer_allocator = CcTest::array_buffer_allocator(); | ||
| 2818 | + v8::Isolate* isolate = v8::Isolate::New(create_params); | ||
| 2819 | + { | ||
| 2820 | + v8::Isolate::Scope iscope(isolate); | ||
| 2821 | + v8::HandleScope scope(isolate); | ||
| 2822 | + v8::Local<v8::Context> context = v8::Context::New(isolate); | ||
| 2823 | + v8::Context::Scope context_scope(context); | ||
| 2824 | + v8::ScriptCompiler::Source source(v8_str(js_source), | ||
| 2825 | + {isolate, v8_str("test")}); | ||
| 2826 | + v8::Local<v8::UnboundScript> script = | ||
| 2827 | + v8::ScriptCompiler::CompileUnboundScript( | ||
| 2828 | + isolate, &source, v8::ScriptCompiler::kEagerCompile) | ||
| 2829 | + .ToLocalChecked(); | ||
| 2830 | + cache.reset(ScriptCompiler::CreateCodeCache(script)); | ||
| 2831 | + } | ||
| 2832 | + isolate->Dispose(); | ||
| 2833 | + } | ||
| 2834 | + | ||
| 2835 | + { | ||
| 2836 | + v8::Isolate::CreateParams create_params; | ||
| 2837 | + create_params.array_buffer_allocator = CcTest::array_buffer_allocator(); | ||
| 2838 | + v8::Isolate* isolate = v8::Isolate::New(create_params); | ||
| 2839 | + { | ||
| 2840 | + v8::Isolate::Scope iscope(isolate); | ||
| 2841 | + v8::ScriptCompiler::CachedData::CompatibilityCheckResult result = | ||
| 2842 | + cache->CompatibilityCheck(isolate); | ||
| 2843 | + CHECK_EQ(result, v8::ScriptCompiler::CachedData::kSuccess); | ||
| 2844 | + } | ||
| 2845 | + isolate->Dispose(); | ||
| 2846 | + } | ||
| 2847 | + | ||
| 2848 | + { | ||
| 2849 | + v8_flags.allow_natives_syntax = | ||
| 2850 | + true; // Flag change should trigger cache reject. | ||
| 2851 | + FlagList::EnforceFlagImplications(); | ||
| 2852 | + v8::Isolate::CreateParams create_params; | ||
| 2853 | + create_params.array_buffer_allocator = CcTest::array_buffer_allocator(); | ||
| 2854 | + v8::Isolate* isolate = v8::Isolate::New(create_params); | ||
| 2855 | + { | ||
| 2856 | + v8::Isolate::Scope iscope(isolate); | ||
| 2857 | + v8::ScriptCompiler::CachedData::CompatibilityCheckResult result = | ||
| 2858 | + cache->CompatibilityCheck(isolate); | ||
| 2859 | + CHECK_EQ(result, v8::ScriptCompiler::CachedData::kFlagsMismatch); | ||
| 2860 | + } | ||
| 2861 | + isolate->Dispose(); | ||
| 2862 | + } | ||
| 2863 | + } | ||
| 2864 | + | ||
| 2793 | 2865 | TEST(CodeSerializerBitFlip) { | |
| 2794 | 2866 | i::v8_flags.verify_snapshot_checksum = true; | |
| 2795 | 2867 | const char* js_source = "function f() { return 'abc'; }; f() + 'def'"; | |
| Back | FazBrowse Home | New Git URL |
0 commit comments