Commit d2fd132b authored by Camillo Bruni's avatar Camillo Bruni Committed by V8 LUCI CQ

[codegen] Respect host defined options in CompilationCache

Bug: v8:10284
Change-Id: If199cbe09964f66aa7346eedefb8ad57fe945c9d
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3069152
Commit-Queue: Camillo Bruni <cbruni@chromium.org>
Reviewed-by: 's avatarJakob Gruber <jgruber@chromium.org>
Cr-Commit-Position: refs/heads/master@{#76083}
parent 3cf7b9ca
......@@ -130,6 +130,17 @@ bool HasOrigin(Isolate* isolate, Handle<SharedFunctionInfo> function_info,
script->origin_options().Flags()) {
return false;
}
Handle<FixedArray> host_defined_options;
if (script_details.host_defined_options.ToHandle(&host_defined_options)) {
if (*host_defined_options != script->host_defined_options()) return false;
}
// script_details.host_defined_options is not provided, the default is an
// empty fixed array.
if (script->host_defined_options() !=
ReadOnlyRoots(isolate).empty_fixed_array()) {
return false;
}
// Compare the two name strings for equality.
return String::Equals(isolate, Handle<String>::cast(name),
Handle<String>(String::cast(script->name()), isolate));
......
......@@ -1718,9 +1718,7 @@ TEST(CodeSerializerPromotedToCompilationCache) {
const char* source = "1 + 1";
Handle<String> src = isolate->factory()
->NewStringFromUtf8(base::CStrVector(source))
.ToHandleChecked();
Handle<String> src = isolate->factory()->NewStringFromAsciiChecked(source);
ScriptData* cache = nullptr;
CompileScriptAndProduceCache(isolate, src, src, &cache,
......@@ -1730,12 +1728,83 @@ TEST(CodeSerializerPromotedToCompilationCache) {
Handle<SharedFunctionInfo> copy = CompileScript(
isolate, src, src, cache, v8::ScriptCompiler::kConsumeCodeCache);
ScriptDetails script_details(src);
MaybeHandle<SharedFunctionInfo> shared =
isolate->compilation_cache()->LookupScript(src, script_details,
LanguageMode::kSloppy);
{
ScriptDetails script_details(src);
MaybeHandle<SharedFunctionInfo> shared =
isolate->compilation_cache()->LookupScript(src, script_details,
LanguageMode::kSloppy);
CHECK_EQ(*shared.ToHandleChecked(), *copy);
}
CHECK(*shared.ToHandleChecked() == *copy);
{
// Lookup with different string with same contents should succeed:
ScriptDetails script_details(
isolate->factory()->NewStringFromAsciiChecked(source));
MaybeHandle<SharedFunctionInfo> shared =
isolate->compilation_cache()->LookupScript(src, script_details,
LanguageMode::kSloppy);
CHECK_EQ(*shared.ToHandleChecked(), *copy);
}
{
// Lookup with different string should fail:
ScriptDetails script_details(
isolate->factory()->NewStringFromAsciiChecked("other"));
MaybeHandle<SharedFunctionInfo> shared =
isolate->compilation_cache()->LookupScript(src, script_details,
LanguageMode::kSloppy);
CHECK(shared.is_null());
}
{
// Lookup with different position should fail:
ScriptDetails script_details(src);
script_details.line_offset = 0xFF;
MaybeHandle<SharedFunctionInfo> shared =
isolate->compilation_cache()->LookupScript(src, script_details,
LanguageMode::kSloppy);
CHECK(shared.is_null());
}
{
// Lookup with different position should fail:
ScriptDetails script_details(src);
script_details.column_offset = 0xFF;
MaybeHandle<SharedFunctionInfo> shared =
isolate->compilation_cache()->LookupScript(src, script_details,
LanguageMode::kSloppy);
CHECK(shared.is_null());
}
{
// Lookup with different language mode should fail:
ScriptDetails script_details(src);
MaybeHandle<SharedFunctionInfo> shared =
isolate->compilation_cache()->LookupScript(src, script_details,
LanguageMode::kStrict);
CHECK(shared.is_null());
}
{
// Lookup with different script_options should fail
ScriptOriginOptions origin_options(false, true);
CHECK_NE(ScriptOriginOptions().Flags(), origin_options.Flags());
ScriptDetails script_details(src, origin_options);
MaybeHandle<SharedFunctionInfo> shared =
isolate->compilation_cache()->LookupScript(src, script_details,
LanguageMode::kSloppy);
CHECK(shared.is_null());
}
{
// Lookup with different host_defined_options should fail:
ScriptDetails script_details(src);
script_details.host_defined_options = isolate->factory()->NewFixedArray(5);
MaybeHandle<SharedFunctionInfo> shared =
isolate->compilation_cache()->LookupScript(src, script_details,
LanguageMode::kSloppy);
CHECK(shared.is_null());
}
delete cache;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment