Commit d0ebe06b authored by Clemens Backes's avatar Clemens Backes Committed by Commit Bot

[factory] Allow undefined source for scripts

According to the Torque definition, the type of the 'source' field is
'String|Undefined'. The Factory only allowed to pass a string though,
which forced us to set an empty string for wasm scripts.

This CL changes the factory to also allow undefined values, which fits
slightly better for wasm.
The inspector needed a minor change to handle undefined source like an
empty string.

R=dinfuehr@chromium.org, yangguo@chromium.org

Bug: chromium:1125986
Change-Id: Iac0a5ee3767ce121aba8a6a2afe37195e77122fa
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2584243Reviewed-by: 's avatarDominik Inführ <dinfuehr@chromium.org>
Reviewed-by: 's avatarBenedikt Meurer <bmeurer@chromium.org>
Reviewed-by: 's avatarYang Guo <yangguo@chromium.org>
Commit-Queue: Clemens Backes <clemensb@chromium.org>
Cr-Commit-Position: refs/heads/master@{#71913}
parent 77a77aea
...@@ -2054,6 +2054,7 @@ void Script::ScriptPrint(std::ostream& os) { // NOLINT ...@@ -2054,6 +2054,7 @@ void Script::ScriptPrint(std::ostream& os) { // NOLINT
PrintHeader(os, "Script"); PrintHeader(os, "Script");
os << "\n - source: " << Brief(source()); os << "\n - source: " << Brief(source());
os << "\n - name: " << Brief(name()); os << "\n - name: " << Brief(name());
os << "\n - source_url: " << Brief(source_url());
os << "\n - line_offset: " << line_offset(); os << "\n - line_offset: " << line_offset();
os << "\n - column_offset: " << column_offset(); os << "\n - column_offset: " << column_offset();
os << "\n - type: " << type(); os << "\n - type: " << type();
......
...@@ -206,13 +206,15 @@ Handle<BytecodeArray> FactoryBase<Impl>::NewBytecodeArray( ...@@ -206,13 +206,15 @@ Handle<BytecodeArray> FactoryBase<Impl>::NewBytecodeArray(
} }
template <typename Impl> template <typename Impl>
Handle<Script> FactoryBase<Impl>::NewScript(Handle<String> source) { Handle<Script> FactoryBase<Impl>::NewScript(
Handle<PrimitiveHeapObject> source) {
return NewScriptWithId(source, isolate()->GetNextScriptId()); return NewScriptWithId(source, isolate()->GetNextScriptId());
} }
template <typename Impl> template <typename Impl>
Handle<Script> FactoryBase<Impl>::NewScriptWithId(Handle<String> source, Handle<Script> FactoryBase<Impl>::NewScriptWithId(
int script_id) { Handle<PrimitiveHeapObject> source, int script_id) {
DCHECK(source->IsString() || source->IsUndefined());
// Create and initialize script object. // Create and initialize script object.
ReadOnlyRoots roots = read_only_roots(); ReadOnlyRoots roots = read_only_roots();
Handle<Script> script = Handle<Script> script =
......
...@@ -141,8 +141,9 @@ class EXPORT_TEMPLATE_DECLARE(V8_EXPORT_PRIVATE) FactoryBase ...@@ -141,8 +141,9 @@ class EXPORT_TEMPLATE_DECLARE(V8_EXPORT_PRIVATE) FactoryBase
Handle<TemplateObjectDescription> NewTemplateObjectDescription( Handle<TemplateObjectDescription> NewTemplateObjectDescription(
Handle<FixedArray> raw_strings, Handle<FixedArray> cooked_strings); Handle<FixedArray> raw_strings, Handle<FixedArray> cooked_strings);
Handle<Script> NewScript(Handle<String> source); Handle<Script> NewScript(Handle<PrimitiveHeapObject> source);
Handle<Script> NewScriptWithId(Handle<String> source, int script_id); Handle<Script> NewScriptWithId(Handle<PrimitiveHeapObject> source,
int script_id);
Handle<SharedFunctionInfo> NewSharedFunctionInfoForLiteral( Handle<SharedFunctionInfo> NewSharedFunctionInfoForLiteral(
FunctionLiteral* literal, Handle<Script> script, bool is_toplevel); FunctionLiteral* literal, Handle<Script> script, bool is_toplevel);
......
...@@ -253,9 +253,10 @@ class ActualScript : public V8DebuggerScript { ...@@ -253,9 +253,10 @@ class ActualScript : public V8DebuggerScript {
if (!m_hash.isEmpty()) return m_hash; if (!m_hash.isEmpty()) return m_hash;
v8::HandleScope scope(m_isolate); v8::HandleScope scope(m_isolate);
v8::Local<v8::String> v8Source; v8::Local<v8::String> v8Source;
if (script()->Source().ToLocal(&v8Source)) { if (!script()->Source().ToLocal(&v8Source)) {
m_hash = calculateHash(m_isolate, v8Source); v8Source = v8::String::Empty(m_isolate);
} }
m_hash = calculateHash(m_isolate, v8Source);
DCHECK(!m_hash.isEmpty()); DCHECK(!m_hash.isEmpty());
return m_hash; return m_hash;
} }
......
...@@ -579,11 +579,12 @@ Handle<Object> GetJSPositionInfo(Handle<Script> script, int position, ...@@ -579,11 +579,12 @@ Handle<Object> GetJSPositionInfo(Handle<Script> script, int position,
return isolate->factory()->null_value(); return isolate->factory()->null_value();
} }
Handle<String> source = handle(String::cast(script->source()), isolate); Handle<String> sourceText =
Handle<String> sourceText = script->type() == Script::TYPE_WASM script->type() == Script::TYPE_WASM
? isolate->factory()->empty_string() ? isolate->factory()->empty_string()
: isolate->factory()->NewSubString( : isolate->factory()->NewSubString(
source, info.line_start, info.line_end); handle(String::cast(script->source()), isolate),
info.line_start, info.line_end);
Handle<JSObject> jsinfo = Handle<JSObject> jsinfo =
isolate->factory()->NewJSObject(isolate->object_function()); isolate->factory()->NewJSObject(isolate->object_function());
......
...@@ -733,7 +733,7 @@ Handle<Script> CreateWasmScript(Isolate* isolate, ...@@ -733,7 +733,7 @@ Handle<Script> CreateWasmScript(Isolate* isolate,
std::shared_ptr<NativeModule> native_module, std::shared_ptr<NativeModule> native_module,
Vector<const char> source_url) { Vector<const char> source_url) {
Handle<Script> script = Handle<Script> script =
isolate->factory()->NewScript(isolate->factory()->empty_string()); isolate->factory()->NewScript(isolate->factory()->undefined_value());
script->set_compilation_state(Script::COMPILATION_STATE_COMPILED); script->set_compilation_state(Script::COMPILATION_STATE_COMPILED);
script->set_context_data(isolate->native_context()->debug_context_id()); script->set_context_data(isolate->native_context()->debug_context_id());
script->set_type(Script::TYPE_WASM); script->set_type(Script::TYPE_WASM);
......
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