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