Commit 87e1b8df authored by Sathya Gunasekaran's avatar Sathya Gunasekaran Committed by Commit Bot

Use MaybeHandle for values that could be empty

This fixes some of the old legacy API that used empty Handle<>

Cq-Include-Trybots: master.tryserver.chromium.linux:linux_chromium_rel_ng
Change-Id: I861e31a4a6f65bc497bfc512174adba39c17abca
Reviewed-on: https://chromium-review.googlesource.com/701634Reviewed-by: 's avatarMichael Starzinger <mstarzinger@chromium.org>
Commit-Queue: Sathya Gunasekaran <gsathya@chromium.org>
Cr-Commit-Position: refs/heads/master@{#48311}
parent c7e84f52
......@@ -2305,9 +2305,9 @@ MaybeLocal<UnboundScript> ScriptCompiler::CompileUnboundInternal(
{
i::HistogramTimerScope total(isolate->counters()->compile_script(), true);
TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("v8.compile"), "V8.CompileScript");
i::Handle<i::Object> name_obj;
i::Handle<i::Object> source_map_url;
i::Handle<i::FixedArray> host_defined_options =
i::MaybeHandle<i::Object> name_obj;
i::MaybeHandle<i::Object> source_map_url;
i::MaybeHandle<i::FixedArray> host_defined_options =
isolate->factory()->empty_fixed_array();
int line_offset = 0;
int column_offset = 0;
......@@ -2327,11 +2327,12 @@ MaybeLocal<UnboundScript> ScriptCompiler::CompileUnboundInternal(
if (!source->source_map_url.IsEmpty()) {
source_map_url = Utils::OpenHandle(*(source->source_map_url));
}
result = i::Compiler::GetSharedFunctionInfoForScript(
str, name_obj, line_offset, column_offset, source->resource_options,
source_map_url, isolate->native_context(), NULL, &script_data, options,
i::NOT_NATIVES_CODE, host_defined_options);
has_pending_exception = result.is_null();
i::MaybeHandle<i::SharedFunctionInfo> maybe_function_info =
i::Compiler::GetSharedFunctionInfoForScript(
str, name_obj, line_offset, column_offset, source->resource_options,
source_map_url, isolate->native_context(), NULL, &script_data,
options, i::NOT_NATIVES_CODE, host_defined_options);
has_pending_exception = !maybe_function_info.ToHandle(&result);
if (has_pending_exception && script_data != NULL) {
// This case won't happen during normal operation; we have compiled
// successfully and produced cached data, and but the second compilation
......@@ -9963,14 +9964,15 @@ MaybeLocal<UnboundScript> debug::CompileInspectorScript(Isolate* v8_isolate,
i::Handle<i::SharedFunctionInfo> result;
{
ScriptOriginOptions origin_options;
result = i::Compiler::GetSharedFunctionInfoForScript(
str, i::Handle<i::Object>(), 0, 0, origin_options,
i::Handle<i::Object>(), isolate->native_context(), NULL, &script_data,
ScriptCompiler::kNoCompileOptions,
i::FLAG_expose_inspector_scripts ? i::NOT_NATIVES_CODE
: i::INSPECTOR_CODE,
i::Handle<i::FixedArray>());
has_pending_exception = result.is_null();
i::MaybeHandle<i::SharedFunctionInfo> maybe_function_info =
i::Compiler::GetSharedFunctionInfoForScript(
str, i::MaybeHandle<i::Object>(), 0, 0, origin_options,
i::MaybeHandle<i::Object>(), isolate->native_context(), NULL,
&script_data, ScriptCompiler::kNoCompileOptions,
i::FLAG_expose_inspector_scripts ? i::NOT_NATIVES_CODE
: i::INSPECTOR_CODE,
i::MaybeHandle<i::FixedArray>());
has_pending_exception = !maybe_function_info.ToHandle(&result);
RETURN_ON_FAILED_EXECUTION(UnboundScript);
}
RETURN_ESCAPED(ToApiHandle<UnboundScript>(result));
......
......@@ -3627,12 +3627,14 @@ bool Bootstrapper::CompileNative(Isolate* isolate, Vector<const char> name,
Handle<String> script_name =
isolate->factory()->NewStringFromUtf8(name).ToHandleChecked();
Handle<SharedFunctionInfo> function_info =
MaybeHandle<SharedFunctionInfo> maybe_function_info =
Compiler::GetSharedFunctionInfoForScript(
source, script_name, 0, 0, ScriptOriginOptions(), Handle<Object>(),
context, NULL, NULL, ScriptCompiler::kNoCompileOptions, natives_flag,
Handle<FixedArray>());
if (function_info.is_null()) return false;
source, script_name, 0, 0, ScriptOriginOptions(),
MaybeHandle<Object>(), context, NULL, NULL,
ScriptCompiler::kNoCompileOptions, natives_flag,
MaybeHandle<FixedArray>());
Handle<SharedFunctionInfo> function_info;
if (!maybe_function_info.ToHandle(&function_info)) return false;
DCHECK(context->IsNativeContext());
......@@ -3691,11 +3693,13 @@ bool Genesis::CompileExtension(Isolate* isolate, v8::Extension* extension) {
if (!cache->Lookup(name, &function_info)) {
Handle<String> script_name =
factory->NewStringFromUtf8(name).ToHandleChecked();
function_info = Compiler::GetSharedFunctionInfoForScript(
source, script_name, 0, 0, ScriptOriginOptions(), Handle<Object>(),
context, extension, NULL, ScriptCompiler::kNoCompileOptions,
EXTENSION_CODE, Handle<FixedArray>());
if (function_info.is_null()) return false;
MaybeHandle<SharedFunctionInfo> maybe_function_info =
Compiler::GetSharedFunctionInfoForScript(
source, script_name, 0, 0, ScriptOriginOptions(),
MaybeHandle<Object>(), context, extension, NULL,
ScriptCompiler::kNoCompileOptions, EXTENSION_CODE,
MaybeHandle<FixedArray>());
if (!maybe_function_info.ToHandle(&function_info)) return false;
cache->Add(name, function_info);
}
......
......@@ -95,14 +95,15 @@ CompilationCacheScript::CompilationCacheScript(Isolate* isolate)
// script originates from the same place. This is to avoid issues
// when reporting errors, etc.
bool CompilationCacheScript::HasOrigin(Handle<SharedFunctionInfo> function_info,
Handle<Object> name, int line_offset,
int column_offset,
MaybeHandle<Object> maybe_name,
int line_offset, int column_offset,
ScriptOriginOptions resource_options) {
Handle<Script> script =
Handle<Script>(Script::cast(function_info->script()), isolate());
// If the script name isn't set, the boilerplate script should have
// an undefined name to have the same origin.
if (name.is_null()) {
Handle<Object> name;
if (!maybe_name.ToHandle(&name)) {
return script->name()->IsUndefined(isolate());
}
// Do the fast bailout checks first.
......@@ -123,7 +124,7 @@ bool CompilationCacheScript::HasOrigin(Handle<SharedFunctionInfo> function_info,
// will be cached, but subsequent code from different source / line
// won't.
InfoVectorPair CompilationCacheScript::Lookup(
Handle<String> source, Handle<Object> name, int line_offset,
Handle<String> source, MaybeHandle<Object> name, int line_offset,
int column_offset, ScriptOriginOptions resource_options,
Handle<Context> context, LanguageMode language_mode) {
InfoVectorPair result;
......@@ -263,7 +264,7 @@ void CompilationCache::Remove(Handle<SharedFunctionInfo> function_info) {
}
InfoVectorPair CompilationCache::LookupScript(
Handle<String> source, Handle<Object> name, int line_offset,
Handle<String> source, MaybeHandle<Object> name, int line_offset,
int column_offset, ScriptOriginOptions resource_options,
Handle<Context> context, LanguageMode language_mode) {
InfoVectorPair empty_result;
......
......@@ -79,7 +79,7 @@ class CompilationCacheScript : public CompilationSubCache {
public:
explicit CompilationCacheScript(Isolate* isolate);
InfoVectorPair Lookup(Handle<String> source, Handle<Object> name,
InfoVectorPair Lookup(Handle<String> source, MaybeHandle<Object> name,
int line_offset, int column_offset,
ScriptOriginOptions resource_options,
Handle<Context> context, LanguageMode language_mode);
......@@ -89,8 +89,8 @@ class CompilationCacheScript : public CompilationSubCache {
Handle<Cell> literals);
private:
bool HasOrigin(Handle<SharedFunctionInfo> function_info, Handle<Object> name,
int line_offset, int column_offset,
bool HasOrigin(Handle<SharedFunctionInfo> function_info,
MaybeHandle<Object> name, int line_offset, int column_offset,
ScriptOriginOptions resource_options);
DISALLOW_IMPLICIT_CONSTRUCTORS(CompilationCacheScript);
......@@ -152,7 +152,7 @@ class CompilationCache {
// Finds the script shared function info for a source
// string. Returns an empty handle if the cache doesn't contain a
// script for the given source string with the right origin.
InfoVectorPair LookupScript(Handle<String> source, Handle<Object> name,
InfoVectorPair LookupScript(Handle<String> source, MaybeHandle<Object> name,
int line_offset, int column_offset,
ScriptOriginOptions resource_options,
Handle<Context> context,
......
......@@ -1208,13 +1208,13 @@ MaybeHandle<JSFunction> Compiler::GetFunctionFromString(
eval_scope_position, eval_position);
}
Handle<SharedFunctionInfo> Compiler::GetSharedFunctionInfoForScript(
Handle<String> source, Handle<Object> script_name, int line_offset,
int column_offset, ScriptOriginOptions resource_options,
Handle<Object> source_map_url, Handle<Context> context,
MaybeHandle<SharedFunctionInfo> Compiler::GetSharedFunctionInfoForScript(
Handle<String> source, MaybeHandle<Object> maybe_script_name,
int line_offset, int column_offset, ScriptOriginOptions resource_options,
MaybeHandle<Object> maybe_source_map_url, Handle<Context> context,
v8::Extension* extension, ScriptData** cached_data,
ScriptCompiler::CompileOptions compile_options, NativesFlag natives,
Handle<FixedArray> host_defined_options) {
MaybeHandle<FixedArray> maybe_host_defined_options) {
Isolate* isolate = source->GetIsolate();
if (compile_options == ScriptCompiler::kNoCompileOptions) {
cached_data = NULL;
......@@ -1237,12 +1237,12 @@ Handle<SharedFunctionInfo> Compiler::GetSharedFunctionInfoForScript(
CompilationCache* compilation_cache = isolate->compilation_cache();
// Do a lookup in the compilation cache but not for extensions.
Handle<SharedFunctionInfo> result;
MaybeHandle<SharedFunctionInfo> maybe_result;
Handle<Cell> vector;
if (extension == NULL) {
// First check per-isolate compilation cache.
InfoVectorPair pair = compilation_cache->LookupScript(
source, script_name, line_offset, column_offset, resource_options,
source, maybe_script_name, line_offset, column_offset, resource_options,
context, language_mode);
if (!pair.has_shared() &&
compile_options == ScriptCompiler::kConsumeCodeCache &&
......@@ -1270,7 +1270,7 @@ Handle<SharedFunctionInfo> Compiler::GetSharedFunctionInfoForScript(
// Deserializer failed. Fall through to compile.
} else {
if (pair.has_shared()) {
result = Handle<SharedFunctionInfo>(pair.shared(), isolate);
maybe_result = MaybeHandle<SharedFunctionInfo>(pair.shared(), isolate);
}
if (pair.has_vector()) {
vector = Handle<Cell>(pair.vector(), isolate);
......@@ -1283,7 +1283,7 @@ Handle<SharedFunctionInfo> Compiler::GetSharedFunctionInfoForScript(
timer.Start();
}
if (result.is_null() || ShouldProduceCodeCache(compile_options)) {
if (maybe_result.is_null() || ShouldProduceCodeCache(compile_options)) {
// No cache entry found, or embedder wants a code cache. Compile the script.
// Create a script object describing the script to be compiled.
......@@ -1298,16 +1298,19 @@ Handle<SharedFunctionInfo> Compiler::GetSharedFunctionInfoForScript(
} else if (natives == INSPECTOR_CODE) {
script->set_type(Script::TYPE_INSPECTOR);
}
if (!script_name.is_null()) {
Handle<Object> script_name;
if (maybe_script_name.ToHandle(&script_name)) {
script->set_name(*script_name);
script->set_line_offset(line_offset);
script->set_column_offset(column_offset);
}
script->set_origin_options(resource_options);
if (!source_map_url.is_null()) {
Handle<Object> source_map_url;
if (maybe_source_map_url.ToHandle(&source_map_url)) {
script->set_source_mapping_url(*source_map_url);
}
if (!host_defined_options.is_null()) {
Handle<FixedArray> host_defined_options;
if (maybe_host_defined_options.ToHandle(&host_defined_options)) {
script->set_host_defined_options(*host_defined_options);
}
......@@ -1331,8 +1334,9 @@ Handle<SharedFunctionInfo> Compiler::GetSharedFunctionInfoForScript(
parse_info.set_language_mode(
static_cast<LanguageMode>(parse_info.language_mode() | language_mode));
CompileToplevel(&parse_info, isolate).ToHandle(&result);
if (extension == NULL && !result.is_null()) {
maybe_result = CompileToplevel(&parse_info, isolate);
Handle<SharedFunctionInfo> result;
if (extension == NULL && maybe_result.ToHandle(&result)) {
// We need a feedback vector.
DCHECK(result->is_compiled());
Handle<FeedbackVector> feedback_vector =
......@@ -1356,7 +1360,7 @@ Handle<SharedFunctionInfo> Compiler::GetSharedFunctionInfoForScript(
}
}
if (result.is_null()) {
if (maybe_result.is_null()) {
if (natives != EXTENSION_CODE && natives != NATIVES_CODE) {
isolate->ReportPendingMessages();
}
......@@ -1364,7 +1368,7 @@ Handle<SharedFunctionInfo> Compiler::GetSharedFunctionInfoForScript(
isolate->debug()->OnAfterCompile(script);
}
}
return result;
return maybe_result;
}
Handle<SharedFunctionInfo> Compiler::GetSharedFunctionInfoForStreamedScript(
......
......@@ -107,13 +107,14 @@ class V8_EXPORT_PRIVATE Compiler : public AllStatic {
ParseRestriction restriction, int parameters_end_pos);
// Create a shared function info object for a String source within a context.
static Handle<SharedFunctionInfo> GetSharedFunctionInfoForScript(
Handle<String> source, Handle<Object> script_name, int line_offset,
int column_offset, ScriptOriginOptions resource_options,
Handle<Object> source_map_url, Handle<Context> context,
static MaybeHandle<SharedFunctionInfo> GetSharedFunctionInfoForScript(
Handle<String> source, MaybeHandle<Object> maybe_script_name,
int line_offset, int column_offset, ScriptOriginOptions resource_options,
MaybeHandle<Object> maybe_source_map_url, Handle<Context> context,
v8::Extension* extension, ScriptData** cached_data,
ScriptCompiler::CompileOptions compile_options,
NativesFlag is_natives_code, Handle<FixedArray> host_defined_options);
NativesFlag is_natives_code,
MaybeHandle<FixedArray> maybe_host_defined_options);
// Create a shared function info object for a Script that has already been
// parsed while the script was being loaded from a streamed source.
......
......@@ -33,11 +33,13 @@ static Handle<JSFunction> Compile(const char* source) {
Handle<String> source_code = isolate->factory()
->NewStringFromUtf8(CStrVector(source))
.ToHandleChecked();
Handle<SharedFunctionInfo> shared = Compiler::GetSharedFunctionInfoForScript(
source_code, Handle<String>(), 0, 0, v8::ScriptOriginOptions(),
Handle<Object>(), Handle<Context>(isolate->native_context()), NULL, NULL,
v8::ScriptCompiler::kNoCompileOptions, NOT_NATIVES_CODE,
Handle<FixedArray>());
Handle<SharedFunctionInfo> shared =
Compiler::GetSharedFunctionInfoForScript(
source_code, MaybeHandle<String>(), 0, 0, v8::ScriptOriginOptions(),
MaybeHandle<Object>(), Handle<Context>(isolate->native_context()),
NULL, NULL, v8::ScriptCompiler::kNoCompileOptions, NOT_NATIVES_CODE,
MaybeHandle<FixedArray>())
.ToHandleChecked();
return isolate->factory()->NewFunctionFromSharedFunctionInfo(
shared, isolate->native_context());
}
......
......@@ -63,11 +63,13 @@ static Handle<JSFunction> Compile(const char* source) {
Isolate* isolate = CcTest::i_isolate();
Handle<String> source_code = isolate->factory()->NewStringFromUtf8(
CStrVector(source)).ToHandleChecked();
Handle<SharedFunctionInfo> shared = Compiler::GetSharedFunctionInfoForScript(
source_code, Handle<String>(), 0, 0, v8::ScriptOriginOptions(),
Handle<Object>(), Handle<Context>(isolate->native_context()), NULL, NULL,
v8::ScriptCompiler::kNoCompileOptions, NOT_NATIVES_CODE,
Handle<FixedArray>());
Handle<SharedFunctionInfo> shared =
Compiler::GetSharedFunctionInfoForScript(
source_code, MaybeHandle<String>(), 0, 0, v8::ScriptOriginOptions(),
MaybeHandle<Object>(), Handle<Context>(isolate->native_context()),
NULL, NULL, v8::ScriptCompiler::kNoCompileOptions, NOT_NATIVES_CODE,
MaybeHandle<FixedArray>())
.ToHandleChecked();
return isolate->factory()->NewFunctionFromSharedFunctionInfo(
shared, isolate->native_context());
}
......
......@@ -1200,9 +1200,10 @@ static Handle<SharedFunctionInfo> CompileScript(
Isolate* isolate, Handle<String> source, Handle<String> name,
ScriptData** cached_data, v8::ScriptCompiler::CompileOptions options) {
return Compiler::GetSharedFunctionInfoForScript(
source, name, 0, 0, v8::ScriptOriginOptions(), Handle<Object>(),
Handle<Context>(isolate->native_context()), NULL, cached_data, options,
NOT_NATIVES_CODE, Handle<FixedArray>());
source, name, 0, 0, v8::ScriptOriginOptions(), Handle<Object>(),
Handle<Context>(isolate->native_context()), NULL, cached_data,
options, NOT_NATIVES_CODE, Handle<FixedArray>())
.ToHandleChecked();
}
TEST(CodeSerializerOnePlusOne) {
......@@ -2089,11 +2090,13 @@ TEST(Regress503552) {
Handle<String> source = isolate->factory()->NewStringFromAsciiChecked(
"function f() {} function g() {}");
ScriptData* script_data = NULL;
Handle<SharedFunctionInfo> shared = Compiler::GetSharedFunctionInfoForScript(
source, Handle<String>(), 0, 0, v8::ScriptOriginOptions(),
Handle<Object>(), Handle<Context>(isolate->native_context()), NULL,
&script_data, v8::ScriptCompiler::kProduceCodeCache, NOT_NATIVES_CODE,
Handle<FixedArray>());
Handle<SharedFunctionInfo> shared =
Compiler::GetSharedFunctionInfoForScript(
source, MaybeHandle<String>(), 0, 0, v8::ScriptOriginOptions(),
MaybeHandle<Object>(), Handle<Context>(isolate->native_context()),
NULL, &script_data, v8::ScriptCompiler::kProduceCodeCache,
NOT_NATIVES_CODE, MaybeHandle<FixedArray>())
.ToHandleChecked();
delete script_data;
heap::SimulateIncrementalMarking(isolate->heap());
......
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